Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed update() method and removed ding feature from stickupcams/floodlight #10428

Merged
merged 4 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Sensor types: Name, category, device_class
SENSOR_TYPES = {
'ding': ['Ding', ['doorbell', 'stickup_cams'], 'occupancy'],
'ding': ['Ding', ['doorbell'], 'occupancy'],
'motion': ['Motion', ['doorbell', 'stickup_cams'], 'motion'],
}

Expand Down
32 changes: 18 additions & 14 deletions homeassistant/components/camera/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import asyncio
import logging

from datetime import datetime, timedelta
from datetime import timedelta

import voluptuous as vol

Expand All @@ -23,6 +23,8 @@

DEPENDENCIES = ['ring', 'ffmpeg']

FORCE_REFRESH_INTERVAL = timedelta(minutes=45)

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(seconds=90)
Expand Down Expand Up @@ -63,8 +65,8 @@ def __init__(self, hass, camera, device_info):
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):
Expand All @@ -82,6 +84,8 @@ def device_state_attributes(self):
'timezone': self._camera.timezone,
'type': self._camera.family,
'video_url': self._video_url,
'expires_at': self._expires_at,
'utcnow': self._utcnow,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. That fill the recorder

'video_id': self._last_video_id
}

Expand Down Expand Up @@ -123,19 +127,19 @@ def should_poll(self):

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")
self._last_video_id = self._camera.last_recording_id
last_recording_id = self._camera.last_recording_id

if self._utcnow >= self._expires_at:
_LOGGER.debug("Updated Ring DoorBell video_url")
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._video_url = self._camera.recording_url(self._last_video_id)
self._expires_at = FORCE_REFRESH_INTERVAL + self._utcnow
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'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,
Expand Down