Skip to content

Action parameter doesn't longer have to be the first parameter#14815

Merged
fabaff merged 2 commits intohome-assistant:devfrom
GruberMischa:fix-unordered-parameters
Jun 5, 2018
Merged

Action parameter doesn't longer have to be the first parameter#14815
fabaff merged 2 commits intohome-assistant:devfrom
GruberMischa:fix-unordered-parameters

Conversation

@GruberMischa
Copy link
Copy Markdown
Contributor

@GruberMischa GruberMischa commented Jun 4, 2018

Description:

The component no longer asumes, that the first parameter is the desired action. Looks throw the list and takes the first acceptable action.
Previously if the api_password parameter was passed and it was the first in the list, the component didn't work.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5497

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

couldn't test with tox, because tox command doesn't continue after py35 installdeps:
but flake8, pylint, pydocstyle and py.test are passing

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @GruberMischa,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

if button_action not in ['single', 'double', 'long', 'touch']:
button_action = None
parameter_list = list(data.keys())
for parameter in parameter_list:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

button_action = next((
    parameter for parameter in data
    if parameter in self.supported_actions), None)

@GruberMischa
Copy link
Copy Markdown
Contributor Author

GruberMischa commented Jun 4, 2018

Added @MartinHjelmare's suggestion

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jun 5, 2018

Documentation update attached because I left api_password out in the first place.

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jun 5, 2018

Works with Firmware 2.56

2018-06-05 17:29:40 INFO (MainThread) [homeassistant.components.http.view] Serving /api/mystrom to 192.168.0.227 (auth: True)
2018-06-05 17:29:40 INFO (MainThread) [homeassistant.components.binary_sensor.mystrom] New myStrom button/action detected: button_green/single
2018-06-05 17:29:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.button_green_single, old_state=None, new_state=<state binary_sensor.button_green_single=off; friendly_name=button_green_single @ 2018-06-05T17:29:40.458983+02:00>>

Now there is an issue: If there is no password provided for one action of the button and that action is triggered then it's logged as login attempt.

2018-06-05 17:30:15 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt or request with invalid authentication from 192.168.0.227

If one uses, let's says, has set login_attempts_threshold: 3 then the IP address is banned and the button is no longer functional even if the other "actions" contain the api_password. A restart of Home Assistant will not help as the IP address is stored in ip_bans.yaml.

@GruberMischa
Copy link
Copy Markdown
Contributor Author

So what do you suggest? Adding a warning about this scenario in the docs?
I mean we can't disable the authenticaion for this component, because then this would be vulnerable to brute force attacks.

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jun 5, 2018

So what do you suggest? Adding a warning about this scenario in the docs?

Yes, we will cover this in the docs (55580b9).

Copy link
Copy Markdown
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐦

@fabaff fabaff merged commit cb6c869 into home-assistant:dev Jun 5, 2018
@balloob balloob mentioned this pull request Jun 22, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
…assistant#14815)

* Action parameter doesn't longer have to be the first parameter

* Minified code upon suggestion
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants