2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Keene Electronics IR-IP devices."""
|
2017-05-13 04:12:47 +00:00
|
|
|
import functools as ft
|
2018-01-21 06:35:38 +00:00
|
|
|
import logging
|
2017-05-13 04:12:47 +00:00
|
|
|
|
2018-07-18 09:54:27 +00:00
|
|
|
from homeassistant.components import remote
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.const import CONF_DEVICE, CONF_NAME
|
2017-05-13 04:12:47 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN = "kira"
|
2017-05-13 04:12:47 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_REMOTE = "remote"
|
2017-05-13 04:12:47 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-13 04:12:47 +00:00
|
|
|
"""Set up the Kira platform."""
|
|
|
|
if discovery_info:
|
|
|
|
name = discovery_info.get(CONF_NAME)
|
|
|
|
device = discovery_info.get(CONF_DEVICE)
|
|
|
|
|
|
|
|
kira = hass.data[DOMAIN][CONF_REMOTE][name]
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([KiraRemote(device, kira)])
|
2017-05-13 04:12:47 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class KiraRemote(Entity):
|
|
|
|
"""Remote representation used to send commands to a Kira device."""
|
|
|
|
|
|
|
|
def __init__(self, name, kira):
|
|
|
|
"""Initialize KiraRemote class."""
|
|
|
|
_LOGGER.debug("KiraRemote device init started for: %s", name)
|
|
|
|
self._name = name
|
|
|
|
self._kira = kira
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the Kira device's name."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""No-op."""
|
|
|
|
|
2017-08-01 03:52:39 +00:00
|
|
|
def send_command(self, command, **kwargs):
|
2017-05-13 04:12:47 +00:00
|
|
|
"""Send a command to one device."""
|
2018-01-29 22:37:19 +00:00
|
|
|
for single_command in command:
|
2019-07-31 19:25:30 +00:00
|
|
|
code_tuple = (single_command, kwargs.get(remote.ATTR_DEVICE))
|
2017-05-24 00:00:52 +00:00
|
|
|
_LOGGER.info("Sending Command: %s to %s", *code_tuple)
|
|
|
|
self._kira.sendCode(code_tuple)
|
2017-05-13 04:12:47 +00:00
|
|
|
|
2017-08-01 03:52:39 +00:00
|
|
|
def async_send_command(self, command, **kwargs):
|
2017-05-13 04:12:47 +00:00
|
|
|
"""Send a command to a device.
|
|
|
|
|
|
|
|
This method must be run in the event loop and returns a coroutine.
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
return self.hass.async_add_job(ft.partial(self.send_command, command, **kwargs))
|