Skip to content

Commit cb9b1d4

Browse files
authored
Merge pull request #96 from plugwise/Fix_p1v2_sensornames
Fix point-sensor-names for P1 v2
2 parents 878e04a + 0c3a430 commit cb9b1d4

File tree

6 files changed

+85
-39
lines changed

6 files changed

+85
-39
lines changed

CHANGELOG.md

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

3+
## 0.13.1 - Smile: fix point-sensor-names for P1 v2
4+
35
## 0.13.0 - Smile: fully support P1 legacy (specifically with firmware v2.1.13)
46

57
## 0.12.0 - Energy support and bugfixes

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.13.0"
3+
__version__ = "0.13.1"
44

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

plugwise/constants.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,17 @@
692692
ATTR_ICON: None,
693693
ATTR_UNIT_OF_MEASUREMENT: POWER_WATT,
694694
}
695+
EL_CONSUMED_POINT = {
696+
ATTR_ID: "electricity_consumed_point",
697+
ATTR_ENABLED: True,
698+
ATTR_NAME: "Electricity Consumed Point",
699+
ATTR_STATE: None,
700+
ATTR_DEVICE_CLASS: "power",
701+
ATTR_STATE_CLASS: "measurement",
702+
ATTR_LAST_RESET: None,
703+
ATTR_ICON: None,
704+
ATTR_UNIT_OF_MEASUREMENT: POWER_WATT,
705+
}
695706
EL_PRODUCED = {
696707
ATTR_ID: "electricity_produced",
697708
ATTR_ENABLED: False,
@@ -780,6 +791,17 @@
780791
ATTR_ICON: None,
781792
ATTR_UNIT_OF_MEASUREMENT: POWER_WATT,
782793
}
794+
EL_PRODUCED_POINT = {
795+
ATTR_ID: "electricity_produced_point",
796+
ATTR_ENABLED: True,
797+
ATTR_NAME: "Electricity Produced Point",
798+
ATTR_STATE: None,
799+
ATTR_DEVICE_CLASS: "power",
800+
ATTR_STATE_CLASS: "measurement",
801+
ATTR_LAST_RESET: None,
802+
ATTR_ICON: None,
803+
ATTR_UNIT_OF_MEASUREMENT: POWER_WATT,
804+
}
783805
GAS_CONSUMED_CUMULATIVE = {
784806
ATTR_ID: "gas_consumed_cumulative",
785807
ATTR_ENABLED: True,
@@ -957,6 +979,7 @@
957979
EL_CONSUMED_PEAK_CUMULATIVE,
958980
EL_CONSUMED_PEAK_INTERVAL,
959981
EL_CONSUMED_PEAK_POINT,
982+
EL_CONSUMED_POINT,
960983
EL_PRODUCED,
961984
EL_PRODUCED_INTERVAL,
962985
EL_PRODUCED_OFF_PEAK_CUMULATIVE,
@@ -965,6 +988,7 @@
965988
EL_PRODUCED_PEAK_CUMULATIVE,
966989
EL_PRODUCED_PEAK_INTERVAL,
967990
EL_PRODUCED_PEAK_POINT,
991+
EL_PRODUCED_POINT,
968992
GAS_CONSUMED_CUMULATIVE,
969993
GAS_CONSUMED_INTERVAL,
970994
HUMIDITY,

plugwise/helper.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ def _all_locations(self):
375375
for location in self._locations.findall("./location"):
376376
loc.name = location.find("name").text
377377
loc.id = location.attrib["id"]
378+
# Filter the valid single location for P1 legacy
379+
if self._smile_legacy and self.smile_type == "power":
380+
locator = "./services/electricity_point_meter"
381+
try:
382+
location.find(locator).attrib["id"]
383+
except AttributeError:
384+
return
385+
378386
loc.types = set()
379387
loc.members = set()
380388

@@ -393,10 +401,6 @@ def _all_locations(self):
393401
"members": loc.members,
394402
}
395403

396-
# Smile P1 has one valid location, skip any left-overs
397-
if self.smile_type == "power":
398-
return
399-
400404
return
401405

402406
def _get_module_data(self, appliance, locator, mod_type):
@@ -524,7 +528,7 @@ def _all_appliances(self):
524528
# appl_data can use the location id as device id.
525529
self._appl_data[self._home_location] = {
526530
"class": "gateway",
527-
"fw": None,
531+
"fw": self.smile_version[0],
528532
"location": self._home_location,
529533
"model": "Smile P1",
530534
"name": "P1",
@@ -926,10 +930,12 @@ def _heating_valves(self):
926930
def _power_data_peak_value(self, loc):
927931
"""Helper-function for _power_data_from_location()."""
928932
loc.found = True
933+
no_tariffs = False
929934

930935
# Only once try to find P1 Legacy values
931936
if loc.logs.find(loc.locator) is None and self.smile_type == "power":
932-
# Skip peak if not split (P1 Legacy), this also results in one (peak_)point sensor for all P1's.
937+
no_tariffs = True
938+
# P1 Legacy: avoid doubling the net_electricity_..._point value by skipping one peak-list option
933939
if loc.peak_select == "nl_offpeak":
934940
loc.found = False
935941
return loc
@@ -948,6 +954,9 @@ def _power_data_peak_value(self, loc):
948954
peak = "off_peak"
949955
log_found = loc.log_type.split("_")[0]
950956
loc.key_string = f"{loc.measurement}_{peak}_{log_found}"
957+
# P1 with fw 2.x does not have tariff indicators for point_log values
958+
if no_tariffs:
959+
loc.key_string = f"{loc.measurement}_{log_found}"
951960
if "gas" in loc.measurement:
952961
loc.key_string = f"{loc.measurement}_{log_found}"
953962
loc.net_string = f"net_electricity_{log_found}"

plugwise/smile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ def single_master_thermostat(self):
434434
Possible output: None, True, False.
435435
"""
436436
if self.smile_type != "thermostat":
437-
self._thermo_locs = self._match_locations()
438437
return None
439438

440439
count = 0

tests/test_smile.py

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ async def device_test(self, smile=pw_smile.Smile, testdata=None):
405405
"zone_thermostat",
406406
"thermostatic_radiator_valve",
407407
]
408-
bsw_lists = ["binary_sensors", "sensors", "switches"]
408+
bsw_list = ["binary_sensors", "sensors", "switches"]
409409
smile.get_all_devices()
410410
await smile.update_gw_devices()
411411
device_list = smile.gw_devices
@@ -419,7 +419,11 @@ async def device_test(self, smile=pw_smile.Smile, testdata=None):
419419
self.show_setup(location_list, device_list)
420420
pp4 = PrettyPrinter(indent=4)
421421

422+
tests = 0
423+
asserts = 0
422424
for testdevice, measurements in testdata.items():
425+
tests += 1
426+
asserts += 1
423427
assert testdevice in device_list
424428
# if testdevice not in device_list:
425429
# _LOGGER.info("Device {} to test against {} not found in device_list for {}".format(testdevice,measurements,self.smile_setup))
@@ -453,37 +457,49 @@ async def device_test(self, smile=pw_smile.Smile, testdata=None):
453457
measure_key, measure_assert
454458
),
455459
)
456-
if measure_key in bsw_lists:
457-
for a, a_item in enumerate(data[measure_key]):
458-
for b, b_item in enumerate(measure_assert):
460+
tests += 1
461+
if measure_key in bsw_list:
462+
tests -= 1
463+
for a, a_item in enumerate(measure_assert):
464+
tests += 1
465+
for b, b_item in enumerate(data[measure_key]):
459466
if a_item["id"] != b_item["id"]:
460467
continue
461468

462-
if isinstance(b_item["state"], list):
463-
assert a_item["state"] == b_item["state"][0]
469+
if isinstance(a_item["state"], list):
470+
tests += 1
471+
asserts += 1
472+
assert b_item["state"] == a_item["state"][0]
473+
asserts += 1
464474
assert (
465-
a_item["last_reset"] == b_item["state"][1]
475+
b_item["last_reset"] == a_item["state"][1]
466476
)
467477
else:
468-
assert a_item["state"] == b_item["state"]
469-
b_sensor = None
470-
if measure_key == "binary_sensors":
471-
b_sensor = pw_entities.GWBinarySensor(
472-
smile, dev_id, a_item["id"]
473-
)
474-
b_sensor.update_data()
475-
assert (
476-
self.bs_prop_selector("state", b_sensor)
477-
== b_item["state"]
478-
)
478+
asserts += 1
479+
if measure_key == "binary_sensors":
480+
b_sensor = None
481+
b_sensor = pw_entities.GWBinarySensor(
482+
smile, dev_id, a_item["id"]
483+
)
484+
b_sensor.update_data()
485+
assert (
486+
self.bs_prop_selector("state", b_sensor)
487+
== a_item["state"]
488+
)
489+
else:
490+
assert b_item["state"] == a_item["state"]
491+
elif self.th_prop_selector(measure_key, thermostat):
492+
asserts += 1
493+
assert (
494+
self.th_prop_selector(measure_key, thermostat)
495+
== measure_assert
496+
)
479497
else:
480498
if measure_key in data:
499+
asserts += 1
481500
assert data[measure_key] == measure_assert
482-
if self.th_prop_selector(measure_key, thermostat):
483-
assert (
484-
self.th_prop_selector(measure_key, thermostat)
485-
== measure_assert
486-
)
501+
502+
assert tests == asserts
487503

488504
@pytest.mark.asyncio
489505
async def tinker_switch(
@@ -616,7 +632,7 @@ async def test_connect_legacy_anna(self):
616632
"no_frost": [10.0, 0],
617633
"vacation": [15.0, 0],
618634
},
619-
"preset_mode": "home",
635+
"active_preset": "home",
620636
"preset_modes": ["away", "vacation", "asleep", "home", "no_frost"],
621637
"schedule_temperature": 20.0,
622638
"sensors": [
@@ -751,7 +767,7 @@ async def test_connect_smile_p1_v2(self):
751767
# Gateway / P1 itself
752768
"938696c4bcdb4b8a9a595cb38ed43913": {
753769
"sensors": [
754-
{"id": "electricity_consumed_peak_point", "state": 456.0},
770+
{"id": "electricity_consumed_point", "state": 456.0},
755771
{"id": "net_electricity_point", "state": 456.0},
756772
{"id": "gas_consumed_cumulative", "state": 584.431},
757773
{"id": "electricity_produced_peak_cumulative", "state": 1296.136},
@@ -794,7 +810,7 @@ async def test_connect_smile_p1_v2_2(self):
794810
# Gateway / P1 itself
795811
"199aa40f126840f392983d171374ab0b": {
796812
"sensors": [
797-
{"id": "electricity_consumed_peak_point", "state": 456.0},
813+
{"id": "electricity_consumed_point", "state": 456.0},
798814
{"id": "net_electricity_point", "state": 456.0},
799815
{"id": "gas_consumed_cumulative", "state": 584.431},
800816
{"id": "electricity_produced_peak_cumulative", "state": 1296.136},
@@ -1276,11 +1292,7 @@ async def test_connect_adam_zone_per_device(self):
12761292
},
12771293
# CV pomp
12781294
"78d1126fc4c743db81b61c20e88342a7": {
1279-
"sensors": [
1280-
{"id": "electricity_consumed", "state": 35.8},
1281-
{"id": "temperature", "state": 26.2},
1282-
{"id": "valve_position", "state": 0},
1283-
],
1295+
"sensors": [{"id": "electricity_consumed", "state": 35.8}],
12841296
"switches": [
12851297
{"id": "relay", "state": True},
12861298
],

0 commit comments

Comments
 (0)