From ddd74a260c0c590995a1b65a682ab8d5493f25e9 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Tue, 3 May 2022 18:16:55 +0000 Subject: [PATCH 1/8] Load modem ALDB --- homeassistant/components/insteon/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/insteon/__init__.py b/homeassistant/components/insteon/__init__.py index 94c18df9a3302a..d7b3f517eff56d 100644 --- a/homeassistant/components/insteon/__init__.py +++ b/homeassistant/components/insteon/__init__.py @@ -49,7 +49,8 @@ async def async_get_device_config(hass, config_entry): with suppress(AttributeError): await devices[address].async_status() - load_aldb = devices.modem.aldb.read_write_mode == ReadWriteMode.UNKNOWN + read_status = devices.modem.aldb.read_write_mode == ReadWriteMode.UNKNOWN + load_aldb = 2 if read_status else 1 await devices.async_load(id_devices=1, load_modem_aldb=load_aldb) for addr in devices: device = devices[addr] From 335c4f3be9e060fe22856066a81707e2ed8bbaa6 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Tue, 3 May 2022 18:20:12 +0000 Subject: [PATCH 2/8] Compress --- homeassistant/components/insteon/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/insteon/__init__.py b/homeassistant/components/insteon/__init__.py index d7b3f517eff56d..e2bebf0bb7f2ce 100644 --- a/homeassistant/components/insteon/__init__.py +++ b/homeassistant/components/insteon/__init__.py @@ -49,8 +49,7 @@ async def async_get_device_config(hass, config_entry): with suppress(AttributeError): await devices[address].async_status() - read_status = devices.modem.aldb.read_write_mode == ReadWriteMode.UNKNOWN - load_aldb = 2 if read_status else 1 + load_aldb = 2 if devices.modem.aldb.read_write_mode == ReadWriteMode.UNKNOWN else 1 await devices.async_load(id_devices=1, load_modem_aldb=load_aldb) for addr in devices: device = devices[addr] From 01ee2012384d55f7cd872f39deee0df8f5b9eb93 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Wed, 4 May 2022 21:17:09 +0000 Subject: [PATCH 3/8] Address when brightness is zero --- homeassistant/components/insteon/insteon_entity.py | 3 ++- homeassistant/components/insteon/light.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 60935f3f951101..15760b5804ac54 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -3,6 +3,7 @@ import logging from pyinsteon import devices +from pyinsteon.config import get_usable_value from homeassistant.core import callback from homeassistant.helpers.dispatcher import ( @@ -155,7 +156,7 @@ def get_device_property(self, name: str): """Get a single Insteon device property value (raw).""" value = None if (prop := self._insteon_device.properties.get(name)) is not None: - value = prop.value if prop.new_value is None else prop.new_value + value = get_usable_value(prop) return value def _get_label(self): diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 05ad9794042422..b44252d709e52e 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -60,7 +60,7 @@ async def async_turn_on(self, **kwargs): brightness = int(kwargs[ATTR_BRIGHTNESS]) else: brightness = self.get_device_property(ON_LEVEL) - if brightness is not None: + if brightness: await self._insteon_device.async_on( on_level=brightness, group=self._insteon_device_group.group ) From aa9f3b9b069ce9edc72e15e28c4abbd38caa5d4b Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Wed, 4 May 2022 21:22:05 +0000 Subject: [PATCH 4/8] Check group is 1 --- homeassistant/components/insteon/light.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index b44252d709e52e..6bbc191fa1484a 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -56,16 +56,15 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Turn light on.""" + brightness = 0xFF if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS]) - else: + elif self._insteon_device_group.group == 1: brightness = self.get_device_property(ON_LEVEL) - if brightness: - await self._insteon_device.async_on( - on_level=brightness, group=self._insteon_device_group.group - ) - else: - await self._insteon_device.async_on(group=self._insteon_device_group.group) + + await self._insteon_device.async_on( + on_level=brightness, group=self._insteon_device_group.group + ) async def async_turn_off(self, **kwargs): """Turn light off.""" From 0e07119d423e74526ca1e54e2253176811857fc6 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Fri, 6 May 2022 14:22:41 +0000 Subject: [PATCH 5/8] Fix issue with default brightness --- homeassistant/components/insteon/insteon_entity.py | 6 ++---- homeassistant/components/insteon/light.py | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 15760b5804ac54..67d30ba8cad932 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -3,7 +3,6 @@ import logging from pyinsteon import devices -from pyinsteon.config import get_usable_value from homeassistant.core import callback from homeassistant.helpers.dispatcher import ( @@ -154,10 +153,9 @@ def _print_aldb(self): def get_device_property(self, name: str): """Get a single Insteon device property value (raw).""" - value = None if (prop := self._insteon_device.properties.get(name)) is not None: - value = get_usable_value(prop) - return value + return prop.value + return None def _get_label(self): """Get the device label for grouped devices.""" diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 6bbc191fa1484a..bf8b693b103919 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -56,15 +56,16 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Turn light on.""" - brightness = 0xFF if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS]) elif self._insteon_device_group.group == 1: brightness = self.get_device_property(ON_LEVEL) - - await self._insteon_device.async_on( - on_level=brightness, group=self._insteon_device_group.group - ) + if brightness: + await self._insteon_device.async_on( + on_level=brightness, group=self._insteon_device_group.group + ) + else: + await self._insteon_device.async_on(group=self._insteon_device_group.group) async def async_turn_off(self, **kwargs): """Turn light off.""" From 69500807d3476c8db021e8b0879fc8d2dc320c6d Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Wed, 4 May 2022 21:17:09 +0000 Subject: [PATCH 6/8] Address when brightness is zero --- homeassistant/components/insteon/insteon_entity.py | 3 ++- homeassistant/components/insteon/light.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 60935f3f951101..15760b5804ac54 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -3,6 +3,7 @@ import logging from pyinsteon import devices +from pyinsteon.config import get_usable_value from homeassistant.core import callback from homeassistant.helpers.dispatcher import ( @@ -155,7 +156,7 @@ def get_device_property(self, name: str): """Get a single Insteon device property value (raw).""" value = None if (prop := self._insteon_device.properties.get(name)) is not None: - value = prop.value if prop.new_value is None else prop.new_value + value = get_usable_value(prop) return value def _get_label(self): diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 05ad9794042422..b44252d709e52e 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -60,7 +60,7 @@ async def async_turn_on(self, **kwargs): brightness = int(kwargs[ATTR_BRIGHTNESS]) else: brightness = self.get_device_property(ON_LEVEL) - if brightness is not None: + if brightness: await self._insteon_device.async_on( on_level=brightness, group=self._insteon_device_group.group ) From e884315c612075e0888694eaea64aace2fd82a02 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Wed, 4 May 2022 21:22:05 +0000 Subject: [PATCH 7/8] Check group is 1 --- homeassistant/components/insteon/light.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index b44252d709e52e..6bbc191fa1484a 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -56,16 +56,15 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Turn light on.""" + brightness = 0xFF if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS]) - else: + elif self._insteon_device_group.group == 1: brightness = self.get_device_property(ON_LEVEL) - if brightness: - await self._insteon_device.async_on( - on_level=brightness, group=self._insteon_device_group.group - ) - else: - await self._insteon_device.async_on(group=self._insteon_device_group.group) + + await self._insteon_device.async_on( + on_level=brightness, group=self._insteon_device_group.group + ) async def async_turn_off(self, **kwargs): """Turn light off.""" From 7453476daacd659d80625182311ef0fe43169573 Mon Sep 17 00:00:00 2001 From: Tom Harris Date: Fri, 6 May 2022 14:22:41 +0000 Subject: [PATCH 8/8] Fix issue with default brightness --- homeassistant/components/insteon/insteon_entity.py | 6 ++---- homeassistant/components/insteon/light.py | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index 15760b5804ac54..67d30ba8cad932 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -3,7 +3,6 @@ import logging from pyinsteon import devices -from pyinsteon.config import get_usable_value from homeassistant.core import callback from homeassistant.helpers.dispatcher import ( @@ -154,10 +153,9 @@ def _print_aldb(self): def get_device_property(self, name: str): """Get a single Insteon device property value (raw).""" - value = None if (prop := self._insteon_device.properties.get(name)) is not None: - value = get_usable_value(prop) - return value + return prop.value + return None def _get_label(self): """Get the device label for grouped devices.""" diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 6bbc191fa1484a..bf8b693b103919 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -56,15 +56,16 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Turn light on.""" - brightness = 0xFF if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS]) elif self._insteon_device_group.group == 1: brightness = self.get_device_property(ON_LEVEL) - - await self._insteon_device.async_on( - on_level=brightness, group=self._insteon_device_group.group - ) + if brightness: + await self._insteon_device.async_on( + on_level=brightness, group=self._insteon_device_group.group + ) + else: + await self._insteon_device.async_on(group=self._insteon_device_group.group) async def async_turn_off(self, **kwargs): """Turn light off."""