Skip to content

Commit

Permalink
Add support for number native step smaller than 1 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
alengwenus authored Mar 2, 2024
1 parent 2976318 commit 27eab16
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions custom_components/smaev/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SmaEvChargerNumberEntityDescription(NumberEntityDescription):
translation_key="energy_charge_session",
type=SMAEV_PARAMETER,
channel="Parameter.Chrg.Plan.En",
native_step=1,
native_step=0.1,
mode=NumberMode.BOX,
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
entity_registry_enabled_default=True,
Expand All @@ -90,7 +90,7 @@ class SmaEvChargerNumberEntityDescription(NumberEntityDescription):
translation_key="charge_current_limit",
type=SMAEV_PARAMETER,
channel="Parameter.Inverter.AcALim",
native_step=1,
native_step=0.001,
mode=NumberMode.BOX,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
entity_registry_enabled_default=False,
Expand Down Expand Up @@ -166,6 +166,7 @@ def __init__(
self._attr_unique_id = f"{config_entry.unique_id}-{self.entity_description.key}"
self._attr_native_min_value = SMAEV_DEFAULT_MIN
self._attr_native_max_value = SMAEV_DEFAULT_MAX
self._attr_native_step = entity_description.native_step

@callback
def _handle_coordinator_update(self) -> None:
Expand All @@ -177,7 +178,9 @@ def _handle_coordinator_update(self) -> None:

min_value = channel.get(SMAEV_MIN_VALUE)
max_value = channel.get(SMAEV_MAX_VALUE)
value = int(float(channel[SMAEV_VALUE]))
value = float(channel[SMAEV_VALUE])
if self.native_step == 1:
value = int(value)
if (
(min_value is not None)
and (max_value is not None)
Expand All @@ -199,6 +202,8 @@ async def force_refresh(self):

async def async_set_native_value(self, value: float) -> None:
"""Update to the EV charger."""
if self.native_step == 1:
value = int(value)
evcharger = self.coordinator.evcharger
await evcharger.set_parameter(f"{value:.0f}", self.entity_description.channel)
await evcharger.set_parameter(f"{value}", self.entity_description.channel)
await self.coordinator.async_request_refresh()

0 comments on commit 27eab16

Please sign in to comment.