Skip to content

Commit

Permalink
Load Ring camera only with Ring Protect plan activated (home-assistan…
Browse files Browse the repository at this point in the history
…t#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
  • Loading branch information
tchellomello authored and MartinHjelmare committed Nov 25, 2017
1 parent 2817f03 commit dbbbe1c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
32 changes: 28 additions & 4 deletions homeassistant/components/camera/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import voluptuous as vol

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.ffmpeg import DATA_FFMPEG
from homeassistant.const import ATTR_ATTRIBUTION, CONF_SCAN_INTERVAL
Expand All @@ -27,6 +28,8 @@

_LOGGER = logging.getLogger(__name__)

NOTIFICATION_TITLE = 'Ring Camera Setup'

SCAN_INTERVAL = timedelta(seconds=90)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand All @@ -42,11 +45,33 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
ring = hass.data[DATA_RING]

cams = []
cams_no_plan = []
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:
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)
return True
Expand Down Expand Up @@ -84,7 +109,6 @@ def device_state_attributes(self):
'timezone': self._camera.timezone,
'type': self._camera.family,
'video_url': self._video_url,
'video_id': self._last_video_id
}

@asyncio.coroutine
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

from requests.exceptions import HTTPError, ConnectTimeout

REQUIREMENTS = ['ring_doorbell==0.1.7']
REQUIREMENTS = ['ring_doorbell==0.1.8']

_LOGGER = logging.getLogger(__name__)

CONF_ATTRIBUTION = "Data provided by Ring.com"

NOTIFICATION_ID = 'ring_notification'
NOTIFICATION_TITLE = 'Ring Sensor Setup'
NOTIFICATION_TITLE = 'Ring Setup'

DATA_RING = 'ring'
DOMAIN = 'ring'
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ restrictedpython==4.0b2
rflink==0.0.34

# homeassistant.components.ring
ring_doorbell==0.1.7
ring_doorbell==0.1.8

# homeassistant.components.notify.rocketchat
rocketchat-API==0.6.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ restrictedpython==4.0b2
rflink==0.0.34

# homeassistant.components.ring
ring_doorbell==0.1.7
ring_doorbell==0.1.8

# homeassistant.components.media_player.yamaha
rxv==0.5.1
Expand Down

0 comments on commit dbbbe1c

Please sign in to comment.