Add Elk light platform (#17222)

* Add Elk light platform.

* Add ElkM1 light code. Doh.

* Fix PR comments.

* Fix hound errors.

* Fix PR comment.

* Move state from base to class(s) where used
pull/17258/head
Glenn Waters 2018-10-08 11:30:27 -04:00 committed by Martin Hjelmare
parent c3b1121d77
commit 9380fca97e
3 changed files with 66 additions and 4 deletions

View File

@ -38,8 +38,11 @@ DISPLAY_MESSAGE_SERVICE_SCHEMA = vol.Schema({
async def async_setup_platform(hass, config, async_add_entities,
discovery_info):
discovery_info=None):
"""Set up the ElkM1 alarm platform."""
if discovery_info is None:
return
elk = hass.data[ELK_DOMAIN]['elk']
entities = create_elk_entities(hass, elk.areas, 'area', ElkArea, [])
async_add_entities(entities, True)
@ -88,6 +91,7 @@ class ElkArea(ElkEntity, alarm.AlarmControlPanel):
"""Initialize Area as Alarm Control Panel."""
super().__init__('alarm_control_panel', element, elk, elk_data)
self._changed_by_entity_id = ''
self._state = None
async def async_added_to_hass(self):
"""Register callback for ElkM1 changes."""

View File

@ -35,7 +35,7 @@ CONF_ENABLED = 'enabled'
_LOGGER = logging.getLogger(__name__)
SUPPORTED_DOMAINS = ['alarm_control_panel']
SUPPORTED_DOMAINS = ['alarm_control_panel', 'light']
def _host_validator(config):
@ -138,7 +138,7 @@ async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
hass.data[DOMAIN] = {'elk': elk, 'config': config, 'keypads': {}}
for component in SUPPORTED_DOMAINS:
hass.async_create_task(
discovery.async_load_platform(hass, component, DOMAIN))
discovery.async_load_platform(hass, component, DOMAIN, {}))
return True
@ -161,7 +161,6 @@ class ElkEntity(Entity):
"""Initialize the base of all Elk devices."""
self._elk = elk
self._element = element
self._state = None
self._temperature_unit = elk_data['config']['temperature_unit']
self._unique_id = 'elkm1_{}'.format(
self._element.default_name('_').lower())

View File

@ -0,0 +1,59 @@
"""
Support for control of ElkM1 lighting (X10, UPB, etc).
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.elkm1/
"""
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.components.elkm1 import (
DOMAIN as ELK_DOMAIN, ElkEntity, create_elk_entities)
DEPENDENCIES = [ELK_DOMAIN]
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Elk light platform."""
if discovery_info is None:
return
elk = hass.data[ELK_DOMAIN]['elk']
async_add_entities(
create_elk_entities(hass, elk.lights, 'plc', ElkLight, []), True)
class ElkLight(ElkEntity, Light):
"""Elk lighting device."""
def __init__(self, element, elk, elk_data):
"""Initialize light."""
super().__init__('light', element, elk, elk_data)
self._brightness = self._element.status
@property
def brightness(self):
"""Get the brightness."""
return self._brightness
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
@property
def is_on(self) -> bool:
"""Get the current brightness."""
return self._brightness != 0
def _element_changed(self, element, changeset):
status = self._element.status if self._element.status != 1 else 100
self._brightness = round(status * 2.55)
async def async_turn_on(self, **kwargs):
"""Turn on the light."""
self._element.level(round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55))
async def async_turn_off(self, **kwargs):
"""Turn off the light."""
self._element.level(0)