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 sensor startup failure: expected str instance, bytes found #11418

Closed
benh57 opened this issue Jan 2, 2018 · 19 comments
Closed

Broadlink sensor startup failure: expected str instance, bytes found #11418

benh57 opened this issue Jan 2, 2018 · 19 comments

Comments

@benh57
Copy link

benh57 commented Jan 2, 2018

Make sure you are running the latest version of Home Assistant before reporting an issue.

Home Assistant release (hass --version):

(homeassistant) homeassistant@pi:~/.homeassistant$ hass --version
0.60.0

Python release (python3 --version):

(homeassistant) homeassistant@pi:~/.homeassistant$ python3 --version
Python 3.4.2

Component/platform:
broadlink-switch

Description of problem:

broadlink component fails to initialize with this error

Expected:
starts up

Problem-relevant configuration.yaml entries and steps to reproduce:

switch:
  - platform: broadlink
    host: 192.168.1.162
    mac: '34EA34CCCF86'
    type: 'rm2'

Traceback (if applicable):

2018-01-01 18:57:41 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform broadlink
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 171, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch/broadlink.py", line 174, in setup_platform
    broadlink_device.auth()
  File "/srv/homeassistant/lib/python3.4/site-packages/broadlink/__init__.py", line 203, in auth
    response = self.send_packet(0x65, payload)
  File "/srv/homeassistant/lib/python3.4/site-packages/broadlink/__init__.py", line 258, in send_packet
    payload = self.encrypt(payload)
  File "/srv/homeassistant/lib/python3.4/site-packages/broadlink/__init__.py", line 162, in encrypt_pyaes
    return "".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
TypeError: sequence item 0: expected str instance, bytes found

Additional info:

(homeassistant) homeassistant@pi:~/.homeassistant$ pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
aiohttp (2.3.6)
aiohttp-cors (0.5.3)
asn1crypto (0.24.0)
astral (1.4)
async-timeout (2.0.0)
boto3 (1.5.6)
botocore (1.8.20)
broadlink (0.5)
certifi (2017.11.5)
cffi (1.11.2)
chardet (3.0.4)
colorlog (3.0.1)
cryptography (2.1.4)
distro (1.1.0)
docutils (0.14)
ecdsa (0.13)
enum-compat (0.0.2)
envs (1.2.4)
future (0.16.0)
fuzzywuzzy (0.15.1)
gTTS-token (1.1.1)
home-assistant-frontend (20171216.0)
homeassistant (0.60.0)
idna (2.6)
Jinja2 (2.10)
jmespath (0.9.3)
MarkupSafe (1.0)
multidict (3.3.2)
mutagen (1.39)
netdisco (1.2.3)
netifaces (0.10.6)
pip (9.0.1)
protobuf (3.5.1)
py3compat (0.4)
pyaes (1.6.0)
PyChromecast (0.8.2)
pycparser (2.18)
pycrypto (2.6.1)
pycryptodome (3.3.1)
python-dateutil (2.6.1)
python-jose-cryptodome (1.3.2)
pytz (2017.3)
pywemo (0.4.20)
PyYAML (3.12)
requests (2.18.4)
rxv (0.5.1)
s3transfer (0.1.12)
setuptools (38.2.4)
six (1.11.0)
SQLAlchemy (1.1.15)
typing (3.6.2)
ua-parser (0.7.3)
urllib3 (1.22)
user-agents (1.1.0)
voluptuous (0.10.5)
warrant (0.6.1)
xmltodict (0.11.0)
yarl (0.16.0)
zeroconf (0.19.1)

@benh57
Copy link
Author

benh57 commented Jan 2, 2018

Upgraded broadlink to 0.6 using pip but I think hass is downgrading the broadlink component to 0.5 when it starts up from 0.6. Is there a way to prevent that (switch to hass-dev maybe?)

@MartinHjelmare
Copy link
Member

MartinHjelmare commented Jan 2, 2018

hass --skip-pip

Note that this will disable pip install for all requirements.

@staraxis
Copy link

staraxis commented Jan 7, 2018

Having the same issue on a new install on ubuntu. The difference being that I am running python 3.6. Would this have any effect?

@cgmnuk
Copy link

cgmnuk commented Jan 7, 2018

The very same error "TypeError: sequence item 0: expected str instance, bytes found". I'm running Arch on Raspberry Pi with Python 3.6 also.

@jamieshaw
Copy link

Also seeing this issue on a clean install of Home Assistant 0.60.1 with Python 3.5.4; both Broadlink 0.5 and 0.6, with latest versions of pyaes and pycrypto. Have updated both switch and sensor broadlink.py files to use 0.6 to no avail.

(This was previously working on a previous install, but have reconfigured using pyenv-virtualenv).

@martyouel
Copy link

Just received my RMPRO today and I try to make it work with HA.

I'm now at the same point here --> TypeError: sequence item 0: expected str instance, bytes found

I'm running on Windows.
I got problem with PyCrypto on python 3.6
So I just rolledback my system to python 3.5.4 and now i'm at the same point with the error above

@benh57
Copy link
Author

benh57 commented Jan 11, 2018

Looks like this is related to conflicting pycrypto vs pycryptodome installs. hass broadlink plugin fails to import AES, so falls back to 'pyaes', which does not work.

I was able to resolve it with the steps noted here:

#2411

pip3 uninstall pycrypto
pip3 uninstall pycryptodome
pip3 install pycryptodome

@jamieshaw
Copy link

Confirmed. Installing pyrcryptodome resolves the issue.

Purged my venv and started afresh. Installed pycryptodome before running hass for the first time and no more errors in the log.

@martyouel
Copy link

martyouel commented Jan 11, 2018

First, thanks for your answer guys.
Second, i've got no luck. I tried what you wrote but I still have the same problem :(
When I did the uninstall of pycryptodome I got the message that it was not installed.

TypeError: sequence item 0: expected str instance, bytes found

Any idea ?

@benh57
Copy link
Author

benh57 commented Jan 24, 2018

You need to do the uninstall/ reinstalling within the virtualenv used by hass.

@martyouel
Copy link

umm sorry for the newb question but i'm not sure to understand what you mean by "within the virtualenv used by hass".
I'm running on a Windows 2k12 server.

Right now the only way I was able to incorporate my RM PRO within my home automation is by installing another automation system on another computer (Domoticz). So I use HA as my main automation system and call all my RM PRO switches by using the Domoticz API.

@AMSHL
Copy link

AMSHL commented Feb 6, 2018

Have the same issue on fresh install

2018-02-07 02:31:00 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform broadlink
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 352, in wait_for
    return fut.result()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/homeassistant/components/switch/broadlink.py", line 176, in setup_platform
    broadlink_device.auth()
  File "/Users/Shlom/.homeassistant/deps/lib/python/site-packages/broadlink/__init__.py", line 203, in auth
    response = self.send_packet(0x65, payload)
  File "/Users/Shlom/.homeassistant/deps/lib/python/site-packages/broadlink/__init__.py", line 258, in send_packet
    payload = self.encrypt(payload)
  File "/Users/Shlom/.homeassistant/deps/lib/python/site-packages/broadlink/__init__.py", line 162, in encrypt_pyaes
    return "".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)])
TypeError: sequence item 0: expected str instance, bytes found

@jamieshaw
Copy link

@AMSHL Have you tried the steps above to install pycryptodome before Hass self-installs the pycrypto libraries?

@AMSHL
Copy link

AMSHL commented Feb 7, 2018

@jamieshaw Yes, tried that already - no result.

@juan11perez
Copy link

@benh57 thank you very much for the instruction. I implemented and got my Broadlinks working!!
this is the commands

sudo systemctl stop home-assistant@homeassistant.service
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 uninstall pycrypto
pip3 uninstall pycryptodome
pip3 install pycryptodomepip3 install
exit
sudo systemctl restart home-assistant@homeassistant.service

@oldfart101
Copy link

pip3 install pycryptodomepip3 install
Collecting pycryptodomepip3
Could not find a version that satisfies the requirement pycryptodomepip3 (from versions: )
No matching distribution found for pycryptodomepip3

@grea09
Copy link
Contributor

grea09 commented Apr 19, 2018

I openned another issue since the logs wasn't the same but there's an easy fix by simply updating the broadlink library.

@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 👍

@balloobbot
Copy link

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem 👍

@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests