From 9049de9f120bc86ef0e8e3c6c98c0887e418bcee Mon Sep 17 00:00:00 2001 From: craibo Date: Wed, 25 May 2022 14:37:13 +1000 Subject: [PATCH] - Refactor to use the image rotate interval directly --- custom_components/ha_strava/camera.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/custom_components/ha_strava/camera.py b/custom_components/ha_strava/camera.py index 7f39f9c..2b2b901 100644 --- a/custom_components/ha_strava/camera.py +++ b/custom_components/ha_strava/camera.py @@ -35,24 +35,21 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities([camera]) - def image_update_listener(event): - """listen for time update event (every second) and update images if appropriate""" - ha_strava_config_entries = hass.config_entries.async_entries(domain=DOMAIN) - + def image_update_listener(): if len(ha_strava_config_entries) != 1: return -1 - img_update_interval_seconds = int( - ha_strava_config_entries[0].options.get( - CONF_IMG_UPDATE_INTERVAL_SECONDS, - CONF_IMG_UPDATE_INTERVAL_SECONDS_DEFAULT, - ) - ) + camera.rotate_img() - if event.data["now"].second % img_update_interval_seconds == 0: - camera.rotate_img() + ha_strava_config_entries = hass.config_entries.async_entries(domain=DOMAIN) + img_update_interval_seconds = int( + ha_strava_config_entries[0].options.get( + CONF_IMG_UPDATE_INTERVAL_SECONDS, + CONF_IMG_UPDATE_INTERVAL_SECONDS_DEFAULT, + ) + ) - async_track_time_interval(image_update_listener, timedelta(minutes=1)) + async_track_time_interval(hass, image_update_listener, timedelta(seconds=img_update_interval_seconds)) return