Invert number option (#68972)
This commit is contained in:
parent
72d0cef169
commit
fbba318a18
1 changed files with 16 additions and 0 deletions
|
@ -28,6 +28,8 @@ class OverkizNumberDescriptionMixin:
|
||||||
class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin):
|
class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin):
|
||||||
"""Class to describe an Overkiz number."""
|
"""Class to describe an Overkiz number."""
|
||||||
|
|
||||||
|
inverted: bool = False
|
||||||
|
|
||||||
|
|
||||||
NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
|
NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
|
||||||
# Cover: My Position (0 - 100)
|
# Cover: My Position (0 - 100)
|
||||||
|
@ -76,6 +78,14 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
|
||||||
max_value=15,
|
max_value=15,
|
||||||
entity_category=EntityCategory.CONFIG,
|
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}
|
SUPPORTED_STATES = {description.key: description for description in NUMBER_DESCRIPTIONS}
|
||||||
|
@ -119,12 +129,18 @@ class OverkizNumber(OverkizDescriptiveEntity, NumberEntity):
|
||||||
def value(self) -> float | None:
|
def value(self) -> float | None:
|
||||||
"""Return the entity value to represent the entity state."""
|
"""Return the entity value to represent the entity state."""
|
||||||
if state := self.device.states.get(self.entity_description.key):
|
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 cast(float, state.value)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def async_set_value(self, value: float) -> None:
|
async def async_set_value(self, value: float) -> None:
|
||||||
"""Set new value."""
|
"""Set new value."""
|
||||||
|
if self.entity_description.inverted:
|
||||||
|
value = self._attr_max_value - value
|
||||||
|
|
||||||
await self.executor.async_execute_command(
|
await self.executor.async_execute_command(
|
||||||
self.entity_description.command, value
|
self.entity_description.command, value
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue