Migrate overkiz NumberEntity to native_value (#73493)

This commit is contained in:
Erik Montnemery 2022-06-15 10:49:40 +02:00 committed by GitHub
parent 94a8fe0052
commit 4ace2c4d3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,8 +6,13 @@ from typing import cast
from pyoverkiz.enums import OverkizCommand, OverkizState from pyoverkiz.enums import OverkizCommand, OverkizState
from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.components.number import (
NumberDeviceClass,
NumberEntity,
NumberEntityDescription,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -38,8 +43,8 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
name="My Position", name="My Position",
icon="mdi:content-save-cog", icon="mdi:content-save-cog",
command=OverkizCommand.SET_MEMORIZED_1_POSITION, command=OverkizCommand.SET_MEMORIZED_1_POSITION,
min_value=0, native_min_value=0,
max_value=100, native_max_value=100,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
# WaterHeater: Expected Number Of Shower (2 - 4) # WaterHeater: Expected Number Of Shower (2 - 4)
@ -48,8 +53,8 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
name="Expected Number Of Shower", name="Expected Number Of Shower",
icon="mdi:shower-head", icon="mdi:shower-head",
command=OverkizCommand.SET_EXPECTED_NUMBER_OF_SHOWER, command=OverkizCommand.SET_EXPECTED_NUMBER_OF_SHOWER,
min_value=2, native_min_value=2,
max_value=4, native_max_value=4,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
# SomfyHeatingTemperatureInterface # SomfyHeatingTemperatureInterface
@ -58,8 +63,10 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
name="Eco Room Temperature", name="Eco Room Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
command=OverkizCommand.SET_ECO_TEMPERATURE, command=OverkizCommand.SET_ECO_TEMPERATURE,
min_value=6, device_class=NumberDeviceClass.TEMPERATURE,
max_value=29, native_min_value=6,
native_max_value=29,
native_unit_of_measurement=TEMP_CELSIUS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
OverkizNumberDescription( OverkizNumberDescription(
@ -67,8 +74,10 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
name="Comfort Room Temperature", name="Comfort Room Temperature",
icon="mdi:home-thermometer-outline", icon="mdi:home-thermometer-outline",
command=OverkizCommand.SET_COMFORT_TEMPERATURE, command=OverkizCommand.SET_COMFORT_TEMPERATURE,
min_value=7, device_class=NumberDeviceClass.TEMPERATURE,
max_value=30, native_min_value=7,
native_max_value=30,
native_unit_of_measurement=TEMP_CELSIUS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
OverkizNumberDescription( OverkizNumberDescription(
@ -76,8 +85,10 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
name="Freeze Protection Temperature", name="Freeze Protection Temperature",
icon="mdi:sun-thermometer-outline", icon="mdi:sun-thermometer-outline",
command=OverkizCommand.SET_SECURED_POSITION_TEMPERATURE, command=OverkizCommand.SET_SECURED_POSITION_TEMPERATURE,
min_value=5, device_class=NumberDeviceClass.TEMPERATURE,
max_value=15, native_min_value=5,
native_max_value=15,
native_unit_of_measurement=TEMP_CELSIUS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
# DimmerExteriorHeating (Somfy Terrace Heater) (0 - 100) # DimmerExteriorHeating (Somfy Terrace Heater) (0 - 100)
@ -86,8 +97,8 @@ NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [
key=OverkizState.CORE_LEVEL, key=OverkizState.CORE_LEVEL,
icon="mdi:patio-heater", icon="mdi:patio-heater",
command=OverkizCommand.SET_LEVEL, command=OverkizCommand.SET_LEVEL,
min_value=0, native_min_value=0,
max_value=100, native_max_value=100,
inverted=True, inverted=True,
), ),
] ]
@ -130,20 +141,20 @@ class OverkizNumber(OverkizDescriptiveEntity, NumberEntity):
entity_description: OverkizNumberDescription entity_description: OverkizNumberDescription
@property @property
def value(self) -> float | None: def native_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: if self.entity_description.inverted:
return self.max_value - cast(float, state.value) return self.native_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_native_value(self, value: float) -> None:
"""Set new value.""" """Set new value."""
if self.entity_description.inverted: if self.entity_description.inverted:
value = self.max_value - value value = self.native_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