Skip to content

Support for multiple Fibaro gateways#19705

Merged
balloob merged 9 commits into
home-assistant:devfrom
pbalogh77:async_setup
Jan 11, 2019
Merged

Support for multiple Fibaro gateways#19705
balloob merged 9 commits into
home-assistant:devfrom
pbalogh77:async_setup

Conversation

@pbalogh77
Copy link
Copy Markdown
Contributor

@pbalogh77 pbalogh77 commented Jan 1, 2019

Description:

Fibaro component now supports multiple Fibaro HC gateways.

  • Added multiple gateway support.
  • Reworked parameter flow to platforms to enable multiple controllers.

Breaking change:
A list of gateways is expected instead of a single config.

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

fibaro:
    gateways:
      - url: http://your.fibaro.url/api
        username: username
        password: password

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

Added multiple gateway support
Reworked parameter flow to platforms to enable multiple controllers
Breaking change to config, now a list of gateways is expected instead of a single config
Added new location of fibaro component
@ghost ghost added the in progress label Jan 1, 2019
@pbalogh77 pbalogh77 changed the title WIP: Support for multiple Fibaro gateways Support for multiple Fibaro gateways Jan 2, 2019
Copy link
Copy Markdown
Contributor

@dgomes dgomes left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment thread homeassistant/components/fibaro/__init__.py Outdated
Comment thread homeassistant/components/fibaro/__init__.py Outdated
@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 5, 2019

ok to merge when comments addressed

Addressed issues raised by code review
Added extended debug logging to get better reports from users if the device type mapping is not perfect
Comment thread homeassistant/components/fibaro/__init__.py Outdated
Comment thread homeassistant/components/fibaro/__init__.py Outdated
hass.data[FIBARO_DEVICES] = controller.fibaro_devices
for controller in hass.data[FIBARO_CONTROLLERS].values():
controller.disable_state_handler()
hass.data[FIBARO_CONTROLLERS] = {}
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.

If we don't need this key anymore we should pop it or delete it from the dict.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that be a less efficient algorithm, tho?
I know it's highly theoretical either way, since it's usually a single element list and it's probably equally readable either way, but this seems like a more appropriate solution on an embedded device. I could be wrong, I'm new here. Of course if you insist, I'll modify it.

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.

I don't think we should worry about speed here, but clean up remaining references.

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.

For now though we don't really need to clean up anything, since this is only done when home assistant shuts down. So we can remove this line completely. Clean up will be relevant if moving this component to use config entries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll keep in mind.

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.

Please remove this line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I removed it. Just for my education, what was wrong with that line? I'm new to python but as far as I understand it did remove the reference to all items in the map and by that freeing up the memory. I understand your suggestion that you'd prefer enumerate + pop, but coming from decades of embedded c programming and knowing how enumerate and pop works, that's really a very wasteful way of solving the problem. Afaik, enumerate iterates through the list an extra time, creates a new index, and pop unlinks items one-by-one from the list. I could be totally wrong on my assumptions, but in general this construct feels like something to discourage on an embedded platform. I could be totally not pythonic in thinking this.
Anyhow, I'd love to learn. Thanks in advance.

Comment thread homeassistant/components/fibaro/__init__.py Outdated
Comment thread homeassistant/components/fibaro/__init__.py Outdated
Comment thread homeassistant/components/fibaro/__init__.py Outdated
Changes to how configuration is read and schemas
Fix to device type mapping logic
oops
Comment thread homeassistant/components/fibaro/__init__.py Outdated
grr
Comment thread homeassistant/components/fibaro/__init__.py Outdated
hass.data[FIBARO_DEVICES] = controller.fibaro_devices
for controller in hass.data[FIBARO_CONTROLLERS].values():
controller.disable_state_handler()
hass.data[FIBARO_CONTROLLERS] = {}
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.

For now though we don't really need to clean up anything, since this is only done when home assistant shuts down. So we can remove this line completely. Clean up will be relevant if moving this component to use config entries.

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.

Good!

@MartinHjelmare
Copy link
Copy Markdown
Member

Can be merged when docs PR is linked in the PR description.

pbalogh77 added a commit to pbalogh77/home-assistant.io that referenced this pull request Jan 11, 2019
@pbalogh77
Copy link
Copy Markdown
Contributor Author

Updated documentation, added link to PR

@balloob balloob merged commit 7dac7b9 into home-assistant:dev Jan 11, 2019
balloob pushed a commit to home-assistant/home-assistant.io that referenced this pull request Jan 11, 2019
* Updated based on changes

Documentation change based on home-assistant/core#19705

* Update fibaro.markdown
@pbalogh77 pbalogh77 deleted the async_setup branch January 12, 2019 18:04
@balloob balloob mentioned this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants