refactor ha_confs() interface

This commit is contained in:
Stefan Allius
2024-03-29 19:21:59 +01:00
parent 5853518afe
commit 738dd708ac
7 changed files with 38 additions and 38 deletions

View File

@@ -87,7 +87,8 @@ class RegisterMap:
class InfosG3(Infos):
def ha_confs(self, ha_prfx, node_id, snr, singleton: bool, sug_area='') \
def ha_confs(self, ha_prfx: str, node_id: str, snr: str,
sug_area: str = '') \
-> Generator[tuple[dict, str], None, None]:
'''Generator function yields a json register struct for home-assistant
auto configuration and a unique entity string
@@ -98,11 +99,8 @@ class InfosG3(Infos):
entity strings
sug_area:str ==> suggested area string from the config file'''
# iterate over RegisterMap.map and get the register values
for key, reg in RegisterMap.map.items():
if reg not in self.info_defs:
continue
row = self.info_defs[reg]
res = self.ha_conf(row, reg, ha_prfx, node_id, snr, singleton, sug_area) # noqa: E501
for reg in RegisterMap.map.values():
res = self.ha_conf(reg, ha_prfx, node_id, snr, False, sug_area) # noqa: E501
if res:
yield res

View File

@@ -110,7 +110,7 @@ class InverterG3(Inverter, ConnectionG3):
'''register all our topics at home assistant'''
for data_json, component, node_id, id in self.db.ha_confs(
self.entity_prfx, self.node_id, self.unique_id,
False, self.sug_area):
self.sug_area):
logger_mqtt.debug(f"MQTT Register: cmp:'{component}'"
f" node_id:'{node_id}' {data_json}")
await self.mqtt.publish(f"{self.discovery_prfx}{component}"