Invert number option (#68972)

pull/69061/head
Mick Vleeshouwer 2022-04-01 01:38:00 -07:00 committed by GitHub
parent 72d0cef169
commit fbba318a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,8 @@ class OverkizNumberDescriptionMixin:
class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin):
"""Class to describe an Overkiz number."""
inverted: bool = False
NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
# Cover: My Position (0 - 100)
@ -76,6 +78,14 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
max_value=15,
entity_category=EntityCategory.CONFIG,
),
# DimmerExteriorHeating (Somfy Terrace Heater) (0 - 100)
# Needs to be inverted since 100 = off, 0 = on
OverkizNumberDescription(
key=OverkizState.CORE_LEVEL,
icon="mdi:patio-heater",
command=OverkizCommand.SET_LEVEL,
inverted=True,
),
]
SUPPORTED_STATES = {description.key: description for description in NUMBER_DESCRIPTIONS}
@ -119,12 +129,18 @@ class OverkizNumber(OverkizDescriptiveEntity, NumberEntity):
def value(self) -> float | None:
"""Return the entity value to represent the entity state."""
if state := self.device.states.get(self.entity_description.key):
if self.entity_description.inverted:
return self._attr_max_value - cast(float, state.value)
return cast(float, state.value)
return None
async def async_set_value(self, value: float) -> None:
"""Set new value."""
if self.entity_description.inverted:
value = self._attr_max_value - value
await self.executor.async_execute_command(
self.entity_description.command, value
)