refactor(controller): rewrite the controller to reuse the IR codes
It doesn't make sense that an IR code files can only be used by the specified controller. So I've refactored the controller source code to make it possible to use the IR code files on different controllers.
Currently, the MQTT(OpenMQTTGateway/IRremoteESP8266), ESPHome and Broadlink controllers can use IR codes each other.
The Xiaomi(unkown IR format for me) and Lookin's controller(no device to test) has not be supported.
Usage
Specify the controller in your HA configuration.yaml:
climate:
- platform: smartir
name: AC
unique_id: ou_ac
device_code: 2100
controller: MQTT # <-- specify your controller here
controller_type: OpenMQTTGateway # IRremoteESP8266 or OpenMQTTGateway, defaults to OpenMQTTGateway
controller_data: home/OpenMQTTGateway1/commands/MQTTtoIR
Development
The controller uses the LIRC format as generic format. So your controller just implements the two methods to convert. eg:
class BroadlinkController(AbstractController):
"""Controls a Broadlink device."""
name = BROADLINK_CONTROLLER # must name your controller here
@classmethod
def toLirc(cls, command, data):
# conver the controller's local command to the lirc format
ok = False
if data._supported_controller == cls.name:
if data._commands_encoding == ENC_HEX:
command = binascii.unhexlify(command)
ok = True
elif data._commands_encoding == ENC_PRONTO:
command = command.replace(' ', '')
command = bytearray.fromhex(command)
command = Helper.pronto2lirc(command)
ok = True
elif data._commands_encoding == ENC_BASE64:
ok = True
if ok and type(command) is not list:
command = Helper.broadlink2lirc(command)
return ok, command
@classmethod
def fromLirc(cls, command, data):
# conver the lirc format command to the controller's local format
command = Helper.lirc2broadlink(command)
command = b64encode(command).decode('utf-8')
return True, command
This pull request introduces 22 alerts and fixes 1 when merging 23f0dae7d54d2df4e243f7ba0ffaa84a7539398b into 61e2960ec46cd766703f0fc9a756e7b6c3ceefad - view on LGTM.com
new alerts:
- 16 for Unused import
- 6 for 'import *' may pollute namespace
fixed alerts:
- 1 for `__init__` method calls overridden method
This pull request introduces 1 alert and fixes 1 when merging ed560e695ce694a24731c001b6f0d0fe7495eefb into 61e2960ec46cd766703f0fc9a756e7b6c3ceefad - view on LGTM.com
new alerts:
- 1 for Unused import
fixed alerts:
- 1 for `__init__` method calls overridden method
This pull request fixes 1 alert when merging 796708716a08e36df36d6195fff72d901f10833f into 61e2960ec46cd766703f0fc9a756e7b6c3ceefad - view on LGTM.com
fixed alerts:
- 1 for `__init__` method calls overridden method
This pull request fixes 1 alert when merging a286b9d33b62f7856835f3f1ea4d344a75933b57 into 61e2960ec46cd766703f0fc9a756e7b6c3ceefad - view on LGTM.com
fixed alerts:
- 1 for `__init__` method calls overridden method
This pull request fixes 1 alert when merging 114aceff3a460262ca02a6ed8eb72be0fd74697f into 61e2960ec46cd766703f0fc9a756e7b6c3ceefad - view on LGTM.com
fixed alerts:
- 1 for `__init__` method calls overridden method
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.