Migrate NumberEntity a-j to native_value (#73486)

This commit is contained in:
Erik Montnemery 2022-06-14 20:16:36 +02:00 committed by GitHub
parent 576de9ac40
commit 1f7340313a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 103 deletions

View File

@ -40,8 +40,8 @@ AUTO_COMFORT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="comfort_min_speed", key="comfort_min_speed",
name="Auto Comfort Minimum Speed", name="Auto Comfort Minimum Speed",
min_value=0, native_min_value=0,
max_value=SPEED_RANGE[1] - 1, native_max_value=SPEED_RANGE[1] - 1,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
value_fn=lambda device: cast(Optional[int], device.comfort_min_speed), value_fn=lambda device: cast(Optional[int], device.comfort_min_speed),
mode=NumberMode.BOX, mode=NumberMode.BOX,
@ -49,8 +49,8 @@ AUTO_COMFORT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="comfort_max_speed", key="comfort_max_speed",
name="Auto Comfort Maximum Speed", name="Auto Comfort Maximum Speed",
min_value=1, native_min_value=1,
max_value=SPEED_RANGE[1], native_max_value=SPEED_RANGE[1],
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
value_fn=lambda device: cast(Optional[int], device.comfort_max_speed), value_fn=lambda device: cast(Optional[int], device.comfort_max_speed),
mode=NumberMode.BOX, mode=NumberMode.BOX,
@ -58,8 +58,8 @@ AUTO_COMFORT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="comfort_heat_assist_speed", key="comfort_heat_assist_speed",
name="Auto Comfort Heat Assist Speed", name="Auto Comfort Heat Assist Speed",
min_value=SPEED_RANGE[0], native_min_value=SPEED_RANGE[0],
max_value=SPEED_RANGE[1], native_max_value=SPEED_RANGE[1],
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
value_fn=lambda device: cast(Optional[int], device.comfort_heat_assist_speed), value_fn=lambda device: cast(Optional[int], device.comfort_heat_assist_speed),
mode=NumberMode.BOX, mode=NumberMode.BOX,
@ -70,20 +70,20 @@ FAN_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="return_to_auto_timeout", key="return_to_auto_timeout",
name="Return to Auto Timeout", name="Return to Auto Timeout",
min_value=ONE_MIN_SECS, native_min_value=ONE_MIN_SECS,
max_value=HALF_DAY_SECS, native_max_value=HALF_DAY_SECS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=TIME_SECONDS,
value_fn=lambda device: cast(Optional[int], device.return_to_auto_timeout), value_fn=lambda device: cast(Optional[int], device.return_to_auto_timeout),
mode=NumberMode.SLIDER, mode=NumberMode.SLIDER,
), ),
BAFNumberDescription( BAFNumberDescription(
key="motion_sense_timeout", key="motion_sense_timeout",
name="Motion Sense Timeout", name="Motion Sense Timeout",
min_value=ONE_MIN_SECS, native_min_value=ONE_MIN_SECS,
max_value=ONE_DAY_SECS, native_max_value=ONE_DAY_SECS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=TIME_SECONDS,
value_fn=lambda device: cast(Optional[int], device.motion_sense_timeout), value_fn=lambda device: cast(Optional[int], device.motion_sense_timeout),
mode=NumberMode.SLIDER, mode=NumberMode.SLIDER,
), ),
@ -93,10 +93,10 @@ LIGHT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="light_return_to_auto_timeout", key="light_return_to_auto_timeout",
name="Light Return to Auto Timeout", name="Light Return to Auto Timeout",
min_value=ONE_MIN_SECS, native_min_value=ONE_MIN_SECS,
max_value=HALF_DAY_SECS, native_max_value=HALF_DAY_SECS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=TIME_SECONDS,
value_fn=lambda device: cast( value_fn=lambda device: cast(
Optional[int], device.light_return_to_auto_timeout Optional[int], device.light_return_to_auto_timeout
), ),
@ -105,10 +105,10 @@ LIGHT_NUMBER_DESCRIPTIONS = (
BAFNumberDescription( BAFNumberDescription(
key="light_auto_motion_timeout", key="light_auto_motion_timeout",
name="Light Motion Sense Timeout", name="Light Motion Sense Timeout",
min_value=ONE_MIN_SECS, native_min_value=ONE_MIN_SECS,
max_value=ONE_DAY_SECS, native_max_value=ONE_DAY_SECS,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=TIME_SECONDS,
value_fn=lambda device: cast(Optional[int], device.light_auto_motion_timeout), value_fn=lambda device: cast(Optional[int], device.light_auto_motion_timeout),
mode=NumberMode.SLIDER, mode=NumberMode.SLIDER,
), ),
@ -149,8 +149,8 @@ class BAFNumber(BAFEntity, NumberEntity):
def _async_update_attrs(self) -> None: def _async_update_attrs(self) -> None:
"""Update attrs from device.""" """Update attrs from device."""
if (value := self.entity_description.value_fn(self._device)) is not None: if (value := self.entity_description.value_fn(self._device)) is not None:
self._attr_value = float(value) self._attr_native_value = float(value)
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Set the value.""" """Set the value."""
setattr(self._device, self.entity_description.key, int(value)) setattr(self._device, self.entity_description.key, int(value))

View File

@ -43,9 +43,9 @@ ENTITY_DESCRIPTIONS = {
value_fn=lambda device: device.delay, value_fn=lambda device: device.delay,
suffix="Delay", suffix="Delay",
update_key=PRESENCE_DELAY, update_key=PRESENCE_DELAY,
max_value=65535, native_max_value=65535,
min_value=0, native_min_value=0,
step=1, native_step=1,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
) )
] ]
@ -107,11 +107,11 @@ class DeconzNumber(DeconzDevice, NumberEntity):
super().async_update_callback() super().async_update_callback()
@property @property
def value(self) -> float | None: def native_value(self) -> float | None:
"""Return the value of the sensor property.""" """Return the value of the sensor property."""
return self.entity_description.value_fn(self._device) return 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 sensor config.""" """Set sensor config."""
data = {self.entity_description.key: int(value)} data = {self.entity_description.key: int(value)}
await self._device.set_config(**data) await self._device.set_config(**data)

View File

@ -85,9 +85,9 @@ class DemoNumber(NumberEntity):
state: float, state: float,
icon: str, icon: str,
assumed: bool, assumed: bool,
min_value: float | None = None, native_min_value: float | None = None,
max_value: float | None = None, native_max_value: float | None = None,
step: float | None = None, native_step: float | None = None,
mode: NumberMode = NumberMode.AUTO, mode: NumberMode = NumberMode.AUTO,
) -> None: ) -> None:
"""Initialize the Demo Number entity.""" """Initialize the Demo Number entity."""
@ -95,15 +95,15 @@ class DemoNumber(NumberEntity):
self._attr_icon = icon self._attr_icon = icon
self._attr_name = name or DEVICE_DEFAULT_NAME self._attr_name = name or DEVICE_DEFAULT_NAME
self._attr_unique_id = unique_id self._attr_unique_id = unique_id
self._attr_value = state self._attr_native_value = state
self._attr_mode = mode self._attr_mode = mode
if min_value is not None: if native_min_value is not None:
self._attr_min_value = min_value self._attr_min_value = native_min_value
if max_value is not None: if native_max_value is not None:
self._attr_max_value = max_value self._attr_max_value = native_max_value
if step is not None: if native_step is not None:
self._attr_step = step self._attr_step = native_step
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={ identifiers={
@ -113,7 +113,7 @@ class DemoNumber(NumberEntity):
name=self.name, name=self.name,
) )
async def async_set_value(self, value): async def async_set_native_value(self, value):
"""Update the current value.""" """Update the current value."""
self._attr_value = value self._attr_native_value = value
self.async_write_ha_state() self.async_write_ha_state()

View File

@ -52,22 +52,22 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
"""A number implementation for esphome.""" """A number implementation for esphome."""
@property @property
def min_value(self) -> float: def native_min_value(self) -> float:
"""Return the minimum value.""" """Return the minimum value."""
return super()._static_info.min_value return super()._static_info.min_value
@property @property
def max_value(self) -> float: def native_max_value(self) -> float:
"""Return the maximum value.""" """Return the maximum value."""
return super()._static_info.max_value return super()._static_info.max_value
@property @property
def step(self) -> float: def native_step(self) -> float:
"""Return the increment/decrement step.""" """Return the increment/decrement step."""
return super()._static_info.step return super()._static_info.step
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement.""" """Return the unit of measurement."""
return super()._static_info.unit_of_measurement return super()._static_info.unit_of_measurement
@ -79,7 +79,7 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
return NumberMode.AUTO return NumberMode.AUTO
@esphome_state_property @esphome_state_property
def value(self) -> float | None: def native_value(self) -> float | None:
"""Return the state of the entity.""" """Return the state of the entity."""
if math.isnan(self._state.state): if math.isnan(self._state.state):
return None return None
@ -87,6 +87,6 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
return None return None
return self._state.state return self._state.state
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Update the current value.""" """Update the current value."""
await self._client.number_command(self._static_info.key, value) await self._client.number_command(self._static_info.key, value)

View File

@ -34,11 +34,11 @@ async def async_setup_entry(
class PeriodicVentingTime(CoordinatorEntity[Coordinator], NumberEntity): class PeriodicVentingTime(CoordinatorEntity[Coordinator], NumberEntity):
"""Periodic Venting.""" """Periodic Venting."""
_attr_max_value: float = 59 _attr_native_max_value: float = 59
_attr_min_value: float = 0 _attr_native_min_value: float = 0
_attr_step: float = 1 _attr_native_step: float = 1
_attr_entity_category = EntityCategory.CONFIG _attr_entity_category = EntityCategory.CONFIG
_attr_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = TIME_MINUTES
def __init__( def __init__(
self, self,
@ -54,13 +54,13 @@ class PeriodicVentingTime(CoordinatorEntity[Coordinator], NumberEntity):
self._attr_name = f"{device_info['name']} Periodic Venting" self._attr_name = f"{device_info['name']} Periodic Venting"
@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 data := self.coordinator.data: if data := self.coordinator.data:
return data.periodic_venting return data.periodic_venting
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."""
await self._device.send_periodic_venting(int(value)) await self._device.send_periodic_venting(int(value))
self.coordinator.async_set_updated_data(self._device.state) self.coordinator.async_set_updated_data(self._device.state)

View File

@ -97,18 +97,18 @@ class FluxSpeedNumber(
): ):
"""Defines a flux_led speed number.""" """Defines a flux_led speed number."""
_attr_min_value = 1 _attr_native_min_value = 1
_attr_max_value = 100 _attr_native_max_value = 100
_attr_step = 1 _attr_native_step = 1
_attr_mode = NumberMode.SLIDER _attr_mode = NumberMode.SLIDER
_attr_icon = "mdi:speedometer" _attr_icon = "mdi:speedometer"
@property @property
def value(self) -> float: def native_value(self) -> float:
"""Return the effect speed.""" """Return the effect speed."""
return cast(float, self._device.speed) return cast(float, self._device.speed)
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Set the flux speed value.""" """Set the flux speed value."""
current_effect = self._device.effect current_effect = self._device.effect
new_speed = int(value) new_speed = int(value)
@ -130,8 +130,8 @@ class FluxConfigNumber(
"""Base class for flux config numbers.""" """Base class for flux config numbers."""
_attr_entity_category = EntityCategory.CONFIG _attr_entity_category = EntityCategory.CONFIG
_attr_min_value = 1 _attr_native_min_value = 1
_attr_step = 1 _attr_native_step = 1
_attr_mode = NumberMode.BOX _attr_mode = NumberMode.BOX
def __init__( def __init__(
@ -153,18 +153,18 @@ class FluxConfigNumber(
logger=_LOGGER, logger=_LOGGER,
cooldown=DEBOUNCE_TIME, cooldown=DEBOUNCE_TIME,
immediate=False, immediate=False,
function=self._async_set_value, function=self._async_set_native_value,
) )
await super().async_added_to_hass() await super().async_added_to_hass()
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Set the value.""" """Set the value."""
self._pending_value = int(value) self._pending_value = int(value)
assert self._debouncer is not None assert self._debouncer is not None
await self._debouncer.async_call() await self._debouncer.async_call()
@abstractmethod @abstractmethod
async def _async_set_value(self) -> None: async def _async_set_native_value(self) -> None:
"""Call on debounce to set the value.""" """Call on debounce to set the value."""
def _pixels_and_segments_fit_in_music_mode(self) -> bool: def _pixels_and_segments_fit_in_music_mode(self) -> bool:
@ -189,19 +189,19 @@ class FluxPixelsPerSegmentNumber(FluxConfigNumber):
_attr_icon = "mdi:dots-grid" _attr_icon = "mdi:dots-grid"
@property @property
def max_value(self) -> int: def native_max_value(self) -> int:
"""Return the max value.""" """Return the max value."""
return min( return min(
PIXELS_PER_SEGMENT_MAX, int(PIXELS_MAX / (self._device.segments or 1)) PIXELS_PER_SEGMENT_MAX, int(PIXELS_MAX / (self._device.segments or 1))
) )
@property @property
def value(self) -> int: def native_value(self) -> int:
"""Return the pixels per segment.""" """Return the pixels per segment."""
assert self._device.pixels_per_segment is not None assert self._device.pixels_per_segment is not None
return self._device.pixels_per_segment return self._device.pixels_per_segment
async def _async_set_value(self) -> None: async def _async_set_native_value(self) -> None:
"""Set the pixels per segment.""" """Set the pixels per segment."""
assert self._pending_value is not None assert self._pending_value is not None
await self._device.async_set_device_config( await self._device.async_set_device_config(
@ -215,7 +215,7 @@ class FluxSegmentsNumber(FluxConfigNumber):
_attr_icon = "mdi:segment" _attr_icon = "mdi:segment"
@property @property
def max_value(self) -> int: def native_max_value(self) -> int:
"""Return the max value.""" """Return the max value."""
assert self._device.pixels_per_segment is not None assert self._device.pixels_per_segment is not None
return min( return min(
@ -223,12 +223,12 @@ class FluxSegmentsNumber(FluxConfigNumber):
) )
@property @property
def value(self) -> int: def native_value(self) -> int:
"""Return the segments.""" """Return the segments."""
assert self._device.segments is not None assert self._device.segments is not None
return self._device.segments return self._device.segments
async def _async_set_value(self) -> None: async def _async_set_native_value(self) -> None:
"""Set the segments.""" """Set the segments."""
assert self._pending_value is not None assert self._pending_value is not None
await self._device.async_set_device_config(segments=self._pending_value) await self._device.async_set_device_config(segments=self._pending_value)
@ -249,7 +249,7 @@ class FluxMusicPixelsPerSegmentNumber(FluxMusicNumber):
_attr_icon = "mdi:dots-grid" _attr_icon = "mdi:dots-grid"
@property @property
def max_value(self) -> int: def native_max_value(self) -> int:
"""Return the max value.""" """Return the max value."""
assert self._device.music_segments is not None assert self._device.music_segments is not None
return min( return min(
@ -258,12 +258,12 @@ class FluxMusicPixelsPerSegmentNumber(FluxMusicNumber):
) )
@property @property
def value(self) -> int: def native_value(self) -> int:
"""Return the music pixels per segment.""" """Return the music pixels per segment."""
assert self._device.music_pixels_per_segment is not None assert self._device.music_pixels_per_segment is not None
return self._device.music_pixels_per_segment return self._device.music_pixels_per_segment
async def _async_set_value(self) -> None: async def _async_set_native_value(self) -> None:
"""Set the music pixels per segment.""" """Set the music pixels per segment."""
assert self._pending_value is not None assert self._pending_value is not None
await self._device.async_set_device_config( await self._device.async_set_device_config(
@ -277,7 +277,7 @@ class FluxMusicSegmentsNumber(FluxMusicNumber):
_attr_icon = "mdi:segment" _attr_icon = "mdi:segment"
@property @property
def max_value(self) -> int: def native_max_value(self) -> int:
"""Return the max value.""" """Return the max value."""
assert self._device.pixels_per_segment is not None assert self._device.pixels_per_segment is not None
return min( return min(
@ -286,12 +286,12 @@ class FluxMusicSegmentsNumber(FluxMusicNumber):
) )
@property @property
def value(self) -> int: def native_value(self) -> int:
"""Return the music segments.""" """Return the music segments."""
assert self._device.music_segments is not None assert self._device.music_segments is not None
return self._device.music_segments return self._device.music_segments
async def _async_set_value(self) -> None: async def _async_set_native_value(self) -> None:
"""Set the music segments.""" """Set the music segments."""
assert self._pending_value is not None assert self._pending_value is not None
await self._device.async_set_device_config(music_segments=self._pending_value) await self._device.async_set_device_config(music_segments=self._pending_value)

View File

@ -40,24 +40,24 @@ NUMBERS = (
name="Grid export limit", name="Grid export limit",
icon="mdi:transmission-tower", icon="mdi:transmission-tower",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
getter=lambda inv: inv.get_grid_export_limit(), getter=lambda inv: inv.get_grid_export_limit(),
setter=lambda inv, val: inv.set_grid_export_limit(val), setter=lambda inv, val: inv.set_grid_export_limit(val),
step=100, native_step=100,
min_value=0, native_min_value=0,
max_value=10000, native_max_value=10000,
), ),
GoodweNumberEntityDescription( GoodweNumberEntityDescription(
key="battery_discharge_depth", key="battery_discharge_depth",
name="Depth of discharge (on-grid)", name="Depth of discharge (on-grid)",
icon="mdi:battery-arrow-down", icon="mdi:battery-arrow-down",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
getter=lambda inv: inv.get_ongrid_battery_dod(), getter=lambda inv: inv.get_ongrid_battery_dod(),
setter=lambda inv, val: inv.set_ongrid_battery_dod(val), setter=lambda inv, val: inv.set_ongrid_battery_dod(val),
step=1, native_step=1,
min_value=0, native_min_value=0,
max_value=99, native_max_value=99,
), ),
) )
@ -105,12 +105,12 @@ class InverterNumberEntity(NumberEntity):
self.entity_description = description self.entity_description = description
self._attr_unique_id = f"{DOMAIN}-{description.key}-{inverter.serial_number}" self._attr_unique_id = f"{DOMAIN}-{description.key}-{inverter.serial_number}"
self._attr_device_info = device_info self._attr_device_info = device_info
self._attr_value = float(current_value) self._attr_native_value = float(current_value)
self._inverter: Inverter = inverter self._inverter: Inverter = inverter
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.setter: if self.entity_description.setter:
await self.entity_description.setter(self._inverter, int(value)) await self.entity_description.setter(self._inverter, int(value))
self._attr_value = value self._attr_native_value = value
self.async_write_ha_state() self.async_write_ha_state()

View File

@ -104,26 +104,26 @@ class HomeKitNumber(CharacteristicEntity, NumberEntity):
return [self._char.type] return [self._char.type]
@property @property
def min_value(self) -> float: def native_min_value(self) -> float:
"""Return the minimum value.""" """Return the minimum value."""
return self._char.minValue or DEFAULT_MIN_VALUE return self._char.minValue or DEFAULT_MIN_VALUE
@property @property
def max_value(self) -> float: def native_max_value(self) -> float:
"""Return the maximum value.""" """Return the maximum value."""
return self._char.maxValue or DEFAULT_MAX_VALUE return self._char.maxValue or DEFAULT_MAX_VALUE
@property @property
def step(self) -> float: def native_step(self) -> float:
"""Return the increment/decrement step.""" """Return the increment/decrement step."""
return self._char.minStep or DEFAULT_STEP return self._char.minStep or DEFAULT_STEP
@property @property
def value(self) -> float: def native_value(self) -> float:
"""Return the current characteristic value.""" """Return the current characteristic value."""
return self._char.value return self._char.value
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Set the characteristic to this value.""" """Set the characteristic to this value."""
await self.async_put_characteristics( await self.async_put_characteristics(
{ {
@ -148,26 +148,26 @@ class HomeKitEcobeeFanModeNumber(CharacteristicEntity, NumberEntity):
return f"{prefix} Fan Mode" return f"{prefix} Fan Mode"
@property @property
def min_value(self) -> float: def native_min_value(self) -> float:
"""Return the minimum value.""" """Return the minimum value."""
return self._char.minValue or DEFAULT_MIN_VALUE return self._char.minValue or DEFAULT_MIN_VALUE
@property @property
def max_value(self) -> float: def native_max_value(self) -> float:
"""Return the maximum value.""" """Return the maximum value."""
return self._char.maxValue or DEFAULT_MAX_VALUE return self._char.maxValue or DEFAULT_MAX_VALUE
@property @property
def step(self) -> float: def native_step(self) -> float:
"""Return the increment/decrement step.""" """Return the increment/decrement step."""
return self._char.minStep or DEFAULT_STEP return self._char.minStep or DEFAULT_STEP
@property @property
def value(self) -> float: def native_value(self) -> float:
"""Return the current characteristic value.""" """Return the current characteristic value."""
return self._char.value return self._char.value
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Set the characteristic to this value.""" """Set the characteristic to this value."""
# Sending the fan mode request sometimes ends up getting ignored by ecobee # Sending the fan mode request sometimes ends up getting ignored by ecobee

View File

@ -29,16 +29,16 @@ class JuiceNetNumberEntityDescription(
): ):
"""An entity description for a JuiceNetNumber.""" """An entity description for a JuiceNetNumber."""
max_value_key: str | None = None native_max_value_key: str | None = None
NUMBER_TYPES: tuple[JuiceNetNumberEntityDescription, ...] = ( NUMBER_TYPES: tuple[JuiceNetNumberEntityDescription, ...] = (
JuiceNetNumberEntityDescription( JuiceNetNumberEntityDescription(
name="Amperage Limit", name="Amperage Limit",
key="current_charging_amperage_limit", key="current_charging_amperage_limit",
min_value=6, native_min_value=6,
max_value_key="max_charging_amperage", native_max_value_key="max_charging_amperage",
step=1, native_step=1,
setter_key="set_charging_amperage_limit", setter_key="set_charging_amperage_limit",
), ),
) )
@ -80,19 +80,19 @@ class JuiceNetNumber(JuiceNetDevice, NumberEntity):
self._attr_name = f"{self.device.name} {description.name}" self._attr_name = f"{self.device.name} {description.name}"
@property @property
def value(self) -> float | None: def native_value(self) -> float | None:
"""Return the value of the entity.""" """Return the value of the entity."""
return getattr(self.device, self.entity_description.key, None) return getattr(self.device, self.entity_description.key, None)
@property @property
def max_value(self) -> float: def native_max_value(self) -> float:
"""Return the maximum value.""" """Return the maximum value."""
if self.entity_description.max_value_key is not None: if self.entity_description.native_max_value_key is not None:
return getattr(self.device, self.entity_description.max_value_key) return getattr(self.device, self.entity_description.native_max_value_key)
if self.entity_description.max_value is not None: if self.entity_description.native_max_value is not None:
return self.entity_description.max_value return self.entity_description.native_max_value
return DEFAULT_MAX_VALUE return DEFAULT_MAX_VALUE
async def async_set_value(self, value: float) -> None: async def async_set_native_value(self, value: float) -> None:
"""Update the current value.""" """Update the current value."""
await getattr(self.device, self.entity_description.setter_key)(value) await getattr(self.device, self.entity_description.setter_key)(value)