pyg90alarm 1.17.2__py3-none-any.whl → 1.18.0__py3-none-any.whl

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/alarm.py CHANGED
@@ -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.
@@ -120,6 +121,14 @@ if TYPE_CHECKING:
120
121
  [int, str, G90RemoteButtonStates], Coroutine[None, None, None]
121
122
  ]
122
123
  ]
124
+ DoorOpenWhenArmingCallback = Union[
125
+ Callable[[int, str], None],
126
+ Callable[[int, str], Coroutine[None, None, None]]
127
+ ]
128
+ TamperCallback = Union[
129
+ Callable[[int, str], None],
130
+ Callable[[int, str], Coroutine[None, None, None]]
131
+ ]
123
132
  # Sensor-related callbacks for `G90Sensor` class - despite that class
124
133
  # stores them, the invocation is done by the `G90Alarm` class hence these
125
134
  # are defined here
@@ -131,6 +140,14 @@ if TYPE_CHECKING:
131
140
  Callable[[], None],
132
141
  Callable[[], Coroutine[None, None, None]]
133
142
  ]
143
+ SensorDoorOpenWhenArmingCallback = Union[
144
+ Callable[[], None],
145
+ Callable[[], Coroutine[None, None, None]]
146
+ ]
147
+ SensorTamperCallback = Union[
148
+ Callable[[], None],
149
+ Callable[[], Coroutine[None, None, None]]
150
+ ]
134
151
 
135
152
 
136
153
  # pylint: disable=too-many-public-methods
@@ -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
@@ -613,6 +634,17 @@ class G90Alarm(G90DeviceNotifications):
613
634
  await self.set_alert_config(
614
635
  await self.alert_config | G90AlertConfigFlags.SMS_PUSH
615
636
  )
637
+
638
+ # Reset the tampered and door open when arming flags on all sensors
639
+ # having those set
640
+ for sensor in await self.get_sensors():
641
+ if sensor.is_tampered:
642
+ # pylint: disable=protected-access
643
+ sensor._set_tampered(False)
644
+ if sensor.is_door_open_when_arming:
645
+ # pylint: disable=protected-access
646
+ sensor._set_door_open_when_arming(False)
647
+
616
648
  G90Callback.invoke(self._armdisarm_cb, state)
617
649
 
618
650
  @property
@@ -627,7 +659,9 @@ class G90Alarm(G90DeviceNotifications):
627
659
  def armdisarm_callback(self, value: ArmDisarmCallback) -> None:
628
660
  self._armdisarm_cb = value
629
661
 
630
- async def on_alarm(self, event_id: int, zone_name: str) -> None:
662
+ async def on_alarm(
663
+ self, event_id: int, zone_name: str, is_tampered: bool
664
+ ) -> None:
631
665
  """
632
666
  Invoked when alarm is triggered. Fires corresponding callback if set by
633
667
  the user with :attr:`.alarm_callback`.
@@ -638,16 +672,31 @@ class G90Alarm(G90DeviceNotifications):
638
672
  :param zone_name: Sensor name
639
673
  """
640
674
  sensor = await self.find_sensor(event_id, zone_name)
641
- # The callback is still delivered to the caller even if the sensor
642
- # isn't found, only `extra_data` is skipped. That is to ensure the
643
- # important callback isn't filtered
644
- extra_data = sensor.extra_data if sensor else None
645
- # Invoke the sensor activity callback to set the sensor occupancy if
646
- # sensor is known, but only if that isn't already set - it helps when
647
- # device notifications on triggerring sensor's activity aren't receveid
648
- # by a reason
649
- if sensor and not sensor.occupancy:
650
- await self.on_sensor_activity(event_id, zone_name, True)
675
+ extra_data = None
676
+ if sensor:
677
+ # The callback is still delivered to the caller even if the sensor
678
+ # isn't found, only `extra_data` is skipped. That is to ensure the
679
+ # important callback isn't filtered
680
+ extra_data = sensor.extra_data
681
+
682
+ # Invoke the sensor activity callback to set the sensor occupancy
683
+ # if sensor is known, but only if that isn't already set - it helps
684
+ # when device notifications on triggerring sensor's activity aren't
685
+ # receveid by a reason
686
+ if not sensor.occupancy:
687
+ await self.on_sensor_activity(event_id, zone_name, True)
688
+
689
+ if is_tampered:
690
+ # Set the tampered flag on the sensor
691
+ # pylint: disable=protected-access
692
+ sensor._set_tampered(True)
693
+
694
+ # Invoke per-sensor callback if provided
695
+ G90Callback.invoke(sensor.tamper_callback)
696
+
697
+ # Invoke global tamper callback if provided and the sensor is tampered
698
+ if is_tampered:
699
+ G90Callback.invoke(self._tamper_cb, event_id, zone_name)
651
700
 
652
701
  G90Callback.invoke(
653
702
  self._alarm_cb, event_id, zone_name, extra_data
@@ -718,7 +767,10 @@ class G90Alarm(G90DeviceNotifications):
718
767
 
719
768
  # Also report the event as alarm for unification, hard-coding the
720
769
  # sensor name in case of host SOS
721
- await self.on_alarm(event_id, 'Host SOS' if is_host_sos else zone_name)
770
+ await self.on_alarm(
771
+ event_id, zone_name='Host SOS' if is_host_sos else zone_name,
772
+ is_tampered=False
773
+ )
722
774
 
723
775
  if not is_host_sos:
724
776
  # Also report the remote button press for SOS - the panel will not
@@ -778,6 +830,58 @@ class G90Alarm(G90DeviceNotifications):
778
830
  ) -> None:
779
831
  self._remote_button_press_cb = value
780
832
 
833
+ async def on_door_open_when_arming(
834
+ self, event_id: int, zone_name: str
835
+ ) -> None:
836
+ """
837
+ Invoked when door is open when arming the device. Fires corresponding
838
+ callback if set by the user with
839
+ :attr:`.door_open_when_arming_callback`.
840
+
841
+ Please note the method is for internal use by the class.
842
+
843
+ :param event_id: The index of the sensor being active when the panel
844
+ is being armed.
845
+ :param zone_name: The name of the sensor
846
+ """
847
+ _LOGGER.debug('on_door_open_when_arming: %s %s', event_id, zone_name)
848
+ sensor = await self.find_sensor(event_id, zone_name)
849
+ if sensor:
850
+ # Set the low battery flag on the sensor
851
+ # pylint: disable=protected-access
852
+ sensor._set_door_open_when_arming(True)
853
+ # Invoke per-sensor callback if provided
854
+ G90Callback.invoke(sensor.door_open_when_arming_callback)
855
+
856
+ G90Callback.invoke(self._door_open_when_arming_cb, event_id, zone_name)
857
+
858
+ @property
859
+ def door_open_when_arming_callback(
860
+ self
861
+ ) -> Optional[DoorOpenWhenArmingCallback]:
862
+ """
863
+ Door open when arming callback, which is invoked when sensor reports
864
+ the condition.
865
+ """
866
+ return self._door_open_when_arming_cb
867
+
868
+ @door_open_when_arming_callback.setter
869
+ def door_open_when_arming_callback(
870
+ self, value: DoorOpenWhenArmingCallback
871
+ ) -> None:
872
+ self._door_open_when_arming_cb = value
873
+
874
+ @property
875
+ async def tamper_callback(self) -> Optional[TamperCallback]:
876
+ """
877
+ Tamper callback, which is invoked when sensor reports the condition.
878
+ """
879
+ return self._tamper_cb
880
+
881
+ @tamper_callback.setter
882
+ def tamper_callback(self, value: TamperCallback) -> None:
883
+ self._tamper_cb = value
884
+
781
885
  async def listen_device_notifications(self) -> None:
782
886
  """
783
887
  Starts internal listener for device notifications/alerts.
pyg90alarm/const.py CHANGED
@@ -201,6 +201,7 @@ class G90AlertSources(IntEnum):
201
201
  """
202
202
  DEVICE = 0
203
203
  SENSOR = 1
204
+ TAMPER = 3
204
205
  REMOTE = 10
205
206
  RFID = 11
206
207
  DOORBELL = 12
@@ -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
- _LOGGER.debug('Alarm: %s', alert.zone_name)
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(self, event_id: int, zone_name: str) -> None:
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
 
@@ -32,7 +32,10 @@ from enum import IntEnum, IntFlag
32
32
  from ..definitions.sensors import SENSOR_DEFINITIONS, SensorDefinition
33
33
  from ..const import G90Commands
34
34
  if TYPE_CHECKING:
35
- from ..alarm import G90Alarm, SensorStateCallback, SensorLowBatteryCallback
35
+ from ..alarm import (
36
+ G90Alarm, SensorStateCallback, SensorLowBatteryCallback,
37
+ SensorDoorOpenWhenArmingCallback, SensorTamperCallback,
38
+ )
36
39
 
37
40
 
38
41
  @dataclass
@@ -157,6 +160,7 @@ class G90SensorTypes(IntEnum):
157
160
  _LOGGER = logging.getLogger(__name__)
158
161
 
159
162
 
163
+ # pylint: disable=too-many-public-methods
160
164
  class G90Sensor: # pylint:disable=too-many-instance-attributes
161
165
  """
162
166
  Interacts with sensor on G90 alarm panel.
@@ -186,6 +190,12 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
186
190
  self._state_callback: Optional[SensorStateCallback] = None
187
191
  self._low_battery_callback: Optional[SensorLowBatteryCallback] = None
188
192
  self._low_battery = False
193
+ self._tampered = False
194
+ self._door_open_when_arming_callback: Optional[
195
+ SensorDoorOpenWhenArmingCallback
196
+ ] = None
197
+ self._tamper_callback: Optional[SensorTamperCallback] = None
198
+ self._door_open_when_arming = False
189
199
  self._proto_idx = proto_idx
190
200
  self._extra_data: Any = None
191
201
 
@@ -238,6 +248,37 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
238
248
  def low_battery_callback(self, value: SensorLowBatteryCallback) -> None:
239
249
  self._low_battery_callback = value
240
250
 
251
+ @property
252
+ def door_open_when_arming_callback(
253
+ self
254
+ ) -> Optional[SensorDoorOpenWhenArmingCallback]:
255
+ """
256
+ Callback that is invoked when the sensor reports on open door
257
+ condition when arming.
258
+
259
+ :return: Sensor's door open when arming callback
260
+ """
261
+ return self._door_open_when_arming_callback
262
+
263
+ @door_open_when_arming_callback.setter
264
+ def door_open_when_arming_callback(
265
+ self, value: SensorDoorOpenWhenArmingCallback
266
+ ) -> None:
267
+ self._door_open_when_arming_callback = value
268
+
269
+ @property
270
+ def tamper_callback(self) -> Optional[SensorTamperCallback]:
271
+ """
272
+ Callback that is invoked when the sensor reports being tampered.
273
+
274
+ :return: Sensor's tamper callback
275
+ """
276
+ return self._tamper_callback
277
+
278
+ @tamper_callback.setter
279
+ def tamper_callback(self, value: SensorTamperCallback) -> None:
280
+ self._tamper_callback = value
281
+
241
282
  @property
242
283
  def occupancy(self) -> bool:
243
284
  """
@@ -365,12 +406,16 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
365
406
  def is_low_battery(self) -> bool:
366
407
  """
367
408
  Indicates if the sensor is reporting low battery.
409
+
410
+ The condition is cleared when the sensor reports activity (i.e. is no
411
+ longer low on battery as it is able to report the activity).
368
412
  """
369
413
  return self._low_battery
370
414
 
371
415
  def _set_low_battery(self, value: bool) -> None:
372
416
  """
373
417
  Sets low battery state of the sensor.
418
+
374
419
  Intentionally private, as low battery state is derived from
375
420
  notifications/alerts.
376
421
 
@@ -383,6 +428,56 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
383
428
  )
384
429
  self._low_battery = value
385
430
 
431
+ @property
432
+ def is_tampered(self) -> bool:
433
+ """
434
+ Indicates if the sensor has been tampered.
435
+
436
+ The condition is cleared when panel is armed/disarmed next time.
437
+ """
438
+ return self._tampered
439
+
440
+ def _set_tampered(self, value: bool) -> None:
441
+ """
442
+ Sets tamper state of the sensor.
443
+
444
+ Intentionally private, as tamper state is derived from
445
+ notifications/alerts.
446
+
447
+ :param value: Tamper state
448
+ """
449
+ _LOGGER.debug(
450
+ "Setting tamper for sensor index=%s '%s': %s"
451
+ " (previous value: %s)",
452
+ self.index, self.name, value, self._tampered
453
+ )
454
+ self._tampered = value
455
+
456
+ @property
457
+ def is_door_open_when_arming(self) -> bool:
458
+ """
459
+ Indicates if the sensor reports on open door when arming.
460
+
461
+ The condition is cleared when panel is armed/disarmed next time.
462
+ """
463
+ return self._door_open_when_arming
464
+
465
+ def _set_door_open_when_arming(self, value: bool) -> None:
466
+ """
467
+ Sets door open state of the sensor when arming.
468
+
469
+ Intentionally private, as door open state is derived from
470
+ notifications/alerts.
471
+
472
+ :param value: Door open state
473
+ """
474
+ _LOGGER.debug(
475
+ "Setting door open when arming for sensor index=%s '%s': %s"
476
+ " (previous value: %s)",
477
+ self.index, self.name, value, self._door_open_when_arming
478
+ )
479
+ self._door_open_when_arming = value
480
+
386
481
  @property
387
482
  def enabled(self) -> bool:
388
483
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyg90alarm
3
- Version: 1.17.2
3
+ Version: 1.18.0
4
4
  Summary: G90 Alarm system protocol
5
5
  Home-page: https://github.com/hostcc/pyg90alarm
6
6
  Author: Ilia Sotnikov
@@ -1,10 +1,10 @@
1
1
  pyg90alarm/__init__.py,sha256=5AITRm5jZSzuQaL7PS8fZZMZb4-IuGRhSqyAdfTt0Cs,2236
2
- pyg90alarm/alarm.py,sha256=nTP0JrXQCqLz_lhA9F_AHK3CPNbYMt3gSeQVOL9QSpI,36589
2
+ pyg90alarm/alarm.py,sha256=dOhe2C2zsJ55VE5NJF-PE7pKRF_YOCF70ACJbDYEgF8,40196
3
3
  pyg90alarm/base_cmd.py,sha256=Bz7yoZ0RpkcjWARya664DKAPo3goD6BeaKtuW-hA804,9902
4
4
  pyg90alarm/callback.py,sha256=3JsD_JChmZD24OyjaCP-PxxuBDBX7myGYhkM4RN7bk4,3742
5
5
  pyg90alarm/config.py,sha256=2YtIgdT7clQXmYvkdn_fhIdS05CY8E1Yc90R8_tAmRI,1961
6
- pyg90alarm/const.py,sha256=0EkfCtySEPi6W0TO-j-F1y7_MVFaMOuKDY1Bx6QGDDQ,6617
7
- pyg90alarm/device_notifications.py,sha256=61oruR70snBRXNzOfj313TO7p2TmbEk-dH9AA1nkDkY,16687
6
+ pyg90alarm/const.py,sha256=uBzDUSlVO3FZxLI11bzfCm6JTI2_ciageyf43JLSehg,6632
7
+ pyg90alarm/device_notifications.py,sha256=pqkeKYORUUZUEovUKajuu8JHCtXD0ulAZIKelNfn2Eg,17602
8
8
  pyg90alarm/discovery.py,sha256=fwyBHDCKGej06OwhpbVCHYTRU9WWkeYysAFgv3FiwqI,3575
9
9
  pyg90alarm/exceptions.py,sha256=eiOcRe7D18EIPyPFDNU9DdFgbnkwPmkiLl8lGPOhBNw,1475
10
10
  pyg90alarm/history.py,sha256=5NfgB0V-7TZlMNHEjtRbOA0ZtJfQTgh2ysZIg5RM7ck,9080
@@ -19,9 +19,9 @@ pyg90alarm/definitions/__init__.py,sha256=s0NZnkW_gMH718DJbgez28z9WA231CyszUf1O_
19
19
  pyg90alarm/definitions/sensors.py,sha256=rKOu21ZpI44xk6aMh_vBjniFqnsNTc1CKwAvnv4PYLQ,19904
20
20
  pyg90alarm/entities/__init__.py,sha256=hHb6AOiC4Tz--rOWiiICMdLaZDs1Tf_xpWk_HeS_gO4,66
21
21
  pyg90alarm/entities/device.py,sha256=f_LHvKCAqTEebZ4mrRh3CpPUI7o-OvpvOfyTRCbftJs,2818
22
- pyg90alarm/entities/sensor.py,sha256=4r8ouAYTZB8ih8I4ncWdQOaifYsRxaC-ukY9jvnrRvk,16139
23
- pyg90alarm-1.17.2.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
- pyg90alarm-1.17.2.dist-info/METADATA,sha256=8PoCUW_lwXEsjV5MZUGOb362h7C2JL0PHIOlEWr8twk,7714
25
- pyg90alarm-1.17.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
26
- pyg90alarm-1.17.2.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
- pyg90alarm-1.17.2.dist-info/RECORD,,
22
+ pyg90alarm/entities/sensor.py,sha256=G9WoFL32Kjh8qgHyyO_Yn2gZkDkkxjNIdKV1DnmkhnU,19125
23
+ pyg90alarm-1.18.0.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
+ pyg90alarm-1.18.0.dist-info/METADATA,sha256=xHpDuXsOvtcHmIS7-lPEeQ6nHG6NkuBZLW-eMEJoroY,7714
25
+ pyg90alarm-1.18.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
26
+ pyg90alarm-1.18.0.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
+ pyg90alarm-1.18.0.dist-info/RECORD,,