From a00f7e9b37edd3b55656dcb4a429fbf7c9d3612a Mon Sep 17 00:00:00 2001 From: samuellazea Date: Wed, 26 Feb 2025 17:34:19 +0200 Subject: [PATCH 1/5] Update gateway.py Fix error on connect to the gateway --- pyit600/gateway.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyit600/gateway.py b/pyit600/gateway.py index e034931..5762fe7 100644 --- a/pyit600/gateway.py +++ b/pyit600/gateway.py @@ -119,7 +119,7 @@ async def connect(self) -> str: return gateway["sGateway"]["NetworkLANMAC"] except IT600ConnectionError as ae: try: - with async_timeout.timeout(self._request_timeout): + async with async_timeout.timeout(self._request_timeout): await self._session.get(f"http://{self._host}:{self._port}/") except Exception: raise IT600ConnectionError( @@ -919,7 +919,7 @@ async def _make_encrypted_request(self, command: str, request_body: dict) -> Any if self._debug: _LOGGER.debug("Gateway request: POST %s\n%s\n", request_url, request_body_json) - with async_timeout.timeout(self._request_timeout): + async with async_timeout.timeout(self._request_timeout): resp = await self._session.post( request_url, data=self._encryptor.encrypt(request_body_json), @@ -953,7 +953,7 @@ async def _make_encrypted_request(self, command: str, request_body: dict) -> Any "check if you have specified host/IP address correctly" ) from e except Exception as e: - _LOGGER.error("Exception. %s / %s", type(e), repr(e.args), e) + _LOGGER.error("Exception: %s", repr(e)) raise IT600CommandError( "Unknown error occurred while communicating with iT600 gateway" ) from e From 2983711883bda6766343aed5e68b81378019ddc0 Mon Sep 17 00:00:00 2001 From: samuellazea Date: Wed, 26 Feb 2025 17:56:54 +0200 Subject: [PATCH 2/5] Update gateway.py to print the Gateway response json pretty --- pyit600/gateway.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyit600/gateway.py b/pyit600/gateway.py index 5762fe7..704870d 100644 --- a/pyit600/gateway.py +++ b/pyit600/gateway.py @@ -929,7 +929,12 @@ async def _make_encrypted_request(self, command: str, request_body: dict) -> Any response_json_string = self._encryptor.decrypt(response_bytes) if self._debug: - _LOGGER.debug("Gateway response:\n%s\n", response_json_string) + try: + response_json = json.loads(response_json_string) # Parse the string into JSON + _LOGGER.debug("Gateway response:\n%s\n", json.dumps(response_json, indent=4)) # Pretty print JSON + except json.JSONDecodeError as e: + _LOGGER.error("Failed to decode JSON response: %s\n", e) + _LOGGER.debug("Raw Gateway response:\n%s\n", response_json_string) response_json = json.loads(response_json_string) From 6e429325ccb0a2ab337bcde25036474ba913eb0a Mon Sep 17 00:00:00 2001 From: sami Date: Wed, 26 Feb 2025 22:29:28 +0200 Subject: [PATCH 3/5] Changes related to smoke sensor list --- pyit600/gateway.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyit600/gateway.py b/pyit600/gateway.py index 704870d..77e04b5 100644 --- a/pyit600/gateway.py +++ b/pyit600/gateway.py @@ -165,7 +165,7 @@ async def poll_status(self, send_callback=False) -> None: filter(lambda x: "sIASZS" in x or ("sBasicS" in x and "ModelIdentifier" in x["sBasicS"] and - x["sBasicS"]["ModelIdentifier"] in ["it600MINITRV", "it600Receiver"]), all_devices["id"]) + x["sBasicS"]["ModelIdentifier"] in ["it600MINITRV", "it600Receiver", "SmokeSensor-EM"]), all_devices["id"]) ) await self._refresh_binary_sensor_devices(binary_sensors, send_callback) @@ -402,6 +402,7 @@ async def _refresh_sensor_devices(self, devices: List[Any], send_callback=False) async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback=False): local_devices = {} + _LOGGER.debug(f"!!!!!!! _refresh_binary_sensor_devices: {devices}") if devices: status = await self._make_encrypted_request( @@ -422,6 +423,10 @@ async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback model: Optional[str] = device_status.get("DeviceL", {}).get("ModelIdentifier_i", None) if model in ["it600MINITRV", "it600Receiver"]: is_on: Optional[bool] = device_status.get("sIT600I", {}).get("RelayStatus", None) + elif model == "SmokeSensor-EM": + # You'll need to set a default state or find the correct attribute + # This assumes the sensor is off by default + is_on = 0 # or use some other attribute that indicates the alarm state else: is_on: Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None) @@ -449,6 +454,8 @@ async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback ) local_devices[device.unique_id] = device + _LOGGER.debug(f"Detected device: {model}, Device Class: {device}, Unique ID: {device_status['data']['UniID']}") + if send_callback: self._binary_sensor_devices[device.unique_id] = device @@ -959,6 +966,7 @@ async def _make_encrypted_request(self, command: str, request_body: dict) -> Any ) from e except Exception as e: _LOGGER.error("Exception: %s", repr(e)) +# _LOGGER.error("Exception. %s / %s", type(e), repr(e.args), e) raise IT600CommandError( "Unknown error occurred while communicating with iT600 gateway" ) from e From 83b2d376c22fd042dbca1f3873a57505421bb13c Mon Sep 17 00:00:00 2001 From: sami Date: Fri, 28 Feb 2025 13:43:40 +0200 Subject: [PATCH 4/5] Add logic for Smoke Sensor --- pyit600/gateway.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyit600/gateway.py b/pyit600/gateway.py index 77e04b5..029179d 100644 --- a/pyit600/gateway.py +++ b/pyit600/gateway.py @@ -424,9 +424,11 @@ async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback if model in ["it600MINITRV", "it600Receiver"]: is_on: Optional[bool] = device_status.get("sIT600I", {}).get("RelayStatus", None) elif model == "SmokeSensor-EM": - # You'll need to set a default state or find the correct attribute - # This assumes the sensor is off by default - is_on = 0 # or use some other attribute that indicates the alarm state + # First try to get the standard alarm attribute + is_on = Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None) + # If it doesn't exist, default to 0 (not alarmed) + if is_on is None: + is_on = 0 else: is_on: Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None) From 9a8917901270fd63e50544f0a6688d65b13b170c Mon Sep 17 00:00:00 2001 From: sami Date: Fri, 7 Mar 2025 11:18:35 +0200 Subject: [PATCH 5/5] Small debugging --- pyit600/gateway.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyit600/gateway.py b/pyit600/gateway.py index 029179d..783496f 100644 --- a/pyit600/gateway.py +++ b/pyit600/gateway.py @@ -402,7 +402,7 @@ async def _refresh_sensor_devices(self, devices: List[Any], send_callback=False) async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback=False): local_devices = {} - _LOGGER.debug(f"!!!!!!! _refresh_binary_sensor_devices: {devices}") + _LOGGER.debug(f"Logging _refresh_binary_sensor_devices: {devices}") if devices: status = await self._make_encrypted_request( @@ -425,10 +425,11 @@ async def _refresh_binary_sensor_devices(self, devices: List[Any], send_callback is_on: Optional[bool] = device_status.get("sIT600I", {}).get("RelayStatus", None) elif model == "SmokeSensor-EM": # First try to get the standard alarm attribute - is_on = Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None) + is_on: Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None) # If it doesn't exist, default to 0 (not alarmed) if is_on is None: is_on = 0 + _LOGGER.debug(f"Smoke sensor is_on: {is_on}") else: is_on: Optional[bool] = device_status.get("sIASZS", {}).get("ErrorIASZSAlarmed1", None)