mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Fix ADS race condition (#21677)
This commit is contained in:
parent
0e78054195
commit
17c3c14833
@ -171,13 +171,12 @@ class AdsHub:
|
|||||||
hnotify, huser = self._client.add_device_notification(
|
hnotify, huser = self._client.add_device_notification(
|
||||||
name, attr, self._device_notification_callback)
|
name, attr, self._device_notification_callback)
|
||||||
hnotify = int(hnotify)
|
hnotify = int(hnotify)
|
||||||
|
self._notification_items[hnotify] = NotificationItem(
|
||||||
|
hnotify, huser, name, plc_datatype, callback)
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Added device notification %d for variable %s", hnotify, name)
|
"Added device notification %d for variable %s", hnotify, name)
|
||||||
|
|
||||||
self._notification_items[hnotify] = NotificationItem(
|
|
||||||
hnotify, huser, name, plc_datatype, callback)
|
|
||||||
|
|
||||||
def _device_notification_callback(self, notification, name):
|
def _device_notification_callback(self, notification, name):
|
||||||
"""Handle device notifications."""
|
"""Handle device notifications."""
|
||||||
contents = notification.contents
|
contents = notification.contents
|
||||||
@ -187,9 +186,10 @@ class AdsHub:
|
|||||||
data = contents.data
|
data = contents.data
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
with self._lock:
|
||||||
notification_item = self._notification_items[hnotify]
|
notification_item = self._notification_items[hnotify]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.debug("Unknown device notification handle: %d", hnotify)
|
_LOGGER.error("Unknown device notification handle: %d", hnotify)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Parse data to desired datatype
|
# Parse data to desired datatype
|
||||||
|
Loading…
x
Reference in New Issue
Block a user