mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Simplify missing Garmin Connect data handling, mark entities un/available (#31718)
* Simplify missing Garmin Connect data handling, mark entities un/available * Remove unnecessary else
This commit is contained in:
parent
e38522c612
commit
1609e33030
@ -160,21 +160,20 @@ class GarminConnectSensor(Entity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await self._data.async_update()
|
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")
|
_LOGGER.error("Didn't receive data from Garmin Connect")
|
||||||
return
|
return
|
||||||
|
if data.get(self._type) is None:
|
||||||
data = self._data.data
|
_LOGGER.debug("Entity type %s not set in fetched data", self._type)
|
||||||
try:
|
self._available = False
|
||||||
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)
|
|
||||||
return
|
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(
|
_LOGGER.debug(
|
||||||
"Entity %s set to state %s %s", self._type, self._state, self._unit
|
"Entity %s set to state %s %s", self._type, self._state, self._unit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user