Skip to content

Commit

Permalink
Merge pull request #4 from craibo/2022.05-BreakingChangeFix
Browse files Browse the repository at this point in the history
- Refactor to use the image rotate interval directly
  • Loading branch information
craibo authored May 25, 2022
2 parents b9b1c51 + 9049de9 commit c8888de
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions custom_components/ha_strava/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c8888de

Please sign in to comment.