Skip to content

Commit

Permalink
Fix ADS race condition (#21677)
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenschroeder authored and MartinHjelmare committed Mar 5, 2019
1 parent 0e78054 commit 17c3c14
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions homeassistant/components/ads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,12 @@ def add_device_notification(self, name, plc_datatype, callback):
hnotify, huser = self._client.add_device_notification(
name, attr, self._device_notification_callback)
hnotify = int(hnotify)
self._notification_items[hnotify] = NotificationItem(
hnotify, huser, name, plc_datatype, callback)

_LOGGER.debug(
"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):
"""Handle device notifications."""
contents = notification.contents
Expand All @@ -187,9 +186,10 @@ def _device_notification_callback(self, notification, name):
data = contents.data

try:
notification_item = self._notification_items[hnotify]
with self._lock:
notification_item = self._notification_items[hnotify]
except KeyError:
_LOGGER.debug("Unknown device notification handle: %d", hnotify)
_LOGGER.error("Unknown device notification handle: %d", hnotify)
return

# Parse data to desired datatype
Expand Down

0 comments on commit 17c3c14

Please sign in to comment.