Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadlink switches dont show up if their IR packet is not a multiple of 4 #18453

Closed
ktaragorn opened this issue Nov 14, 2018 · 8 comments · Fixed by #23408
Closed

Broadlink switches dont show up if their IR packet is not a multiple of 4 #18453

ktaragorn opened this issue Nov 14, 2018 · 8 comments · Fixed by #23408

Comments

@ktaragorn
Copy link
Contributor

Home Assistant release with the issue:

Version 0.82.0

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Running on Ubuntu 16.04

Component/platform:

https://www.home-assistant.io/components/switch.broadlink/

Description of problem:
When configuring the Broadlink switch with commands, if the commands are not a multiple of 4, the switch doesnt load on the interface and throws an esoteric error "binascii.Error: Incorrect padding". This has occured to me after copy pasting the command generated by the "learn_command" function of the same component.
Please check out https://community.home-assistant.io/t/switches-not-showing-up-anymore/63377 for the work around, which is to add "=" in the end of the command to make it divisible by 4

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

switch:
  - platform: broadlink
    host: blackbean1
    mac: '78:0F:77:50:98:D3'
    switches:
      ac:
        friendly_name: Aircon
        command_on: JgBQAg0QDBAMEQwQDBANAANFcTkOKw4ODg8ODg4rDg4ODg8ODg4OKw4ODisOKw4ODisOKw4qDyoOKw4ODg8OKg8ODg4ODg8ODg4ODw4ODg4ODw4ODisODg4rDg4ODw4ODisOKw4ODg4ODw4ODg4PDg4ODg8ODg4ODg8ODg4ODw4ODg4PDioOKw4rDg4OKw4ODisOKw4ABHlwOwwsDRAMEAwRDCwNEAwQDBEMEAwtDBAMLQwsDRAMLQwsDC0MLQwtDBAMEAwtDBANEAwQDBEMEAwQDBEMEAwQDRAMEAwtDBAMEQwQDBANLAwRDBAMLQwsDSwMEQwQDBAMEQwQDBANLAwRDBAMEAwRDBAMEA0sDC0MEAwRDCwNLAwRDAAEe3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A0QDBAMEQwQDBANEAwQDBANEAwtDCwNEAwQDBANEAwQDBEMEAwQDRAMEAwRDBAMEAwRDBAMEAwRDBAMEA0QDBANEAwQDC0MLA0QDBAMEQwQDBAMEQwQDBANEAwQDBEMEAwQDBEMEAwQDRAMEAwtDBAMEQwQDC0MEAwADQUAAAAAAAAAAA==

This config has already been "fixed" by adding the ==

Traceback (if applicable):

Error while setting up platform broadlink
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 129, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py”, line 157, in setup_platform
device_config.get(CONF_COMMAND_OFF)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py”, line 193, in init
self._command_on = b64decode(command_on) if command_on else None
File “/usr/local/lib/python3.6/base64.py”, line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

I copied the error log from the above linked forum page since i already fixed my config

Additional information:
I feel like this should be fixed internally. At the Learn command level and at the switches level as well. If there is no reason this should not be done, I can get a PR together for this.

@ktaragorn
Copy link
Contributor Author

The broadlink switch I am using is RM3 Mini, which already had issues with the python_broadlink library.. I wonder if this is related. However my switch DOES work after fixing the config as above.

@ktaragorn
Copy link
Contributor Author

http://tomeko.net/online_tools/hex_to_base64.php as recommended in the config for other approaches, does infact generate the trailing ==, looks like the broadlink switch code should as well

@ktaragorn
Copy link
Contributor Author

it appears that _send_packet already fixes this, I could validate this via dev tools, but i believe the bug lies in the fact that the Switch classes bypass this method to call senddata directly on the device without padding it first.

@ktaragorn
Copy link
Contributor Author

Previous PR fixing this in send_packet #10560

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@deftdawg
Copy link
Contributor

deftdawg commented Feb 21, 2019

Yeap, I hit this problem as well with 0.84.1...
One way to accomplish the same thing as what they did with _send_packet is just to append + '===' every call to b64decode.

        self._command_on = b64decode(command_on + '===') if command_on else None
        self._command_off = b64decode(command_off + '===') if command_off else None

Seems in my messing with b64decode in a shell, it doesn't care if you have more = than you need.

@ktaragorn
Copy link
Contributor Author

Im still seeing this issue on 0.91.1 as well

@elupus
Copy link
Contributor

elupus commented Apr 25, 2019

This is getting sideeffect fixed from a unintended fallout from refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants