Skip to content

Commit

Permalink
reformatting modbus items
Browse files Browse the repository at this point in the history
  • Loading branch information
OStrama committed Oct 27, 2024
1 parent 25bb43d commit fca0cfc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 239 deletions.
12 changes: 6 additions & 6 deletions custom_components/weishaupt_modbus/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
256 changes: 31 additions & 225 deletions custom_components/weishaupt_modbus/hpconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions custom_components/weishaupt_modbus/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/weishaupt_modbus/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/weishaupt_modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit fca0cfc

Please sign in to comment.