Load Ring camera only with Ring Protect plan activated (#10739)
* Added ability to only load Ring camera if the Ring Protect plan is activated. * Fixed notification for all invalid cameras * Fixed attribute name * Using asyncio for persistent notifications
This commit is contained in:
parent
2817f03378
commit
dbbbe1ceef
4 changed files with 32 additions and 8 deletions
|
@ -12,7 +12,8 @@ from datetime import timedelta
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.components.ring import DATA_RING, CONF_ATTRIBUTION
|
from homeassistant.components.ring import (
|
||||||
|
DATA_RING, CONF_ATTRIBUTION, NOTIFICATION_ID)
|
||||||
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
|
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
|
||||||
from homeassistant.components.ffmpeg import DATA_FFMPEG
|
from homeassistant.components.ffmpeg import DATA_FFMPEG
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_SCAN_INTERVAL
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_SCAN_INTERVAL
|
||||||
|
@ -27,6 +28,8 @@ FORCE_REFRESH_INTERVAL = timedelta(minutes=45)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
NOTIFICATION_TITLE = 'Ring Camera Setup'
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=90)
|
SCAN_INTERVAL = timedelta(seconds=90)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
@ -42,11 +45,33 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
ring = hass.data[DATA_RING]
|
ring = hass.data[DATA_RING]
|
||||||
|
|
||||||
cams = []
|
cams = []
|
||||||
|
cams_no_plan = []
|
||||||
for camera in ring.doorbells:
|
for camera in ring.doorbells:
|
||||||
cams.append(RingCam(hass, camera, config))
|
if camera.has_subscription:
|
||||||
|
cams.append(RingCam(hass, camera, config))
|
||||||
|
else:
|
||||||
|
cams_no_plan.append(camera)
|
||||||
|
|
||||||
for camera in ring.stickup_cams:
|
for camera in ring.stickup_cams:
|
||||||
cams.append(RingCam(hass, camera, config))
|
if camera.has_subscription:
|
||||||
|
cams.append(RingCam(hass, camera, config))
|
||||||
|
else:
|
||||||
|
cams_no_plan.append(camera)
|
||||||
|
|
||||||
|
# show notification for all cameras without an active subscription
|
||||||
|
if cams_no_plan:
|
||||||
|
cameras = str(', '.join([camera.name for camera in cams_no_plan]))
|
||||||
|
|
||||||
|
err_msg = '''A Ring Protect Plan is required for the''' \
|
||||||
|
''' following cameras: {}.'''.format(cameras)
|
||||||
|
|
||||||
|
_LOGGER.error(err_msg)
|
||||||
|
hass.components.persistent_notification.async_create(
|
||||||
|
'Error: {}<br />'
|
||||||
|
'You will need to restart hass after fixing.'
|
||||||
|
''.format(err_msg),
|
||||||
|
title=NOTIFICATION_TITLE,
|
||||||
|
notification_id=NOTIFICATION_ID)
|
||||||
|
|
||||||
async_add_devices(cams, True)
|
async_add_devices(cams, True)
|
||||||
return True
|
return True
|
||||||
|
@ -84,7 +109,6 @@ class RingCam(Camera):
|
||||||
'timezone': self._camera.timezone,
|
'timezone': self._camera.timezone,
|
||||||
'type': self._camera.family,
|
'type': self._camera.family,
|
||||||
'video_url': self._video_url,
|
'video_url': self._video_url,
|
||||||
'video_id': self._last_video_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|
|
@ -12,14 +12,14 @@ from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
||||||
|
|
||||||
from requests.exceptions import HTTPError, ConnectTimeout
|
from requests.exceptions import HTTPError, ConnectTimeout
|
||||||
|
|
||||||
REQUIREMENTS = ['ring_doorbell==0.1.7']
|
REQUIREMENTS = ['ring_doorbell==0.1.8']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_ATTRIBUTION = "Data provided by Ring.com"
|
CONF_ATTRIBUTION = "Data provided by Ring.com"
|
||||||
|
|
||||||
NOTIFICATION_ID = 'ring_notification'
|
NOTIFICATION_ID = 'ring_notification'
|
||||||
NOTIFICATION_TITLE = 'Ring Sensor Setup'
|
NOTIFICATION_TITLE = 'Ring Setup'
|
||||||
|
|
||||||
DATA_RING = 'ring'
|
DATA_RING = 'ring'
|
||||||
DOMAIN = 'ring'
|
DOMAIN = 'ring'
|
||||||
|
|
|
@ -952,7 +952,7 @@ restrictedpython==4.0b2
|
||||||
rflink==0.0.34
|
rflink==0.0.34
|
||||||
|
|
||||||
# homeassistant.components.ring
|
# homeassistant.components.ring
|
||||||
ring_doorbell==0.1.7
|
ring_doorbell==0.1.8
|
||||||
|
|
||||||
# homeassistant.components.notify.rocketchat
|
# homeassistant.components.notify.rocketchat
|
||||||
rocketchat-API==0.6.1
|
rocketchat-API==0.6.1
|
||||||
|
|
|
@ -144,7 +144,7 @@ restrictedpython==4.0b2
|
||||||
rflink==0.0.34
|
rflink==0.0.34
|
||||||
|
|
||||||
# homeassistant.components.ring
|
# homeassistant.components.ring
|
||||||
ring_doorbell==0.1.7
|
ring_doorbell==0.1.8
|
||||||
|
|
||||||
# homeassistant.components.media_player.yamaha
|
# homeassistant.components.media_player.yamaha
|
||||||
rxv==0.5.1
|
rxv==0.5.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue