Skip to content

Commit 03e4a89

Browse files
committed
Improve _add_or_update_notifications()
1 parent d99b49d commit 03e4a89

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

plugwise/data.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,17 @@ def _add_or_update_notifications(
107107
self, entity_id: str, entity: GwEntityData
108108
) -> None:
109109
"""Helper-function adding or updating the Plugwise notifications."""
110-
if (
111-
entity_id == self._gateway_id
112-
and (self._is_thermostat or self.smile.type == "power")
113-
) or (
114-
"binary_sensors" in entity
115-
and "plugwise_notification" in entity["binary_sensors"]
116-
):
117-
entity["binary_sensors"]["plugwise_notification"] = bool(
118-
self._notifications
119-
)
110+
111+
if entity_id != self._gateway_id:
112+
return
113+
114+
if (self._is_thermostat or self.smile.type == "power") and "binary_sensors" not in entity:
115+
entity.update({"binary_sensors": {"plugwise_notification": bool(self._notifications)}})
116+
entity.update({"notifications": self._notifications})
117+
self._count += 2
118+
119+
if "plugwise_notification" in entity["binary_sensors"]:
120+
entity["binary_sensors"]["plugwise_notification"] = bool(self._notifications)
120121
entity["notifications"] = self._notifications
121122
self._count += 2
122123

0 commit comments

Comments
 (0)