Add Elk-M1 switch and scene platforms (#17256)
* Add Elk-M1 switch platform. * Fix travis error. * Fix very annoying lint error. * Fix PR comments. * Fix comment. * Fix lint errors. * Fix PR comments. * Fix PR Apologize. Going too fast. You should not have to find those.
This commit is contained in:
parent
c434ad6af5
commit
93e3596e5a
5 changed files with 76 additions and 5 deletions
|
@ -89,7 +89,7 @@ class ElkArea(ElkEntity, alarm.AlarmControlPanel):
|
||||||
|
|
||||||
def __init__(self, element, elk, elk_data):
|
def __init__(self, element, elk, elk_data):
|
||||||
"""Initialize Area as Alarm Control Panel."""
|
"""Initialize Area as Alarm Control Panel."""
|
||||||
super().__init__('alarm_control_panel', element, elk, elk_data)
|
super().__init__(element, elk, elk_data)
|
||||||
self._changed_by_entity_id = ''
|
self._changed_by_entity_id = ''
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ CONF_ENABLED = 'enabled'
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SUPPORTED_DOMAINS = ['alarm_control_panel', 'light']
|
SUPPORTED_DOMAINS = ['alarm_control_panel', 'light', 'scene', 'switch']
|
||||||
|
|
||||||
|
|
||||||
def _host_validator(config):
|
def _host_validator(config):
|
||||||
|
@ -157,7 +157,7 @@ def create_elk_entities(hass, elk_elements, element_type, class_, entities):
|
||||||
class ElkEntity(Entity):
|
class ElkEntity(Entity):
|
||||||
"""Base class for all Elk entities."""
|
"""Base class for all Elk entities."""
|
||||||
|
|
||||||
def __init__(self, platform, element, elk, elk_data):
|
def __init__(self, element, elk, elk_data):
|
||||||
"""Initialize the base of all Elk devices."""
|
"""Initialize the base of all Elk devices."""
|
||||||
self._elk = elk
|
self._elk = elk
|
||||||
self._element = element
|
self._element = element
|
||||||
|
@ -197,7 +197,7 @@ class ElkEntity(Entity):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def _element_changed(self, element, changeset):
|
def _element_changed(self, element, changeset):
|
||||||
raise NotImplementedError()
|
pass
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _element_callback(self, element, changeset):
|
def _element_callback(self, element, changeset):
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ElkLight(ElkEntity, Light):
|
||||||
|
|
||||||
def __init__(self, element, elk, elk_data):
|
def __init__(self, element, elk, elk_data):
|
||||||
"""Initialize light."""
|
"""Initialize light."""
|
||||||
super().__init__('light', element, elk, elk_data)
|
super().__init__(element, elk, elk_data)
|
||||||
self._brightness = self._element.status
|
self._brightness = self._element.status
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
31
homeassistant/components/scene/elkm1.py
Normal file
31
homeassistant/components/scene/elkm1.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
"""
|
||||||
|
Support for control of ElkM1 tasks ("macros").
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/scene.elkm1/
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from homeassistant.components.elkm1 import (
|
||||||
|
DOMAIN as ELK_DOMAIN, ElkEntity, create_elk_entities)
|
||||||
|
from homeassistant.components.scene import Scene
|
||||||
|
|
||||||
|
DEPENDENCIES = [ELK_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_platform(hass, config, async_add_entities,
|
||||||
|
discovery_info=None):
|
||||||
|
"""Create the Elk-M1 scene platform."""
|
||||||
|
if discovery_info is None:
|
||||||
|
return
|
||||||
|
elk = hass.data[ELK_DOMAIN]['elk']
|
||||||
|
entities = create_elk_entities(hass, elk.tasks, 'task', ElkTask, [])
|
||||||
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
|
class ElkTask(ElkEntity, Scene):
|
||||||
|
"""Elk-M1 task as scene."""
|
||||||
|
|
||||||
|
async def async_activate(self):
|
||||||
|
"""Activate the task."""
|
||||||
|
self._element.activate()
|
40
homeassistant/components/switch/elkm1.py
Normal file
40
homeassistant/components/switch/elkm1.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
"""
|
||||||
|
Support for control of ElkM1 outputs (relays).
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/switch.elkm1/
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from homeassistant.components.elkm1 import (
|
||||||
|
DOMAIN as ELK_DOMAIN, ElkEntity, create_elk_entities)
|
||||||
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
|
||||||
|
DEPENDENCIES = [ELK_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_platform(hass, config, async_add_entities,
|
||||||
|
discovery_info=None):
|
||||||
|
"""Create the Elk-M1 switch platform."""
|
||||||
|
if discovery_info is None:
|
||||||
|
return
|
||||||
|
elk = hass.data[ELK_DOMAIN]['elk']
|
||||||
|
entities = create_elk_entities(hass, elk.outputs, 'output', ElkOutput, [])
|
||||||
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
|
class ElkOutput(ElkEntity, SwitchDevice):
|
||||||
|
"""Elk output as switch."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Get the current output status."""
|
||||||
|
return self._element.output_on
|
||||||
|
|
||||||
|
async def async_turn_on(self, **kwargs):
|
||||||
|
"""Turn on the output."""
|
||||||
|
self._element.turn_on(0)
|
||||||
|
|
||||||
|
async def async_turn_off(self, **kwargs):
|
||||||
|
"""Turn off the output."""
|
||||||
|
self._element.turn_off()
|
Loading…
Add table
Reference in a new issue