Skip to content

Commit aa647dc

Browse files
committed
Fix depreciation-warning
1 parent 8a1f930 commit aa647dc

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

plugwise/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
from plugwise.constants import ModelData
8-
from plugwise.util import check_heater_central, check_model, get_vendor_name
8+
from plugwise.util import check_heater_central, check_model, get_vendor_name, safe
99

1010
from defusedxml import ElementTree as etree
1111
from munch import Munch
@@ -32,7 +32,7 @@ def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None)
3232
"""Helper-function for _appliance_info_finder()."""
3333
locator = "./logs/point_log[type='thermostat']/thermostat"
3434
mod_type = "thermostat"
35-
xml_2 = xml_2 or self._domain_objects
35+
xml_2 = safe(xml_2, self._domain_objects)
3636
module_data = self._get_module_data(xml_1, locator, mod_type, xml_2)
3737
appl.vendor_name = module_data["vendor_name"]
3838
appl.model = check_model(module_data["vendor_model"], appl.vendor_name)
@@ -56,7 +56,8 @@ def _appl_heater_central_info(
5656

5757
# Find the valid heater_central
5858
# xml_2 self._appliances for legacy, self._domain_objects for actual
59-
self._heater_id = check_heater_central(xml_2 or self._domain_objects)
59+
xml_2 = safe(xml_2, self._domain_objects)
60+
self._heater_id = check_heater_central(xml_2)
6061

6162
# Info for On-Off device
6263
if self._on_off_device:
@@ -72,7 +73,7 @@ def _appl_heater_central_info(
7273
mod_type = "boiler_state"
7374
# xml_1: appliance
7475
# xml_3: self._modules for legacy, self._domain_objects for actual
75-
xml_3 = xml_3 or self._domain_objects
76+
xml_3 = safe(xml_3, self._domain_objects)
7677
module_data = self._get_module_data(xml_1, locator_1, mod_type, xml_3)
7778
if not module_data["contents"]:
7879
module_data = self._get_module_data(xml_1, locator_2, mod_type, xml_3)

plugwise/util.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ def power_data_local_format(
113113
return format_measure(val, attrs_uom)
114114

115115

116+
def remove_empty_platform_dicts(data: DeviceData) -> None:
117+
"""Helper-function for removing any empty platform dicts."""
118+
if not data["binary_sensors"]:
119+
data.pop("binary_sensors")
120+
if not data["sensors"]:
121+
data.pop("sensors")
122+
if not data["switches"]:
123+
data.pop("switches")
124+
125+
126+
def safe(value, default):
127+
"""Return default when value is None."""
128+
return value if value is not None else default
129+
130+
116131
# NOTE: this function version_to_model is shared between Smile and USB
117132
def version_to_model(version: str | None) -> str | None:
118133
"""Translate hardware_version to device type."""
@@ -128,13 +143,3 @@ def version_to_model(version: str | None) -> str | None:
128143
model = HW_MODELS.get(version[-2:] + version[-4:-2] + version[-6:-4])
129144

130145
return model if model is not None else "Unknown"
131-
132-
133-
def remove_empty_platform_dicts(data: DeviceData) -> None:
134-
"""Helper-function for removing any empty platform dicts."""
135-
if not data["binary_sensors"]:
136-
data.pop("binary_sensors")
137-
if not data["sensors"]:
138-
data.pop("sensors")
139-
if not data["switches"]:
140-
data.pop("switches")

0 commit comments

Comments
 (0)