Skip to content

Commit d8d1b49

Browse files
authored
Merge pull request #1493 from infradom/main
enhance debugging output; rename entity_group to scan_group
2 parents 5dc30f5 + 69f936f commit d8d1b49

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

custom_components/solax_modbus/__init__.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry)
163163
async def async_setup(hass, config):
164164
"""Set up the SolaX modbus component."""
165165
hass.data[DOMAIN] = {}
166-
_LOGGER.debug("solax data %d", hass.data)
166+
#_LOGGER.debug("solax data %d", hass.data)
167167
return True
168168

169169

@@ -190,7 +190,7 @@ def _load_plugin(plugin_name: str) -> ModuleType:
190190

191191
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
192192
"""Set up a SolaX modbus."""
193-
_LOGGER.debug(f"setup entries - data: {entry.data}, options: {entry.options}")
193+
_LOGGER.info(f"setup config entries - data: {entry.data}, options: {entry.options}")
194194
config = entry.options
195195
plugin_name = config[CONF_PLUGIN]
196196

@@ -376,7 +376,7 @@ def __init__(
376376
self.blocks_changed = False
377377
self.initial_groups = {} # as returned by the sensor setup - holdingRegs and inputRegs should not change
378378

379-
_LOGGER.debug("solax modbushub done %s", self.__dict__)
379+
#_LOGGER.debug("solax modbushub done %s", self.__dict__)
380380

381381

382382
async def async_init(self, *args: Any) -> None: # noqa: D102
@@ -447,14 +447,16 @@ def loadLocalData(self):
447447

448448
# end of save and load section
449449

450-
def entity_group(self, sensor): # seems to be called for non-sensor entities also - strange
450+
def scan_group(self, sensor): # seems to be called for non-sensor entities also - strange
451451
# scan group
452452
g = getattr(sensor.entity_description, "scan_group", None)
453453
if not g:
454454
regtype = getattr(sensor.entity_description, "register_type", None)
455455
if regtype == REG_HOLDING: g = self.plugin.default_holding_scangroup
456456
elif regtype == REG_INPUT: g = self.plugin.default_input_scangroup
457-
else: g = SCAN_GROUP_DEFAULT # should not occur
457+
else:
458+
_LOGGER.debug(f"**** default scan_group for {sensor.entity_description.key} returned {g} - {SCAN_GROUP_DEFAULT}")
459+
g = SCAN_GROUP_DEFAULT # should not occur
458460

459461
if g == SCAN_GROUP_AUTO:
460462
unit = getattr(sensor.entity_description, "native_unit_of_measurement", None)
@@ -471,8 +473,10 @@ def entity_group(self, sensor): # seems to be called for non-sensor entities als
471473
# scan interval
472474
g = self.config.get(g, None)
473475
# when declared but not present in config, use default; this MUST exist
474-
if not g:
476+
if g is None:
477+
_LOGGER.warning(f"Fast or Medium scan groups do not seem to exist in config: {g} using default {self.config[SCAN_GROUP_DEFAULT]}")
475478
g = self.config[SCAN_GROUP_DEFAULT]
479+
else: _LOGGER.debug(f"**** returning scan_group interval {g} for {sensor.entity_description.key}")
476480
return g
477481

478482
def device_group_key(self, device_info: DeviceInfo):
@@ -488,7 +492,7 @@ def device_group_key(self, device_info: DeviceInfo):
488492
async def async_add_solax_modbus_sensor(self, sensor: SolaXModbusSensor):
489493
"""Listen for data updates."""
490494
# This is the first sensor, set up interval.
491-
interval = self.entity_group(sensor)
495+
interval = self.scan_group(sensor)
492496
interval_group = self.groups.setdefault(interval, empty_hub_interval_group_lambda())
493497
if not interval_group.device_groups:
494498
interval_group.interval = interval
@@ -510,7 +514,7 @@ async def _refresh(_now: Optional[int] = None) -> None:
510514
@callback
511515
async def async_remove_solax_modbus_sensor(self, sensor):
512516
"""Remove data update."""
513-
interval = self.entity_group(sensor)
517+
interval = self.scan_group(sensor)
514518
interval_group = self.groups.get(interval, None)
515519
if interval_group is None:
516520
return
@@ -1144,8 +1148,8 @@ def rebuild_blocks(self, initial_groups): #, computedRegs):
11441148
#self.computedSensors = computedRegs # moved outside the loops
11451149
for i in hub_device_group.holdingBlocks: _LOGGER.info(f"{device_name} - interval {interval}s: adding holding block: {', '.join('0x{:x}'.format(num) for num in i.regs)}")
11461150
for i in hub_device_group.inputBlocks: _LOGGER.info(f"{device_name} - interval {interval}s: adding input block: {', '.join('0x{:x}'.format(num) for num in i.regs)}")
1147-
_LOGGER.debug(f"holdingBlocks: {hub_device_group.holdingBlocks}")
1148-
_LOGGER.debug(f"inputBlocks: {hub_device_group.inputBlocks}")
1151+
#_LOGGER.debug(f"holdingBlocks: {hub_device_group.holdingBlocks}")
1152+
#_LOGGER.debug(f"inputBlocks: {hub_device_group.inputBlocks}")
11491153
self.blocks_changed = False
11501154
_LOGGER.info(f"done rebuilding groups and blocks - post: {self.initial_groups.keys()}")
11511155

custom_components/solax_modbus/number.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ def __init__(
9898
self.entity_description = number_info
9999
self._write_method = number_info.write_method
100100

101-
async def async_added_to_hass(self) -> None:
102-
"""Register callbacks."""
103-
await self._hub.async_add_solax_modbus_sensor(self)
101+
#async def async_added_to_hass(self) -> None:
102+
# """Register callbacks."""
103+
# await self._hub.async_add_solax_modbus_sensor(self)
104104

105-
async def async_will_remove_from_hass(self) -> None:
106-
await self._hub.async_remove_solax_modbus_sensor(self)
105+
#async def async_will_remove_from_hass(self) -> None:
106+
# await self._hub.async_remove_solax_modbus_sensor(self)
107107

108108
""" remove duplicate declaration
109109
async def async_set_value(self, native_value: float) -> None:

custom_components/solax_modbus/select.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ def __init__(self,
6161
self._attr_options = list(select_info.option_dict.values())
6262
self._write_method = select_info.write_method
6363

64-
async def async_added_to_hass(self):
65-
"""Register callbacks."""
66-
await self._hub.async_add_solax_modbus_sensor(self)
64+
65+
##sync def async_added_to_hass(self):
66+
# """Register callbacks."""
67+
# await self._hub.async_add_solax_modbus_sensor(self)
68+
69+
#async def async_will_remove_from_hass(self) -> None:
70+
# await self._hub.async_remove_solax_modbus_sensor(self)
71+
6772

68-
async def async_will_remove_from_hass(self) -> None:
69-
await self._hub.async_remove_solax_modbus_sensor(self)
7073
@callback
7174
def modbus_data_updated(self):
7275
self.async_write_ha_state()

custom_components/solax_modbus/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def entityToListSingle(hub, hub_name, entities, groups, computedRegs, device_inf
177177
else: _LOGGER.warning(f"entity without modbus register address and without value_function found: {newdescr.key}")
178178
else:
179179
#target group
180-
interval_group = groups.setdefault(hub.entity_group(sensor), empty_input_interval_group_lambda())
180+
interval_group = groups.setdefault(hub.scan_group(sensor), empty_input_interval_group_lambda())
181181
device_group_key = hub.device_group_key(device_info)
182182
device_group = interval_group.device_groups.setdefault(device_group_key, empty_input_device_group_lambda())
183183
holdingRegs = device_group.holdingRegs

docs/developer_guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ To be documented:
8080
* _write_method_: int = `WRITE_SINGLE_MODBUS` # `WRITE_SINGLE_MOBUS` or `WRITE_MULTI_MODBUS` or `WRITE_DATA_LOCAL`
8181
* _sensor_key_: str = None # The associated sensor key
8282
* _initvalue_: int = None # initial default value for WRITE_DATA_LOCAL entities
83+
* _value_function_: callable = None
84+
85+
Currently switch entities are used when the modbus register contains different switches in one modbus register.
86+
If a switch entity has a `value_function, the value function will take 4 parameters: bit, state, key, datadict). The value function must extract the bit and return the state of that single bit.
8387

8488

8589
## Local Data Entities

0 commit comments

Comments
 (0)