Unverified Commit 24f2a3aa authored by Vassilis Panos's avatar Vassilis Panos Committed by GitHub
Browse files

Merge pull request #370 from ixkor/esphome-support

Add support ESPHome remote transmitter as controller
parents 1ce1a56a 80b7d276
Loading
Loading
Loading
Loading
+463 −0

File added.

Preview size limit exceeded, changes collapsed.

+18 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from base64 import b64encode
import binascii
import requests
import logging
import json

from homeassistant.const import ATTR_ENTITY_ID
from . import Helper
@@ -12,6 +13,7 @@ BROADLINK_CONTROLLER = 'Broadlink'
XIAOMI_CONTROLLER = 'Xiaomi'
MQTT_CONTROLLER = 'MQTT'
LOOKIN_CONTROLLER = 'LOOKin'
ESPHOME_CONTROLLER = 'ESPHome'

ENC_BASE64 = 'Base64'
ENC_HEX = 'Hex'
@@ -22,12 +24,13 @@ 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]
ESPHOME_COMMANDS_ENCODING = [ENC_RAW]

class Controller():
    def __init__(self, hass, controller, encoding, controller_data):
        if controller not in [
            BROADLINK_CONTROLLER, XIAOMI_CONTROLLER, 
            MQTT_CONTROLLER, LOOKIN_CONTROLLER]:
            MQTT_CONTROLLER, LOOKIN_CONTROLLER, ESPHOME_CONTROLLER]:
            raise Exception("The controller is not supported.")

        if controller == BROADLINK_CONTROLLER:
@@ -50,6 +53,11 @@ class Controller():
                raise Exception("The encoding is not supported "
                                "by the LOOKin controller.")

        if controller == ESPHOME_CONTROLLER:
            if encoding not in ESPHOME_COMMANDS_ENCODING:
                raise Exception("The encoding is not supported "
                                "by the ESPHome controller.")

        self.hass = hass
        self._controller = controller
        self._encoding = encoding
@@ -111,3 +119,11 @@ class Controller():
            await self.hass.async_add_executor_job(
                requests.get, url
            )

        if self._controller == ESPHOME_CONTROLLER:
            service_data = {
                'command':  json.loads(command)
            }

            await self.hass.services.async_call(
               'esphome', self._controller_data, service_data)
+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ Below are the code files created by the people in the community. Before you star
| [1284](../codes/climate/1284.json) | AR-REG1U (Remote control)                   | Broadlink  |
| [1285](../codes/climate/1285.json) | AR-RCE1E (Remote control)                   | Broadlink  |
| [3285](../codes/climate/3285.json) | AR-RCE1E (Remote control)                   | Xiaomi (v2)|
| [7285](../codes/climate/7285.json) | AR-RCE1E (Remote control)                   | ESPHome    |
| [1286](../codes/climate/1286.json) | AR-JE5 (Remote control)                     | Broadlink  |
| [1287](../codes/climate/1287.json) | AR-REB1E (Remote control)                   | Broadlink  |

+11 −0
Original line number Diff line number Diff line
@@ -7,6 +7,17 @@ SmartIR is a custom integration for controlling AC units, TV sets and fans via I
* [Xiaomi IR Remote (ChuangmiIr)](https://www.home-assistant.io/integrations/remote.xiaomi_miio/)
* [LOOK.in Remote](http://look-in.club/devices/remote)
* [MQTT Publish service](https://www.home-assistant.io/docs/mqtt/service/)
* [ESPHome User-defined service for remote transmitter](https://esphome.io/components/api.html#user-defined-services)
  ```yml
  api:
    services:
      - service: send_raw_command
        variables:
          command: int[]
        then:
          - remote_transmitter.transmit_raw:
              code: !lambda 'return command;'
  ```

## **Platform setup instructions**
<p align="center">