Init support for LOOKin IR controller
import asyncio
from base64 import b64encode
import binascii
+import requests
import logging
from homeassistant.const import ATTR_ENTITY_ID
@@ -12,19 +13,17 @@ _LOGGER = logging.getLogger(__name__)
BROADLINK_CONTROLLER = 'Broadlink'
XIAOMI_CONTROLLER = 'Xiaomi'
MQTT_CONTROLLER = 'MQTT'
+LOOKIN_CONTROLLER = 'LOOKin'
ENC_BASE64 = 'Base64'
ENC_HEX = 'Hex'
ENC_PRONTO = 'Pronto'
ENC_RAW = 'Raw'
-BROADLINK_COMMANDS_ENCODING = [
- ENC_BASE64, ENC_HEX, ENC_PRONTO]
-
-XIAOMI_COMMANDS_ENCODING = [
- ENC_PRONTO, ENC_RAW]
-
+BROADLINK_COMMANDS_ENCODING = [ENC_BASE64, ENC_HEX, ENC_PRONTO]
+XIAOMI_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
MQTT_COMMANDS_ENCODING = [ENC_RAW]
+LOOKIN_COMMANDS_ENCODING = [ENC_PRONTO, ENC_RAW]
class Controller():
def __init__(self, hass, controller, encoding, controller_data):
@@ -47,6 +46,11 @@ class Controller():
raise Exception("The encoding is not supported "
"by the mqtt controller.")
+ if controller == LOOKIN_CONTROLLER:
+ if encoding not in LOOKIN_COMMANDS_ENCODING:
+ raise Exception("The encoding is not supported "
+ "by the LOOKin controller.")
+
self.hass = hass
self._controller = controller
self._encoding = encoding
@@ -100,3 +104,10 @@ class Controller():
await self.hass.services.async_call(
'mqtt', 'publish', service_data)
+
+ if self._controller == LOOKIN_CONTROLLER:
+ url = f"http://{self._controller_data}/commands/ir/" \
+ f"{self._encoding.lower()}/{command}"
+ await self.hass.async_add_executor_job(
+ requests.get, url
+ )
\ No newline at end of file
