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

Load Ring camera only with Ring Protect plan activated #10739

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions homeassistant/components/camera/ring.py
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)
Copy link
Contributor

@NovapaX NovapaX Nov 22, 2017

Choose a reason for hiding this comment

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

You're possibly adding multiple persistent notifications. This ID should be unique or only the last one will be shown.
From the persistent-notification docs: If notification_id is given, it will overwrite the notification if there already was a notification with that ID.
Other possible solution: Show a list of camera names in a single notification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NovapaX good point. I'll update it. I was not aware of this detail. Thanks for the heads up!


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
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
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
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