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

Error while setting up mystrom platform for light #50116

Closed
boostvolt opened this issue May 5, 2021 · 4 comments
Closed

Error while setting up mystrom platform for light #50116

boostvolt opened this issue May 5, 2021 · 4 comments

Comments

@boostvolt
Copy link

The problem

I have tried to integrate the myStrom light bulbs but unfortunately without success. Everything works via the myStrom app. I was also able to integrate the myStrom switch into homeassistant. I followed the following instructions for the configuration: https://www.home-assistant.io/integrations/mystrom/. However, I receive the following error message when I start the server:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/mystrom/light.py", line 51, in async_setup_platform
    await bulb.get_state()
  File "/usr/local/lib/python3.8/site-packages/pymystrom/bulb.py", line 41, in get_state
    self._consumption = response[self._mac]["power"]
TypeError: 'method' object is not subscriptable

What is version of Home Assistant Core has the issue?

core-2021.4.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

myStrom

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mystrom/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/mystrom/light.py", line 51, in async_setup_platform
    await bulb.get_state()
  File "/usr/local/lib/python3.8/site-packages/pymystrom/bulb.py", line 41, in get_state
    self._consumption = response[self._mac]["power"]
TypeError: 'method' object is not subscriptable

Additional information

No response

@probot-home-assistant
Copy link

mystrom documentation
mystrom source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @fabaff, mind taking a look at this issue as its been labeled with an integration (mystrom) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@github-actions
Copy link

github-actions bot commented Aug 3, 2021

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 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@shastah
Copy link

shastah commented Sep 3, 2021

For anyone in the future who might stumble upon this: I had a similar problem setting up myStrom switch. Turns out aiohttp library (which pymystrom uses underneath to talk http to the device) unconditionally add this header to the http request:

Accept-Encoding: gzip, deflate

without adding Referer or Origin headers, and this in turn triggers myStrom's CORS protection

This mechanism works in a simple way to minimize its impact on external integrating systems. If the HTTP request in the header contains the Accept-Encoding field then the same request should also have a Referer or Origin header field starting with http://{target device ip}. If the Referer or Origin field does not match the expected value or is missing in the case of a request with Accept-Encoding then the request is rejected. If the request is made without the Accept-Encoding header then the Referer and Origin fields do not need to be provided.

This protection can be disabled by sending a POST request to the device - just be mindful of the security implications.

curl -i -X POST http://{deviceip}/api/v1/protection/disable

@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2021
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

3 participants