Repository navigation
refactor DomoMaj #1489
Description
Activity
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
in progress. a first part done in 7.1.006
1- Fix if → elif / early return (lowest risk)
Within _domo_maj_one_cluster_type_entry, convert the sequential if blocks to an if/elif/else chain (or add return after each handler call). This alone eliminates the double-execution risk and makes intent clearer.2- Extract domain handler functions (medium refactor)
Break the single dispatcher into per-domain handler functions, each with a clear signature:_handle_electrical(self, Devices, NwkId, Ep, …) → bool _handle_climate(self, Devices, NwkId, Ep, …) → bool _handle_environment(self, Devices, NwkId, Ep, …) → bool _handle_motion_security(self, Devices, NwkId, Ep, …) → bool _handle_level_cover_color(self, Devices, NwkId, Ep, …) → bool _handle_water_quality(self, Devices, NwkId, Ep, …) → bool _handle_linky(self, Devices, NwkId, Ep, …) → bool _handle_special_widgets(self, Devices, NwkId, Ep, …) → boolEach returns True if it handled the update (so the dispatcher can stop) or False to pass to the next handler.
3- Introduce a dispatch table
Replace the flat if/elif chain in _domo_maj_one_cluster_type_entry with a ClusterType-keyed dispatch table:_CLUSTER_HANDLERS = { "Power": _handle_electrical, "Meter": _handle_electrical, "Ampere": _handle_electrical, "Voltage": _handle_electrical, "Temp": _handle_environment, "Humi": _handle_environment, "Baro": _handle_environment, "Lux": _handle_environment, "ThermoMode": _handle_climate, "ThermoSetpoint": _handle_climate, "FanControl": _handle_climate, "Motion": _handle_motion_security, "Door": _handle_motion_security, "Switch": _handle_motion_security, "LvlControl": _handle_level_cover_color, "WindowCovering": _handle_level_cover_color, "ColorControl*": _handle_level_cover_color, "phMeter": _handle_water_quality, "ec": _handle_water_quality, … }4- Hoist inline constants to module level
Move mode-mapping dicts (THERMOSTAT_MODE, FAN_MODE, FIL_PILOT_MODE, VALUE_MAPPING, etc.) out of function bodies to module-level constants (or into a companion domoMajConsts.py).5- split into sub-modules
If the file remains large after Steps 1–4, consider extracting the handler groups into separate files:
Modules/
domoMaj.py ← entry point + dispatcher only
domoMaj_electrical.py ← Power, Meter, P1Meter, ZLinky, Ampere…
domoMaj_climate.py ← Thermostat, FanControl, Valve…
domoMaj_environment.py ← Temp, Humi, Baro, Lux…
domoMaj_security.py ← Motion, Switch, Door, Alarm…
domoMaj_cover.py ← LvlControl, WindowCovering, ColorControl…
DomoMaj.py requires a big refactoring