From 0ab4cf10ccbbd1314095cadcbbd949dc42de5860 Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 13 Feb 2023 11:36:59 +1000 Subject: [PATCH 1/2] Fix window status when partially open --- custom_components/fordpass/sensor.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/custom_components/fordpass/sensor.py b/custom_components/fordpass/sensor.py index e107b86..ec65bf1 100644 --- a/custom_components/fordpass/sensor.py +++ b/custom_components/fordpass/sensor.py @@ -92,12 +92,11 @@ def get_value(self, ftype): elif self.sensor == "windowPosition": if self.coordinator.data[self.sensor] == None: return "Unsupported" + status = "Closed" for key, value in self.coordinator.data[self.sensor].items(): - if "open" in value["value"].lower(): - return "Open" - elif "closed" in value["value"].lower(): - return "Closed" - return "Unsupported" + if "open" or "btwn" in value["value"].lower(): + status = "Open" + return status elif self.sensor == "lastRefresh": return dt.as_local( datetime.strptime( From 2038bfda8b687db92a864f1120c5d3835e3d9ba0 Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 13 Feb 2023 12:07:21 +1000 Subject: [PATCH 2/2] Add reload integration service --- custom_components/fordpass/__init__.py | 20 ++++++++++++++++++-- custom_components/fordpass/services.yaml | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/custom_components/fordpass/__init__.py b/custom_components/fordpass/__init__.py index 5af60e4..b3e0670 100644 --- a/custom_components/fordpass/__init__.py +++ b/custom_components/fordpass/__init__.py @@ -93,8 +93,18 @@ async def async_refresh_status_service(service_call): async def async_clear_tokens_service(service_call): await hass.async_add_executor_job(clear_tokens, hass, service_call, coordinator) - async def async_clear_tokens_service(service_call): - await hass.async_add_executor_job(clear_tokens, hass, service_call, coordinator) + + async def handle_reload(service): + """Handle reload service call.""" + _LOGGER.debug("Reloading Integration") + + current_entries = hass.config_entries.async_entries(DOMAIN) + reload_tasks = [ + hass.config_entries.async_reload(entry.entry_id) + for entry in current_entries + ] + + await asyncio.gather(*reload_tasks) hass.services.async_register( DOMAIN, @@ -107,6 +117,12 @@ async def async_clear_tokens_service(service_call): async_clear_tokens_service, ) + hass.services.async_register( + DOMAIN, + "reload", + handle_reload + ) + return True diff --git a/custom_components/fordpass/services.yaml b/custom_components/fordpass/services.yaml index 89b3b5b..bda85d5 100644 --- a/custom_components/fordpass/services.yaml +++ b/custom_components/fordpass/services.yaml @@ -9,3 +9,6 @@ refresh_status: text: clear_tokens: description: "Clear the cached tokens" +reload: + name: Reload + description: "Reload the Fordpass Integration"