Skip to content

Commit 3e0a2ab

Browse files
authored
Merge pull request #610 from plugwise/batt_too_low
Improve the low_battery-related feature, also take the battery-critically-low warning notification into account.
2 parents ad61375 + d2aecdb commit 3e0a2ab

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
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+
## v1.2.0
4+
5+
- Improve the low_battery feature, also take the battery-critically-low warning notification into account.
6+
37
## v1.1.0
48

59
- New Feature: add a low_battery binary_sensor for battery-powered devices and block the related battery-low notifications.

plugwise/data.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,11 @@ def _update_gw_devices(self) -> None:
6262
self._add_or_update_notifications(device_id, device, data)
6363

6464
device.update(data)
65-
6665
is_battery_low = (
6766
mac_list
6867
and "low_battery" in device["binary_sensors"]
6968
and device["zigbee_mac_address"] in mac_list
70-
and (
71-
(device["dev_class"] in ("thermo_sensor", "thermostatic_radiator_valve") and device["sensors"]["battery"] < 30)
72-
or (device["dev_class"] in ("zone_thermometer", "zone_thermostat") and device["sensors"]["battery"] < 15)
73-
)
69+
and device["dev_class"] in ("thermo_sensor", "thermostatic_radiator_valve", "zone_thermometer", "zone_thermostat")
7470
)
7571
if is_battery_low:
7672
device["binary_sensors"]["low_battery"] = True
@@ -88,12 +84,15 @@ def _detect_low_batteries(self) -> list[str]:
8884
for msg_id, notification in list(self._notifications.items()):
8985
mac_address: str | None = None
9086
message: str | None = notification.get("message")
91-
if message is not None and all(x in message for x in matches) and (mac_addresses := mac_pattern.findall(message)):
87+
warning: str | None = notification.get("warning")
88+
notify = message or warning
89+
if notify is not None and all(x in notify for x in matches) and (mac_addresses := mac_pattern.findall(notify)):
9290
mac_address = mac_addresses[0] # re.findall() outputs a list
9391

9492
if mac_address is not None:
95-
self._notifications.pop(msg_id)
9693
mac_address_list.append(mac_address)
94+
if message is not None: # only block message-type notifications
95+
self._notifications.pop(msg_id)
9796

9897
return mac_address_list
9998

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "1.1.0"
7+
version = "1.2.0"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

tests/data/adam/adam_plus_anna_new_UPDATED_DATA.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"e2f4322d57924fa090fbbc48b3a140dc": {
3030
"binary_sensors": {
31-
"low_battery": false
31+
"low_battery": true
3232
},
3333
"mode": "off"
3434
},

userdata/updated/adam_plus_anna_new/core.domain_objects.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,30 @@
171171
</offset_functionality>
172172
</actuator_functionalities>
173173
</appliance>
174-
<notification id='af82e4ccf9c548528166d38e560662a4'>
174+
<notification id='af82e4ccf9c548528166d38e560662a4'>
175175
<type>warning</type>
176176
<origin>local</origin>
177-
<title>Plug has been unreachable since 23:03 2020-01-18.</title>
177+
<title>Plug has been unreachable since 23:03 2023-12-21.</title>
178178
<message>Node Plug (with MAC address 000D6F000D13CB01, in room &apos;n.a.&apos;) has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device.</message>
179179
<valid_from></valid_from>
180180
<valid_to></valid_to>
181-
<read_date>2020-01-23T10:54:59.710+01:00</read_date>
182-
<created_date>2020-01-18T23:03:43.689+01:00</created_date>
183-
<modified_date>2020-01-18T23:03:43.749+01:00</modified_date>
181+
<read_date>2023-12-22T10:54:59.710+01:00</read_date>
182+
<created_date>2023-12-21T22:03:43.689+01:00</created_date>
183+
<modified_date>2023-12-21T22:03:43.749+01:00</modified_date>
184184
<deleted_date></deleted_date>
185185
</notification>
186+
<notification id="aeeb31fcc226439b8ec4fddf0163367e">
187+
<type>warning</type>
188+
<origin>local</origin>
189+
<title>Battery of Lisa is critically low.</title>
190+
<message>Battery of Lisa (with MAC address 000D6F000C869B61, in room 'Bathroom') is below the critical level of 15%. Please replace the battery or connect the device to a power adapter.</message>
191+
<valid_from/>
192+
<valid_to/>
193+
<read_date/>
194+
<created_date>2023-12-21T08:06:18.095+02:00</created_date>
195+
<modified_date>2023-12-21T08:06:18.164+02:00</modified_date>
196+
<deleted_date/>
197+
</notification>
186198
<open_therm_regulation id='f47674d5b4fd44778d2e0c9df77e0186'>
187199
<created_date>2021-12-16T19:30:15.976+01:00</created_date>
188200
<modified_date>2023-12-22T16:30:02.561+01:00</modified_date>

0 commit comments

Comments
 (0)