From cb55711997ec887f7a6b593007376bc7a2643264 Mon Sep 17 00:00:00 2001 From: pavoni Date: Fri, 5 Feb 2021 16:46:25 +0000 Subject: [PATCH 1/3] Add better logic for comms failure. --- pyvera/__init__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pyvera/__init__.py b/pyvera/__init__.py index d6eadfe..c9800a8 100755 --- a/pyvera/__init__.py +++ b/pyvera/__init__.py @@ -529,6 +529,11 @@ def color_service(self) -> str: """Vera service string for color.""" return "urn:micasaverde-com:serviceId:Color1" + @property + def poll_service(self) -> str: + """Vera service string for poll.""" + return "urn:micasaverde-com:serviceId:HaDevice1" + def vera_request(self, **kwargs: Any) -> requests.Response: """Perfom a vera_request for this device.""" request_payload = {"output_format": "json", "DeviceNum": self.device_id} @@ -567,12 +572,17 @@ def call_service(self, service_id: str, action: str) -> requests.Response: """ result = self.vera_request(id="action", serviceId=service_id, action=action) LOG.debug( - "call_service: " "result of vera_request with id %s: %s", + "call_service: " "result of vera_request for %s with id %s: %s", + self.name, service_id, result.text, ) return result + def poll_device(self) -> None: + """Poll the device to try and connect.""" + self.call_service(self.poll_service, "Poll") + def set_cache_value(self, name: str, value: Any) -> None: """Set a variable in the local state dictionary. @@ -660,7 +670,7 @@ def get_alerts(self) -> List["VeraAlert"]: """Get any alerts present during the most recent poll cycle.""" return self.alerts - def refresh(self) -> None: + def refresh(self, poll_on_failure: bool = False) -> None: """Refresh the dev_info data used by get_value. Only needed if you're not using subscriptions. @@ -671,6 +681,9 @@ def refresh(self) -> None: if device_data.get("id") == self.device_id: self.update(device_data) + if poll_on_failure and self.comm_failure: + self.poll_device() + def update(self, params: dict) -> None: """Update the dev_info data from a dictionary. @@ -785,7 +798,7 @@ def vera_device_id(self) -> int: @property def should_poll(self) -> bool: """Whether polling is needed if using subscriptions for this device.""" - return False + return self.comm_failure class VeraSwitch(VeraDevice): From 68d61db361d68a47f6300749d4327b534ab0f34f Mon Sep 17 00:00:00 2001 From: pavoni Date: Fri, 5 Feb 2021 16:58:22 +0000 Subject: [PATCH 2/3] Remove poll experiment. --- pyvera/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyvera/__init__.py b/pyvera/__init__.py index c9800a8..ebe9405 100755 --- a/pyvera/__init__.py +++ b/pyvera/__init__.py @@ -670,7 +670,7 @@ def get_alerts(self) -> List["VeraAlert"]: """Get any alerts present during the most recent poll cycle.""" return self.alerts - def refresh(self, poll_on_failure: bool = False) -> None: + def refresh(self) -> None: """Refresh the dev_info data used by get_value. Only needed if you're not using subscriptions. @@ -681,9 +681,6 @@ def refresh(self, poll_on_failure: bool = False) -> None: if device_data.get("id") == self.device_id: self.update(device_data) - if poll_on_failure and self.comm_failure: - self.poll_device() - def update(self, params: dict) -> None: """Update the dev_info data from a dictionary. From 573a2f79ac698d7fc013b49d6df8f9321c66c3fd Mon Sep 17 00:00:00 2001 From: pavoni Date: Fri, 5 Feb 2021 16:59:14 +0000 Subject: [PATCH 3/3] Bump version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cfb77e6..4c3a18b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyvera" -version = "0.3.12" +version = "0.3.13" description = "Python API for talking to Veracontrollers" license = "GPL2"