mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Don't assume that the sleep
value is a dictionary in Tractive integration (#103138)
* Sleep value can be null * Catch TypeError
This commit is contained in:
parent
d078a4396c
commit
8e8f2a2163
@ -240,7 +240,7 @@ class TractiveClient:
|
|||||||
self._config_entry.data[CONF_EMAIL],
|
self._config_entry.data[CONF_EMAIL],
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except KeyError as error:
|
except (KeyError, TypeError) as error:
|
||||||
_LOGGER.error("Error while listening for events: %s", error)
|
_LOGGER.error("Error while listening for events: %s", error)
|
||||||
continue
|
continue
|
||||||
except aiotractive.exceptions.TractiveError:
|
except aiotractive.exceptions.TractiveError:
|
||||||
@ -284,11 +284,16 @@ class TractiveClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _send_wellness_update(self, event: dict[str, Any]) -> None:
|
def _send_wellness_update(self, event: dict[str, Any]) -> None:
|
||||||
|
sleep_day = None
|
||||||
|
sleep_night = None
|
||||||
|
if isinstance(event["sleep"], dict):
|
||||||
|
sleep_day = event["sleep"]["minutes_day_sleep"]
|
||||||
|
sleep_night = event["sleep"]["minutes_night_sleep"]
|
||||||
payload = {
|
payload = {
|
||||||
ATTR_ACTIVITY_LABEL: event["wellness"].get("activity_label"),
|
ATTR_ACTIVITY_LABEL: event["wellness"].get("activity_label"),
|
||||||
ATTR_CALORIES: event["activity"]["calories"],
|
ATTR_CALORIES: event["activity"]["calories"],
|
||||||
ATTR_MINUTES_DAY_SLEEP: event["sleep"]["minutes_day_sleep"],
|
ATTR_MINUTES_DAY_SLEEP: sleep_day,
|
||||||
ATTR_MINUTES_NIGHT_SLEEP: event["sleep"]["minutes_night_sleep"],
|
ATTR_MINUTES_NIGHT_SLEEP: sleep_night,
|
||||||
ATTR_MINUTES_REST: event["activity"]["minutes_rest"],
|
ATTR_MINUTES_REST: event["activity"]["minutes_rest"],
|
||||||
ATTR_SLEEP_LABEL: event["wellness"].get("sleep_label"),
|
ATTR_SLEEP_LABEL: event["wellness"].get("sleep_label"),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user