pyg90alarm 1.14.0__py3-none-any.whl → 1.15.1__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
@@ -56,9 +56,6 @@ from typing import (
56
56
  TYPE_CHECKING, Any, List, Optional, AsyncGenerator,
57
57
  Callable, Coroutine, Union
58
58
  )
59
- from typing_extensions import (
60
- TypeAlias
61
- )
62
59
  from .const import (
63
60
  G90Commands, REMOTE_PORT,
64
61
  REMOTE_TARGETED_DISCOVERY_PORT,
@@ -91,7 +88,7 @@ if TYPE_CHECKING:
91
88
  # Type alias for the callback functions available to the user, should be
92
89
  # compatible with `G90Callback.Callback` type, since `G90Callback.invoke`
93
90
  # is used to invoke them
94
- AlarmCallback: TypeAlias = Union[
91
+ AlarmCallback = Union[
95
92
  Callable[[int, str, Any], None],
96
93
  Callable[[int, str, Any], Coroutine[None, None, None]]
97
94
  ]
@@ -103,22 +100,25 @@ if TYPE_CHECKING:
103
100
  Callable[[int, str, bool], None],
104
101
  Callable[[int, str, bool], Coroutine[None, None, None]]
105
102
  ]
106
- SensorStateCallback = Union[
107
- Callable[[bool], None],
108
- Callable[[bool], Coroutine[None, None, None]]
109
- ]
110
103
  LowBatteryCallback = Union[
111
104
  Callable[[int, str], None],
112
105
  Callable[[int, str], Coroutine[None, None, None]]
113
106
  ]
114
- SensorLowBatteryCallback = Union[
115
- Callable[[bool], None],
116
- Callable[[bool], Coroutine[None, None, None]]
117
- ]
118
107
  ArmDisarmCallback = Union[
119
108
  Callable[[G90ArmDisarmTypes], None],
120
109
  Callable[[G90ArmDisarmTypes], Coroutine[None, None, None]]
121
110
  ]
111
+ # Sensor-related callbacks for `G90Sensor` class - despite that class
112
+ # stores them, the invication is done by the `G90Alarm` class hence these
113
+ # are defined here
114
+ SensorStateCallback = Union[
115
+ Callable[[bool], None],
116
+ Callable[[bool], Coroutine[None, None, None]]
117
+ ]
118
+ SensorLowBatteryCallback = Union[
119
+ Callable[[], None],
120
+ Callable[[], Coroutine[None, None, None]]
121
+ ]
122
122
 
123
123
 
124
124
  # pylint: disable=too-many-public-methods
@@ -470,16 +470,19 @@ class G90Alarm(G90DeviceNotifications):
470
470
  _LOGGER.debug('on_sensor_activity: %s %s %s', idx, name, occupancy)
471
471
  sensor = await self.find_sensor(idx, name)
472
472
  if sensor:
473
- _LOGGER.debug('Setting occupancy to %s (previously %s)',
474
- occupancy, sensor.occupancy)
475
- sensor.occupancy = occupancy
473
+ # Reset the low battery flag since the sensor reports activity,
474
+ # implying it has sufficient battery power
475
+ # pylint: disable=protected-access
476
+ sensor._set_low_battery(False)
477
+ # Set the sensor occupancy
478
+ # pylint: disable=protected-access
479
+ sensor._set_occupancy(occupancy)
476
480
 
477
481
  # Emulate turning off the occupancy - most of sensors will not
478
482
  # notify the device of that, nor the device would emit such
479
483
  # notification itself
480
484
  def reset_sensor_occupancy(sensor: G90Sensor) -> None:
481
- _LOGGER.debug('Resetting occupancy for sensor %s', sensor)
482
- sensor.occupancy = False
485
+ sensor._set_occupancy(False)
483
486
  G90Callback.invoke(sensor.state_callback, sensor.occupancy)
484
487
 
485
488
  # Determine if door close notifications are available for the given
@@ -639,8 +642,12 @@ class G90Alarm(G90DeviceNotifications):
639
642
  :param event_id: Index of the sensor triggered alarm
640
643
  :param zone_name: Sensor name
641
644
  """
645
+ _LOGGER.debug('on_low_battery: %s %s', event_id, zone_name)
642
646
  sensor = await self.find_sensor(event_id, zone_name)
643
647
  if sensor:
648
+ # Set the low battery flag on the sensor
649
+ # pylint: disable=protected-access
650
+ sensor._set_low_battery(True)
644
651
  # Invoke per-sensor callback if provided
645
652
  G90Callback.invoke(sensor.low_battery_callback)
646
653
 
@@ -185,6 +185,7 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
185
185
  self._occupancy = False
186
186
  self._state_callback: Optional[SensorStateCallback] = None
187
187
  self._low_battery_callback: Optional[SensorLowBatteryCallback] = None
188
+ self._low_battery = False
188
189
  self._proto_idx = proto_idx
189
190
  self._extra_data: Any = None
190
191
 
@@ -247,8 +248,19 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
247
248
  """
248
249
  return self._occupancy
249
250
 
250
- @occupancy.setter
251
- def occupancy(self, value: bool) -> None:
251
+ def _set_occupancy(self, value: bool) -> None:
252
+ """
253
+ Sets occupancy state of the sensor.
254
+ Intentionally private, as occupancy state is derived from
255
+ notifications/alerts.
256
+
257
+ :param value: Occupancy state
258
+ """
259
+ _LOGGER.debug(
260
+ "Setting occupancy for sensor index=%s: '%s' %s"
261
+ " (previous value: %s)",
262
+ self.index, self.name, value, self._occupancy
263
+ )
252
264
  self._occupancy = value
253
265
 
254
266
  @property
@@ -342,6 +354,35 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
342
354
  """
343
355
  return self._definition is not None
344
356
 
357
+ @property
358
+ def is_wireless(self) -> bool:
359
+ """
360
+ Indicates if the sensor is wireless.
361
+ """
362
+ return self.protocol not in (G90SensorProtocols.CORD,)
363
+
364
+ @property
365
+ def is_low_battery(self) -> bool:
366
+ """
367
+ Indicates if the sensor is reporting low battery.
368
+ """
369
+ return self._low_battery
370
+
371
+ def _set_low_battery(self, value: bool) -> None:
372
+ """
373
+ Sets low battery state of the sensor.
374
+ Intentionally private, as low battery state is derived from
375
+ notifications/alerts.
376
+
377
+ :param value: Low battery state
378
+ """
379
+ _LOGGER.debug(
380
+ "Setting low battery for sensor index=%s '%s': %s"
381
+ " (previous value: %s)",
382
+ self.index, self.name, value, self._low_battery
383
+ )
384
+ self._low_battery = value
385
+
345
386
  @property
346
387
  def enabled(self) -> bool:
347
388
  """
@@ -485,6 +526,8 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
485
526
  'extra_data': self.extra_data,
486
527
  'enabled': self.enabled,
487
528
  'supports_enable_disable': self.supports_enable_disable,
529
+ 'is_wireless': self.is_wireless,
530
+ 'is_low_battery': self.is_low_battery,
488
531
  }
489
532
 
490
533
  def __repr__(self) -> str:
@@ -493,11 +536,4 @@ class G90Sensor: # pylint:disable=too-many-instance-attributes
493
536
 
494
537
  :return: String representation
495
538
  """
496
- return super().__repr__() + f"(name='{str(self.name)}'" \
497
- f' type={str(self.type)}' \
498
- f' subtype={str(self.subtype)}' \
499
- f' protocol={str(self.protocol)}' \
500
- f' occupancy={self.occupancy}' \
501
- f' user flag={str(self.user_flag)}' \
502
- f' reserved={str(self.reserved)}' \
503
- f" extra_data={str(self.extra_data)})"
539
+ return super().__repr__() + f'({repr(self._asdict())})'
pyg90alarm/history.py CHANGED
@@ -211,9 +211,4 @@ class G90History:
211
211
  """
212
212
  Textural representation of the history entry.
213
213
  """
214
- return f'type={repr(self.type)}' \
215
- + f' source={repr(self.source)}' \
216
- + f' state={repr(self.state)}' \
217
- + f' sensor_name={self.sensor_name}' \
218
- + f' sensor_idx={self.sensor_idx}' \
219
- + f' datetime={repr(self.datetime)}'
214
+ return super().__repr__() + f'({repr(self._asdict())})'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyg90alarm
3
- Version: 1.14.0
3
+ Version: 1.15.1
4
4
  Summary: G90 Alarm system protocol
5
5
  Home-page: https://github.com/hostcc/pyg90alarm
6
6
  Author: Ilia Sotnikov
@@ -1,5 +1,5 @@
1
1
  pyg90alarm/__init__.py,sha256=5AITRm5jZSzuQaL7PS8fZZMZb4-IuGRhSqyAdfTt0Cs,2236
2
- pyg90alarm/alarm.py,sha256=N2TTK1F1ZVmj_fCxrx1zNvdMO6HsPOz4yIVcoWnyd2I,31777
2
+ pyg90alarm/alarm.py,sha256=9SqJHGK6wawFUZSaRo6-GkLBz_SxONNgCwGeD38MsSU,32211
3
3
  pyg90alarm/base_cmd.py,sha256=wu2v_RKpcPHxUW4HBDLWcUFMzPsGooY4o2Rc0LgcanU,9754
4
4
  pyg90alarm/callback.py,sha256=3JsD_JChmZD24OyjaCP-PxxuBDBX7myGYhkM4RN7bk4,3742
5
5
  pyg90alarm/config.py,sha256=2YtIgdT7clQXmYvkdn_fhIdS05CY8E1Yc90R8_tAmRI,1961
@@ -7,7 +7,7 @@ pyg90alarm/const.py,sha256=4eJyEZpUE5XZkNL1sePKnuPloIvcjKIAJJ4g2e1cXVA,6054
7
7
  pyg90alarm/device_notifications.py,sha256=I5K8IsyYTe0XDJT8XiQoC8a2xY1XLjaGx4QFrEsaixg,11135
8
8
  pyg90alarm/discovery.py,sha256=fwyBHDCKGej06OwhpbVCHYTRU9WWkeYysAFgv3FiwqI,3575
9
9
  pyg90alarm/exceptions.py,sha256=eiOcRe7D18EIPyPFDNU9DdFgbnkwPmkiLl8lGPOhBNw,1475
10
- pyg90alarm/history.py,sha256=st9RWfrBbn4LLjfz3MguocPSnaTIATzIiBq2hLNeVTY,7380
10
+ pyg90alarm/history.py,sha256=GnCVRsQNV2x9g6KngBBvvIUnTAIyXKX2nVKF_aFA0oM,7160
11
11
  pyg90alarm/host_info.py,sha256=4lFIaFEpYd3EvgNrDJmKijTrzX9i29nFISLLlXGnkmE,2759
12
12
  pyg90alarm/host_status.py,sha256=4XhuilBzB8XsXkpeWj3PAVpmDPcTnBBOYunO21Flabo,1862
13
13
  pyg90alarm/paginated_cmd.py,sha256=vJ8slMS7aNLpkAxnIe25EHstusYy1bYTl1j306ps-MQ,4439
@@ -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=qg08Myz_P4aTd29R37Js0feSfuJ-u2U6F-6FZiS76D0,15124
23
- pyg90alarm-1.14.0.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
- pyg90alarm-1.14.0.dist-info/METADATA,sha256=Km8Q2Kl5fdxdypLxpA201_A8kfujIpzu5hiSozidmR4,7663
25
- pyg90alarm-1.14.0.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
26
- pyg90alarm-1.14.0.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
- pyg90alarm-1.14.0.dist-info/RECORD,,
22
+ pyg90alarm/entities/sensor.py,sha256=4r8ouAYTZB8ih8I4ncWdQOaifYsRxaC-ukY9jvnrRvk,16139
23
+ pyg90alarm-1.15.1.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
+ pyg90alarm-1.15.1.dist-info/METADATA,sha256=csITqi1utrvJOAqm0PtFGz9UIeDZzTX7JBWJRBjjIzY,7663
25
+ pyg90alarm-1.15.1.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
26
+ pyg90alarm-1.15.1.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
+ pyg90alarm-1.15.1.dist-info/RECORD,,