Skip to content

Commit 43d8692

Browse files
authored
Merge pull request #109 from plugwise/removed_thermostat
Detect removed thermostats
2 parents 93dbe9f + c9a4d74 commit 43d8692

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.15.4 - Smile - Bugfix: handle removed thermostats
4+
- Recognize when a thermostat has been removed from a zone and don't show it in Core
5+
- Rename Group Switch to Switchgroup, remove vendor name
6+
37
## v0.15.3 - Skipping, not released
48

59
## v0.15.2 - Smile: Implement possible fix for HA Core issue #59711

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.15.2"
3+
__version__ = "0.15.4"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import Stick

plugwise/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@
365365
DEFAULT_TIMEOUT = 30
366366
DEFAULT_USERNAME = "smile"
367367
DEFAULT_PORT = 80
368+
FAKE_LOC = "0000aaaa0000aaaa0000aaaa0000aa00"
368369

369370
SEVERITIES = ["other", "info", "warning", "error"]
370371
SWITCH_GROUP_TYPES = ["switching", "report"]
@@ -396,8 +397,6 @@
396397
# Excluded:
397398
# zone_thermosstat 'temperature_offset'
398399
# radiator_valve 'uncorrected_temperature', 'temperature_offset'
399-
400-
401400
DEVICE_MEASUREMENTS = {
402401
# HA Core current_temperature
403402
"temperature": {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS},

plugwise/helper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
DOMAIN_OBJECTS,
3030
ENERGY_KILO_WATT_HOUR,
3131
ENERGY_WATT_HOUR,
32+
FAKE_LOC,
3233
FLAME_ICON,
3334
HEATER_CENTRAL_MEASUREMENTS,
3435
HEATING_ICON,
@@ -314,20 +315,20 @@ def _locations_legacy(self):
314315
Create locations for legacy devices.
315316
"""
316317
appliances = set()
317-
self._home_location = 0
318+
self._home_location = FAKE_LOC
318319

319320
# Add Anna appliances
320321
for appliance in self._appliances.findall("./appliance"):
321322
appliances.add(appliance.attrib["id"])
322323

323324
if self.smile_type == "thermostat":
324-
self._loc_data[0] = {
325+
self._loc_data[FAKE_LOC] = {
325326
"name": "Legacy Anna",
326327
"types": {"temperature"},
327328
"members": appliances,
328329
}
329330
if self.smile_type == "stretch":
330-
self._loc_data[0] = {
331+
self._loc_data[FAKE_LOC] = {
331332
"name": "Legacy Stretch",
332333
"types": {"power"},
333334
"members": appliances,
@@ -421,7 +422,7 @@ def _energy_device_info_finder(self, appliance, appl):
421422
mod_type = "electricity_point_meter"
422423
module_data = self._get_module_data(appliance, locator, mod_type)
423424
appl.v_name = module_data[0]
424-
if appl.model != "Group Switch":
425+
if appl.model != "Switchgroup":
425426
appl.model = None
426427
if module_data[2] is not None:
427428
hw_version = module_data[2].replace("-", "")
@@ -492,7 +493,11 @@ def _appliance_types_finder(self, appliance, appl):
492493
for appl_type in types_finder(appliance):
493494
appl.types.add(appl_type)
494495
else:
495-
# Preset all types applicable to home
496+
# Provide a home_location for legacy_anna, preset all types applicable to home
497+
if self._smile_legacy and self.smile_type == "thermostat":
498+
appl.location = self._home_location
499+
# For legacy_anna gateway and heater_central is the same device
500+
self.gateway_id = self._heater_id
496501
appl.types = self._loc_data[self._home_location]["types"]
497502

498503
# Determine appliance_type from functionality
@@ -583,10 +588,6 @@ def _all_appliances(self):
583588
):
584589
self._appl_data.pop(appl.id)
585590

586-
# For legacy Anna gateway and heater_central is the same device
587-
if self._smile_legacy and self.smile_type == "thermostat":
588-
self.gateway_id = self._heater_id
589-
590591
def _match_locations(self):
591592
"""Helper-function for _scan_thermostats().
592593
Update locations with present appliance-types.
@@ -835,7 +836,7 @@ def _group_switches(self):
835836
Collect switching- or pump-group info.
836837
"""
837838
switch_groups = {}
838-
# P1 and Anna don't have switch groups
839+
# P1 and Anna don't have switchgroups
839840
if self.smile_type == "power" or self.smile_name == "Anna":
840841
return switch_groups
841842

@@ -867,11 +868,11 @@ def _group_switches(self):
867868
"class": group_type,
868869
"fw": None,
869870
"location": None,
870-
"members": members,
871-
"model": "Group Switch",
871+
"model": "Switchgroup",
872872
"name": group_name,
873+
"members": members,
873874
"types": {"switch_group"},
874-
"vendor": "Plugwise",
875+
"vendor": None,
875876
}
876877

877878
switch_groups.update(group_appl)

plugwise/smile.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _append_special(self, data, d_id, bs_list, s_list):
5656
bs_list.append(PW_NOTIFICATION)
5757
if not self._active_device_present and "heating_state" in data:
5858
s_list.append(DEVICE_STATE)
59-
if d_id == self._heater_id and self.single_master_thermostat() is False:
59+
if d_id == self._heater_id and self.single_master_thermostat() is not None:
6060
s_list.append(DEVICE_STATE)
6161

6262
def _all_device_data(self):
@@ -100,7 +100,8 @@ def get_all_devices(self):
100100

101101
for appliance, details in self._appl_data.items():
102102
loc_id = details["location"]
103-
if loc_id is None:
103+
# Don't assign the _home_location to thermostat-devices without a location, they are not active
104+
if loc_id is None and details["class"] not in THERMOSTAT_CLASSES:
104105
details["location"] = self._home_location
105106

106107
# Override slave thermostat class
@@ -109,7 +110,9 @@ def get_all_devices(self):
109110
if appliance in self._thermo_locs[loc_id]["slaves"]:
110111
details["class"] = "thermo_sensor"
111112

112-
self._devices[appliance] = details
113+
# Filter for thermostat-devices without a location
114+
if details["location"] is not None:
115+
self._devices[appliance] = details
113116

114117
group_data = self._group_switches()
115118
if group_data is not None:

tests/test_smile.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ async def device_test(self, smile=pw_smile.Smile, testdata=None):
380380

381381
_LOGGER.info("Gateway id = %s", extra["gateway_id"])
382382
_LOGGER.info("Hostname = %s", smile.smile_hostname)
383+
_LOGGER.info("Extra = %s", extra)
384+
_LOGGER.info("Device list = %s", device_list)
383385
self.show_setup(location_list, device_list)
384386

385387
tests = 0
@@ -548,7 +550,6 @@ async def test_connect_legacy_anna(self):
548550
"available_schedules": ["Thermostat schedule"],
549551
"selected_schedule": "Thermostat schedule",
550552
"last_used": "Thermostat schedule",
551-
"location": 0,
552553
"presets": {
553554
"asleep": [19.0, 0],
554555
"away": [19.0, 0],
@@ -566,13 +567,15 @@ async def test_connect_legacy_anna(self):
566567
},
567568
# Central
568569
"04e4cbfe7f4340f090f85ec3b9e6a950": {
570+
"location": pw_constants.FAKE_LOC,
569571
"heating_state": True,
570572
"sensors": [
571573
{"id": "water_temperature", "state": 23.6},
572574
{"id": "intended_boiler_temperature", "state": 17.0},
573575
{"id": "modulation_level", "state": 0.0},
574576
{"id": "return_temperature", "state": 21.7},
575577
{"id": "water_pressure", "state": 1.2},
578+
{"id": "device_state", "state": "heating"},
576579
],
577580
},
578581
}
@@ -784,6 +787,7 @@ async def test_connect_anna_v4(self):
784787
"sensors": [
785788
{"id": "water_pressure", "state": 2.1},
786789
{"id": "water_temperature", "state": 52.0},
790+
{"id": "device_state", "state": "heating"},
787791
],
788792
},
789793
"0466eae8520144c78afb29628384edeb": {
@@ -1001,12 +1005,8 @@ async def test_connect_adam_plus_anna(self):
10011005
# Central
10021006
"2743216f626f43948deec1f7ab3b3d70": {
10031007
"heating_state": False,
1004-
"binary_sensors": [
1005-
{
1006-
"id": "flame_state",
1007-
"state": False,
1008-
}
1009-
],
1008+
"binary_sensors": [{"id": "flame_state", "state": False}],
1009+
"sensors": [{"id": "device_state", "state": "idle"}],
10101010
},
10111011
"b128b4bbbd1f47e9bf4d756e8fb5ee94": {
10121012
"sensors": [{"id": "outdoor_temperature", "state": 11.9}]
@@ -1070,12 +1070,8 @@ async def test_connect_adam_plus_anna_new(self):
10701070
testdata = {
10711071
# Central
10721072
"2743216f626f43948deec1f7ab3b3d70": {
1073-
"binary_sensors": [
1074-
{
1075-
"id": "dhw_state",
1076-
"state": True,
1077-
}
1078-
]
1073+
"binary_sensors": [{"id": "dhw_state", "state": True}],
1074+
"sensors": [{"id": "device_state", "state": "dhw-heating"}],
10791075
},
10801076
# Test Switch
10811077
"b83f9f9758064c0fab4af6578cba4c6d": {
@@ -1126,12 +1122,8 @@ async def test_connect_adam_plus_anna_new_copy_dhw_and_heating(self):
11261122
# Central
11271123
"2743216f626f43948deec1f7ab3b3d70": {
11281124
"heating_state": True,
1129-
"binary_sensors": [
1130-
{
1131-
"id": "dhw_state",
1132-
"state": True,
1133-
}
1134-
],
1125+
"binary_sensors": [{"id": "dhw_state", "state": True}],
1126+
"sensors": [{"id": "device_state", "state": "dhw and heating"}],
11351127
}
11361128
}
11371129

@@ -1150,6 +1142,7 @@ async def test_connect_adam_plus_anna_new_copy_cooling(self):
11501142
# Central
11511143
"2743216f626f43948deec1f7ab3b3d70": {
11521144
"cooling_state": True,
1145+
"sensors": [{"id": "device_state", "state": "cooling"}],
11531146
},
11541147
}
11551148

@@ -1168,12 +1161,8 @@ async def test_connect_adam_plus_anna_new_copy_dhw_and_cooling(self):
11681161
# Central
11691162
"2743216f626f43948deec1f7ab3b3d70": {
11701163
"cooling_state": True,
1171-
"binary_sensors": [
1172-
{
1173-
"id": "dhw_state",
1174-
"state": True,
1175-
}
1176-
],
1164+
"binary_sensors": [{"id": "dhw_state", "state": True}],
1165+
"sensors": [{"id": "device_state", "state": "dhw and cooling"}],
11771166
}
11781167
}
11791168

@@ -1232,6 +1221,7 @@ async def test_connect_adam_zone_per_device(self):
12321221
],
12331222
"sensors": [
12341223
{"id": "outdoor_temperature", "state": 7.69},
1224+
{"id": "device_state", "state": "idle"},
12351225
],
12361226
},
12371227
# Modem
@@ -1346,6 +1336,7 @@ async def test_connect_adam_multiple_devices_per_zone(self):
13461336
"heating_state": True,
13471337
"sensors": [
13481338
{"id": "outdoor_temperature", "state": 7.81},
1339+
{"id": "device_state", "state": "heating"},
13491340
],
13501341
},
13511342
# Modem

0 commit comments

Comments
 (0)