diff --git a/homeassistant/components/alarm_control_panel/elkm1.py b/homeassistant/components/alarm_control_panel/elkm1.py index 8026a3736fb..a01898ac959 100644 --- a/homeassistant/components/alarm_control_panel/elkm1.py +++ b/homeassistant/components/alarm_control_panel/elkm1.py @@ -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.""" diff --git a/homeassistant/components/elkm1/__init__.py b/homeassistant/components/elkm1/__init__.py index 505280d4f26..2dd85e02215 100644 --- a/homeassistant/components/elkm1/__init__.py +++ b/homeassistant/components/elkm1/__init__.py @@ -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()) diff --git a/homeassistant/components/light/elkm1.py b/homeassistant/components/light/elkm1.py new file mode 100644 index 00000000000..c6cb138877b --- /dev/null +++ b/homeassistant/components/light/elkm1.py @@ -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)