Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugwise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
), # Available with the Loria and Elga (newer Anna firmware) heatpumps
"cooling_state": UOM(NONE),
"domestic_hot_water_mode": DATA("select_dhw_mode", NONE),
"domestic_hot_water_comfort_mode": DATA("select_dhw_mode", NONE),
"domestic_hot_water_setpoint": UOM(TEMP_CELSIUS),
"domestic_hot_water_state": DATA("dhw_state", NONE),
"domestic_hot_water_temperature": DATA("dhw_temperature", TEMP_CELSIUS),
Expand Down
40 changes: 31 additions & 9 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@
appl := self._appl_heater_central_info(appl, appliance, False)
): # False means non-legacy entity
return Munch()
self._dhw_allowed_modes = self._get_appl_actuator_modes(
appliance, "domestic_hot_water_mode_control_functionality"
)
self._collect_dhw_modes(appliance)

return appl
case _ as s if s.endswith("_plug"):
# Collect info from plug-types (Plug, Aqara Smart Plug)
Expand All @@ -265,6 +264,18 @@
case _: # pragma: no cover
return Munch()

def _collect_dhw_modes(self, appliance: etree.Element) -> None:
"""Collect the DHW modes."""
# Collect the Loria dhw_modes
self._dhw_allowed_modes = self._get_appl_actuator_modes(
appliance, "domestic_hot_water_mode_control_functionality"
)
# Collect the default dhw modes: comfort and off
if not self._dhw_allowed_modes:
self._get_toggle_state(
appliance, "domestic_hot_water_comfort_mode", "dhw_cm_switch", None

Check failure on line 276 in plugwise/helper.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change this argument; Function "_get_toggle_state" expects a different type

See more on https://sonarcloud.io/project/issues?id=plugwise_python-plugwise&issues=AZ6wNCaVmCdZ_xXR-5TY&open=AZ6wNCaVmCdZ_xXR-5TY&pullRequest=883
)

Comment thread
bouwew marked this conversation as resolved.
def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
"""Helper-function for _appliance_info_finder()."""
self._gateway_id = appl.entity_id
Expand Down Expand Up @@ -351,7 +362,7 @@
measurements = DEVICE_MEASUREMENTS
if self._is_thermostat and entity_id == self.heater_id:
measurements = HEATER_CENTRAL_MEASUREMENTS
# Show the allowed dhw_modes (Loria only)
# Show the available dhw_modes
if self._dhw_allowed_modes:
data["dhw_modes"] = self._dhw_allowed_modes
# Counting of this item is done in _appliance_measurements()
Expand Down Expand Up @@ -407,12 +418,14 @@
if (
appliance := self._domain_objects.find(f'./appliance[@id="{entity_id}"]')
) is not None:
# Collect the cooling enabled toggle state
self._get_toggle_state(
appliance, "cooling_enabled", "cooling_ena_switch", data
)

self._appliance_measurements(appliance, data, measurements)
self._get_lock_state(appliance, data)

for toggle, name in TOGGLES.items():
self._get_toggle_state(appliance, toggle, name, data)

if appliance.find("type").text in ACTUATOR_CLASSES:
self._get_actuator_functionalities(appliance, entity, data)

Expand All @@ -438,7 +451,7 @@
self._count += len(data["sensors"])
return data

def _appliance_measurements(

Check failure on line 454 in plugwise/helper.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=plugwise_python-plugwise&issues=AZ6wNCaVmCdZ_xXR-5TZ&open=AZ6wNCaVmCdZ_xXR-5TZ&pullRequest=883
self,
appliance: etree.Element,
data: GwEntityData,
Expand All @@ -452,6 +465,7 @@
continue

if new_name := getattr(attrs, ATTR_NAME, None):
old_measurement = measurement
measurement = new_name

match measurement:
Expand All @@ -460,6 +474,10 @@
case "select_dhw_mode":
if self._dhw_allowed_modes:
data["select_dhw_mode"] = appl_p_loc.text
if old_measurement == "domestic_hot_water_comfort_mode":
data["select_dhw_mode"] = (
"comfort" if appl_p_loc.text == "on" else "off"
)

common_match_cases(measurement, attrs, appl_p_loc, data)

Expand All @@ -482,8 +500,12 @@
if xml.find("type").text == "heater_central":
locator = f"./actuator_functionalities/toggle_functionality[type='{toggle}']/state"
if (state := xml.find(locator)) is not None:
data["switches"][name] = state.text == "on"
self._count += 1
match toggle:
case "cooling_enabled":
data["switches"][name] = state.text == "on"
self._count += 1
case "domestic_hot_water_comfort_mode":
self._dhw_allowed_modes = ["comfort", "off"]

def _get_plugwise_notifications(self) -> None:
"""Collect the Plugwise notifications."""
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_bad_thermostat.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"heating_state": false
},
"dev_class": "heater_central",
"dhw_modes": [
"comfort",
"off"
],
"location": "856285a783f24bf4b2573c8bc510eabf",
"max_dhw_temperature": {
"lower_bound": 0.0,
Expand All @@ -23,6 +27,7 @@
"model": "Generic heater",
"model_id": "1.1",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"dhw_temperature": 49.9,
"intended_boiler_temperature": 0.0,
Expand All @@ -31,9 +36,6 @@
"return_temperature": 33.0,
"water_temperature": 20.9
},
"switches": {
"dhw_cm_switch": false
},
"vendor": "WeHeat"
},
"3ee6b9486cb04c258a3130fff2b144a4": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_heatpump_cooling.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
},
"dev_class": "heater_central",
"location": "eedadcb297564f1483faa509179aebed",
"dhw_modes": [
"comfort",
"off"
],
"max_dhw_temperature": {
"lower_bound": 40.0,
"resolution": 0.01,
Expand All @@ -59,6 +63,7 @@
"model": "Generic heater/cooler",
"model_id": "17.1",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"dhw_temperature": 63.5,
"intended_boiler_temperature": 0.0,
Expand All @@ -68,9 +73,6 @@
"water_pressure": 2.0,
"water_temperature": 24.5
},
"switches": {
"dhw_cm_switch": true
},
"vendor": "Remeha B.V."
},
"1053c8bbf8be43c6921742b146a625f1": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_jip.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@
},
"dev_class": "heater_central",
"location": "9e4433a9d69f40b3aefd15e74395eaec",
"dhw_modes": [
"comfort",
"off"
],
"max_dhw_temperature": {
"lower_bound": 40.0,
"resolution": 0.01,
Expand All @@ -345,16 +349,14 @@
"model": "Generic heater",
"model_id": "10.20",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"intended_boiler_temperature": 0.0,
"modulation_level": 0.0,
"return_temperature": 37.1,
"water_pressure": 1.4,
"water_temperature": 37.3
},
"switches": {
"dhw_cm_switch": false
},
"vendor": "Remeha B.V."
},
"f61f1a2535f54f52ad006a3d18e459ca": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_onoff_cooling_fake_firmware.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
},
"dev_class": "heater_central",
"location": "eedadcb297564f1483faa509179aebed",
"dhw_modes": [
"comfort",
"off"
],
"max_dhw_temperature": {
"lower_bound": 40.0,
"resolution": 0.01,
Expand All @@ -23,6 +27,7 @@
},
"model": "Unknown",
"name": "OnOff",
"select_dhw_mode": "comfort",
"sensors": {
"dhw_temperature": 63.5,
"intended_boiler_temperature": 0.0,
Expand All @@ -31,9 +36,6 @@
"return_temperature": 24.9,
"water_pressure": 2.0,
"water_temperature": 24.5
},
"switches": {
"dhw_cm_switch": true
}
},
"7d97fc3117784cfdafe347bcedcbbbcb": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_plus_anna.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
},
"dev_class": "heater_central",
"location": "07d618f0bb80412687f065b8698ce3e7",
"dhw_modes": [
"comfort",
"off"
],
"maximum_boiler_temperature": {
"lower_bound": 0.0,
"resolution": 1.0,
Expand All @@ -43,12 +47,10 @@
},
"model": "Generic heater",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"intended_boiler_temperature": 0.0,
"water_temperature": 48.0
},
"switches": {
"dhw_cm_switch": false
}
},
"aa6b0002df0a46e1b1eb94beb61eddfe": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_plus_anna_new.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"dev_class": "heater_central",
"location": "bc93488efab249e5bc54fd7e175a6f91",
"dhw_modes": [
"comfort",
"off"
],
"maximum_boiler_temperature": {
"lower_bound": 25.0,
"resolution": 0.01,
Expand All @@ -16,12 +20,10 @@
},
"model": "Generic heater",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"intended_boiler_temperature": 22.5,
"water_temperature": 43.0
},
"switches": {
"dhw_cm_switch": false
}
},
"10016900610d4c7481df78c89606ef22": {
Expand Down
8 changes: 5 additions & 3 deletions tests/data/adam/adam_plus_anna_new_regulation_off.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"dev_class": "heater_central",
"location": "bc93488efab249e5bc54fd7e175a6f91",
"dhw_modes": [
"comfort",
"off"
],
"maximum_boiler_temperature": {
"lower_bound": 25.0,
"resolution": 0.01,
Expand All @@ -16,12 +20,10 @@
},
"model": "Generic heater",
"name": "OpenTherm",
"select_dhw_mode": "off",
"sensors": {
"intended_boiler_temperature": 0.0,
"water_temperature": 30.0
},
"switches": {
"dhw_cm_switch": false
}
},
"10016900610d4c7481df78c89606ef22": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def test_connect_adam_plus_anna_new(self):

test_items = await self.device_test(api, "2025-10-12 00:00:01", testdata)
assert api.gateway_id == "da224107914542988a88561b4452b0f6"
assert self.entity_items == 231
assert self.entity_items == 232
assert test_items == self.entity_items
assert self.entity_list == [
"da224107914542988a88561b4452b0f6",
Expand Down
Loading