pyg90alarm 1.17.1__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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyg90alarm
3
- Version: 1.17.1
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,5 +1,5 @@
1
1
  pyg90alarm/__init__.py,sha256=5AITRm5jZSzuQaL7PS8fZZMZb4-IuGRhSqyAdfTt0Cs,2236
2
- pyg90alarm/alarm.py,sha256=GMft1R4Yp70VeWQLHApE8yVcfsDBbzhbHj1rc_gIj8k,35947
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
@@ -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.1.dist-info/LICENSE,sha256=f884inRbeNv-O-hbwz62Ro_1J8xiHRTnJ2cCx6A0WvU,1070
24
- pyg90alarm-1.17.1.dist-info/METADATA,sha256=7lYmor4_swZNNn3P2yF7FRse5Hz4X3xpgAeNE55t0LA,7714
25
- pyg90alarm-1.17.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
26
- pyg90alarm-1.17.1.dist-info/top_level.txt,sha256=czHiGxYMyTk5QEDTDb0EpPiKqUMRa8zI4zx58Ii409M,11
27
- pyg90alarm-1.17.1.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,,