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

Pollen.com: Entity Registry updates and cleanup #12361

Merged
merged 4 commits into from
Feb 14, 2018

Conversation

bachya
Copy link
Contributor

@bachya bachya commented Feb 12, 2018

Description:

  1. Gives Pollen.com sensors a unique ID (based on ZIP code) for inclusion in the entity registry.
  2. General cleanup.

Related issue (if applicable): N/A

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

Example entry for configuration.yaml (if applicable):

sensor:
  platform: pollen
  zip_code: 12345
  monitored_conditions:
    - allergy_average_forecasted
    - allergy_average_historical
    - allergy_index_today
    - allergy_index_tomorrow
    - allergy_index_yesterday
    - disease_average_forecasted

Checklist:

  • The code change is tested and works locally.

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

@balloob
Copy link
Member

balloob commented Feb 13, 2018

If Pollen.com had been configured previously, new entries will be placed into the entity registry, causing there to be two of each sensor type defined. To address, simply alter the entity_registry.yaml as desired.

What does this mean? We don't duplicate entities with the registry. We only make sure that they get the same entity ID each time

datas[data_key],
params,
name,
icon
icon,
adler32(str(config[CONF_ZIP_CODE]).encode('utf-8'))
Copy link
Member

Choose a reason for hiding this comment

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

Why would you do this? Why not just pass the zip ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fighting a cold and my brain was locked on what I did for AirVisual. Will simplify.

@property
def unique_id(self):
"""Return a unique, HASS-friendly identifier for this entity."""
return '{0}_{1}'.format(self._entity_id, slugify(self._name))
Copy link
Member

Choose a reason for hiding this comment

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

Names are configurable and thus not unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Name" is a misnomer here: those are defined within CONDITIONS (example: Allergy Index: Forecasted Average). The user cannot change them.

"""Initialize the sensor."""
self._attrs = {}
self._icon = icon
self._name = name
self._data_params = data_params
self._state = None
self._unit = None
self._entity_id = entity_id
Copy link
Member

Choose a reason for hiding this comment

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

This is not an entity id. Do you mean unique id?

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

You're overthinking this. Just pass zip code as unique id. Don't use zlib, don't use name.

@bachya
Copy link
Contributor Author

bachya commented Feb 13, 2018

@balloob RE: my breaking change note, I was stating that this PR changes the unique ID for these sensors (thus creating the possibility that duplicates of each sensor – with different unique IDs – was possible). That said, in review, I didn't have unique IDs before, so perhaps it's a moot point. Let me know and I can remove the breaking change warning.

@balloob
Copy link
Member

balloob commented Feb 14, 2018

If there were no unique IDs before, they were not added to the entity registry.

@balloob balloob merged commit c5c409b into home-assistant:dev Feb 14, 2018
@bachya bachya deleted the pollen-entity-registry branch February 14, 2018 00:40
@balloob balloob mentioned this pull request Feb 22, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 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.

3 participants