diff options
Diffstat (limited to 'client.py')
| -rw-r--r-- | client.py | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -527,7 +527,7 @@ class ClientTask(Thread): self.video_threads[camera_id].device_threshold = _value # <-- integer! # configparser requires strings: cfg.set('cameras', f"{camera_id.decode('utf-8')}.contour_size_threshold", str(value)) - logger.info("Modified contour size threshold of camera %r to %d.", camera_id, value) + logger.info("Modified contour size threshold of camera %r to %d.", camera_id, _value) case b'modify_camera_grace_pd': try: _value = int(value) @@ -537,7 +537,7 @@ class ClientTask(Thread): CAMERAS[camera_id][b'movement_grace_period'] = _value # <-- integer! self.video_threads[camera_id].device_grace_period = _value # <-- integer! cfg.set('cameras', f"{camera_id.decode('utf-8')}.movement_grace_period", str(value)) - logger.info("Modified movement grace period of camera %r to %d.", camera_id, value) + logger.info("Modified movement grace period of camera %r to %d.", camera_id, _value) case b'add_camera': CAMERAS[camera_id] = {b'address': value} # vid_cl = ClientVideo(camera_id, CAMERAS[camera_id], self.queue) @@ -865,9 +865,10 @@ def validate_camera_address(address: str) -> bool: True if address is valid, False otherwise """ # Check if address is an integer (device index): + retval = False if address.startswith('/dev/video'): - return True - raise False + retval = True + return retval def validate_camera_threshold(threshold: str) -> bool: @@ -886,10 +887,12 @@ def validate_camera_threshold(threshold: str) -> bool: """ try: if int(threshold) > 0: - return True + retval = True + else: + retval = False except ValueError: - raise False - return False + retval = False + return retval def validate_camera_grace_pd(grace_pd: str) -> bool: @@ -908,10 +911,12 @@ def validate_camera_grace_pd(grace_pd: str) -> bool: """ try: if int(grace_pd) >= 0: - return True + retval = True + else: + retval = False except ValueError: - return False - return False + retval = False + return retval def camera_address_unique(cfg: ConfigParser, address: str) -> bool: @@ -930,14 +935,15 @@ def camera_address_unique(cfg: ConfigParser, address: str) -> bool: bool True if address is unique, False otherwise """ + retval = True for key, val in cfg.items('cameras'): try: _, param = key.split('.', 1) if param == 'address' and val == address: - return False + retval = False except ValueError: continue - return True + return retval def set_up_cameras(cameras_cfg_section: list[tuple[str, str]]) -> dict: @@ -1015,16 +1021,17 @@ def get_serial_number() -> bytes: bytes Serial number as string """ + serial = uuid.uuid4().hex.encode('utf-8') # Default to random uuid if we can't get serial try: with open('/proc/cpuinfo', 'r') as f: for line in f: if line.startswith('Serial'): serial = line.split(':')[1].strip() - return serial.encode('utf-8') + serial = serial.encode('utf-8') except Exception as exc: - logger.error("Error getting serial number: %r, using uuid.", exc) + logger.warning("Error getting serial number: %r, using uuid.", exc) - return str(uuid.getnode()).encode('utf-8') + return serial if __name__ == "__main__": |
