Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.2.0

- Improve the low_battery feature, also take the battery-critically-low warning notification into account.

## v1.1.0

- New Feature: add a low_battery binary_sensor for battery-powered devices and block the related battery-low notifications.
Expand Down
13 changes: 6 additions & 7 deletions plugwise/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ def _update_gw_devices(self) -> None:
self._add_or_update_notifications(device_id, device, data)

device.update(data)

is_battery_low = (
mac_list
and "low_battery" in device["binary_sensors"]
and device["zigbee_mac_address"] in mac_list
and (
(device["dev_class"] in ("thermo_sensor", "thermostatic_radiator_valve") and device["sensors"]["battery"] < 30)
or (device["dev_class"] in ("zone_thermometer", "zone_thermostat") and device["sensors"]["battery"] < 15)
)
and device["dev_class"] in ("thermo_sensor", "thermostatic_radiator_valve", "zone_thermometer", "zone_thermostat")
)
if is_battery_low:
device["binary_sensors"]["low_battery"] = True
Expand All @@ -88,12 +84,15 @@ def _detect_low_batteries(self) -> list[str]:
for msg_id, notification in list(self._notifications.items()):
mac_address: str | None = None
message: str | None = notification.get("message")
if message is not None and all(x in message for x in matches) and (mac_addresses := mac_pattern.findall(message)):
warning: str | None = notification.get("warning")
notify = message or warning
if notify is not None and all(x in notify for x in matches) and (mac_addresses := mac_pattern.findall(notify)):
mac_address = mac_addresses[0] # re.findall() outputs a list

if mac_address is not None:
self._notifications.pop(msg_id)
mac_address_list.append(mac_address)
if message is not None: # only block message-type notifications
self._notifications.pop(msg_id)

return mac_address_list

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "plugwise"
version = "1.1.0"
version = "1.2.0"
license = {file = "LICENSE"}
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/data/adam/adam_plus_anna_new_UPDATED_DATA.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"e2f4322d57924fa090fbbc48b3a140dc": {
"binary_sensors": {
"low_battery": false
"low_battery": true
},
"mode": "off"
},
Expand Down
22 changes: 17 additions & 5 deletions userdata/updated/adam_plus_anna_new/core.domain_objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,30 @@
</offset_functionality>
</actuator_functionalities>
</appliance>
<notification id='af82e4ccf9c548528166d38e560662a4'>
<notification id='af82e4ccf9c548528166d38e560662a4'>
<type>warning</type>
<origin>local</origin>
<title>Plug has been unreachable since 23:03 2020-01-18.</title>
<title>Plug has been unreachable since 23:03 2023-12-21.</title>
<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>
<valid_from></valid_from>
<valid_to></valid_to>
<read_date>2020-01-23T10:54:59.710+01:00</read_date>
<created_date>2020-01-18T23:03:43.689+01:00</created_date>
<modified_date>2020-01-18T23:03:43.749+01:00</modified_date>
<read_date>2023-12-22T10:54:59.710+01:00</read_date>
<created_date>2023-12-21T22:03:43.689+01:00</created_date>
<modified_date>2023-12-21T22:03:43.749+01:00</modified_date>
<deleted_date></deleted_date>
</notification>
<notification id="aeeb31fcc226439b8ec4fddf0163367e">
<type>warning</type>
<origin>local</origin>
<title>Battery of Lisa is critically low.</title>
<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>
<valid_from/>
<valid_to/>
<read_date/>
<created_date>2023-12-21T08:06:18.095+02:00</created_date>
<modified_date>2023-12-21T08:06:18.164+02:00</modified_date>
<deleted_date/>
</notification>
<open_therm_regulation id='f47674d5b4fd44778d2e0c9df77e0186'>
<created_date>2021-12-16T19:30:15.976+01:00</created_date>
<modified_date>2023-12-22T16:30:02.561+01:00</modified_date>
Expand Down