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.
This commit is contained in:
Franchie 2020-09-08 22:00:38 +01:00 committed by Paulus Schoutsen
parent 807bfb71df
commit d32e3dc31a

View File

@ -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