mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fixed update() method and removed ding
feature from stickupcams/floodlight (#10428)
* Simplified URL expiration calculation and fixed refresh method * Remove support from Ring from StickupCams or floodlight cameras * Makes lint happy * Removed unecessary attributes
This commit is contained in:
parent
2fff065b2c
commit
2118ab2503
@ -27,7 +27,7 @@ SCAN_INTERVAL = timedelta(seconds=5)
|
|||||||
|
|
||||||
# Sensor types: Name, category, device_class
|
# Sensor types: Name, category, device_class
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'ding': ['Ding', ['doorbell', 'stickup_cams'], 'occupancy'],
|
'ding': ['Ding', ['doorbell'], 'occupancy'],
|
||||||
'motion': ['Motion', ['doorbell', 'stickup_cams'], 'motion'],
|
'motion': ['Motion', ['doorbell', 'stickup_cams'], 'motion'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ https://home-assistant.io/components/camera.ring/
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -23,6 +23,8 @@ CONF_FFMPEG_ARGUMENTS = 'ffmpeg_arguments'
|
|||||||
|
|
||||||
DEPENDENCIES = ['ring', 'ffmpeg']
|
DEPENDENCIES = ['ring', 'ffmpeg']
|
||||||
|
|
||||||
|
FORCE_REFRESH_INTERVAL = timedelta(minutes=45)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=90)
|
SCAN_INTERVAL = timedelta(seconds=90)
|
||||||
@ -63,8 +65,8 @@ class RingCam(Camera):
|
|||||||
self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS)
|
self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS)
|
||||||
self._last_video_id = self._camera.last_recording_id
|
self._last_video_id = self._camera.last_recording_id
|
||||||
self._video_url = self._camera.recording_url(self._last_video_id)
|
self._video_url = self._camera.recording_url(self._last_video_id)
|
||||||
self._expires_at = None
|
self._utcnow = dt_util.utcnow()
|
||||||
self._utcnow = None
|
self._expires_at = FORCE_REFRESH_INTERVAL + self._utcnow
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -123,19 +125,19 @@ class RingCam(Camera):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update camera entity and refresh attributes."""
|
"""Update camera entity and refresh attributes."""
|
||||||
# extract the video expiration from URL
|
_LOGGER.debug("Checking if Ring DoorBell needs to refresh video_url")
|
||||||
x_amz_expires = int(self._video_url.split('&')[0].split('=')[-1])
|
|
||||||
x_amz_date = self._video_url.split('&')[1].split('=')[-1]
|
|
||||||
|
|
||||||
|
self._camera.update()
|
||||||
self._utcnow = dt_util.utcnow()
|
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:
|
last_recording_id = self._camera.last_recording_id
|
||||||
_LOGGER.debug("Updated Ring DoorBell last_video_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
|
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._video_url = self._camera.recording_url(self._last_video_id)
|
||||||
|
self._expires_at = FORCE_REFRESH_INTERVAL + self._utcnow
|
||||||
|
@ -34,7 +34,7 @@ SENSOR_TYPES = {
|
|||||||
'Last Activity', ['doorbell', 'stickup_cams'], None, 'history', None],
|
'Last Activity', ['doorbell', 'stickup_cams'], None, 'history', None],
|
||||||
|
|
||||||
'last_ding': [
|
'last_ding': [
|
||||||
'Last Ding', ['doorbell', 'stickup_cams'], None, 'history', 'ding'],
|
'Last Ding', ['doorbell'], None, 'history', 'ding'],
|
||||||
|
|
||||||
'last_motion': [
|
'last_motion': [
|
||||||
'Last Motion', ['doorbell', 'stickup_cams'], None,
|
'Last Motion', ['doorbell', 'stickup_cams'], None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user