mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Migrate NumberEntity r-t to native_value (#73485)
This commit is contained in:
parent
4ace2c4d3a
commit
e05e79e53d
@ -38,8 +38,8 @@ class DiffuserPerfumeAmount(DiffuserEntity, NumberEntity):
|
||||
"""Representation of a diffuser perfume amount number."""
|
||||
|
||||
_attr_icon = "mdi:gauge"
|
||||
_attr_max_value = MAX_PERFUME_AMOUNT
|
||||
_attr_min_value = MIN_PERFUME_AMOUNT
|
||||
_attr_native_max_value = MAX_PERFUME_AMOUNT
|
||||
_attr_native_min_value = MIN_PERFUME_AMOUNT
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
@ -48,11 +48,11 @@ class DiffuserPerfumeAmount(DiffuserEntity, NumberEntity):
|
||||
super().__init__(diffuser, coordinator, PERFUME_AMOUNT_SUFFIX)
|
||||
|
||||
@property
|
||||
def value(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the current perfume amount."""
|
||||
return self._diffuser.perfume_amount
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set the perfume amount."""
|
||||
if not value.is_integer():
|
||||
raise ValueError(
|
||||
|
@ -46,16 +46,16 @@ class ScreenLogicNumber(ScreenlogicEntity, NumberEntity):
|
||||
"""Initialize of the entity."""
|
||||
super().__init__(coordinator, data_key, enabled)
|
||||
self._body_type = SUPPORTED_SCG_NUMBERS.index(self._data_key)
|
||||
self._attr_max_value = SCG.LIMIT_FOR_BODY[self._body_type]
|
||||
self._attr_native_max_value = SCG.LIMIT_FOR_BODY[self._body_type]
|
||||
self._attr_name = f"{self.gateway_name} {self.sensor['name']}"
|
||||
self._attr_unit_of_measurement = self.sensor["unit"]
|
||||
self._attr_native_unit_of_measurement = self.sensor["unit"]
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the current value."""
|
||||
return self.sensor["value"]
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the current value."""
|
||||
# Need to set both levels at the same time, so we gather
|
||||
# both existing level values and override the one that changed.
|
||||
|
@ -39,9 +39,9 @@ DEVICE_NUMBER_TYPES = (
|
||||
icon="mdi:thermometer",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_registry_enabled_default=False,
|
||||
min_value=-10,
|
||||
max_value=10,
|
||||
step=0.1,
|
||||
native_min_value=-10,
|
||||
native_max_value=10,
|
||||
native_step=0.1,
|
||||
),
|
||||
SensiboNumberEntityDescription(
|
||||
key="calibration_hum",
|
||||
@ -50,9 +50,9 @@ DEVICE_NUMBER_TYPES = (
|
||||
icon="mdi:water",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_registry_enabled_default=False,
|
||||
min_value=-10,
|
||||
max_value=10,
|
||||
step=0.1,
|
||||
native_min_value=-10,
|
||||
native_max_value=10,
|
||||
native_step=0.1,
|
||||
),
|
||||
)
|
||||
|
||||
@ -89,12 +89,12 @@ class SensiboNumber(SensiboDeviceBaseEntity, NumberEntity):
|
||||
self._attr_name = f"{self.device_data.name} {entity_description.name}"
|
||||
|
||||
@property
|
||||
def value(self) -> float | None:
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the value from coordinator data."""
|
||||
value: float | None = getattr(self.device_data, self.entity_description.key)
|
||||
return value
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set value for calibration."""
|
||||
data = {self.entity_description.remote_key: value}
|
||||
result = await self.async_send_command("set_calibration", {"data": data})
|
||||
|
@ -42,12 +42,12 @@ NUMBERS: Final = {
|
||||
key="device|valvepos",
|
||||
icon="mdi:pipe-valve",
|
||||
name="Valve Position",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
available=lambda block: cast(int, block.valveError) != 1,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
min_value=0,
|
||||
max_value=100,
|
||||
step=1,
|
||||
native_min_value=0,
|
||||
native_max_value=100,
|
||||
native_step=1,
|
||||
mode=NumberMode("slider"),
|
||||
rest_path="thermostat/0",
|
||||
rest_arg="pos",
|
||||
@ -62,11 +62,11 @@ def _build_block_description(entry: RegistryEntry) -> BlockNumberDescription:
|
||||
key="",
|
||||
name="",
|
||||
icon=entry.original_icon,
|
||||
unit_of_measurement=entry.unit_of_measurement,
|
||||
native_unit_of_measurement=entry.unit_of_measurement,
|
||||
device_class=entry.original_device_class,
|
||||
min_value=cast(float, entry.capabilities.get("min")),
|
||||
max_value=cast(float, entry.capabilities.get("max")),
|
||||
step=cast(float, entry.capabilities.get("step")),
|
||||
native_min_value=cast(float, entry.capabilities.get("min")),
|
||||
native_max_value=cast(float, entry.capabilities.get("max")),
|
||||
native_step=cast(float, entry.capabilities.get("step")),
|
||||
mode=cast(NumberMode, entry.capabilities.get("mode")),
|
||||
)
|
||||
|
||||
@ -97,14 +97,14 @@ class BlockSleepingNumber(ShellySleepingBlockAttributeEntity, NumberEntity):
|
||||
entity_description: BlockNumberDescription
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return value of number."""
|
||||
if self.block is not None:
|
||||
return cast(float, self.attribute_value)
|
||||
|
||||
return cast(float, self.last_state)
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set value."""
|
||||
# Example for Shelly Valve: http://192.168.188.187/thermostat/0?pos=13.0
|
||||
await self._set_state_full_path(
|
||||
|
@ -70,9 +70,9 @@ def _get_sleeper_unique_id(bed: SleepIQBed, sleeper: SleepIQSleeper) -> str:
|
||||
NUMBER_DESCRIPTIONS: dict[str, SleepIQNumberEntityDescription] = {
|
||||
FIRMNESS: SleepIQNumberEntityDescription(
|
||||
key=FIRMNESS,
|
||||
min_value=5,
|
||||
max_value=100,
|
||||
step=5,
|
||||
native_min_value=5,
|
||||
native_max_value=100,
|
||||
native_step=5,
|
||||
name=ENTITY_TYPES[FIRMNESS],
|
||||
icon=ICON_OCCUPIED,
|
||||
value_fn=lambda sleeper: cast(float, sleeper.sleep_number),
|
||||
@ -82,9 +82,9 @@ NUMBER_DESCRIPTIONS: dict[str, SleepIQNumberEntityDescription] = {
|
||||
),
|
||||
ACTUATOR: SleepIQNumberEntityDescription(
|
||||
key=ACTUATOR,
|
||||
min_value=0,
|
||||
max_value=100,
|
||||
step=1,
|
||||
native_min_value=0,
|
||||
native_max_value=100,
|
||||
native_step=1,
|
||||
name=ENTITY_TYPES[ACTUATOR],
|
||||
icon=ICON_OCCUPIED,
|
||||
value_fn=lambda actuator: cast(float, actuator.position),
|
||||
@ -152,9 +152,9 @@ class SleepIQNumberEntity(SleepIQBedEntity, NumberEntity):
|
||||
@callback
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update number attributes."""
|
||||
self._attr_value = float(self.entity_description.value_fn(self.device))
|
||||
self._attr_native_value = float(self.entity_description.value_fn(self.device))
|
||||
|
||||
async def async_set_value(self, value: float) -> None:
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set the number value."""
|
||||
await self.entity_description.set_value_fn(self.device, int(value))
|
||||
self._attr_value = value
|
||||
|
@ -73,7 +73,7 @@ class SonosLevelEntity(SonosEntity, NumberEntity):
|
||||
name_suffix = level_type.replace("_", " ").title()
|
||||
self._attr_name = f"{self.speaker.zone_name} {name_suffix}"
|
||||
self.level_type = level_type
|
||||
self._attr_min_value, self._attr_max_value = valid_range
|
||||
self._attr_native_min_value, self._attr_native_max_value = valid_range
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Poll the value if subscriptions are not working."""
|
||||
@ -86,11 +86,11 @@ class SonosLevelEntity(SonosEntity, NumberEntity):
|
||||
setattr(self.speaker, self.level_type, state)
|
||||
|
||||
@soco_error()
|
||||
def set_value(self, value: float) -> None:
|
||||
def set_native_value(self, value: float) -> None:
|
||||
"""Set a new value."""
|
||||
setattr(self.soco, self.level_type, value)
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the current value."""
|
||||
return getattr(self.speaker, self.level_type)
|
||||
|
@ -34,8 +34,8 @@ class ToloNumberEntityDescription(
|
||||
"""Class describing TOLO Number entities."""
|
||||
|
||||
entity_category = EntityCategory.CONFIG
|
||||
min_value = 0
|
||||
step = 1
|
||||
native_min_value = 0
|
||||
native_step = 1
|
||||
|
||||
|
||||
NUMBERS = (
|
||||
@ -43,8 +43,8 @@ NUMBERS = (
|
||||
key="power_timer",
|
||||
icon="mdi:power-settings",
|
||||
name="Power Timer",
|
||||
unit_of_measurement=TIME_MINUTES,
|
||||
max_value=POWER_TIMER_MAX,
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_max_value=POWER_TIMER_MAX,
|
||||
getter=lambda settings: settings.power_timer,
|
||||
setter=lambda client, value: client.set_power_timer(value),
|
||||
),
|
||||
@ -52,8 +52,8 @@ NUMBERS = (
|
||||
key="salt_bath_timer",
|
||||
icon="mdi:shaker-outline",
|
||||
name="Salt Bath Timer",
|
||||
unit_of_measurement=TIME_MINUTES,
|
||||
max_value=SALT_BATH_TIMER_MAX,
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_max_value=SALT_BATH_TIMER_MAX,
|
||||
getter=lambda settings: settings.salt_bath_timer,
|
||||
setter=lambda client, value: client.set_salt_bath_timer(value),
|
||||
),
|
||||
@ -61,8 +61,8 @@ NUMBERS = (
|
||||
key="fan_timer",
|
||||
icon="mdi:fan-auto",
|
||||
name="Fan Timer",
|
||||
unit_of_measurement=TIME_MINUTES,
|
||||
max_value=FAN_TIMER_MAX,
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_max_value=FAN_TIMER_MAX,
|
||||
getter=lambda settings: settings.fan_timer,
|
||||
setter=lambda client, value: client.set_fan_timer(value),
|
||||
),
|
||||
@ -98,11 +98,11 @@ class ToloNumberEntity(ToloSaunaCoordinatorEntity, NumberEntity):
|
||||
self._attr_unique_id = f"{entry.entry_id}_{entity_description.key}"
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the value of this TOLO Number entity."""
|
||||
return self.entity_description.getter(self.coordinator.data.settings) or 0
|
||||
|
||||
def set_value(self, value: float) -> None:
|
||||
def set_native_value(self, value: float) -> None:
|
||||
"""Set the value of this TOLO Number entity."""
|
||||
int_value = int(value)
|
||||
if int_value == 0:
|
||||
|
Loading…
x
Reference in New Issue
Block a user