From fbba318a180d660e07593ad57c764d1d754e7c22 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 1 Apr 2022 01:38:00 -0700 Subject: [PATCH] Invert number option (#68972) --- homeassistant/components/overkiz/number.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py index 40d04b9bf71..e6e64162dd8 100644 --- a/homeassistant/components/overkiz/number.py +++ b/homeassistant/components/overkiz/number.py @@ -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 )