From bb3300e40b1f8e9f45db48687b5bae090d1599ca Mon Sep 17 00:00:00 2001 From: Vassilis Panos <4130346+vassilis-panos@users.noreply.github.com> Date: Sat, 19 Sep 2020 14:24:46 +0300 Subject: [PATCH] Fixes Broadlink commands sequence #481 --- custom_components/smartir/__init__.py | 2 +- custom_components/smartir/controller.py | 48 ++++++++++++++----------- custom_components/smartir/manifest.json | 4 +-- hacs.json | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/custom_components/smartir/__init__.py b/custom_components/smartir/__init__.py index a57b8d37..d2cf4732 100644 --- a/custom_components/smartir/__init__.py +++ b/custom_components/smartir/__init__.py @@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = 'smartir' -VERSION = '1.13.1' +VERSION = '1.13.2' MANIFEST_URL = ( "https://raw.githubusercontent.com/" "smartHomeHub/SmartIR/{}/" diff --git a/custom_components/smartir/controller.py b/custom_components/smartir/controller.py index 7b0a928a..3ceff13c 100644 --- a/custom_components/smartir/controller.py +++ b/custom_components/smartir/controller.py @@ -74,28 +74,36 @@ def check_encoding(self, encoding): async def send(self, command): """Send a command.""" - if self._encoding == ENC_HEX: - try: - command = binascii.unhexlify(command) - command = b64encode(command).decode('utf-8') - except: - raise Exception("Error while converting " - "Hex to Base64 encoding") - - if self._encoding == ENC_PRONTO: - try: - command = command.replace(' ', '') - command = bytearray.fromhex(command) - command = Helper.pronto2lirc(command) - command = Helper.lirc2broadlink(command) - command = b64encode(command).decode('utf-8') - except: - raise Exception("Error while converting " - "Pronto to Base64 encoding") + commands = [] + + if not isinstance(command, list): + command = [command] + + for _command in command: + if self._encoding == ENC_HEX: + try: + _command = binascii.unhexlify(_command) + _command = b64encode(_command).decode('utf-8') + except: + raise Exception("Error while converting " + "Hex to Base64 encoding") + + if self._encoding == ENC_PRONTO: + try: + _command = _command.replace(' ', '') + _command = bytearray.fromhex(_command) + _command = Helper.pronto2lirc(_command) + _command = Helper.lirc2broadlink(_command) + _command = b64encode(_command).decode('utf-8') + except: + raise Exception("Error while converting " + "Pronto to Base64 encoding") + + commands.append('b64:' + _command) service_data = { ATTR_ENTITY_ID: self._controller_data, - 'command': 'b64:' + command + 'command': commands } await self.hass.services.async_call( @@ -173,4 +181,4 @@ async def send(self, command): service_data = {'command': json.loads(command)} await self.hass.services.async_call( - 'esphome', self._controller_data, service_data) + 'esphome', self._controller_data, service_data) \ No newline at end of file diff --git a/custom_components/smartir/manifest.json b/custom_components/smartir/manifest.json index a3a32831..66c9c5cd 100644 --- a/custom_components/smartir/manifest.json +++ b/custom_components/smartir/manifest.json @@ -7,8 +7,8 @@ "requirements": ["aiofiles==0.5.0"], "homeassistant": "0.115.0", "updater": { - "version": "1.13.1", - "releaseNotes": "-- Adds support for the new Broadlink integration (Breaking change!)", + "version": "1.13.2", + "releaseNotes": "-- Fixes Broadlink commands sequence #481", "files": [ "__init__.py", "climate.py", diff --git a/hacs.json b/hacs.json index 11f8ae4a..c910b722 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { "name": "SmartIR", - "homeassistant": "0.115.0b0", + "homeassistant": "0.115.0", "persistent_directory": "codes" }