From fca0cfc920d50d02ba6512740c123372a766fd72 Mon Sep 17 00:00:00 2001 From: Olaf Strama Date: Sun, 27 Oct 2024 17:38:42 +0000 Subject: [PATCH] reformatting modbus items --- .../weishaupt_modbus/entities.py | 12 +- custom_components/weishaupt_modbus/hpconst.py | 256 +++--------------- custom_components/weishaupt_modbus/number.py | 4 +- custom_components/weishaupt_modbus/select.py | 4 +- custom_components/weishaupt_modbus/sensor.py | 8 +- 5 files changed, 45 insertions(+), 239 deletions(-) diff --git a/custom_components/weishaupt_modbus/entities.py b/custom_components/weishaupt_modbus/entities.py index 227eca6..962b6b7 100644 --- a/custom_components/weishaupt_modbus/entities.py +++ b/custom_components/weishaupt_modbus/entities.py @@ -45,7 +45,7 @@ async def check_available(modbus_item, config_entry) -> bool: return False -async def BuildEntityList(entries, config_entry, modbusitems, item_type, coordinator): +async def build_entity_list(entries, config_entry, modbusitems, item_type, coordinator): """Build entity list. function builds a list of entities that can be used as parameter by async_setup_entry() @@ -145,16 +145,16 @@ async def fetch_data(self, idx=None): # if idx is not None: if idx is None: # first run: Update all entitiys - toUpdate = tuple(range(len(self._modbusitems))) + to_update = tuple(range(len(self._modbusitems))) elif len(idx) == 0: # idx exists but is not yet filled up: Update all entitiys. - toUpdate = tuple(range(len(self._modbusitems))) + to_update = tuple(range(len(self._modbusitems))) else: # idx exists and is filled up: Update only entitys requested by the coordinator. - toUpdate = idx + to_update = idx # await self._modbus_api.connect() - for index in toUpdate: + for index in to_update: item = self._modbusitems[index] match item.type: # here the entities are created with the parameters provided by the ModbusItem object @@ -502,7 +502,7 @@ def __init__(self, config_entry, modbus_item, coordinator, idx=None) -> None: ] # option list build from the status list of the ModbusItem self.options = [] - for index, item in enumerate(self._modbus_item._resultlist): + for _useless, item in enumerate(self._modbus_item._resultlist): self.options.append(item.text) async def async_select_option(self, option: str) -> None: diff --git a/custom_components/weishaupt_modbus/hpconst.py b/custom_components/weishaupt_modbus/hpconst.py index 514ea37..2cdba33 100644 --- a/custom_components/weishaupt_modbus/hpconst.py +++ b/custom_components/weishaupt_modbus/hpconst.py @@ -328,6 +328,8 @@ class DeviceConstants: StatusItem(33104, "y"), ] +# pylint: disable=line-too-long + ############################################################################################################################## # Modbus Register List: # # https://docs.google.com/spreadsheets/d/1EZ3QgyB41xaXo4B5CfZe0Pi8KPwzIGzK/edit?gid=1730751621#gid=1730751621 # @@ -415,229 +417,33 @@ class DeviceConstants: ModbusItem( 44103, "Bivalenztemperatur", FORMATS.TEMPERATUR, TYPES.NUMBER, DEVICES.W2, TEMPRANGE_BIVALENZ), ModbusItem( 44104, "Bivalenztemperatur WW", FORMATS.TEMPERATUR, TYPES.NUMBER, DEVICES.W2, TEMPRANGE_BIVALENZ), - ModbusItem( - 36101, - "Gesamt Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36102, - "Gesamt Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36103, - "Gesamt Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36104, - "Gesamt Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36201, - "Heizen Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36202, - "Heizen Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36203, - "Heizen Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36204, - "Heizen Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36301, - "Warmwasser Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36302, - "Warmwasser Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36303, - "Warmwasser Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36304, - "Warmwasser Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36401, - "Kühlen Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36402, - "Kühlen Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36403, - "Kühlen Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36404, - "Kühlen Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36501, - "Abtauen Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36502, - "Abtauen Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36503, - "Abtauen Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36504, - "Abtauen Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36601, - "Gesamt Energie II heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36602, - "Gesamt Energie II gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36603, - "Gesamt Energie II Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36604, - "Gesamt Energie II Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36701, - "Elektr. Energie heute", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36702, - "Elektr. Energie gestern", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36703, - "Elektr. Energie Monat", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), - ModbusItem( - 36704, - "Elektr. Energie Jahr", - FORMATS.ENERGY, - TYPES.SENSOR, - DEVICES.ST, - RANGE_ENERGY, - ), -] + ModbusItem( 36101, "Gesamt Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36102, "Gesamt Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36103, "Gesamt Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36104, "Gesamt Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36201, "Heizen Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36202, "Heizen Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36203, "Heizen Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36204, "Heizen Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36301, "Warmwasser Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36302, "Warmwasser Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36303, "Warmwasser Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36304, "Warmwasser Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36401, "Kühlen Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36402, "Kühlen Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36403, "Kühlen Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36404, "Kühlen Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36501, "Abtauen Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36502, "Abtauen Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36503, "Abtauen Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36504, "Abtauen Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36601, "Gesamt Energie II heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36602, "Gesamt Energie II gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36603, "Gesamt Energie II Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36604, "Gesamt Energie II Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36701, "Elektr. Energie heute", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36702, "Elektr. Energie gestern", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36703, "Elektr. Energie Monat", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), + ModbusItem( 36704, "Elektr. Energie Jahr", FORMATS.ENERGY, TYPES.SENSOR, DEVICES.ST, RANGE_ENERGY), +] # noqa: E501 # fmt: on diff --git a/custom_components/weishaupt_modbus/number.py b/custom_components/weishaupt_modbus/number.py index 2627fac..622eb14 100644 --- a/custom_components/weishaupt_modbus/number.py +++ b/custom_components/weishaupt_modbus/number.py @@ -10,7 +10,7 @@ # from time import gmtime, strftime from .const import TYPES from .hpconst import MODBUS_SYS_ITEMS -from .entities import BuildEntityList, MyCoordinator +from .entities import build_entity_list, MyCoordinator # from .modbusobject import ModbusAPI @@ -29,7 +29,7 @@ async def async_setup_entry( entries = [] async_add_entities( - await BuildEntityList( + await build_entity_list( entries, config_entry, MODBUS_SYS_ITEMS, TYPES.NUMBER, coordinator ), update_before_add=True, diff --git a/custom_components/weishaupt_modbus/select.py b/custom_components/weishaupt_modbus/select.py index ec653ac..e5c1c6f 100644 --- a/custom_components/weishaupt_modbus/select.py +++ b/custom_components/weishaupt_modbus/select.py @@ -6,7 +6,7 @@ from .const import TYPES from .hpconst import MODBUS_SYS_ITEMS -from .entities import BuildEntityList, MyCoordinator +from .entities import build_entity_list, MyCoordinator async def async_setup_entry( @@ -22,7 +22,7 @@ async def async_setup_entry( entries = [] async_add_entities( - await BuildEntityList( + await build_entity_list( entries, config_entry, MODBUS_SYS_ITEMS, TYPES.SELECT, coordinator ), update_before_add=True, diff --git a/custom_components/weishaupt_modbus/sensor.py b/custom_components/weishaupt_modbus/sensor.py index d72824b..0db03e7 100644 --- a/custom_components/weishaupt_modbus/sensor.py +++ b/custom_components/weishaupt_modbus/sensor.py @@ -8,7 +8,7 @@ from .const import TYPES from .hpconst import MODBUS_SYS_ITEMS -from .entities import BuildEntityList, MyCoordinator +from .entities import build_entity_list, MyCoordinator async def async_setup_entry( @@ -25,14 +25,14 @@ async def async_setup_entry( entries = [] - entries = await BuildEntityList( + entries = await build_entity_list( entries, config_entry, MODBUS_SYS_ITEMS, TYPES.NUMBER_RO, coordinator ) - entries = await BuildEntityList( + entries = await build_entity_list( entries, config_entry, MODBUS_SYS_ITEMS, TYPES.SENSOR_CALC, coordinator ) async_add_entities( - await BuildEntityList( + await build_entity_list( entries, config_entry, MODBUS_SYS_ITEMS, TYPES.SENSOR, coordinator ), update_before_add=True,