Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 39 additions & 5 deletions homeassistant/components/camera/skybell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import logging

import requests
import voluptuous as vol

from homeassistant.components.sensor import PLATFORM_SCHEMA
Comment thread
nhorvath marked this conversation as resolved.
Outdated
from homeassistant.const import CONF_MONITORED_CONDITIONS
import homeassistant.helpers.config_validation as cv

from homeassistant.components.camera import Camera
from homeassistant.components.skybell import (
Expand All @@ -19,26 +24,48 @@

SCAN_INTERVAL = timedelta(seconds=90)

IMAGE_AVATAR = 'avatar'
IMAGE_ACTIVITY = 'activity'

CONF_ACTIVITY_NAME = 'activity_name'
CONF_AVATAR_NAME = 'avatar_name'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_MONITORED_CONDITIONS, default=[IMAGE_AVATAR]):
vol.All(cv.ensure_list, [vol.In([IMAGE_AVATAR, IMAGE_ACTIVITY])]),
vol.Optional(CONF_ACTIVITY_NAME, default=""): cv.string,
Comment thread
nhorvath marked this conversation as resolved.
Outdated
vol.Optional(CONF_AVATAR_NAME, default=""): cv.string,
Comment thread
nhorvath marked this conversation as resolved.
Outdated
})


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the platform for a Skybell device."""
cond = config[CONF_MONITORED_CONDITIONS]
names = {}
names[IMAGE_ACTIVITY] = config[CONF_ACTIVITY_NAME]
Comment thread
nhorvath marked this conversation as resolved.
Outdated
names[IMAGE_AVATAR] = config[CONF_AVATAR_NAME]
skybell = hass.data.get(SKYBELL_DOMAIN)

sensors = []
for device in skybell.get_devices():
sensors.append(SkybellCamera(device))
for camera_type in cond:
sensors.append(SkybellCamera(device, type, names[camera_type]))
Comment thread
nhorvath marked this conversation as resolved.
Outdated

add_entities(sensors, True)


class SkybellCamera(SkybellDevice, Camera):
"""A camera implementation for Skybell devices."""

def __init__(self, device):
def __init__(self, device, camera_type, name=""):
"""Initialize a camera for a Skybell device."""
self._type = camera_type
SkybellDevice.__init__(self, device)
Camera.__init__(self)
self._name = self._device.name
if name != "":
Comment thread
nhorvath marked this conversation as resolved.
Outdated
self._name = self._device.name + " " + name
Comment thread
nhorvath marked this conversation as resolved.
Outdated
else:
self._name = self._device.name
self._url = None
self._response = None

Expand All @@ -47,12 +74,19 @@ def name(self):
"""Return the name of the sensor."""
return self._name

@property
def image_url(self):
"""Get the camera image url based on type."""
if self._type == IMAGE_ACTIVITY:
return self._device.activity_image
return self._device.image

def camera_image(self):
"""Get the latest camera image."""
super().update()

if self._url != self._device.image:
self._url = self._device.image
if self._url != self.image_url:
self._url = self.image_url

try:
self._response = requests.get(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/skybell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['skybellpy==0.2.0']
REQUIREMENTS = ['skybellpy==0.3.0']

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ simplisafe-python==3.1.14
sisyphus-control==2.1

# homeassistant.components.skybell
skybellpy==0.2.0
skybellpy==0.3.0

# homeassistant.components.notify.slack
slacker==0.12.0
Expand Down