From 56f05bee91b03eecf710602215b163eccfa883ad Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 8 Sep 2023 01:15:34 +0200 Subject: [PATCH] Use shorthand attributes in Tradfri (#99890) --- .../components/tradfri/base_class.py | 24 +++++++---------- homeassistant/components/tradfri/fan.py | 26 ++++++------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/homeassistant/components/tradfri/base_class.py b/homeassistant/components/tradfri/base_class.py index d186e19a2c8..416eb175d31 100644 --- a/homeassistant/components/tradfri/base_class.py +++ b/homeassistant/components/tradfri/base_class.py @@ -55,7 +55,16 @@ class TradfriBaseEntity(CoordinatorEntity[TradfriDeviceDataUpdateCoordinator]): self._device_id = self._device.id self._api = handle_error(api) - self._attr_unique_id = f"{self._gateway_id}-{self._device.id}" + info = self._device.device_info + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self._device_id)}, + manufacturer=info.manufacturer, + model=info.model_number, + name=self._device.name, + sw_version=info.firmware_version, + via_device=(DOMAIN, gateway_id), + ) + self._attr_unique_id = f"{gateway_id}-{self._device_id}" @abstractmethod @callback @@ -71,19 +80,6 @@ class TradfriBaseEntity(CoordinatorEntity[TradfriDeviceDataUpdateCoordinator]): self._refresh() super()._handle_coordinator_update() - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - info = self._device.device_info - return DeviceInfo( - identifiers={(DOMAIN, self._device.id)}, - manufacturer=info.manufacturer, - model=info.model_number, - name=self._device.name, - sw_version=info.firmware_version, - via_device=(DOMAIN, self._gateway_id), - ) - @property def available(self) -> bool: """Return if entity is available.""" diff --git a/homeassistant/components/tradfri/fan.py b/homeassistant/components/tradfri/fan.py index a26dfa1d9a0..c41b24a2647 100644 --- a/homeassistant/components/tradfri/fan.py +++ b/homeassistant/components/tradfri/fan.py @@ -56,6 +56,14 @@ class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity): _attr_name = None _attr_supported_features = FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED + _attr_preset_modes = [ATTR_AUTO] + # These are the steps: + # 0 = Off + # 1 = Preset: Auto mode + # 2 = Min + # ... with step size 1 + # 50 = Max + _attr_speed_count = ATTR_MAX_FAN_STEPS def __init__( self, @@ -77,19 +85,6 @@ class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity): """Refresh the device.""" self._device_data = self.coordinator.data.air_purifier_control.air_purifiers[0] - @property - def speed_count(self) -> int: - """Return the number of speeds the fan supports. - - These are the steps: - 0 = Off - 1 = Preset: Auto mode - 2 = Min - ... with step size 1 - 50 = Max - """ - return ATTR_MAX_FAN_STEPS - @property def is_on(self) -> bool: """Return true if switch is on.""" @@ -97,11 +92,6 @@ class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity): return False return cast(bool, self._device_data.state) - @property - def preset_modes(self) -> list[str] | None: - """Return a list of available preset modes.""" - return [ATTR_AUTO] - @property def percentage(self) -> int | None: """Return the current speed percentage."""