pyg90alarm 1.17.0__py3-none-any.whl → 1.17.2__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
@@ -161,7 +161,9 @@ class G90Alarm(G90DeviceNotifications):
161
161
  self._host: str = host
162
162
  self._port: int = port
163
163
  self._sensors: List[G90Sensor] = []
164
+ self._sensors_lock = asyncio.Lock()
164
165
  self._devices: List[G90Device] = []
166
+ self._devices_lock = asyncio.Lock()
165
167
  self._notifications: Optional[G90DeviceNotifications] = None
166
168
  self._sensor_cb: Optional[SensorCallback] = None
167
169
  self._armdisarm_cb: Optional[ArmDisarmCallback] = None
@@ -258,20 +260,26 @@ class G90Alarm(G90DeviceNotifications):
258
260
 
259
261
  :return: List of sensors
260
262
  """
261
- if not self._sensors:
262
- sensors = self.paginated_result(
263
- G90Commands.GETSENSORLIST
264
- )
265
- async for sensor in sensors:
266
- obj = G90Sensor(
267
- *sensor.data, parent=self, subindex=0,
268
- proto_idx=sensor.proto_idx
263
+ # Use lock around the operation, to ensure no duplicated entries in the
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
269
270
  )
270
- self._sensors.append(obj)
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)
271
277
 
272
- _LOGGER.debug('Total number of sensors: %s', len(self._sensors))
278
+ _LOGGER.debug(
279
+ 'Total number of sensors: %s', len(self._sensors)
280
+ )
273
281
 
274
- return self._sensors
282
+ return self._sensors
275
283
 
276
284
  async def find_sensor(self, idx: int, name: str) -> Optional[G90Sensor]:
277
285
  """
@@ -316,28 +324,32 @@ class G90Alarm(G90DeviceNotifications):
316
324
 
317
325
  :return: List of devices
318
326
  """
319
- if not self._devices:
320
- devices = self.paginated_result(
321
- G90Commands.GETDEVICELIST
322
- )
323
- async for device in devices:
324
- obj = G90Device(
325
- *device.data, parent=self, subindex=0,
326
- proto_idx=device.proto_idx
327
+ # See `get_sensors` method for the rationale behind the lock usage
328
+ async with self._devices_lock:
329
+ if not self._devices:
330
+ devices = self.paginated_result(
331
+ G90Commands.GETDEVICELIST
327
332
  )
328
- self._devices.append(obj)
329
- # Multi-node devices (first node has already been added
330
- # above
331
- for node in range(1, obj.node_count):
333
+ async for device in devices:
332
334
  obj = G90Device(
333
- *device.data, parent=self,
334
- subindex=node, proto_idx=device.proto_idx
335
+ *device.data, parent=self, subindex=0,
336
+ proto_idx=device.proto_idx
335
337
  )
336
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)
337
347
 
338
- _LOGGER.debug('Total number of devices: %s', len(self._devices))
348
+ _LOGGER.debug(
349
+ 'Total number of devices: %s', len(self._devices)
350
+ )
339
351
 
340
- return self._devices
352
+ return self._devices
341
353
 
342
354
  @property
343
355
  async def host_info(self) -> G90HostInfo:
@@ -915,7 +927,10 @@ class G90Alarm(G90DeviceNotifications):
915
927
  # notifications port
916
928
  self._handle_alert(
917
929
  (self._host, self._notifications_local_port),
918
- item.as_device_alert()
930
+ item.as_device_alert(),
931
+ # Skip verifying device GUID, since history entry
932
+ # don't have it
933
+ verify_device_id=False
919
934
  )
920
935
 
921
936
  # Record the entry as most recent one
@@ -208,13 +208,17 @@ class G90DeviceNotifications(DatagramProtocol):
208
208
  return False
209
209
 
210
210
  def _handle_alert(
211
- self, addr: Tuple[str, int], alert: G90DeviceAlert
211
+ self, addr: Tuple[str, int], alert: G90DeviceAlert,
212
+ verify_device_id: bool = True
212
213
  ) -> None:
213
214
  handled = False
214
215
 
215
216
  # Stop processing when alert is received from the device with different
216
- # GUID
217
- if self.device_id and alert.device_id != self.device_id:
217
+ # GUID (if enabled)
218
+ if (
219
+ verify_device_id and self.device_id
220
+ and alert.device_id != self.device_id
221
+ ):
218
222
  _LOGGER.error(
219
223
  "Received alert from wrong device: expected '%s', got '%s'",
220
224
  self.device_id, alert.device_id
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyg90alarm
3
- Version: 1.17.0
3
+ Version: 1.17.2
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=N4A-R3_R39FR2jtwuAtHr1r4H8H_1HxBMfNizYFOK1E,35773
2
+ pyg90alarm/alarm.py,sha256=nTP0JrXQCqLz_lhA9F_AHK3CPNbYMt3gSeQVOL9QSpI,36589
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
6
  pyg90alarm/const.py,sha256=0EkfCtySEPi6W0TO-j-F1y7_MVFaMOuKDY1Bx6QGDDQ,6617
7
- pyg90alarm/device_notifications.py,sha256=2ZiQNKlSOFYK9eZgP_u4KtRuB9PG0o4Q9fS-Emi9MIw,16578
7
+ pyg90alarm/device_notifications.py,sha256=61oruR70snBRXNzOfj313TO7p2TmbEk-dH9AA1nkDkY,16687
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
@@ -20,8 +20,8 @@ pyg90alarm/definitions/sensors.py,sha256=rKOu21ZpI44xk6aMh_vBjniFqnsNTc1CKwAvnv4
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
22
  pyg90alarm/entities/sensor.py,sha256=4r8ouAYTZB8ih8I4ncWdQOaifYsRxaC-ukY9jvnrRvk,16139
23
- pyg90alarm-1.17.0.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
- pyg90alarm-1.17.0.dist-info/METADATA,sha256=LLdZ_3HEA3rIlt1VnNPSIrH5QR5OP68XrlcDT_FN6wk,7714
25
- pyg90alarm-1.17.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
26
- pyg90alarm-1.17.0.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
- pyg90alarm-1.17.0.dist-info/RECORD,,
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,,