From 11bf6053b5410ed93d675fb86eb4d12971b663ce Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Sun, 1 Dec 2024 22:17:34 +0100 Subject: [PATCH 01/11] Added a method to obtain the operating status of a camera. Works for Panasonic cameras, sony cameras are ToDo --- occameracontrol/camera.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 632d75a..0b592de 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -75,6 +75,33 @@ def __str__(self) -> str: ''' return f"'{self.agent.agent_id}' @ '{self.url}'" + def is_standby(self) -> int: + """Retrieve whether or not the camera is in Standby. + For Panasonic camera AW-UE70: + 0 if Standby + 1 if On + 3 if Transferring from Standby to On + TODO: Which panasonic models do we have? Maybe there is a difference for other models? + + For Sony camera: + TODO + """ + + if self.type == CameraType.panasonic: + url = f'{self.url}/cgi-bin/aw_ptz' + command = "#O" + params = {'cmd':command, 'res':1} + auth = (self.user, self.password) \ + if self.user and self.password else None + logger.debug('GET %s with params: %s', url, params) + response = requests.get(url, auth=auth, params=params, timeout=5) + response.raise_for_status() + state = response.content.decode() + return state.removeprefix('p') + elif self.type == CameraType.sony: + # TODO + return -1 + def activate_camera(self, on=True): """Activate the camera or put it into standby mode. :param bool on: camera should be online or standby (default: True) From aba52177937c02577827238e228ce6b8881add71 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Sun, 1 Dec 2024 22:39:43 +0100 Subject: [PATCH 02/11] Added support for sony cameras --- occameracontrol/camera.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 0b592de..db8a07c 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -84,7 +84,10 @@ def is_standby(self) -> int: TODO: Which panasonic models do we have? Maybe there is a difference for other models? For Sony camera: - TODO + 0 if Standby + 1 if On + + -1 if Something went wrong """ if self.type == CameraType.panasonic: @@ -99,8 +102,24 @@ def is_standby(self) -> int: state = response.content.decode() return state.removeprefix('p') elif self.type == CameraType.sony: - # TODO - return -1 + url = f'{self.url}/command/inquiry.cgi' + params = {'inq': 'system'} + headers = {'referer': f'{self.url}/'} + auth = HTTPDigestAuth(self.user, self.password) \ + if self.user and self.password else None + logger.debug('GET %s with params: %s', url, params) + response = requests.get(url, + auth=auth, + headers=headers, + params=params, + timeout=5) + response.raise_for_status() + values = response.content.decode().split("&") + state = -1 + for v in values: + if "Power" in v: + state = 1 if v.removeprefix("Power=")[1] == 'on' else state = 0 + return state def activate_camera(self, on=True): """Activate the camera or put it into standby mode. From a98183f192f801bc7ba0475b0b86f82d1b88c963 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Wed, 11 Dec 2024 20:41:14 +0100 Subject: [PATCH 03/11] Added the is_standby() check for the activate camera function calls --- occameracontrol/camera.py | 43 +++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index db8a07c..c342948 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -75,13 +75,14 @@ def __str__(self) -> str: ''' return f"'{self.agent.agent_id}' @ '{self.url}'" - def is_standby(self) -> int: + def is_standby(self) -> bool: """Retrieve whether or not the camera is in Standby. For Panasonic camera AW-UE70: 0 if Standby 1 if On 3 if Transferring from Standby to On - TODO: Which panasonic models do we have? Maybe there is a difference for other models? + TODO: Which panasonic models do we have? Maybe there is a difference for other models? + --> Works for the two models that we have For Sony camera: 0 if Standby @@ -89,7 +90,7 @@ def is_standby(self) -> int: -1 if Something went wrong """ - + if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' command = "#O" @@ -99,9 +100,17 @@ def is_standby(self) -> int: logger.debug('GET %s with params: %s', url, params) response = requests.get(url, auth=auth, params=params, timeout=5) response.raise_for_status() - state = response.content.decode() - return state.removeprefix('p') - elif self.type == CameraType.sony: + state = int(response.content.decode()) + while state == 3: + # Escape the transition from standby to on + time.sleep(3) + response = requests.get(url, auth=auth, params=params, timeout=5) + response.raise_for_status() + state = int(response.content.decode()) + state = bool(state) + return(state) + + if self.type == CameraType.sony: url = f'{self.url}/command/inquiry.cgi' params = {'inq': 'system'} headers = {'referer': f'{self.url}/'} @@ -117,9 +126,15 @@ def is_standby(self) -> int: values = response.content.decode().split("&") state = -1 for v in values: - if "Power" in v: - state = 1 if v.removeprefix("Power=")[1] == 'on' else state = 0 + if "Power" in v: + if v.removeprefix("Power=")[1] == 'on': + state = True + else: + state = False return state + + # Else case + return -1 def activate_camera(self, on=True): """Activate the camera or put it into standby mode. @@ -127,7 +142,8 @@ def activate_camera(self, on=True): """ if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' - command = '#On' if on else '#Of' + # If the camera is in Standby, turn it on (Does this make sense here?) + command = '#On' if not on else '#Of' params = {'cmd': command, 'res': 1} auth = (self.user, self.password) \ if self.user and self.password else None @@ -137,7 +153,8 @@ def activate_camera(self, on=True): elif self.type == CameraType.sony: url = f'{self.url}/command/main.cgi' - command = 'on' if on else 'standby' + # If the camera is in Standby, turn it on + command = 'on' if not on else 'standby' params = {'System': command} headers = {'referer': f'{self.url}/'} auth = HTTPDigestAuth(self.user, self.password) \ @@ -216,17 +233,17 @@ def update_position(self): logger.info('[%s] Event `%s` started', agent_id, event.title) logger.info('[%s] Moving to preset %i', agent_id, self.preset_active) - self.activate_camera() + self.activate_camera(self.is_standby()) self.move_to_preset(self.preset_active) else: # No active event if self.position != self.preset_inactive: logger.info('[%s] Returning to preset %i', agent_id, self.preset_inactive) - self.activate_camera() + self.activate_camera(self.is_standby()) self.move_to_preset(self.preset_inactive) if time.time() - self.last_updated >= self.update_frequency: logger.info('[%s] Re-sending preset %i to camera', agent_id, self.position) - self.activate_camera() + self.activate_camera(self.is_standby()) self.move_to_preset(self.position) From fa8771e2b8d4b9a1021f796ca62e587452d27765 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Wed, 11 Dec 2024 20:46:29 +0100 Subject: [PATCH 04/11] flake8 conformity --- occameracontrol/camera.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index c342948..3730fde 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -79,22 +79,24 @@ def is_standby(self) -> bool: """Retrieve whether or not the camera is in Standby. For Panasonic camera AW-UE70: 0 if Standby - 1 if On + 1 if On 3 if Transferring from Standby to On - TODO: Which panasonic models do we have? Maybe there is a difference for other models? - --> Works for the two models that we have - + TODO: + - Which panasonic models do we have? + - Maybe there is a difference for other models? + --> Works for the two models that we have + For Sony camera: 0 if Standby - 1 if On + 1 if On - -1 if Something went wrong + -1 if Something went wrong """ if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' command = "#O" - params = {'cmd':command, 'res':1} + params = {'cmd': command, 'res': 1} auth = (self.user, self.password) \ if self.user and self.password else None logger.debug('GET %s with params: %s', url, params) @@ -104,11 +106,15 @@ def is_standby(self) -> bool: while state == 3: # Escape the transition from standby to on time.sleep(3) - response = requests.get(url, auth=auth, params=params, timeout=5) + response = requests.get( + url, + auth=auth, + params=params, + timeout=5) response.raise_for_status() state = int(response.content.decode()) state = bool(state) - return(state) + return state if self.type == CameraType.sony: url = f'{self.url}/command/inquiry.cgi' @@ -132,7 +138,7 @@ def is_standby(self) -> bool: else: state = False return state - + # Else case return -1 @@ -142,7 +148,8 @@ def activate_camera(self, on=True): """ if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' - # If the camera is in Standby, turn it on (Does this make sense here?) + # If the camera is in Standby, turn it on + # (Does this make sense here?) command = '#On' if not on else '#Of' params = {'cmd': command, 'res': 1} auth = (self.user, self.password) \ From 9515acd082a977fd7e3ef07b2fae2ce2692ffc50 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Wed, 11 Dec 2024 20:51:49 +0100 Subject: [PATCH 05/11] removed designated return type for is_standby --- occameracontrol/camera.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 3730fde..204d776 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -75,7 +75,7 @@ def __str__(self) -> str: ''' return f"'{self.agent.agent_id}' @ '{self.url}'" - def is_standby(self) -> bool: + def is_standby(self): """Retrieve whether or not the camera is in Standby. For Panasonic camera AW-UE70: 0 if Standby @@ -113,8 +113,7 @@ def is_standby(self) -> bool: timeout=5) response.raise_for_status() state = int(response.content.decode()) - state = bool(state) - return state + return bool(state) if self.type == CameraType.sony: url = f'{self.url}/command/inquiry.cgi' From 3d6c891b2130537c52219be3dd2778c04cdd897a Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Wed, 11 Dec 2024 20:59:32 +0100 Subject: [PATCH 06/11] pyright conformity --- occameracontrol/camera.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 204d776..d508bb1 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -129,17 +129,14 @@ def is_standby(self): timeout=5) response.raise_for_status() values = response.content.decode().split("&") - state = -1 + state = False for v in values: if "Power" in v: if v.removeprefix("Power=")[1] == 'on': - state = True + return True else: - state = False - return state - - # Else case - return -1 + return False + return False def activate_camera(self, on=True): """Activate the camera or put it into standby mode. From 2816e9100d50c44b3d2ab114443b49a491fbef78 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Thu, 12 Dec 2024 11:05:09 +0100 Subject: [PATCH 07/11] Changed funciton names, completed functionality for Panasonic cameras --- occameracontrol/camera.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index d508bb1..8cab5ef 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -75,7 +75,7 @@ def __str__(self) -> str: ''' return f"'{self.agent.agent_id}' @ '{self.url}'" - def is_standby(self): + def is_on(self): """Retrieve whether or not the camera is in Standby. For Panasonic camera AW-UE70: 0 if Standby @@ -102,7 +102,7 @@ def is_standby(self): logger.debug('GET %s with params: %s', url, params) response = requests.get(url, auth=auth, params=params, timeout=5) response.raise_for_status() - state = int(response.content.decode()) + state = int(response.content.decode().removeprefix('p')) while state == 3: # Escape the transition from standby to on time.sleep(3) @@ -112,7 +112,7 @@ def is_standby(self): params=params, timeout=5) response.raise_for_status() - state = int(response.content.decode()) + state = int(response.content.decode().removeprefix('p')) return bool(state) if self.type == CameraType.sony: @@ -138,15 +138,16 @@ def is_standby(self): return False return False - def activate_camera(self, on=True): + def set_power(self, turn_on=True): """Activate the camera or put it into standby mode. - :param bool on: camera should be online or standby (default: True) + :param bool on: camera should be turned on (True) + or set to standby (False) (default: True) """ if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' # If the camera is in Standby, turn it on # (Does this make sense here?) - command = '#On' if not on else '#Of' + command = '#On' if not turn_on else '#Of' params = {'cmd': command, 'res': 1} auth = (self.user, self.password) \ if self.user and self.password else None @@ -157,7 +158,7 @@ def activate_camera(self, on=True): elif self.type == CameraType.sony: url = f'{self.url}/command/main.cgi' # If the camera is in Standby, turn it on - command = 'on' if not on else 'standby' + command = 'on' if not turn_on else 'standby' params = {'System': command} headers = {'referer': f'{self.url}/'} auth = HTTPDigestAuth(self.user, self.password) \ @@ -236,17 +237,23 @@ def update_position(self): logger.info('[%s] Event `%s` started', agent_id, event.title) logger.info('[%s] Moving to preset %i', agent_id, self.preset_active) - self.activate_camera(self.is_standby()) + if not self.is_on(): + self.set_power() + time.sleep(10) self.move_to_preset(self.preset_active) else: # No active event if self.position != self.preset_inactive: logger.info('[%s] Returning to preset %i', agent_id, self.preset_inactive) - self.activate_camera(self.is_standby()) + if not self.is_on(): + self.set_power() + time.sleep(10) self.move_to_preset(self.preset_inactive) if time.time() - self.last_updated >= self.update_frequency: logger.info('[%s] Re-sending preset %i to camera', agent_id, self.position) - self.activate_camera(self.is_standby()) + if not self.is_on(): + self.set_power() + time.sleep(10) self.move_to_preset(self.position) From 160464ff00dead0af77d01497e54f7c200758da8 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Thu, 12 Dec 2024 11:05:36 +0100 Subject: [PATCH 08/11] removed an old comment --- occameracontrol/camera.py | 1 - 1 file changed, 1 deletion(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 8cab5ef..f7d7095 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -146,7 +146,6 @@ def set_power(self, turn_on=True): if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' # If the camera is in Standby, turn it on - # (Does this make sense here?) command = '#On' if not turn_on else '#Of' params = {'cmd': command, 'res': 1} auth = (self.user, self.password) \ From 2835d7b590770bd5213ff1204bf33f9b772d9d27 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Wed, 18 Dec 2024 17:51:10 +0100 Subject: [PATCH 09/11] Added a metric for the camera mode --- occameracontrol/camera.py | 30 ++++++++++++++++++------------ occameracontrol/metrics.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index f7d7095..f73377b 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -26,7 +26,7 @@ from occameracontrol.agent import Agent from occameracontrol.metrics import register_camera_move, \ - register_camera_expectation + register_camera_expectation, register_camera_status logger = logging.getLogger(__name__) @@ -75,7 +75,7 @@ def __str__(self) -> str: ''' return f"'{self.agent.agent_id}' @ '{self.url}'" - def is_on(self): + def is_on(self) -> bool: """Retrieve whether or not the camera is in Standby. For Panasonic camera AW-UE70: 0 if Standby @@ -92,7 +92,7 @@ def is_on(self): -1 if Something went wrong """ - + state = False if self.type == CameraType.panasonic: url = f'{self.url}/cgi-bin/aw_ptz' command = "#O" @@ -102,8 +102,8 @@ def is_on(self): logger.debug('GET %s with params: %s', url, params) response = requests.get(url, auth=auth, params=params, timeout=5) response.raise_for_status() - state = int(response.content.decode().removeprefix('p')) - while state == 3: + state_int = int(response.content.decode().removeprefix('p')) + while state_int == 3: # Escape the transition from standby to on time.sleep(3) response = requests.get( @@ -112,8 +112,7 @@ def is_on(self): params=params, timeout=5) response.raise_for_status() - state = int(response.content.decode().removeprefix('p')) - return bool(state) + state = bool(state_int) if self.type == CameraType.sony: url = f'{self.url}/command/inquiry.cgi' @@ -129,14 +128,14 @@ def is_on(self): timeout=5) response.raise_for_status() values = response.content.decode().split("&") - state = False for v in values: if "Power" in v: if v.removeprefix("Power=")[1] == 'on': - return True + state = True else: - return False - return False + state = False + register_camera_status(self.url, state) + return state def set_power(self, turn_on=True): """Activate the camera or put it into standby mode. @@ -170,6 +169,8 @@ def set_power(self, turn_on=True): timeout=5) response.raise_for_status() + self.is_on() + def move_to_preset(self, preset: int): '''Move the PTZ camera to the specified preset position ''' @@ -236,6 +237,7 @@ def update_position(self): logger.info('[%s] Event `%s` started', agent_id, event.title) logger.info('[%s] Moving to preset %i', agent_id, self.preset_active) + logger.debug('[%s] Retrieving the camera state', agent_id) if not self.is_on(): self.set_power() time.sleep(10) @@ -244,15 +246,19 @@ def update_position(self): if self.position != self.preset_inactive: logger.info('[%s] Returning to preset %i', agent_id, self.preset_inactive) + logger.debug('[%s] Retrieving the camera state', agent_id) if not self.is_on(): self.set_power() time.sleep(10) self.move_to_preset(self.preset_inactive) - + # Regular update if time.time() - self.last_updated >= self.update_frequency: logger.info('[%s] Re-sending preset %i to camera', agent_id, self.position) + + logger.debug('[%s] Retrieving the camera state', agent_id) if not self.is_on(): self.set_power() time.sleep(10) + register_camera_status(self.url, self.is_on()) self.move_to_preset(self.position) diff --git a/occameracontrol/metrics.py b/occameracontrol/metrics.py index e16695a..731571c 100644 --- a/occameracontrol/metrics.py +++ b/occameracontrol/metrics.py @@ -45,6 +45,10 @@ 'camera_position_expected', 'The position (preset number) a camera should be in', ('camera',)) +camera_is_on = Gauge( + 'camera_status', + 'Whether the camera is on (True) or in standby (False)', + ('camera',)) class RequestErrorHandler(): @@ -120,6 +124,16 @@ def register_camera_expectation(camera: str, position: int): camera_position_expected.labels(camera).set(position) +def register_camera_status(camera: str, status: bool): + '''Update metrics for the status of the camera. This ensures the (power) + state of the camera is available as part of the metrics. + + :param camera: Camera identified + :param status: True if camera is 'on', False if 'standby' + ''' + camera_is_on.labels(camera).set(status) + + def start_metrics_exporter(): '''Start the web server for the metrics exporter endpoint if it is enabled in the configuration. From e33a7d1f4e11699063c89623a62a55d82a1d1c51 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Fri, 20 Dec 2024 13:28:58 +0100 Subject: [PATCH 10/11] Added a functioning metric for the camera's status --- occameracontrol/camera.py | 19 ++++++++++++++----- occameracontrol/metrics.py | 7 +++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index f73377b..9e61fff 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -24,9 +24,9 @@ from requests.auth import HTTPDigestAuth from typing import Optional -from occameracontrol.agent import Agent +from agent import Agent from occameracontrol.metrics import register_camera_move, \ - register_camera_expectation, register_camera_status + register_camera_expectation, register_camera_status logger = logging.getLogger(__name__) @@ -112,7 +112,7 @@ def is_on(self) -> bool: params=params, timeout=5) response.raise_for_status() - state = bool(state_int) + state = bool(state_int) if self.type == CameraType.sony: url = f'{self.url}/command/inquiry.cgi' @@ -134,7 +134,9 @@ def is_on(self) -> bool: state = True else: state = False - register_camera_status(self.url, state) + + logger.debug("[%s] is_on is %s (%d)", self.url, state, int(state)) + register_camera_status(self.url, int(state)) return state def set_power(self, turn_on=True): @@ -241,6 +243,9 @@ def update_position(self): if not self.is_on(): self.set_power() time.sleep(10) + + # To update the metrics + self.is_on() self.move_to_preset(self.preset_active) else: # No active event if self.position != self.preset_inactive: @@ -250,6 +255,9 @@ def update_position(self): if not self.is_on(): self.set_power() time.sleep(10) + + # To update the metrics + self.is_on() self.move_to_preset(self.preset_inactive) # Regular update if time.time() - self.last_updated >= self.update_frequency: @@ -260,5 +268,6 @@ def update_position(self): if not self.is_on(): self.set_power() time.sleep(10) - register_camera_status(self.url, self.is_on()) + # To update the metrics + self.is_on() self.move_to_preset(self.position) diff --git a/occameracontrol/metrics.py b/occameracontrol/metrics.py index 731571c..fe181da 100644 --- a/occameracontrol/metrics.py +++ b/occameracontrol/metrics.py @@ -47,7 +47,7 @@ ('camera',)) camera_is_on = Gauge( 'camera_status', - 'Whether the camera is on (True) or in standby (False)', + 'Whether the camera is On (1.0) or Standby (0.0)', ('camera',)) @@ -124,16 +124,15 @@ def register_camera_expectation(camera: str, position: int): camera_position_expected.labels(camera).set(position) -def register_camera_status(camera: str, status: bool): +def register_camera_status(camera: str, status: int): '''Update metrics for the status of the camera. This ensures the (power) state of the camera is available as part of the metrics. :param camera: Camera identified - :param status: True if camera is 'on', False if 'standby' + :param status: 1.0 if camera is 'on', 0.0 if 'standby' ''' camera_is_on.labels(camera).set(status) - def start_metrics_exporter(): '''Start the web server for the metrics exporter endpoint if it is enabled in the configuration. From d2a9a3b9d97af411007a5f4b68a6ddbda2025b1b Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Fri, 20 Dec 2024 13:31:36 +0100 Subject: [PATCH 11/11] A bit of clean up and flake8 confirmity --- occameracontrol/camera.py | 7 +++++-- occameracontrol/metrics.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/occameracontrol/camera.py b/occameracontrol/camera.py index 9e61fff..d0d60ca 100644 --- a/occameracontrol/camera.py +++ b/occameracontrol/camera.py @@ -134,8 +134,7 @@ def is_on(self) -> bool: state = True else: state = False - - logger.debug("[%s] is_on is %s (%d)", self.url, state, int(state)) + register_camera_status(self.url, int(state)) return state @@ -246,6 +245,7 @@ def update_position(self): # To update the metrics self.is_on() + self.move_to_preset(self.preset_active) else: # No active event if self.position != self.preset_inactive: @@ -258,6 +258,7 @@ def update_position(self): # To update the metrics self.is_on() + self.move_to_preset(self.preset_inactive) # Regular update if time.time() - self.last_updated >= self.update_frequency: @@ -268,6 +269,8 @@ def update_position(self): if not self.is_on(): self.set_power() time.sleep(10) + # To update the metrics self.is_on() + self.move_to_preset(self.position) diff --git a/occameracontrol/metrics.py b/occameracontrol/metrics.py index fe181da..c553025 100644 --- a/occameracontrol/metrics.py +++ b/occameracontrol/metrics.py @@ -133,6 +133,7 @@ def register_camera_status(camera: str, status: int): ''' camera_is_on.labels(camera).set(status) + def start_metrics_exporter(): '''Start the web server for the metrics exporter endpoint if it is enabled in the configuration.