pyg90alarm 1.17.2__tar.gz → 1.20.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/PKG-INFO +13 -2
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/alarm.py +144 -91
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/const.py +1 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/device_notifications.py +29 -3
- pyg90alarm-1.20.0/src/pyg90alarm/entities/base_entity.py +83 -0
- pyg90alarm-1.20.0/src/pyg90alarm/entities/base_list.py +165 -0
- pyg90alarm-1.20.0/src/pyg90alarm/entities/device_list.py +58 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/entities/sensor.py +210 -21
- pyg90alarm-1.20.0/src/pyg90alarm/entities/sensor_list.py +50 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm.egg-info/PKG-INFO +13 -2
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm.egg-info/SOURCES.txt +4 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_alarm.py +252 -40
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_history.py +1 -1
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_notifications.py +51 -1
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/.github/CODEOWNERS +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/.github/workflows/main.yml +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/.gitignore +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/.pylintrc +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/.readthedocs.yaml +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/LICENSE +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/MANIFEST.in +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/README.rst +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/.DS_Store +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/.gitignore +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/api-docs.rst +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/conf.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/index.rst +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/protocol.rst +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/docs/requirements.txt +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/pyproject.toml +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/setup.cfg +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/setup.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/sonar-project.properties +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/__init__.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/base_cmd.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/callback.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/config.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/definitions/__init__.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/definitions/sensors.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/discovery.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/entities/__init__.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/entities/device.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/exceptions.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/history.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/host_info.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/host_status.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/paginated_cmd.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/paginated_result.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/py.typed +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/targeted_discovery.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm/user_data_crc.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm.egg-info/dependency_links.txt +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm.egg-info/requires.txt +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/src/pyg90alarm.egg-info/top_level.txt +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/__init__.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/conftest.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/device_mock.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_base_commands.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_discovery.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tests/test_paginated_commands.py +0 -0
- {pyg90alarm-1.17.2 → pyg90alarm-1.20.0}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: pyg90alarm
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.20.0
|
|
4
4
|
Summary: G90 Alarm system protocol
|
|
5
5
|
Home-page: https://github.com/hostcc/pyg90alarm
|
|
6
6
|
Author: Ilia Sotnikov
|
|
@@ -33,6 +33,17 @@ Requires-Dist: asynctest; extra == "test"
|
|
|
33
33
|
Provides-Extra: docs
|
|
34
34
|
Requires-Dist: sphinx; extra == "docs"
|
|
35
35
|
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
36
|
+
Dynamic: author
|
|
37
|
+
Dynamic: author-email
|
|
38
|
+
Dynamic: classifier
|
|
39
|
+
Dynamic: description
|
|
40
|
+
Dynamic: description-content-type
|
|
41
|
+
Dynamic: home-page
|
|
42
|
+
Dynamic: keywords
|
|
43
|
+
Dynamic: project-url
|
|
44
|
+
Dynamic: provides-extra
|
|
45
|
+
Dynamic: requires-python
|
|
46
|
+
Dynamic: summary
|
|
36
47
|
|
|
37
48
|
.. image:: https://github.com/hostcc/pyg90alarm/actions/workflows/main.yml/badge.svg?branch=master
|
|
38
49
|
:target: https://github.com/hostcc/pyg90alarm/tree/master
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
19
|
# SOFTWARE.
|
|
20
|
+
# pylint: disable=too-many-lines
|
|
20
21
|
|
|
21
22
|
"""
|
|
22
23
|
Provides interface to G90 alarm panel.
|
|
@@ -68,7 +69,9 @@ from .const import (
|
|
|
68
69
|
from .base_cmd import (G90BaseCommand, G90BaseCommandData)
|
|
69
70
|
from .paginated_result import G90PaginatedResult, G90PaginatedResponse
|
|
70
71
|
from .entities.sensor import (G90Sensor, G90SensorTypes)
|
|
72
|
+
from .entities.sensor_list import G90SensorList
|
|
71
73
|
from .entities.device import G90Device
|
|
74
|
+
from .entities.device_list import G90DeviceList
|
|
72
75
|
from .device_notifications import (
|
|
73
76
|
G90DeviceNotifications,
|
|
74
77
|
)
|
|
@@ -120,6 +123,14 @@ if TYPE_CHECKING:
|
|
|
120
123
|
[int, str, G90RemoteButtonStates], Coroutine[None, None, None]
|
|
121
124
|
]
|
|
122
125
|
]
|
|
126
|
+
DoorOpenWhenArmingCallback = Union[
|
|
127
|
+
Callable[[int, str], None],
|
|
128
|
+
Callable[[int, str], Coroutine[None, None, None]]
|
|
129
|
+
]
|
|
130
|
+
TamperCallback = Union[
|
|
131
|
+
Callable[[int, str], None],
|
|
132
|
+
Callable[[int, str], Coroutine[None, None, None]]
|
|
133
|
+
]
|
|
123
134
|
# Sensor-related callbacks for `G90Sensor` class - despite that class
|
|
124
135
|
# stores them, the invocation is done by the `G90Alarm` class hence these
|
|
125
136
|
# are defined here
|
|
@@ -131,6 +142,14 @@ if TYPE_CHECKING:
|
|
|
131
142
|
Callable[[], None],
|
|
132
143
|
Callable[[], Coroutine[None, None, None]]
|
|
133
144
|
]
|
|
145
|
+
SensorDoorOpenWhenArmingCallback = Union[
|
|
146
|
+
Callable[[], None],
|
|
147
|
+
Callable[[], Coroutine[None, None, None]]
|
|
148
|
+
]
|
|
149
|
+
SensorTamperCallback = Union[
|
|
150
|
+
Callable[[], None],
|
|
151
|
+
Callable[[], Coroutine[None, None, None]]
|
|
152
|
+
]
|
|
134
153
|
|
|
135
154
|
|
|
136
155
|
# pylint: disable=too-many-public-methods
|
|
@@ -160,10 +179,8 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
160
179
|
)
|
|
161
180
|
self._host: str = host
|
|
162
181
|
self._port: int = port
|
|
163
|
-
self._sensors
|
|
164
|
-
self.
|
|
165
|
-
self._devices: List[G90Device] = []
|
|
166
|
-
self._devices_lock = asyncio.Lock()
|
|
182
|
+
self._sensors = G90SensorList(self)
|
|
183
|
+
self._devices = G90DeviceList(self)
|
|
167
184
|
self._notifications: Optional[G90DeviceNotifications] = None
|
|
168
185
|
self._sensor_cb: Optional[SensorCallback] = None
|
|
169
186
|
self._armdisarm_cb: Optional[ArmDisarmCallback] = None
|
|
@@ -174,6 +191,10 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
174
191
|
self._remote_button_press_cb: Optional[
|
|
175
192
|
RemoteButtonPressCallback
|
|
176
193
|
] = None
|
|
194
|
+
self._door_open_when_arming_cb: Optional[
|
|
195
|
+
DoorOpenWhenArmingCallback
|
|
196
|
+
] = None
|
|
197
|
+
self._tamper_cb: Optional[TamperCallback] = None
|
|
177
198
|
self._reset_occupancy_interval = reset_occupancy_interval
|
|
178
199
|
self._alert_config: Optional[G90AlertConfigFlags] = None
|
|
179
200
|
self._sms_alert_when_armed = False
|
|
@@ -247,109 +268,58 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
247
268
|
@property
|
|
248
269
|
async def sensors(self) -> List[G90Sensor]:
|
|
249
270
|
"""
|
|
250
|
-
|
|
251
|
-
|
|
271
|
+
Returns the list of sensors configured in the device. Please note
|
|
272
|
+
it doesn't update those from the panel except initially when the list
|
|
273
|
+
if empty.
|
|
274
|
+
|
|
275
|
+
:return: List of sensors
|
|
252
276
|
"""
|
|
253
|
-
return await self.
|
|
277
|
+
return await self._sensors.entities
|
|
254
278
|
|
|
255
279
|
async def get_sensors(self) -> List[G90Sensor]:
|
|
256
280
|
"""
|
|
257
|
-
Provides list of sensors configured in the device
|
|
258
|
-
|
|
259
|
-
reflect any updates there.
|
|
281
|
+
Provides list of sensors configured in the device, updating them from
|
|
282
|
+
panel on each call.
|
|
260
283
|
|
|
261
284
|
:return: List of sensors
|
|
262
285
|
"""
|
|
263
|
-
|
|
264
|
-
# resulting list or redundant exchanges with panel are made when the
|
|
265
|
-
# method is called concurrently
|
|
266
|
-
async with self._sensors_lock:
|
|
267
|
-
if not self._sensors:
|
|
268
|
-
sensors = self.paginated_result(
|
|
269
|
-
G90Commands.GETSENSORLIST
|
|
270
|
-
)
|
|
271
|
-
async for sensor in sensors:
|
|
272
|
-
obj = G90Sensor(
|
|
273
|
-
*sensor.data, parent=self, subindex=0,
|
|
274
|
-
proto_idx=sensor.proto_idx
|
|
275
|
-
)
|
|
276
|
-
self._sensors.append(obj)
|
|
277
|
-
|
|
278
|
-
_LOGGER.debug(
|
|
279
|
-
'Total number of sensors: %s', len(self._sensors)
|
|
280
|
-
)
|
|
286
|
+
return await self._sensors.update()
|
|
281
287
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
288
|
+
async def find_sensor(
|
|
289
|
+
self, idx: int, name: str, exclude_unavailable: bool = True
|
|
290
|
+
) -> Optional[G90Sensor]:
|
|
285
291
|
"""
|
|
286
292
|
Finds sensor by index and name.
|
|
287
293
|
|
|
288
294
|
:param idx: Sensor index
|
|
289
295
|
:param name: Sensor name
|
|
296
|
+
:param exclude_unavailable: Flag indicating if unavailable sensors
|
|
297
|
+
should be excluded from the search
|
|
290
298
|
:return: Sensor instance
|
|
291
299
|
"""
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
# Fast lookup by direct index
|
|
295
|
-
if idx < len(sensors) and sensors[idx].name == name:
|
|
296
|
-
sensor = sensors[idx]
|
|
297
|
-
_LOGGER.debug('Found sensor via fast lookup: %s', sensor)
|
|
298
|
-
return sensor
|
|
299
|
-
|
|
300
|
-
# Fast lookup failed, perform slow one over the whole sensors list
|
|
301
|
-
for sensor in sensors:
|
|
302
|
-
if sensor.index == idx and sensor.name == name:
|
|
303
|
-
_LOGGER.debug('Found sensor: %s', sensor)
|
|
304
|
-
return sensor
|
|
305
|
-
|
|
306
|
-
_LOGGER.error('Sensor not found: idx=%s, name=%s', idx, name)
|
|
307
|
-
return None
|
|
300
|
+
return await self._sensors.find(idx, name, exclude_unavailable)
|
|
308
301
|
|
|
309
302
|
@property
|
|
310
303
|
async def devices(self) -> List[G90Device]:
|
|
311
304
|
"""
|
|
312
|
-
|
|
313
|
-
|
|
305
|
+
Returns the list of devices (switches) configured in the device. Please
|
|
306
|
+
note it doesn't update those from the panel except initially when
|
|
307
|
+
the list if empty.
|
|
308
|
+
|
|
309
|
+
:return: List of devices
|
|
314
310
|
"""
|
|
315
|
-
return await self.
|
|
311
|
+
return await self._devices.entities
|
|
316
312
|
|
|
317
313
|
async def get_devices(self) -> List[G90Device]:
|
|
318
314
|
"""
|
|
319
|
-
Provides list of devices (switches) configured in the device
|
|
320
|
-
|
|
321
|
-
the class to reflect any updates there. Multi-node devices, those
|
|
315
|
+
Provides list of devices (switches) configured in the device, updating
|
|
316
|
+
them from panel on each call. Multi-node devices, those
|
|
322
317
|
having multiple ports, are expanded into corresponding number of
|
|
323
318
|
resulting entries.
|
|
324
319
|
|
|
325
320
|
:return: List of devices
|
|
326
321
|
"""
|
|
327
|
-
|
|
328
|
-
async with self._devices_lock:
|
|
329
|
-
if not self._devices:
|
|
330
|
-
devices = self.paginated_result(
|
|
331
|
-
G90Commands.GETDEVICELIST
|
|
332
|
-
)
|
|
333
|
-
async for device in devices:
|
|
334
|
-
obj = G90Device(
|
|
335
|
-
*device.data, parent=self, subindex=0,
|
|
336
|
-
proto_idx=device.proto_idx
|
|
337
|
-
)
|
|
338
|
-
self._devices.append(obj)
|
|
339
|
-
# Multi-node devices (first node has already been added
|
|
340
|
-
# above
|
|
341
|
-
for node in range(1, obj.node_count):
|
|
342
|
-
obj = G90Device(
|
|
343
|
-
*device.data, parent=self,
|
|
344
|
-
subindex=node, proto_idx=device.proto_idx
|
|
345
|
-
)
|
|
346
|
-
self._devices.append(obj)
|
|
347
|
-
|
|
348
|
-
_LOGGER.debug(
|
|
349
|
-
'Total number of devices: %s', len(self._devices)
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
return self._devices
|
|
322
|
+
return await self._devices.update()
|
|
353
323
|
|
|
354
324
|
@property
|
|
355
325
|
async def host_info(self) -> G90HostInfo:
|
|
@@ -613,6 +583,17 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
613
583
|
await self.set_alert_config(
|
|
614
584
|
await self.alert_config | G90AlertConfigFlags.SMS_PUSH
|
|
615
585
|
)
|
|
586
|
+
|
|
587
|
+
# Reset the tampered and door open when arming flags on all sensors
|
|
588
|
+
# having those set
|
|
589
|
+
for sensor in await self.sensors:
|
|
590
|
+
if sensor.is_tampered:
|
|
591
|
+
# pylint: disable=protected-access
|
|
592
|
+
sensor._set_tampered(False)
|
|
593
|
+
if sensor.is_door_open_when_arming:
|
|
594
|
+
# pylint: disable=protected-access
|
|
595
|
+
sensor._set_door_open_when_arming(False)
|
|
596
|
+
|
|
616
597
|
G90Callback.invoke(self._armdisarm_cb, state)
|
|
617
598
|
|
|
618
599
|
@property
|
|
@@ -627,7 +608,9 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
627
608
|
def armdisarm_callback(self, value: ArmDisarmCallback) -> None:
|
|
628
609
|
self._armdisarm_cb = value
|
|
629
610
|
|
|
630
|
-
async def on_alarm(
|
|
611
|
+
async def on_alarm(
|
|
612
|
+
self, event_id: int, zone_name: str, is_tampered: bool
|
|
613
|
+
) -> None:
|
|
631
614
|
"""
|
|
632
615
|
Invoked when alarm is triggered. Fires corresponding callback if set by
|
|
633
616
|
the user with :attr:`.alarm_callback`.
|
|
@@ -638,16 +621,31 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
638
621
|
:param zone_name: Sensor name
|
|
639
622
|
"""
|
|
640
623
|
sensor = await self.find_sensor(event_id, zone_name)
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
624
|
+
extra_data = None
|
|
625
|
+
if sensor:
|
|
626
|
+
# The callback is still delivered to the caller even if the sensor
|
|
627
|
+
# isn't found, only `extra_data` is skipped. That is to ensure the
|
|
628
|
+
# important callback isn't filtered
|
|
629
|
+
extra_data = sensor.extra_data
|
|
630
|
+
|
|
631
|
+
# Invoke the sensor activity callback to set the sensor occupancy
|
|
632
|
+
# if sensor is known, but only if that isn't already set - it helps
|
|
633
|
+
# when device notifications on triggerring sensor's activity aren't
|
|
634
|
+
# receveid by a reason
|
|
635
|
+
if not sensor.occupancy:
|
|
636
|
+
await self.on_sensor_activity(event_id, zone_name, True)
|
|
637
|
+
|
|
638
|
+
if is_tampered:
|
|
639
|
+
# Set the tampered flag on the sensor
|
|
640
|
+
# pylint: disable=protected-access
|
|
641
|
+
sensor._set_tampered(True)
|
|
642
|
+
|
|
643
|
+
# Invoke per-sensor callback if provided
|
|
644
|
+
G90Callback.invoke(sensor.tamper_callback)
|
|
645
|
+
|
|
646
|
+
# Invoke global tamper callback if provided and the sensor is tampered
|
|
647
|
+
if is_tampered:
|
|
648
|
+
G90Callback.invoke(self._tamper_cb, event_id, zone_name)
|
|
651
649
|
|
|
652
650
|
G90Callback.invoke(
|
|
653
651
|
self._alarm_cb, event_id, zone_name, extra_data
|
|
@@ -718,7 +716,10 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
718
716
|
|
|
719
717
|
# Also report the event as alarm for unification, hard-coding the
|
|
720
718
|
# sensor name in case of host SOS
|
|
721
|
-
await self.on_alarm(
|
|
719
|
+
await self.on_alarm(
|
|
720
|
+
event_id, zone_name='Host SOS' if is_host_sos else zone_name,
|
|
721
|
+
is_tampered=False
|
|
722
|
+
)
|
|
722
723
|
|
|
723
724
|
if not is_host_sos:
|
|
724
725
|
# Also report the remote button press for SOS - the panel will not
|
|
@@ -778,6 +779,58 @@ class G90Alarm(G90DeviceNotifications):
|
|
|
778
779
|
) -> None:
|
|
779
780
|
self._remote_button_press_cb = value
|
|
780
781
|
|
|
782
|
+
async def on_door_open_when_arming(
|
|
783
|
+
self, event_id: int, zone_name: str
|
|
784
|
+
) -> None:
|
|
785
|
+
"""
|
|
786
|
+
Invoked when door is open when arming the device. Fires corresponding
|
|
787
|
+
callback if set by the user with
|
|
788
|
+
:attr:`.door_open_when_arming_callback`.
|
|
789
|
+
|
|
790
|
+
Please note the method is for internal use by the class.
|
|
791
|
+
|
|
792
|
+
:param event_id: The index of the sensor being active when the panel
|
|
793
|
+
is being armed.
|
|
794
|
+
:param zone_name: The name of the sensor
|
|
795
|
+
"""
|
|
796
|
+
_LOGGER.debug('on_door_open_when_arming: %s %s', event_id, zone_name)
|
|
797
|
+
sensor = await self.find_sensor(event_id, zone_name)
|
|
798
|
+
if sensor:
|
|
799
|
+
# Set the low battery flag on the sensor
|
|
800
|
+
# pylint: disable=protected-access
|
|
801
|
+
sensor._set_door_open_when_arming(True)
|
|
802
|
+
# Invoke per-sensor callback if provided
|
|
803
|
+
G90Callback.invoke(sensor.door_open_when_arming_callback)
|
|
804
|
+
|
|
805
|
+
G90Callback.invoke(self._door_open_when_arming_cb, event_id, zone_name)
|
|
806
|
+
|
|
807
|
+
@property
|
|
808
|
+
def door_open_when_arming_callback(
|
|
809
|
+
self
|
|
810
|
+
) -> Optional[DoorOpenWhenArmingCallback]:
|
|
811
|
+
"""
|
|
812
|
+
Door open when arming callback, which is invoked when sensor reports
|
|
813
|
+
the condition.
|
|
814
|
+
"""
|
|
815
|
+
return self._door_open_when_arming_cb
|
|
816
|
+
|
|
817
|
+
@door_open_when_arming_callback.setter
|
|
818
|
+
def door_open_when_arming_callback(
|
|
819
|
+
self, value: DoorOpenWhenArmingCallback
|
|
820
|
+
) -> None:
|
|
821
|
+
self._door_open_when_arming_cb = value
|
|
822
|
+
|
|
823
|
+
@property
|
|
824
|
+
async def tamper_callback(self) -> Optional[TamperCallback]:
|
|
825
|
+
"""
|
|
826
|
+
Tamper callback, which is invoked when sensor reports the condition.
|
|
827
|
+
"""
|
|
828
|
+
return self._tamper_cb
|
|
829
|
+
|
|
830
|
+
@tamper_callback.setter
|
|
831
|
+
def tamper_callback(self, value: TamperCallback) -> None:
|
|
832
|
+
self._tamper_cb = value
|
|
833
|
+
|
|
781
834
|
async def listen_device_notifications(self) -> None:
|
|
782
835
|
"""
|
|
783
836
|
Starts internal listener for device notifications/alerts.
|
|
@@ -159,6 +159,16 @@ class G90DeviceNotifications(DatagramProtocol):
|
|
|
159
159
|
|
|
160
160
|
return
|
|
161
161
|
|
|
162
|
+
# An open door is detected when arming
|
|
163
|
+
if notification.kind == G90NotificationTypes.DOOR_OPEN_WHEN_ARMING:
|
|
164
|
+
g90_zone_info = G90ZoneInfo(*notification.data)
|
|
165
|
+
_LOGGER.debug('Door open detected when arming: %s', g90_zone_info)
|
|
166
|
+
G90Callback.invoke(
|
|
167
|
+
self.on_door_open_when_arming,
|
|
168
|
+
g90_zone_info.idx, g90_zone_info.name
|
|
169
|
+
)
|
|
170
|
+
return
|
|
171
|
+
|
|
162
172
|
_LOGGER.warning('Unknown notification received from %s:%s:'
|
|
163
173
|
' kind %s, data %s',
|
|
164
174
|
addr[0], addr[1], notification.kind, notification.data)
|
|
@@ -259,11 +269,15 @@ class G90DeviceNotifications(DatagramProtocol):
|
|
|
259
269
|
)
|
|
260
270
|
# Regular alarm
|
|
261
271
|
else:
|
|
262
|
-
|
|
272
|
+
is_tampered = alert.state == G90AlertStates.TAMPER
|
|
273
|
+
_LOGGER.debug(
|
|
274
|
+
'Alarm: %s, is tampered: %s', alert.zone_name, is_tampered
|
|
275
|
+
)
|
|
263
276
|
G90Callback.invoke(
|
|
264
277
|
self.on_alarm,
|
|
265
|
-
alert.event_id, alert.zone_name
|
|
278
|
+
alert.event_id, alert.zone_name, is_tampered
|
|
266
279
|
)
|
|
280
|
+
|
|
267
281
|
handled = True
|
|
268
282
|
|
|
269
283
|
# Host SOS
|
|
@@ -372,6 +386,16 @@ class G90DeviceNotifications(DatagramProtocol):
|
|
|
372
386
|
:param name: Name of the sensor.
|
|
373
387
|
"""
|
|
374
388
|
|
|
389
|
+
async def on_door_open_when_arming(
|
|
390
|
+
self, event_id: int, zone_name: str
|
|
391
|
+
) -> None:
|
|
392
|
+
"""
|
|
393
|
+
Invoked when door open is detected when panel is armed.
|
|
394
|
+
|
|
395
|
+
:param event_id: Index of the sensor.
|
|
396
|
+
:param zone_name: Name of the sensor that reports door open.
|
|
397
|
+
"""
|
|
398
|
+
|
|
375
399
|
async def on_door_open_close(
|
|
376
400
|
self, event_id: int, zone_name: str, is_open: bool
|
|
377
401
|
) -> None:
|
|
@@ -391,7 +415,9 @@ class G90DeviceNotifications(DatagramProtocol):
|
|
|
391
415
|
:param zone_name: Name of the sensor that reports low battery.
|
|
392
416
|
"""
|
|
393
417
|
|
|
394
|
-
async def on_alarm(
|
|
418
|
+
async def on_alarm(
|
|
419
|
+
self, event_id: int, zone_name: str, is_tampered: bool
|
|
420
|
+
) -> None:
|
|
395
421
|
"""
|
|
396
422
|
Invoked when device triggers the alarm.
|
|
397
423
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright (c) 2025 Ilia Sotnikov
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
"""
|
|
21
|
+
Base entity.
|
|
22
|
+
"""
|
|
23
|
+
from abc import ABC, abstractmethod
|
|
24
|
+
# `Self` has been introduced in Python 3.11, need to use `typing_extensions`
|
|
25
|
+
# for earlier versions
|
|
26
|
+
try:
|
|
27
|
+
from typing import Self # type: ignore[attr-defined,unused-ignore]
|
|
28
|
+
except ImportError:
|
|
29
|
+
from typing_extensions import Self
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class G90BaseEntity(ABC):
|
|
33
|
+
"""
|
|
34
|
+
Base entity class.
|
|
35
|
+
|
|
36
|
+
Contains minimal set of method for :class:`.G90BaseList` class
|
|
37
|
+
"""
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def update(
|
|
40
|
+
self,
|
|
41
|
+
obj: Self # pylint: disable=used-before-assignment
|
|
42
|
+
) -> None:
|
|
43
|
+
"""
|
|
44
|
+
Update the entity from another one.
|
|
45
|
+
|
|
46
|
+
:param obj: Object to update from.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def is_unavailable(self) -> bool:
|
|
52
|
+
"""
|
|
53
|
+
Check if the entity is unavailable.
|
|
54
|
+
|
|
55
|
+
:return: True if the entity is unavailable.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
@is_unavailable.setter
|
|
59
|
+
@abstractmethod
|
|
60
|
+
def is_unavailable(self, value: bool) -> None:
|
|
61
|
+
"""
|
|
62
|
+
Set the entity as unavailable.
|
|
63
|
+
|
|
64
|
+
:param value: Value to set.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def name(self) -> str:
|
|
70
|
+
"""
|
|
71
|
+
Get the name of the entity.
|
|
72
|
+
|
|
73
|
+
:return: Name of the entity.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def index(self) -> int:
|
|
79
|
+
"""
|
|
80
|
+
Get the index of the entity.
|
|
81
|
+
|
|
82
|
+
:return: Index of the entity.
|
|
83
|
+
"""
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Copyright (c) 2025 Ilia Sotnikov
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
Base entity list.
|
|
23
|
+
"""
|
|
24
|
+
from abc import ABC, abstractmethod
|
|
25
|
+
from typing import (
|
|
26
|
+
List, AsyncGenerator, Optional, TypeVar, Generic, cast, TYPE_CHECKING,
|
|
27
|
+
)
|
|
28
|
+
import asyncio
|
|
29
|
+
import logging
|
|
30
|
+
|
|
31
|
+
from .base_entity import G90BaseEntity
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from ..alarm import G90Alarm
|
|
34
|
+
else:
|
|
35
|
+
# Alias G90Alarm to object avoid circular imports
|
|
36
|
+
# (`G90Alarm` -> `G90SensorList` -> `G90BaseList` -> `G90Alarm`)
|
|
37
|
+
G90Alarm = object
|
|
38
|
+
|
|
39
|
+
T = TypeVar('T', bound=G90BaseEntity)
|
|
40
|
+
_LOGGER = logging.getLogger(__name__)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class G90BaseList(Generic[T], ABC):
|
|
44
|
+
"""
|
|
45
|
+
Base entity list class.
|
|
46
|
+
|
|
47
|
+
:param parent: Parent alarm panel instance.
|
|
48
|
+
"""
|
|
49
|
+
def __init__(self, parent: G90Alarm) -> None:
|
|
50
|
+
self._entities: List[T] = []
|
|
51
|
+
self._lock = asyncio.Lock()
|
|
52
|
+
self._parent = parent
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
async def _fetch(self) -> AsyncGenerator[T, None]:
|
|
56
|
+
"""
|
|
57
|
+
Fetch the list of entities from the panel.
|
|
58
|
+
|
|
59
|
+
:return: Async generator of entities
|
|
60
|
+
"""
|
|
61
|
+
yield cast(T, None)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
async def entities(self) -> List[T]:
|
|
65
|
+
"""
|
|
66
|
+
Return the list of entities.
|
|
67
|
+
|
|
68
|
+
:meth:`update` is called if the list is empty.
|
|
69
|
+
|
|
70
|
+
:return: List of entities
|
|
71
|
+
"""
|
|
72
|
+
# Please see below for the explanation of the lock usage
|
|
73
|
+
async with self._lock:
|
|
74
|
+
entities = self._entities
|
|
75
|
+
|
|
76
|
+
if not entities:
|
|
77
|
+
return await self.update()
|
|
78
|
+
|
|
79
|
+
return entities
|
|
80
|
+
|
|
81
|
+
async def update(self) -> List[T]:
|
|
82
|
+
"""
|
|
83
|
+
Update the list of entities from the panel.
|
|
84
|
+
|
|
85
|
+
:return: List of entities
|
|
86
|
+
"""
|
|
87
|
+
# Use lock around the operation, to ensure no duplicated entries in the
|
|
88
|
+
# resulting list or redundant exchanges with panel are made when the
|
|
89
|
+
# method is called concurrently
|
|
90
|
+
async with self._lock:
|
|
91
|
+
entities = self._fetch()
|
|
92
|
+
|
|
93
|
+
non_existing_entities = self._entities.copy()
|
|
94
|
+
async for entity in entities:
|
|
95
|
+
try:
|
|
96
|
+
existing_entity_idx = self._entities.index(entity)
|
|
97
|
+
except ValueError:
|
|
98
|
+
existing_entity_idx = None
|
|
99
|
+
|
|
100
|
+
if existing_entity_idx is not None:
|
|
101
|
+
existing_entity = self._entities[existing_entity_idx]
|
|
102
|
+
# Update the existing entity with the new data
|
|
103
|
+
_LOGGER.debug(
|
|
104
|
+
"Updating existing entity '%s' from protocol"
|
|
105
|
+
" data '%s'", existing_entity, entity
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
self._entities[existing_entity_idx].update(entity)
|
|
109
|
+
non_existing_entities.remove(entity)
|
|
110
|
+
else:
|
|
111
|
+
# Add the new entity to the list
|
|
112
|
+
_LOGGER.debug('Adding new entity: %s', entity)
|
|
113
|
+
self._entities.append(entity)
|
|
114
|
+
|
|
115
|
+
# Mark the entities that are no longer in the list
|
|
116
|
+
for unavailable_entity in non_existing_entities:
|
|
117
|
+
_LOGGER.debug(
|
|
118
|
+
'Marking entity as unavailable: %s', unavailable_entity
|
|
119
|
+
)
|
|
120
|
+
unavailable_entity.is_unavailable = True
|
|
121
|
+
|
|
122
|
+
_LOGGER.debug(
|
|
123
|
+
'Total number of entities: %s, unavailable: %s',
|
|
124
|
+
len(self._entities), len(non_existing_entities)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return self._entities
|
|
128
|
+
|
|
129
|
+
async def find(
|
|
130
|
+
self, idx: int, name: str, exclude_unavailable: bool
|
|
131
|
+
) -> Optional[T]:
|
|
132
|
+
"""
|
|
133
|
+
Finds entity by index and name.
|
|
134
|
+
|
|
135
|
+
:param idx: Entity index
|
|
136
|
+
:param name: Entity name
|
|
137
|
+
:param exclude_unavailable: Exclude unavailable entities
|
|
138
|
+
:return: Entity instance
|
|
139
|
+
"""
|
|
140
|
+
entities = await self.entities
|
|
141
|
+
|
|
142
|
+
found = None
|
|
143
|
+
# Fast lookup by direct index
|
|
144
|
+
if idx < len(entities) and entities[idx].name == name:
|
|
145
|
+
entity = entities[idx]
|
|
146
|
+
_LOGGER.debug('Found entity via fast lookup: %s', entity)
|
|
147
|
+
found = entity
|
|
148
|
+
|
|
149
|
+
# Fast lookup failed, perform slow one over the whole entities list
|
|
150
|
+
if not found:
|
|
151
|
+
for entity in entities:
|
|
152
|
+
if entity.index == idx and entity.name == name:
|
|
153
|
+
_LOGGER.debug('Found entity: %s', entity)
|
|
154
|
+
found = entity
|
|
155
|
+
|
|
156
|
+
if found:
|
|
157
|
+
if not exclude_unavailable or not found.is_unavailable:
|
|
158
|
+
return found
|
|
159
|
+
|
|
160
|
+
_LOGGER.debug(
|
|
161
|
+
'Entity is found but unavailable, will result in none returned'
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
_LOGGER.error('Entity not found: idx=%s, name=%s', idx, name)
|
|
165
|
+
return None
|