From 505a4bfc34554dd2bc8b7a69500a7d036c613016 Mon Sep 17 00:00:00 2001 From: Marco <46717884+marcodutto@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:06:15 -0400 Subject: [PATCH] Add Smarty versions to device (#129418) --- homeassistant/components/smarty/coordinator.py | 8 ++++++++ homeassistant/components/smarty/entity.py | 2 ++ homeassistant/components/smarty/sensor.py | 4 +++- tests/components/smarty/conftest.py | 2 ++ tests/components/smarty/snapshots/test_init.ambr | 4 ++-- tests/components/smarty/snapshots/test_sensor.ambr | 6 ++++-- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/smarty/coordinator.py b/homeassistant/components/smarty/coordinator.py index 20d7995a644..d7f3e2452d1 100644 --- a/homeassistant/components/smarty/coordinator.py +++ b/homeassistant/components/smarty/coordinator.py @@ -19,6 +19,8 @@ class SmartyCoordinator(DataUpdateCoordinator[None]): """Smarty Coordinator.""" config_entry: SmartyConfigEntry + software_version: str + configuration_version: str def __init__(self, hass: HomeAssistant) -> None: """Initialize.""" @@ -30,6 +32,12 @@ class SmartyCoordinator(DataUpdateCoordinator[None]): ) self.client = Smarty(host=self.config_entry.data[CONF_HOST]) + async def _async_setup(self) -> None: + if not await self.hass.async_add_executor_job(self.client.update): + raise UpdateFailed("Failed to update Smarty data") + self.software_version = self.client.get_software_version() + self.configuration_version = self.client.get_configuration_version() + async def _async_update_data(self) -> None: """Fetch data from Smarty.""" if not await self.hass.async_add_executor_job(self.client.update): diff --git a/homeassistant/components/smarty/entity.py b/homeassistant/components/smarty/entity.py index 92f73e2ace7..d26b56d489f 100644 --- a/homeassistant/components/smarty/entity.py +++ b/homeassistant/components/smarty/entity.py @@ -18,4 +18,6 @@ class SmartyEntity(CoordinatorEntity[SmartyCoordinator]): self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, coordinator.config_entry.entry_id)}, manufacturer="Salda", + sw_version=self.coordinator.software_version, + hw_version=self.coordinator.configuration_version, ) diff --git a/homeassistant/components/smarty/sensor.py b/homeassistant/components/smarty/sensor.py index 90a2d1eade2..9d847003a59 100644 --- a/homeassistant/components/smarty/sensor.py +++ b/homeassistant/components/smarty/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( SensorEntity, SensorEntityDescription, ) -from homeassistant.const import UnitOfTemperature +from homeassistant.const import REVOLUTIONS_PER_MINUTE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback import homeassistant.util.dt as dt_util @@ -64,11 +64,13 @@ ENTITIES: tuple[SmartySensorDescription, ...] = ( SmartySensorDescription( key="supply_fan_speed", translation_key="supply_fan_speed", + native_unit_of_measurement=REVOLUTIONS_PER_MINUTE, value_fn=lambda smarty: smarty.supply_fan_speed, ), SmartySensorDescription( key="extract_fan_speed", translation_key="extract_fan_speed", + native_unit_of_measurement=REVOLUTIONS_PER_MINUTE, value_fn=lambda smarty: smarty.extract_fan_speed, ), SmartySensorDescription( diff --git a/tests/components/smarty/conftest.py b/tests/components/smarty/conftest.py index 73cc7209fcd..c62097f0516 100644 --- a/tests/components/smarty/conftest.py +++ b/tests/components/smarty/conftest.py @@ -46,6 +46,8 @@ def mock_smarty() -> Generator[AsyncMock]: client.supply_fan_speed = 66 client.extract_fan_speed = 100 client.filter_timer = 31 + client.get_configuration_version.return_value = 111 + client.get_software_version.return_value = 127 yield client diff --git a/tests/components/smarty/snapshots/test_init.ambr b/tests/components/smarty/snapshots/test_init.ambr index 1545491c7d3..b25cdb9dc3a 100644 --- a/tests/components/smarty/snapshots/test_init.ambr +++ b/tests/components/smarty/snapshots/test_init.ambr @@ -8,7 +8,7 @@ }), 'disabled_by': None, 'entry_type': None, - 'hw_version': None, + 'hw_version': 111, 'id': , 'identifiers': set({ tuple( @@ -27,7 +27,7 @@ 'primary_config_entry': , 'serial_number': None, 'suggested_area': None, - 'sw_version': None, + 'sw_version': 127, 'via_device_id': None, }) # --- diff --git a/tests/components/smarty/snapshots/test_sensor.ambr b/tests/components/smarty/snapshots/test_sensor.ambr index 2a5a6a33a84..2f713db7f83 100644 --- a/tests/components/smarty/snapshots/test_sensor.ambr +++ b/tests/components/smarty/snapshots/test_sensor.ambr @@ -77,13 +77,14 @@ 'supported_features': 0, 'translation_key': 'extract_fan_speed', 'unique_id': '01JAZ5DPW8C62D620DGYNG2R8H_extract_fan_speed', - 'unit_of_measurement': None, + 'unit_of_measurement': 'rpm', }) # --- # name: test_all_entities[sensor.mock_title_extract_fan_speed-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'friendly_name': 'Mock Title Extract fan speed', + 'unit_of_measurement': 'rpm', }), 'context': , 'entity_id': 'sensor.mock_title_extract_fan_speed', @@ -266,13 +267,14 @@ 'supported_features': 0, 'translation_key': 'supply_fan_speed', 'unique_id': '01JAZ5DPW8C62D620DGYNG2R8H_supply_fan_speed', - 'unit_of_measurement': None, + 'unit_of_measurement': 'rpm', }) # --- # name: test_all_entities[sensor.mock_title_supply_fan_speed-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'friendly_name': 'Mock Title Supply fan speed', + 'unit_of_measurement': 'rpm', }), 'context': , 'entity_id': 'sensor.mock_title_supply_fan_speed',