Skip to content

Commit

Permalink
Fixes for range and for setting number values
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsK1 committed Oct 23, 2024
1 parent 38cb5c8 commit f398aff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/solvis_control/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async def async_setup_entry(
register.range_data,
register.step_size,
register.address,
register.multiplier,
)
)

Expand All @@ -107,10 +108,12 @@ def __init__(
range_data: tuple = None,
step_size: int | None = None,
modbus_address: int = None,
multiplier: float = 1,
):
"""Initialize the Solvis number entity."""
super().__init__(coordinator)

self.multiplier = multiplier
self.modbus_address = modbus_address
self._address = address
self._response_key = name
Expand All @@ -125,12 +128,13 @@ def __init__(
self.translation_key = name
if step_size is not None:
self.native_step = step_size
else:
self.native_step = 1.0

# Set min/max values if provided in range_data
if range_data:
self.native_min_value = range_data[0]
self.native_max_value = range_data[1]
self.native_step = 1.0

@callback
def _handle_coordinator_update(self) -> None:
Expand Down Expand Up @@ -170,7 +174,7 @@ async def async_set_native_value(self, value: float) -> None:
try:
await self.coordinator.modbus.connect()
await self.coordinator.modbus.write_register(
self.modbus_address, int(value), slave=1
self.modbus_address, int(value / self.multiplier), slave=1
)
except ConnectionException:
_LOGGER.warning("Couldn't connect to device")
Expand Down

0 comments on commit f398aff

Please sign in to comment.