From 0db8cb8b679b263c2c98ddbf7b8b809f07f7aa6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Schr=C3=B6der?= Date: Tue, 5 Mar 2019 10:05:37 +0100 Subject: [PATCH] fix race condition --- homeassistant/components/ads/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/ads/__init__.py b/homeassistant/components/ads/__init__.py index 060e9b2b98792..1b90e645af4dc 100644 --- a/homeassistant/components/ads/__init__.py +++ b/homeassistant/components/ads/__init__.py @@ -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 @@ -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