Overhaul of Blink platform (#16942)
* Using new methods for blink camera - Refactored blink platform (breaking change) - Camera needs to be uniquely enabled in config from now on - Added motion detection enable/disable to camera platform * Fix motion detection - bumped blinkpy to 0.8.1 - Added wifi strength sensor * Added platform schema to sensor - Added global variables for brand and attribution to main platform * Removed blink binary sensor * Add alarm control panel * Fixed dependency, added alarm_home * Update requirements * Fix lint errors * Updated throttle times * Add trigger_camera service (replaced snap_picture) * Add refresh after camera trigger * Update blinkpy version * Wait for valid camera response before returning image - Motion detection now working! * Updated for new blinkpy 0.9.0 * Add refresh control and other fixes for new blinkpy release * Add save video service * Pushing to force bot to update * Changed based on first review - Pass blink as BLINK_DATA instead of DOMAIN - Remove alarm_arm_home from alarm_control_panel - Re-add discovery with schema for sensors/binar_sensors - Change motion_detected to a binary_sensor - Added camera_armed binary sensor - Update camera device_state_attributes rather than state_attributes * Moved blink.py to own folder. Added service hints. * Updated coveragerc to reflect previous change * Register services with DOMAIN - Change device add for loop order in binary_sensor * Fix lint error * services.async_register -> services.register
This commit is contained in:
parent
8e3a70e568
commit
c78850a983
9 changed files with 346 additions and 197 deletions
|
@ -6,34 +6,24 @@ https://home-assistant.io/components/sensor.blink/
|
|||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.blink import DOMAIN
|
||||
from homeassistant.const import TEMP_FAHRENHEIT
|
||||
from homeassistant.components.blink import BLINK_DATA, SENSORS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['blink']
|
||||
|
||||
SENSOR_TYPES = {
|
||||
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
||||
'battery': ['Battery', ''],
|
||||
'notifications': ['Notifications', '']
|
||||
}
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up a Blink sensor."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
data = hass.data[DOMAIN].blink
|
||||
devs = list()
|
||||
index = 0
|
||||
for name in data.cameras:
|
||||
devs.append(BlinkSensor(name, 'temperature', index, data))
|
||||
devs.append(BlinkSensor(name, 'battery', index, data))
|
||||
devs.append(BlinkSensor(name, 'notifications', index, data))
|
||||
index += 1
|
||||
data = hass.data[BLINK_DATA]
|
||||
devs = []
|
||||
for camera in data.sync.cameras:
|
||||
for sensor_type in discovery_info[CONF_MONITORED_CONDITIONS]:
|
||||
devs.append(BlinkSensor(data, camera, sensor_type))
|
||||
|
||||
add_entities(devs, True)
|
||||
|
||||
|
@ -41,21 +31,29 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class BlinkSensor(Entity):
|
||||
"""A Blink camera sensor."""
|
||||
|
||||
def __init__(self, name, sensor_type, index, data):
|
||||
def __init__(self, data, camera, sensor_type):
|
||||
"""Initialize sensors from Blink camera."""
|
||||
self._name = 'blink_' + name + '_' + SENSOR_TYPES[sensor_type][0]
|
||||
name, units, icon = SENSORS[sensor_type]
|
||||
self._name = "{} {} {}".format(
|
||||
BLINK_DATA, camera, name)
|
||||
self._camera_name = name
|
||||
self._type = sensor_type
|
||||
self.data = data
|
||||
self.index = index
|
||||
self._camera = data.sync.cameras[camera]
|
||||
self._state = None
|
||||
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||
self._unit_of_measurement = units
|
||||
self._icon = icon
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the camera."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon of the sensor."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the camera's current state."""
|
||||
|
@ -68,13 +66,11 @@ class BlinkSensor(Entity):
|
|||
|
||||
def update(self):
|
||||
"""Retrieve sensor data from the camera."""
|
||||
camera = self.data.cameras[self._camera_name]
|
||||
if self._type == 'temperature':
|
||||
self._state = camera.temperature
|
||||
elif self._type == 'battery':
|
||||
self._state = camera.battery_string
|
||||
elif self._type == 'notifications':
|
||||
self._state = camera.notifications
|
||||
else:
|
||||
self.data.refresh()
|
||||
try:
|
||||
self._state = self._camera.attributes[self._type]
|
||||
except KeyError:
|
||||
self._state = None
|
||||
_LOGGER.warning("Could not retrieve state from %s", self.name)
|
||||
_LOGGER.error(
|
||||
"%s not a valid camera attribute. Did the API change?",
|
||||
self._type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue