Skip to content

Use 'hass.data' instead of global#8245

Merged
pvizeli merged 1 commit into
home-assistant:devfrom
fabaff:hass.data-do
Jun 30, 2017
Merged

Use 'hass.data' instead of global#8245
pvizeli merged 1 commit into
home-assistant:devfrom
fabaff:hass.data-do

Conversation

@fabaff
Copy link
Copy Markdown
Member

@fabaff fabaff commented Jun 29, 2017

Description:

Use 'hass.data' instead of global and don't call update() in constructor..

Example entry for configuration.yaml (if applicable):

digital_ocean:
  access_token: !secret do_token

binary_sensor:
  - platform: digital_ocean
    droplets:
      - 'fedora-512mb-nyc3-01'

switch:
  - platform: digital_ocean
    droplets:
      - 'fedora-512mb-nyc3-01'

Checklist:

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

@mention-bot
Copy link
Copy Markdown

@fabaff, thanks for your PR! By analyzing the history of the files in this pull request, we identified @armills to be a potential reviewer.

Copy link
Copy Markdown
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

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

You should not use DOMAIN for hass.data or if you import DOMAIN into a other namespace as platform rename to ... DOMAIN AS XY_DOMAIN. Otherwise it overwrite the domain of component from other platofrm. That is the reason for DATA_XY constante they easy to Import into other namespace.

@fabaff
Copy link
Copy Markdown
Member Author

fabaff commented Jun 29, 2017

Using hass.data[DOMAIN] and importing DOMAIN on the platform-level seems to be pretty much how a bunch of components/platforms works. I don't understand why DOMAIN should overwrite the value of another platforms. Isn't the scope preventing this and if that happens wouldn't we see side effects from this?

I guess that prefixing the entries with DATA_ make sense.

@pvizeli pvizeli merged commit 27c9293 into home-assistant:dev Jun 30, 2017
@balloob balloob mentioned this pull request Jul 1, 2017
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants