From ea1cec25250fe3c8e2ba26711aa495c0e8d099a9 Mon Sep 17 00:00:00 2001 From: Markus Adrario Date: Wed, 22 Jan 2025 19:55:52 +0000 Subject: [PATCH] Bump pyHomee to 1.2.3 (#136213) Co-authored-by: Joostlek --- homeassistant/components/homee/cover.py | 84 +++++++++++--------- homeassistant/components/homee/entity.py | 58 +++++++------- homeassistant/components/homee/manifest.json | 2 +- homeassistant/components/homee/sensor.py | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 80 insertions(+), 70 deletions(-) diff --git a/homeassistant/components/homee/cover.py b/homeassistant/components/homee/cover.py index b594b23cc59..b4a853f7c35 100644 --- a/homeassistant/components/homee/cover.py +++ b/homeassistant/components/homee/cover.py @@ -121,14 +121,15 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): def current_cover_position(self) -> int | None: """Return the cover's position.""" # Translate the homee position values to HA's 0-100 scale - if self.has_attribute(AttributeType.POSITION): - attribute = self._node.get_attribute_by_type(AttributeType.POSITION) + if ( + attribute := self._node.get_attribute_by_type(AttributeType.POSITION) + ) is not None: homee_min = attribute.minimum homee_max = attribute.maximum homee_position = attribute.current_value position = ((homee_position - homee_min) / (homee_max - homee_min)) * 100 - return 100 - position + return int(100 - position) return None @@ -136,16 +137,17 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): def current_cover_tilt_position(self) -> int | None: """Return the cover's tilt position.""" # Translate the homee position values to HA's 0-100 scale - if self.has_attribute(AttributeType.SHUTTER_SLAT_POSITION): - attribute = self._node.get_attribute_by_type( + if ( + attribute := self._node.get_attribute_by_type( AttributeType.SHUTTER_SLAT_POSITION ) + ) is not None: homee_min = attribute.minimum homee_max = attribute.maximum homee_position = attribute.current_value position = ((homee_position - homee_min) / (homee_max - homee_min)) * 100 - return 100 - position + return int(100 - position) return None @@ -176,8 +178,9 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): @property def is_closed(self) -> bool | None: """Return if the cover is closed.""" - if self.has_attribute(AttributeType.POSITION): - attribute = self._node.get_attribute_by_type(AttributeType.POSITION) + if ( + attribute := self._node.get_attribute_by_type(AttributeType.POSITION) + ) is not None: return attribute.get_value() == attribute.maximum if self._open_close_attribute is not None: @@ -187,10 +190,11 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): return self._open_close_attribute.get_value() == 0 # If none of the above is present, it might be a slat only cover. - if self.has_attribute(AttributeType.SHUTTER_SLAT_POSITION): - attribute = self._node.get_attribute_by_type( + if ( + attribute := self._node.get_attribute_by_type( AttributeType.SHUTTER_SLAT_POSITION ) + ) is not None: return attribute.get_value() == attribute.minimum return None @@ -217,12 +221,14 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): position = 100 - cast(int, kwargs[ATTR_POSITION]) # Convert position to range of our entity. - attribute = self._node.get_attribute_by_type(AttributeType.POSITION) - homee_min = attribute.minimum - homee_max = attribute.maximum - homee_position = (position / 100) * (homee_max - homee_min) + homee_min + if ( + attribute := self._node.get_attribute_by_type(AttributeType.POSITION) + ) is not None: + homee_min = attribute.minimum + homee_max = attribute.maximum + homee_position = (position / 100) * (homee_max - homee_min) + homee_min - await self.async_set_value(attribute, homee_position) + await self.async_set_value(attribute, homee_position) async def async_stop_cover(self, **kwargs: Any) -> None: """Stop the cover.""" @@ -231,23 +237,27 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): async def async_open_cover_tilt(self, **kwargs: Any) -> None: """Open the cover tilt.""" - slat_attribute = self._node.get_attribute_by_type( - AttributeType.SLAT_ROTATION_IMPULSE - ) - if not slat_attribute.is_reversed: - await self.async_set_value(slat_attribute, 2) - else: - await self.async_set_value(slat_attribute, 1) + if ( + slat_attribute := self._node.get_attribute_by_type( + AttributeType.SLAT_ROTATION_IMPULSE + ) + ) is not None: + if not slat_attribute.is_reversed: + await self.async_set_value(slat_attribute, 2) + else: + await self.async_set_value(slat_attribute, 1) async def async_close_cover_tilt(self, **kwargs: Any) -> None: """Close the cover tilt.""" - slat_attribute = self._node.get_attribute_by_type( - AttributeType.SLAT_ROTATION_IMPULSE - ) - if not slat_attribute.is_reversed: - await self.async_set_value(slat_attribute, 1) - else: - await self.async_set_value(slat_attribute, 2) + if ( + slat_attribute := self._node.get_attribute_by_type( + AttributeType.SLAT_ROTATION_IMPULSE + ) + ) is not None: + if not slat_attribute.is_reversed: + await self.async_set_value(slat_attribute, 1) + else: + await self.async_set_value(slat_attribute, 2) async def async_set_cover_tilt_position(self, **kwargs: Any) -> None: """Move the cover tilt to a specific position.""" @@ -255,11 +265,13 @@ class HomeeCover(HomeeNodeEntity, CoverEntity): position = 100 - cast(int, kwargs[ATTR_TILT_POSITION]) # Convert position to range of our entity. - attribute = self._node.get_attribute_by_type( - AttributeType.SHUTTER_SLAT_POSITION - ) - homee_min = attribute.minimum - homee_max = attribute.maximum - homee_position = (position / 100) * (homee_max - homee_min) + homee_min + if ( + attribute := self._node.get_attribute_by_type( + AttributeType.SHUTTER_SLAT_POSITION + ) + ) is not None: + homee_min = attribute.minimum + homee_max = attribute.maximum + homee_position = (position / 100) * (homee_max - homee_min) + homee_min - await self.async_set_value(attribute, homee_position) + await self.async_set_value(attribute, homee_position) diff --git a/homeassistant/components/homee/entity.py b/homeassistant/components/homee/entity.py index 2af01358752..a6cd54354bf 100644 --- a/homeassistant/components/homee/entity.py +++ b/homeassistant/components/homee/entity.py @@ -73,13 +73,20 @@ class HomeeNodeEntity(Entity): self._attr_unique_id = f"{entry.unique_id}-{node.id}" self._entry = entry - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, str(node.id))}, - name=node.name, - model=get_name_for_enum(NodeProfile, node.profile), - sw_version=self._get_software_version(), - via_device=(DOMAIN, entry.runtime_data.settings.uid), - ) + ## Homee hub itself has node-id -1 + if node.id == -1: + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, entry.runtime_data.settings.uid)}, + ) + else: + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, f"{entry.unique_id}-{node.id}")}, + name=node.name, + model=get_name_for_enum(NodeProfile, node.profile), + sw_version=self._get_software_version(), + via_device=(DOMAIN, entry.runtime_data.settings.uid), + ) + self._host_connected = entry.runtime_data.connected async def async_added_to_hass(self) -> None: @@ -91,23 +98,6 @@ class HomeeNodeEntity(Entity): ) ) - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - # Homee hub has id -1, but is identified only by the UID. - if self._node.id == -1: - return DeviceInfo( - identifiers={(DOMAIN, self._entry.runtime_data.settings.uid)}, - ) - - return DeviceInfo( - identifiers={(DOMAIN, f"{self._entry.unique_id}-{self._node.id}")}, - name=self._node.name, - model=get_name_for_enum(NodeProfile, self._node.profile), - sw_version=self._get_software_version(), - via_device=(DOMAIN, self._entry.runtime_data.settings.uid), - ) - @property def available(self) -> bool: """Return the availability of the underlying node.""" @@ -122,18 +112,26 @@ class HomeeNodeEntity(Entity): def _get_software_version(self) -> str | None: """Return the software version of the node.""" - if self.has_attribute(AttributeType.FIRMWARE_REVISION): - return self._node.get_attribute_by_type( + if ( + attribute := self._node.get_attribute_by_type( AttributeType.FIRMWARE_REVISION - ).get_value() - if self.has_attribute(AttributeType.SOFTWARE_REVISION): - return self._node.get_attribute_by_type( + ) + ) is not None: + return str(attribute.get_value()) + if ( + attribute := self._node.get_attribute_by_type( AttributeType.SOFTWARE_REVISION - ).get_value() + ) + ) is not None: + return str(attribute.get_value()) + return None def has_attribute(self, attribute_type: AttributeType) -> bool: """Check if an attribute of the given type exists.""" + if self._node.attribute_map is None: + return False + return attribute_type in self._node.attribute_map async def async_set_value(self, attribute: HomeeAttribute, value: float) -> None: diff --git a/homeassistant/components/homee/manifest.json b/homeassistant/components/homee/manifest.json index 5869a9760ea..6d03547efc9 100644 --- a/homeassistant/components/homee/manifest.json +++ b/homeassistant/components/homee/manifest.json @@ -8,5 +8,5 @@ "iot_class": "local_push", "loggers": ["homee"], "quality_scale": "bronze", - "requirements": ["pyHomee==1.2.0"] + "requirements": ["pyHomee==1.2.3"] } diff --git a/homeassistant/components/homee/sensor.py b/homeassistant/components/homee/sensor.py index 75b11811460..e9ef298ab4f 100644 --- a/homeassistant/components/homee/sensor.py +++ b/homeassistant/components/homee/sensor.py @@ -263,7 +263,7 @@ class HomeeSensor(HomeeEntity, SensorEntity): self.entity_description = description self._attr_translation_key = description.key if attribute.instance > 0: - self._attr_translation_key = f"{description.translation_key}_instance" + self._attr_translation_key = f"{self._attr_translation_key}_instance" self._attr_translation_placeholders = {"instance": str(attribute.instance)} @property diff --git a/requirements_all.txt b/requirements_all.txt index 00be847c2d9..a374b7f7e8a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1763,7 +1763,7 @@ pyEmby==1.10 pyHik==0.3.2 # homeassistant.components.homee -pyHomee==1.2.0 +pyHomee==1.2.3 # homeassistant.components.rfxtrx pyRFXtrx==0.31.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d6be4597d25..cf740431956 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1452,7 +1452,7 @@ pyDuotecno==2024.10.1 pyElectra==1.2.4 # homeassistant.components.homee -pyHomee==1.2.0 +pyHomee==1.2.3 # homeassistant.components.rfxtrx pyRFXtrx==0.31.1