From d32e3dc31a6d9b552037dd916094c17c43acef76 Mon Sep 17 00:00:00 2001 From: Franchie <3265760+Franchie@users.noreply.github.com> Date: Tue, 8 Sep 2020 22:00:38 +0100 Subject: [PATCH] Avoid failing when hub does not provide cover position information (#39826) The powerview hub, seemingly randomly, will occasionally not provide data for cover positions. Some requests will return the desired response, but minutes later the same request might not. It appears this issue is being experienced by a number of people: https://community.home-assistant.io/t/hunter-douglas-powerview-component-expanding-this-api/88635/48 While an unfortunate bug with the hub, crashing the integration as a result of this missing data appears somewhat excessive. This patch adds a simple check to ensure the 'position' key has been returned by the hub before attempting to access its data. --- homeassistant/components/hunterdouglas_powerview/cover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/hunterdouglas_powerview/cover.py b/homeassistant/components/hunterdouglas_powerview/cover.py index 402451da26e..48b5f86cd02 100644 --- a/homeassistant/components/hunterdouglas_powerview/cover.py +++ b/homeassistant/components/hunterdouglas_powerview/cover.py @@ -215,7 +215,7 @@ class PowerViewShade(ShadeEntity, CoverEntity): def _async_update_current_cover_position(self): """Update the current cover position from the data.""" _LOGGER.debug("Raw data update: %s", self._shade.raw_data) - position_data = self._shade.raw_data[ATTR_POSITION_DATA] + position_data = self._shade.raw_data.get(ATTR_POSITION_DATA, {}) if ATTR_POSITION1 in position_data: self._current_cover_position = position_data[ATTR_POSITION1] self._is_opening = False