Skip to content

Commit

Permalink
Added param dictionary for ModbusItwems
Browse files Browse the repository at this point in the history
  • Loading branch information
OStrama committed Nov 30, 2024
1 parent 7b09482 commit b9b5366
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 169 deletions.
14 changes: 7 additions & 7 deletions custom_components/weishaupt_modbus/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
CONF_HK4,
CONF_HK5,
)
from .hpconst import DEVICES, TEMPRANGE_STD
from .hpconst import DEVICES, PARAMS_STDTEMP
from .items import ModbusItem
from .modbusobject import ModbusObject, ModbusAPI
from .configentry import MyConfigEntry
Expand Down Expand Up @@ -127,32 +127,32 @@ async def fetch_data(self, idx=None):
case TYPES.SENSOR_CALC:
r1 = await self.get_value_a(item)
item_x = ModbusItem(
item.get_number_from_text("x"),
item.params["x"],
"x",
FORMATS.TEMPERATUR,
TYPES.SENSOR_CALC,
DEVICES.SYS,
TEMPRANGE_STD,
params=PARAMS_STDTEMP,
)
r2 = await self.get_value(item_x)
if r2 is None:
# use Aussentemperatur if Luftansaugtemperatur not available
item_x = ModbusItem(
item.get_number_from_text("x2"),
item.params["x2"],
"x2",
FORMATS.TEMPERATUR,
TYPES.SENSOR_CALC,
DEVICES.SYS,
TEMPRANGE_STD,
params=PARAMS_STDTEMP,
)
r2 = await self.get_value(item_x)
item_y = ModbusItem(
item.get_number_from_text("y"),
item.params["y"],
"y",
FORMATS.TEMPERATUR,
TYPES.SENSOR_CALC,
DEVICES.WP,
TEMPRANGE_STD,
params=PARAMS_STDTEMP,
)
r3 = await self.get_value(item_y)

Expand Down
24 changes: 10 additions & 14 deletions custom_components/weishaupt_modbus/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,12 @@ def __init__(
):
self._attr_state_class = SensorStateClass.MEASUREMENT

if self._modbus_item.resultlist is not None:
self._attr_native_min_value = self._modbus_item.get_number_from_text(
"min"
)
self._attr_native_max_value = self._modbus_item.get_number_from_text(
"max"
)
self._attr_native_step = self._modbus_item.get_number_from_text("step")
self._divider = self._modbus_item.get_number_from_text("divider")
self._attr_device_class = self._modbus_item.get_text_from_number(-1)
if self._modbus_item.params is not None:
self._attr_native_min_value = self._modbus_item.params["min"]
self._attr_native_max_value = self._modbus_item.params["max"]
self._attr_native_step = self._modbus_item.params["step"]
self._divider = self._modbus_item.params["divider"]
self._attr_device_class = self._modbus_item.params["deviceclass"]

def translate_val(self, val) -> float:
"""Translate modbus value into sensful format."""
Expand Down Expand Up @@ -370,10 +366,10 @@ def __init__(
self._idx = idx
MyEntity.__init__(self, config_entry, modbus_item, coordinator._modbus_api)

if self._modbus_item.resultlist is not None:
self._attr_native_min_value = self._modbus_item.get_number_from_text("min")
self._attr_native_max_value = self._modbus_item.get_number_from_text("max")
self._attr_native_step = self._modbus_item.get_number_from_text("step")
# if self._modbus_item.resultlist is not None:
# self._attr_native_min_value = self._modbus_item.get_number_from_text("min")
# self._attr_native_max_value = self._modbus_item.get_number_from_text("max")
# self._attr_native_step = self._modbus_item.get_number_from_text("step")

@callback
def _handle_coordinator_update(self) -> None:
Expand Down
Loading

0 comments on commit b9b5366

Please sign in to comment.