|
|
@@ -1,6 +1,7 @@
|
|
|
import asyncio
|
|
|
from base64 import b64encode
|
|
|
import binascii
|
|
|
+import requests
|
|
|
import logging
|
|
|
|
|
|
from homeassistant.const import ATTR_ENTITY_ID
|
|
|
@@ -12,24 +13,23 @@ _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):
|
|
|
if controller not in [
|
|
|
- BROADLINK_CONTROLLER, XIAOMI_CONTROLLER, MQTT_CONTROLLER]:
|
|
|
+ BROADLINK_CONTROLLER, XIAOMI_CONTROLLER,
|
|
|
+ MQTT_CONTROLLER, LOOKIN_CONTROLLER]:
|
|
|
raise Exception("The controller is not supported.")
|
|
|
|
|
|
if controller == BROADLINK_CONTROLLER:
|
|
|
@@ -47,6 +47,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
|
|
|
@@ -99,4 +104,12 @@ class Controller():
|
|
|
}
|
|
|
|
|
|
await self.hass.services.async_call(
|
|
|
- 'mqtt', 'publish', service_data)
|
|
|
+ 'mqtt', 'publish', service_data)
|
|
|
+
|
|
|
+ if self._controller == LOOKIN_CONTROLLER:
|
|
|
+ encoding = self._encoding.lower().replace('pronto', 'prontohex')
|
|
|
+ url = f"http://{self._controller_data}/commands/ir/" \
|
|
|
+ f"{encoding}/{command}"
|
|
|
+ await self.hass.async_add_executor_job(
|
|
|
+ requests.get, url
|
|
|
+ )
|