mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Use shorthand attributes in Tradfri (#99890)
This commit is contained in:
parent
c2b119bfaf
commit
56f05bee91
@ -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."""
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user