From 1609e33030bab3c9f14954af4cf94b869491b619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 15 Feb 2020 17:53:10 +0200 Subject: [PATCH] Simplify missing Garmin Connect data handling, mark entities un/available (#31718) * Simplify missing Garmin Connect data handling, mark entities un/available * Remove unnecessary else --- .../components/garmin_connect/sensor.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/garmin_connect/sensor.py b/homeassistant/components/garmin_connect/sensor.py index d3f95b162bf..5edf54d95dc 100644 --- a/homeassistant/components/garmin_connect/sensor.py +++ b/homeassistant/components/garmin_connect/sensor.py @@ -160,21 +160,20 @@ class GarminConnectSensor(Entity): return await self._data.async_update() - if not self._data.data: + data = self._data.data + if not data: _LOGGER.error("Didn't receive data from Garmin Connect") return - - data = self._data.data - try: - if "Duration" in self._type and data[self._type]: - self._state = data[self._type] // 60 - elif "Seconds" in self._type and data[self._type]: - self._state = data[self._type] // 60 - else: - self._state = data[self._type] - except KeyError: - _LOGGER.debug("Entity type %s not found in fetched data", self._type) + if data.get(self._type) is None: + _LOGGER.debug("Entity type %s not set in fetched data", self._type) + self._available = False return + self._available = True + + if "Duration" in self._type or "Seconds" in self._type: + self._state = data[self._type] // 60 + else: + self._state = data[self._type] _LOGGER.debug( "Entity %s set to state %s %s", self._type, self._state, self._unit