Simplify FanEntity percentage and speed_count shorthand attributes (#130935)

This commit is contained in:
epenet 2024-11-19 22:17:29 +01:00 committed by GitHub
parent c1f03f34b2
commit ea989f7ca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -234,10 +234,10 @@ class FanEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
entity_description: FanEntityDescription
_attr_current_direction: str | None = None
_attr_oscillating: bool | None = None
_attr_percentage: int | None
_attr_percentage: int | None = 0
_attr_preset_mode: str | None = None
_attr_preset_modes: list[str] | None = None
_attr_speed_count: int
_attr_speed_count: int = 100
_attr_supported_features: FanEntityFeature = FanEntityFeature(0)
__mod_supported_features: FanEntityFeature = FanEntityFeature(0)
@ -463,16 +463,12 @@ class FanEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
@cached_property
def percentage(self) -> int | None:
"""Return the current speed as a percentage."""
if hasattr(self, "_attr_percentage"):
return self._attr_percentage
return 0
return self._attr_percentage
@cached_property
def speed_count(self) -> int:
"""Return the number of speeds the fan supports."""
if hasattr(self, "_attr_speed_count"):
return self._attr_speed_count
return 100
return self._attr_speed_count
@property
def percentage_step(self) -> float: