pyg90alarm 1.14.0__py3-none-any.whl → 1.15.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
@@ -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
  ]
@@ -470,16 +467,19 @@ class G90Alarm(G90DeviceNotifications):
470
467
  _LOGGER.debug('on_sensor_activity: %s %s %s', idx, name, occupancy)
471
468
  sensor = await self.find_sensor(idx, name)
472
469
  if sensor:
473
- _LOGGER.debug('Setting occupancy to %s (previously %s)',
474
- occupancy, sensor.occupancy)
475
- sensor.occupancy = occupancy
470
+ # Reset the low battery flag since the sensor reports activity,
471
+ # implying it has sufficient battery power
472
+ # pylint: disable=protected-access
473
+ sensor._set_low_battery(False)
474
+ # Set the sensor occupancy
475
+ # pylint: disable=protected-access
476
+ sensor._set_occupancy(occupancy)
476
477
 
477
478
  # Emulate turning off the occupancy - most of sensors will not
478
479
  # notify the device of that, nor the device would emit such
479
480
  # notification itself
480
481
  def reset_sensor_occupancy(sensor: G90Sensor) -> None:
481
- _LOGGER.debug('Resetting occupancy for sensor %s', sensor)
482
- sensor.occupancy = False
482
+ sensor._set_occupancy(False)
483
483
  G90Callback.invoke(sensor.state_callback, sensor.occupancy)
484
484
 
485
485
  # Determine if door close notifications are available for the given
@@ -639,8 +639,12 @@ class G90Alarm(G90DeviceNotifications):
639
639
  :param event_id: Index of the sensor triggered alarm
640
640
  :param zone_name: Sensor name
641
641
  """
642
+ _LOGGER.debug('on_low_battery: %s %s', event_id, zone_name)
642
643
  sensor = await self.find_sensor(event_id, zone_name)
643
644
  if sensor:
645
+ # Set the low battery flag on the sensor
646
+ # pylint: disable=protected-access
647
+ sensor._set_low_battery(True)
644
648
  # Invoke per-sensor callback if provided
645
649
  G90Callback.invoke(sensor.low_battery_callback)
646
650
 
@@ -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.0
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=jCxNzyjfnCUfJl6bSvXih-0YoNtz66EbsYhUvlElFxs,32044
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.0.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
+ pyg90alarm-1.15.0.dist-info/METADATA,sha256=-NPVNpOmAXyptTOMERM1rWW81EtU0BnXMsklnSsbaqg,7663
25
+ pyg90alarm-1.15.0.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
26
+ pyg90alarm-1.15.0.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
+ pyg90alarm-1.15.0.dist-info/RECORD,,