mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Support float in modbus register sensor (#86128)
register sensor should support float
This commit is contained in:
parent
6f44bd43b0
commit
bcd4c031c6
@ -110,7 +110,9 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
|
|||||||
result = self.unpack_structure_result(raw_result.registers)
|
result = self.unpack_structure_result(raw_result.registers)
|
||||||
if self._coordinator:
|
if self._coordinator:
|
||||||
if result:
|
if result:
|
||||||
result_array = list(map(int, result.split(",")))
|
result_array = list(
|
||||||
|
map(float if self._precision else int, result.split(","))
|
||||||
|
)
|
||||||
self._attr_native_value = result_array[0]
|
self._attr_native_value = result_array[0]
|
||||||
self._coordinator.async_set_updated_data(result_array)
|
self._coordinator.async_set_updated_data(result_array)
|
||||||
else:
|
else:
|
||||||
@ -131,7 +133,7 @@ class SlaveSensor(
|
|||||||
RestoreEntity,
|
RestoreEntity,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
):
|
):
|
||||||
"""Modbus slave binary sensor."""
|
"""Modbus slave register sensor."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -139,7 +141,7 @@ class SlaveSensor(
|
|||||||
idx: int,
|
idx: int,
|
||||||
entry: dict[str, Any],
|
entry: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Modbus binary sensor."""
|
"""Initialize the Modbus register sensor."""
|
||||||
idx += 1
|
idx += 1
|
||||||
self._idx = idx
|
self._idx = idx
|
||||||
self._attr_name = f"{entry[CONF_NAME]} {idx}"
|
self._attr_name = f"{entry[CONF_NAME]} {idx}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user