From 80fa29c61c63d3eb384305580766bf36da642f57 Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Sun, 3 Sep 2017 10:28:42 -0500 Subject: [PATCH 1/7] DoorBird Component --- .coveragerc | 3 + .../components/binary_sensor/doorbird.py | 62 ++++++++++ homeassistant/components/camera/doorbird.py | 106 ++++++++++++++++++ homeassistant/components/doorbird.py | 44 ++++++++ homeassistant/components/switch/doorbird.py | 103 +++++++++++++++++ requirements_all.txt | 3 + 6 files changed, 321 insertions(+) create mode 100644 homeassistant/components/binary_sensor/doorbird.py create mode 100644 homeassistant/components/camera/doorbird.py create mode 100644 homeassistant/components/doorbird.py create mode 100644 homeassistant/components/switch/doorbird.py diff --git a/.coveragerc b/.coveragerc index 5e27aed0182534..49fb8d04353e67 100644 --- a/.coveragerc +++ b/.coveragerc @@ -52,6 +52,9 @@ omit = homeassistant/components/digital_ocean.py homeassistant/components/*/digital_ocean.py + + homeassistant/components/doorbird.py + homeassistant/components/*/doorbird.py homeassistant/components/dweet.py homeassistant/components/*/dweet.py diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py new file mode 100644 index 00000000000000..161be31c23f46b --- /dev/null +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -0,0 +1,62 @@ +"""Support for reading binary states from a DoorBird video doorbell.""" +from datetime import timedelta +import logging + +from homeassistant.components.binary_sensor import BinarySensorDevice +from homeassistant.components.doorbird import DOMAIN +from homeassistant.const import STATE_UNKNOWN +from homeassistant.util import Throttle + +DEPENDENCIES = ['doorbird'] + +_LOGGER = logging.getLogger(__name__) +_MIN_UPDATE_INTERVAL = timedelta(milliseconds=250) + +SENSOR_TYPES = { + "doorbell": { + "name": "Doorbell Ringing", + "icon": { + True: "bell-ring", + False: "bell", + STATE_UNKNOWN: "bell-outline" + } + } +} + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the DoorBird binary sensor component.""" + device = hass.data.get(DOMAIN) + add_devices([DoorBirdBinarySensor(device, "doorbell")], True) + return True + + +class DoorBirdBinarySensor(BinarySensorDevice): + """A binary sensor of a DoorBird device.""" + def __init__(self, device, sensor_type): + """Initialize a binary sensor on a DoorBird device.""" + self._device = device + self._sensor_type = sensor_type + self._state = STATE_UNKNOWN + super(DoorBirdBinarySensor, self).__init__() + + @property + def name(self): + """Get the name of the sensor.""" + return SENSOR_TYPES[self._sensor_type]["name"] + + @property + def icon(self): + """Get an icon to display.""" + icon = SENSOR_TYPES[self._sensor_type]["icon"][self._state] + return "mdi:{}".format(icon) + + @property + def is_on(self): + """Get the state of the binary sensor.""" + return self._state + + @Throttle(_MIN_UPDATE_INTERVAL) + def update(self): + """Pull the latest value from the device.""" + self._state = self._device.doorbell_state() \ No newline at end of file diff --git a/homeassistant/components/camera/doorbird.py b/homeassistant/components/camera/doorbird.py new file mode 100644 index 00000000000000..31f26435782413 --- /dev/null +++ b/homeassistant/components/camera/doorbird.py @@ -0,0 +1,106 @@ +"""Support for viewing the camera feed from a DoorBird video doorbell.""" + +import asyncio +import datetime +import logging +import voluptuous as vol + +import aiohttp +import async_timeout + +from homeassistant.components.camera import PLATFORM_SCHEMA, Camera +from homeassistant.components.doorbird import DOMAIN +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.util.async import run_coroutine_threadsafe + +DEPENDENCIES = ['doorbird'] + +_CAMERA_LIVE = "DoorBird Live" +_CAMERA_LAST_VISITOR = "DoorBird Last Ring" +_LIVE_INTERVAL = datetime.timedelta(seconds=1) +_LAST_VISITOR_INTERVAL = datetime.timedelta(minutes=1) +_LOGGER = logging.getLogger(__name__) +_TIMEOUT = 10 # seconds + +CONF_SHOW_LAST_VISITOR = 'last_visitor' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Optional(CONF_SHOW_LAST_VISITOR, default=False): cv.boolean +}) + + +@asyncio.coroutine +def async_setup_platform(hass, config, async_add_devices, discovery_info=None): + """Set up the DoorBird camera platform.""" + device = hass.data.get(DOMAIN) + + _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LIVE) + entities = [DoorBirdCamera(hass, device.live_image_url, _CAMERA_LIVE, + _LIVE_INTERVAL)] + + if config.get(CONF_SHOW_LAST_VISITOR): + _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LAST_VISITOR) + entities.append(DoorBirdCamera(hass, device.history_image_url(1), + _CAMERA_LAST_VISITOR, + _LAST_VISITOR_INTERVAL)) + + async_add_devices(entities) + _LOGGER.info("Added DoorBird camera(s)") + return True + + +class DoorBirdCamera(Camera): + """The camera on a DoorBird device.""" + + def __init__(self, hass, url, name, interval=None): + """Initialize the camera on a DoorBird device.""" + self._hass = hass + self._url = url + self._name = name + self._last_image = None + self._interval = interval or datetime.timedelta + self._last_update = datetime.datetime.min + super().__init__() + + @property + def name(self): + """Get the name of the camera.""" + return self._name + + def camera_image(self): + """Get the bytes of a camera image.""" + return run_coroutine_threadsafe( + self.async_camera_image(), self._hass.loop).result() + + @asyncio.coroutine + def async_camera_image(self): + """Pull a still image from the camera.""" + now = datetime.datetime.now() + + if self._last_image and now - self._last_update < self._interval: + return self._last_image + + try: + websession = async_get_clientsession(self._hass) + + with async_timeout.timeout(_TIMEOUT, loop=self._hass.loop): + response = yield from websession.get(self._url) + + self._last_image = yield from response.read() + self._last_update = now + return self._last_image + except asyncio.TimeoutError: + _LOGGER.error("Camera image timed out") + return self._last_image + except aiohttp.ClientError as error: + _LOGGER.error("Error getting camera image: %s", error) + return self._last_image + + def enable_motion_detection(self): + """Network callbacks are not supported by HA yet.""" + pass + + def disable_motion_detection(self): + """Network callbacks are not supported by HA yet.""" + pass \ No newline at end of file diff --git a/homeassistant/components/doorbird.py b/homeassistant/components/doorbird.py new file mode 100644 index 00000000000000..203c4d9c5cd281 --- /dev/null +++ b/homeassistant/components/doorbird.py @@ -0,0 +1,44 @@ +"""Support for a DoorBird video doorbell.""" + +import logging +import voluptuous as vol + +from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD +import homeassistant.helpers.config_validation as cv + +REQUIREMENTS = ['DoorBirdPy==0.0.4'] + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'doorbird' + +CONFIG_SCHEMA = vol.Schema({ + DOMAIN: vol.Schema({ + vol.Required(CONF_HOST): cv.string, + vol.Required(CONF_USERNAME): cv.string, + vol.Required(CONF_PASSWORD): cv.string + }) +}, extra=vol.ALLOW_EXTRA) + + +def setup(hass, config): + """Set up the DoorBird component.""" + ip = config[DOMAIN].get(CONF_HOST) + username = config[DOMAIN].get(CONF_USERNAME) + password = config[DOMAIN].get(CONF_PASSWORD) + + from doorbirdpy import DoorBird + device = DoorBird(ip, username, password) + status = device.ready() + + if status[0]: + _LOGGER.info("Connected to DoorBird at %s as %s", ip, username) + hass.data[DOMAIN] = device + return True + elif status[1] == 401: + _LOGGER.error("Authorization rejected by DoorBird at %s", ip) + return False + else: + _LOGGER.error("Could not connect to DoorBird at %s: Error %s", + ip, str(status[1])) + return False \ No newline at end of file diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py new file mode 100644 index 00000000000000..28653589569754 --- /dev/null +++ b/homeassistant/components/switch/doorbird.py @@ -0,0 +1,103 @@ +"""Support for powering relays in a DoorBird video doorbell.""" +import datetime +import logging +import voluptuous as vol + +from homeassistant.components.doorbird import DOMAIN +from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA +from homeassistant.const import CONF_SWITCHES +import homeassistant.helpers.config_validation as cv + +DEPENDENCIES = ['doorbird'] + +_LOGGER = logging.getLogger(__name__) + +SWITCHES = { + "open_door": { + "name": "Open Door", + "icon": { + True: "lock-open", + False: "lock" + }, + "time": datetime.timedelta(seconds=3) + }, + "light_on": { + "name": "Light On", + "icon": { + True: "lightbulb-on", + False: "lightbulb" + }, + "time": datetime.timedelta(minutes=5) + } +} + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_SWITCHES, default=[]): + vol.All(cv.ensure_list([vol.In(SWITCHES)])) +}) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the DoorBird switch platform.""" + device = hass.data.get(DOMAIN) + + switches = [] + for switch in SWITCHES: + if switch in config.get(CONF_SWITCHES): + _LOGGER.debug("Adding DoorBird switch " + + SWITCHES[switch]["name"]) + switches.append(DoorBirdSwitch(device, switch)) + + add_devices(switches) + _LOGGER.info("Added DoorBird switches") + return True + + +class DoorBirdSwitch(SwitchDevice): + """A relay in a DoorBird device.""" + def __init__(self, device, switch): + """Initialize a relay in a DoorBird device.""" + if switch not in SWITCHES: + msg = switch + " is not a valid DoorBird switch" + raise NotImplementedError(msg) + + self._device = device + self._switch = switch + self._state = False + self._assume_off = datetime.datetime.min + + @property + def name(self): + """Get the name of the switch.""" + return SWITCHES[self._switch]["name"] + + @property + def icon(self): + """Get an icon to display.""" + return "mdi:" + SWITCHES[self._switch]["icon"][self._state] + + @property + def is_on(self): + """Get the assumed state of the relay.""" + return self._state + + def turn_on(self, **kwargs): + """Power the relay.""" + if self._switch == "open_door": + self._state = self._device.open_door() + elif self._switch == "light_on": + self._state = self._device.turn_light_on() + + now = datetime.datetime.now() + self._assume_off = now + SWITCHES[self._switch]["time"] + return True + + def turn_off(self, **kwargs): + """The relays are time-based and cannot be turned off.""" + return False + + def update(self): + """Wait for the correct amount of assumed time to pass.""" + if self._state and self._assume_off <= datetime.datetime.now(): + self._state = False + self._assume_off = datetime.datetime.min \ No newline at end of file diff --git a/requirements_all.txt b/requirements_all.txt index df92881ccb66af..8e4ab80bbdcf7b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -17,6 +17,9 @@ astral==1.4 # homeassistant.components.bbb_gpio # Adafruit_BBIO==1.0.0 +# homeassistant.components.doorbird +DoorBirdPy==0.0.4 + # homeassistant.components.isy994 PyISY==1.0.8 From db3bd1a32de5c9e86da948c59863a948ac6a62b3 Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Sun, 3 Sep 2017 10:36:01 -0500 Subject: [PATCH 2/7] add newlines at end of files --- homeassistant/components/binary_sensor/doorbird.py | 2 +- homeassistant/components/camera/doorbird.py | 2 +- homeassistant/components/doorbird.py | 2 +- homeassistant/components/switch/doorbird.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py index 161be31c23f46b..a575cca1d23357 100644 --- a/homeassistant/components/binary_sensor/doorbird.py +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -59,4 +59,4 @@ def is_on(self): @Throttle(_MIN_UPDATE_INTERVAL) def update(self): """Pull the latest value from the device.""" - self._state = self._device.doorbell_state() \ No newline at end of file + self._state = self._device.doorbell_state() diff --git a/homeassistant/components/camera/doorbird.py b/homeassistant/components/camera/doorbird.py index 31f26435782413..58054b69088c67 100644 --- a/homeassistant/components/camera/doorbird.py +++ b/homeassistant/components/camera/doorbird.py @@ -103,4 +103,4 @@ def enable_motion_detection(self): def disable_motion_detection(self): """Network callbacks are not supported by HA yet.""" - pass \ No newline at end of file + pass diff --git a/homeassistant/components/doorbird.py b/homeassistant/components/doorbird.py index 203c4d9c5cd281..d7658f99ab28a7 100644 --- a/homeassistant/components/doorbird.py +++ b/homeassistant/components/doorbird.py @@ -41,4 +41,4 @@ def setup(hass, config): else: _LOGGER.error("Could not connect to DoorBird at %s: Error %s", ip, str(status[1])) - return False \ No newline at end of file + return False diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py index 28653589569754..73091537e6c265 100644 --- a/homeassistant/components/switch/doorbird.py +++ b/homeassistant/components/switch/doorbird.py @@ -100,4 +100,4 @@ def update(self): """Wait for the correct amount of assumed time to pass.""" if self._state and self._assume_off <= datetime.datetime.now(): self._state = False - self._assume_off = datetime.datetime.min \ No newline at end of file + self._assume_off = datetime.datetime.min From b2f2c9d7797b3ef13a728bc96560592c8a6ff88c Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Thu, 14 Sep 2017 17:13:17 -0500 Subject: [PATCH 3/7] fix lint --- homeassistant/components/binary_sensor/doorbird.py | 1 + homeassistant/components/doorbird.py | 10 +++++----- homeassistant/components/switch/doorbird.py | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py index a575cca1d23357..3e5d9f9de47926 100644 --- a/homeassistant/components/binary_sensor/doorbird.py +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -33,6 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class DoorBirdBinarySensor(BinarySensorDevice): """A binary sensor of a DoorBird device.""" + def __init__(self, device, sensor_type): """Initialize a binary sensor on a DoorBird device.""" self._device = device diff --git a/homeassistant/components/doorbird.py b/homeassistant/components/doorbird.py index d7658f99ab28a7..421c85a0f94b02 100644 --- a/homeassistant/components/doorbird.py +++ b/homeassistant/components/doorbird.py @@ -23,22 +23,22 @@ def setup(hass, config): """Set up the DoorBird component.""" - ip = config[DOMAIN].get(CONF_HOST) + device_ip = config[DOMAIN].get(CONF_HOST) username = config[DOMAIN].get(CONF_USERNAME) password = config[DOMAIN].get(CONF_PASSWORD) from doorbirdpy import DoorBird - device = DoorBird(ip, username, password) + device = DoorBird(device_ip, username, password) status = device.ready() if status[0]: - _LOGGER.info("Connected to DoorBird at %s as %s", ip, username) + _LOGGER.info("Connected to DoorBird at %s as %s", device_ip, username) hass.data[DOMAIN] = device return True elif status[1] == 401: - _LOGGER.error("Authorization rejected by DoorBird at %s", ip) + _LOGGER.error("Authorization rejected by DoorBird at %s", device_ip) return False else: _LOGGER.error("Could not connect to DoorBird at %s: Error %s", - ip, str(status[1])) + device_ip, str(status[1])) return False diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py index 73091537e6c265..fecee6ca74db95 100644 --- a/homeassistant/components/switch/doorbird.py +++ b/homeassistant/components/switch/doorbird.py @@ -55,6 +55,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class DoorBirdSwitch(SwitchDevice): """A relay in a DoorBird device.""" + def __init__(self, device, switch): """Initialize a relay in a DoorBird device.""" if switch not in SWITCHES: From 991b63e7f01e795a82d9914de772adb92a10389a Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Fri, 15 Sep 2017 21:55:18 -0500 Subject: [PATCH 4/7] fix doorbird components conventions --- homeassistant/components/binary_sensor/doorbird.py | 10 ++++++---- homeassistant/components/camera/doorbird.py | 13 ++++++------- homeassistant/components/switch/doorbird.py | 11 +++-------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py index 3e5d9f9de47926..8676cb5dea6958 100644 --- a/homeassistant/components/binary_sensor/doorbird.py +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -4,7 +4,6 @@ from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.doorbird import DOMAIN -from homeassistant.const import STATE_UNKNOWN from homeassistant.util import Throttle DEPENDENCIES = ['doorbird'] @@ -18,7 +17,7 @@ "icon": { True: "bell-ring", False: "bell", - STATE_UNKNOWN: "bell-outline" + "None": "bell-outline" } } } @@ -38,7 +37,7 @@ def __init__(self, device, sensor_type): """Initialize a binary sensor on a DoorBird device.""" self._device = device self._sensor_type = sensor_type - self._state = STATE_UNKNOWN + self._state = None super(DoorBirdBinarySensor, self).__init__() @property @@ -49,7 +48,10 @@ def name(self): @property def icon(self): """Get an icon to display.""" - icon = SENSOR_TYPES[self._sensor_type]["icon"][self._state] + if self._state is None: + icon = SENSOR_TYPES[self._sensor_type]["icon"]["None"] + else: + icon = SENSOR_TYPES[self._sensor_type]["icon"][self._state] return "mdi:{}".format(icon) @property diff --git a/homeassistant/components/camera/doorbird.py b/homeassistant/components/camera/doorbird.py index 58054b69088c67..6d37af3553994a 100644 --- a/homeassistant/components/camera/doorbird.py +++ b/homeassistant/components/camera/doorbird.py @@ -36,12 +36,12 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): device = hass.data.get(DOMAIN) _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LIVE) - entities = [DoorBirdCamera(hass, device.live_image_url, _CAMERA_LIVE, + entities = [DoorBirdCamera(device.live_image_url, _CAMERA_LIVE, _LIVE_INTERVAL)] if config.get(CONF_SHOW_LAST_VISITOR): _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LAST_VISITOR) - entities.append(DoorBirdCamera(hass, device.history_image_url(1), + entities.append(DoorBirdCamera(device.history_image_url(1), _CAMERA_LAST_VISITOR, _LAST_VISITOR_INTERVAL)) @@ -53,9 +53,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): class DoorBirdCamera(Camera): """The camera on a DoorBird device.""" - def __init__(self, hass, url, name, interval=None): + def __init__(self, url, name, interval=None): """Initialize the camera on a DoorBird device.""" - self._hass = hass self._url = url self._name = name self._last_image = None @@ -71,7 +70,7 @@ def name(self): def camera_image(self): """Get the bytes of a camera image.""" return run_coroutine_threadsafe( - self.async_camera_image(), self._hass.loop).result() + self.async_camera_image(), self.hass.loop).result() @asyncio.coroutine def async_camera_image(self): @@ -82,9 +81,9 @@ def async_camera_image(self): return self._last_image try: - websession = async_get_clientsession(self._hass) + websession = async_get_clientsession(self.hass) - with async_timeout.timeout(_TIMEOUT, loop=self._hass.loop): + with async_timeout.timeout(_TIMEOUT, loop=self.hass.loop): response = yield from websession.get(self._url) self._last_image = yield from response.read() diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py index fecee6ca74db95..bc72d980917d08 100644 --- a/homeassistant/components/switch/doorbird.py +++ b/homeassistant/components/switch/doorbird.py @@ -50,7 +50,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(switches) _LOGGER.info("Added DoorBird switches") - return True class DoorBirdSwitch(SwitchDevice): @@ -58,10 +57,6 @@ class DoorBirdSwitch(SwitchDevice): def __init__(self, device, switch): """Initialize a relay in a DoorBird device.""" - if switch not in SWITCHES: - msg = switch + " is not a valid DoorBird switch" - raise NotImplementedError(msg) - self._device = device self._switch = switch self._state = False @@ -91,11 +86,11 @@ def turn_on(self, **kwargs): now = datetime.datetime.now() self._assume_off = now + SWITCHES[self._switch]["time"] - return True def turn_off(self, **kwargs): - """The relays are time-based and cannot be turned off.""" - return False + """The relays are time-based.""" + raise NotImplementedError("DoorBird relays cannot be manually turned " + "off.") def update(self): """Wait for the correct amount of assumed time to pass.""" From 4abe29442d12156939884f375dc3d8d58b0c4382 Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Sun, 17 Sep 2017 09:35:45 -0500 Subject: [PATCH 5/7] fix doorbird domain import and log strings --- .../components/binary_sensor/doorbird.py | 14 ++++------- homeassistant/components/camera/doorbird.py | 23 ++++--------------- homeassistant/components/switch/doorbird.py | 6 ++--- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py index 8676cb5dea6958..83bc22aca5aa22 100644 --- a/homeassistant/components/binary_sensor/doorbird.py +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -3,7 +3,7 @@ import logging from homeassistant.components.binary_sensor import BinarySensorDevice -from homeassistant.components.doorbird import DOMAIN +from homeassistant.components.doorbird import DOMAIN as DOORBIRD_DOMAIN from homeassistant.util import Throttle DEPENDENCIES = ['doorbird'] @@ -17,7 +17,7 @@ "icon": { True: "bell-ring", False: "bell", - "None": "bell-outline" + None: "bell-outline" } } } @@ -25,7 +25,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DoorBird binary sensor component.""" - device = hass.data.get(DOMAIN) + device = hass.data.get(DOORBIRD_DOMAIN) add_devices([DoorBirdBinarySensor(device, "doorbell")], True) return True @@ -38,7 +38,6 @@ def __init__(self, device, sensor_type): self._device = device self._sensor_type = sensor_type self._state = None - super(DoorBirdBinarySensor, self).__init__() @property def name(self): @@ -48,11 +47,8 @@ def name(self): @property def icon(self): """Get an icon to display.""" - if self._state is None: - icon = SENSOR_TYPES[self._sensor_type]["icon"]["None"] - else: - icon = SENSOR_TYPES[self._sensor_type]["icon"][self._state] - return "mdi:{}".format(icon) + state_icon = SENSOR_TYPES[self._sensor_type]["icon"][self._state] + return "mdi:{}".format(state_icon) @property def is_on(self): diff --git a/homeassistant/components/camera/doorbird.py b/homeassistant/components/camera/doorbird.py index 6d37af3553994a..cf6b6b2871f2b0 100644 --- a/homeassistant/components/camera/doorbird.py +++ b/homeassistant/components/camera/doorbird.py @@ -9,10 +9,9 @@ import async_timeout from homeassistant.components.camera import PLATFORM_SCHEMA, Camera -from homeassistant.components.doorbird import DOMAIN +from homeassistant.components.doorbird import DOMAIN as DOORBIRD_DOMAIN from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.util.async import run_coroutine_threadsafe DEPENDENCIES = ['doorbird'] @@ -33,21 +32,20 @@ @asyncio.coroutine def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the DoorBird camera platform.""" - device = hass.data.get(DOMAIN) + device = hass.data.get(DOORBIRD_DOMAIN) - _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LIVE) + _LOGGER.debug("Adding DoorBird camera %s", _CAMERA_LIVE) entities = [DoorBirdCamera(device.live_image_url, _CAMERA_LIVE, _LIVE_INTERVAL)] if config.get(CONF_SHOW_LAST_VISITOR): - _LOGGER.debug("Adding DoorBird camera " + _CAMERA_LAST_VISITOR) + _LOGGER.debug("Adding DoorBird camera %s", _CAMERA_LAST_VISITOR) entities.append(DoorBirdCamera(device.history_image_url(1), _CAMERA_LAST_VISITOR, _LAST_VISITOR_INTERVAL)) async_add_devices(entities) _LOGGER.info("Added DoorBird camera(s)") - return True class DoorBirdCamera(Camera): @@ -67,11 +65,6 @@ def name(self): """Get the name of the camera.""" return self._name - def camera_image(self): - """Get the bytes of a camera image.""" - return run_coroutine_threadsafe( - self.async_camera_image(), self.hass.loop).result() - @asyncio.coroutine def async_camera_image(self): """Pull a still image from the camera.""" @@ -95,11 +88,3 @@ def async_camera_image(self): except aiohttp.ClientError as error: _LOGGER.error("Error getting camera image: %s", error) return self._last_image - - def enable_motion_detection(self): - """Network callbacks are not supported by HA yet.""" - pass - - def disable_motion_detection(self): - """Network callbacks are not supported by HA yet.""" - pass diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py index bc72d980917d08..ff76e1318e8a52 100644 --- a/homeassistant/components/switch/doorbird.py +++ b/homeassistant/components/switch/doorbird.py @@ -3,7 +3,7 @@ import logging import voluptuous as vol -from homeassistant.components.doorbird import DOMAIN +from homeassistant.components.doorbird import DOMAIN as DOORBIRD_DOMAIN from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA from homeassistant.const import CONF_SWITCHES import homeassistant.helpers.config_validation as cv @@ -39,7 +39,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DoorBird switch platform.""" - device = hass.data.get(DOMAIN) + device = hass.data.get(DOORBIRD_DOMAIN) switches = [] for switch in SWITCHES: @@ -70,7 +70,7 @@ def name(self): @property def icon(self): """Get an icon to display.""" - return "mdi:" + SWITCHES[self._switch]["icon"][self._state] + return "mdi:{}".format(SWITCHES[self._switch]["icon"][self._state]) @property def is_on(self): From 6dcb00981923eb6448172f823887a998a3a991ac Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Sun, 17 Sep 2017 09:45:33 -0500 Subject: [PATCH 6/7] don't redundantly add switches --- homeassistant/components/switch/doorbird.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/switch/doorbird.py b/homeassistant/components/switch/doorbird.py index ff76e1318e8a52..66c3bf731164bf 100644 --- a/homeassistant/components/switch/doorbird.py +++ b/homeassistant/components/switch/doorbird.py @@ -43,10 +43,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): switches = [] for switch in SWITCHES: - if switch in config.get(CONF_SWITCHES): - _LOGGER.debug("Adding DoorBird switch " + - SWITCHES[switch]["name"]) - switches.append(DoorBirdSwitch(device, switch)) + _LOGGER.debug("Adding DoorBird switch %s", SWITCHES[switch]["name"]) + switches.append(DoorBirdSwitch(device, switch)) add_devices(switches) _LOGGER.info("Added DoorBird switches") From d4736af5c689b0390893b2d73a417269f6b2f598 Mon Sep 17 00:00:00 2001 From: Andy Castille Date: Sun, 17 Sep 2017 11:52:39 -0500 Subject: [PATCH 7/7] Remove return statement from setup_platform --- homeassistant/components/binary_sensor/doorbird.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/doorbird.py b/homeassistant/components/binary_sensor/doorbird.py index 83bc22aca5aa22..9a13687fc54e49 100644 --- a/homeassistant/components/binary_sensor/doorbird.py +++ b/homeassistant/components/binary_sensor/doorbird.py @@ -27,7 +27,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DoorBird binary sensor component.""" device = hass.data.get(DOORBIRD_DOMAIN) add_devices([DoorBirdBinarySensor(device, "doorbell")], True) - return True class DoorBirdBinarySensor(BinarySensorDevice):