diff --git a/homeassistant/components/binary_sensor/ring.py b/homeassistant/components/binary_sensor/ring.py index 1e926f00a2f..e84009301ab 100644 --- a/homeassistant/components/binary_sensor/ring.py +++ b/homeassistant/components/binary_sensor/ring.py @@ -27,7 +27,7 @@ SCAN_INTERVAL = timedelta(seconds=5) # Sensor types: Name, category, device_class SENSOR_TYPES = { - 'ding': ['Ding', ['doorbell', 'stickup_cams'], 'occupancy'], + 'ding': ['Ding', ['doorbell'], 'occupancy'], 'motion': ['Motion', ['doorbell', 'stickup_cams'], 'motion'], } diff --git a/homeassistant/components/camera/ring.py b/homeassistant/components/camera/ring.py index 70569825764..a5e9855bf37 100644 --- a/homeassistant/components/camera/ring.py +++ b/homeassistant/components/camera/ring.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/camera.ring/ import asyncio import logging -from datetime import datetime, timedelta +from datetime import timedelta import voluptuous as vol @@ -23,6 +23,8 @@ CONF_FFMPEG_ARGUMENTS = 'ffmpeg_arguments' DEPENDENCIES = ['ring', 'ffmpeg'] +FORCE_REFRESH_INTERVAL = timedelta(minutes=45) + _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(seconds=90) @@ -63,8 +65,8 @@ class RingCam(Camera): self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS) self._last_video_id = self._camera.last_recording_id self._video_url = self._camera.recording_url(self._last_video_id) - self._expires_at = None - self._utcnow = None + self._utcnow = dt_util.utcnow() + self._expires_at = FORCE_REFRESH_INTERVAL + self._utcnow @property def name(self): @@ -123,19 +125,19 @@ class RingCam(Camera): def update(self): """Update camera entity and refresh attributes.""" - # extract the video expiration from URL - x_amz_expires = int(self._video_url.split('&')[0].split('=')[-1]) - x_amz_date = self._video_url.split('&')[1].split('=')[-1] + _LOGGER.debug("Checking if Ring DoorBell needs to refresh video_url") + self._camera.update() self._utcnow = dt_util.utcnow() - self._expires_at = \ - timedelta(seconds=x_amz_expires) + \ - dt_util.as_utc(datetime.strptime(x_amz_date, "%Y%m%dT%H%M%SZ")) - if self._last_video_id != self._camera.last_recording_id: - _LOGGER.debug("Updated Ring DoorBell last_video_id") + last_recording_id = self._camera.last_recording_id + + if self._last_video_id != last_recording_id or \ + self._utcnow >= self._expires_at: + + _LOGGER.info("Ring DoorBell properties refreshed") + + # update attributes if new video or if URL has expired self._last_video_id = self._camera.last_recording_id - - if self._utcnow >= self._expires_at: - _LOGGER.debug("Updated Ring DoorBell video_url") self._video_url = self._camera.recording_url(self._last_video_id) + self._expires_at = FORCE_REFRESH_INTERVAL + self._utcnow diff --git a/homeassistant/components/sensor/ring.py b/homeassistant/components/sensor/ring.py index 6c8794d096f..cae7690103d 100644 --- a/homeassistant/components/sensor/ring.py +++ b/homeassistant/components/sensor/ring.py @@ -34,7 +34,7 @@ SENSOR_TYPES = { 'Last Activity', ['doorbell', 'stickup_cams'], None, 'history', None], 'last_ding': [ - 'Last Ding', ['doorbell', 'stickup_cams'], None, 'history', 'ding'], + 'Last Ding', ['doorbell'], None, 'history', 'ding'], 'last_motion': [ 'Last Motion', ['doorbell', 'stickup_cams'], None,