From 7d67b6c91bbdf94f5fb3735a048a0c33ca890acb Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sat, 16 Nov 2024 05:06:14 +0100 Subject: [PATCH] Introduced concept of pollables --- .../zigbee2mqtt/entities/contact_sensor_z2m.py | 5 +++++ src/mash/core/entities/contact_sensor.py | 11 +++++++++++ src/mash/core/entities/entity.py | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/mash/bridges/zigbee2mqtt/entities/contact_sensor_z2m.py diff --git a/src/mash/bridges/zigbee2mqtt/entities/contact_sensor_z2m.py b/src/mash/bridges/zigbee2mqtt/entities/contact_sensor_z2m.py new file mode 100644 index 0000000..178d18b --- /dev/null +++ b/src/mash/bridges/zigbee2mqtt/entities/contact_sensor_z2m.py @@ -0,0 +1,5 @@ +from mash.core.entities.contact_sensor import ContactSensor + + +class ContactSensorZ2M(ContactSensor): + \ No newline at end of file diff --git a/src/mash/core/entities/contact_sensor.py b/src/mash/core/entities/contact_sensor.py index b8710aa..6abb978 100644 --- a/src/mash/core/entities/contact_sensor.py +++ b/src/mash/core/entities/contact_sensor.py @@ -18,4 +18,15 @@ class ContactSensor(Entity): def is_closed(self) -> bool: return self._has_contact + def is_open(self) -> bool: + return not self._has_contact + + def is_closed_for_seconds(self, duration_in_seconds: float) -> bool: + # TODO + pass + + def is_open_for_seconds(self, duration_in_seconds: float) -> bool: + # TODO + pass + # TODO: Update state diff --git a/src/mash/core/entities/entity.py b/src/mash/core/entities/entity.py index a60252a..18d9702 100644 --- a/src/mash/core/entities/entity.py +++ b/src/mash/core/entities/entity.py @@ -16,6 +16,7 @@ class Entity: self._room = room self._device_type = device_type self._groups = set(groups) + self._pollable = False @property def id(self) -> str: @@ -37,5 +38,13 @@ class Entity: def groups(self) -> set[str]: return self._groups + @property + def is_pollable(self) -> bool: + return self._pollable + + def _poll_(self) -> None: + """Polls the bridge for the latest state.""" + pass + def __str__(self) -> str: return f"{self.name} [{self.id}, type {self.device_type}, room {self.room}, in {len(self.groups)} groups]"