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

Support multiple Elk instances #23839

Merged
merged 52 commits into from Jul 27, 2019
Merged

Support multiple Elk instances #23839

merged 52 commits into from Jul 27, 2019

Conversation

gjbadros
Copy link
Contributor

@gjbadros gjbadros commented May 13, 2019

  • Allow more than one Elk M1 alarm system to be integrated into a single hass instance.

  • Introduces new "devices" schema at the top level, each of which has
    the prior configuration schema.

  • Requires new version of elkm1, 0.7.14, that gwww and I just updated (thanks Glen!)

  • Changes to the docs are in a separate PR (Bug: recorder component does not Vacuum SQLite DB on purge #9441) on that repo.

Related issue (if applicable): fixes #

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#9441

Example entry for configuration.yaml (if applicable):

elkm1:
     - host: elk://192.168.0.2:2101/
     ....
     - host: elk://192.168.0.3:2101/

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.
  • I have followed the development checklist

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

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

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

* Allow more than one Elk M1 alarm system to be integrated into a single hass instance.

* Introduces new "devices" schema at the top level, each of which has
  the prior configuration schema.

* Requires new version of elkm1, 0.7.14, that gwww and I just updated (thanks Glen!)

QUESTION: Should the "devices" section be optional to avoid breaking
old configuration files?  I chose not to do that for simplicity and
because I was following the doorbird code which requires the "devices"
section for all configurations even with only one device.
Fixed issues raised by hound -- there was clearly
a tool I was supposed to run to get those warnings
before submitting the PR.  Sorry!

Updated REQUIREMENTS.
Also fixed unused prefix local variable lint warning.
Not sure if I missed these on the first pass or if the linter stopped
after a certain number of warnings or something else.

Switched logging to use %d and %s instead of string concatenation (per
lint request and because I imagine it migth be better performing
in some (oldish, I presume) implementations of python.
This eliminates the breaking change for configurations wanting a
singleton elk m1 instance (the majority of users, no doubt).  I did
not do it like this before because I was following the lead of the
doorbird component which introduced a devices: section when moving
to support multiple doorbells.  But Rohan Kapoor kindly pointed me
at the zoneminder component which sets the other (IMO) preferable
precedent. Will update the docs change shortly.
Just move async_add_entities() outside of the loops across the elk m1
controllers, so it's called once for each platform.
Move it to after the loop, so it's called only once
per platform even when there are multiple elk m1 controllers.
Thanks to Martin Hjelmare for the careful review and suggestions.
(All mistaken improvements and new bugs are my own.)
Use dict.values() (instead of making it easier to add local looping variable
on the keys by using _, bar = ...items())

Use [] when the key is known to exist.
* Allow more than one Elk M1 alarm system to be integrated into a single hass instance.

* Introduces new "devices" schema at the top level, each of which has
  the prior configuration schema.

* Requires new version of elkm1, 0.7.14, that gwww and I just updated (thanks Glen!)

QUESTION: Should the "devices" section be optional to avoid breaking
old configuration files?  I chose not to do that for simplicity and
because I was following the doorbird code which requires the "devices"
section for all configurations even with only one device.
Fixed issues raised by hound -- there was clearly
a tool I was supposed to run to get those warnings
before submitting the PR.  Sorry!

Updated REQUIREMENTS.
Also fixed unused prefix local variable lint warning.
Not sure if I missed these on the first pass or if the linter stopped
after a certain number of warnings or something else.

Switched logging to use %d and %s instead of string concatenation (per
lint request and because I imagine it migth be better performing
in some (oldish, I presume) implementations of python.
This eliminates the breaking change for configurations wanting a
singleton elk m1 instance (the majority of users, no doubt).  I did
not do it like this before because I was following the lead of the
doorbird component which introduced a devices: section when moving
to support multiple doorbells.  But Rohan Kapoor kindly pointed me
at the zoneminder component which sets the other (IMO) preferable
precedent. Will update the docs change shortly.
Just move async_add_entities() outside of the loops across the elk m1
controllers, so it's called once for each platform.
Move it to after the loop, so it's called only once
per platform even when there are multiple elk m1 controllers.
Thanks to Martin Hjelmare for the careful review and suggestions.
(All mistaken improvements and new bugs are my own.)
Use dict.values() (instead of making it easier to add local looping variable
on the keys by using _, bar = ...items())

Use [] when the key is known to exist.
@gjbadros
Copy link
Contributor Author

Ping @balloob ... I'd love to get my first commit to HA done :-)

@MartinHjelmare MartinHjelmare added this to Review in progress in Dev Jul 23, 2019
Copy link
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.

@balloob decided to approve the configurable prefix to be part of unique_id.

homeassistant/components/elkm1/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/elkm1/__init__.py Show resolved Hide resolved
…onna use .lower() on creating the entity id that has to be unique; do the _has_all_unique_prefixes check last so we get errors from the device schema before complaining about the uniqueness problem, if any
CONFIG_SCHEMA_SUBDOMAIN = vol.Schema({
def _has_all_unique_prefixes(value):
"""Validate that each m1 configured has a unique prefix."""
prefixes = [device.get(CONF_PREFIX, "").lower() for device in value]
Copy link
Member

Choose a reason for hiding this comment

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

Use dict[key] for the prefix since there's a default in the previous config schema.

Copy link
Member

Choose a reason for hiding this comment

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

Move the lower string modification to be part of the prefix schema below instead and use vol.Lower.

vol.Optional(CONF_ENABLED, default=True): cv.boolean,
vol.Optional(CONF_INCLUDE, default=[]): [_elk_range_validator],
vol.Optional(CONF_EXCLUDE, default=[]): [_elk_range_validator],
})

DEVICE_SCHEMA = vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PREFIX, default=''): cv.string,
Copy link
Member

Choose a reason for hiding this comment

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

vol.All(cv.string, vol.Lower)

…a pair of bugs for the alarm control panel display message service -- since data templates always generate strings, the values subject to range/set restrictions need to be coerced to their proper type before the check
Dev automation moved this from Review in progress to Reviewer approved Jul 26, 2019
@MartinHjelmare
Copy link
Member

We should probably mark this a breaking change, due to changing unique_id, and ask users to remove old entities from the entity registry.

self._temperature_unit = elk_data['config']['temperature_unit']
self._unique_id = 'elkm1_{}'.format(
self._element.default_name('_').lower())
self._unique_id = 'elkm1_{prefix}_{name}'.format(
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove the extra underscore between prefix and name to make this a non breaking change?

@gjbadros
Copy link
Contributor Author

gjbadros commented Jul 26, 2019 via email

@MartinHjelmare
Copy link
Member

As long as unique_id won't change for existing entities, there won't be a breaking change. Existing registered entities won't change entity_id, since they are registered in the entity registry.

@gjbadros
Copy link
Contributor Author

gjbadros commented Jul 26, 2019 via email

…on-empty prefix given; this enables backward compatibility to avoid a breaking change by letting the elkm1_ start to unique_id keep working exactly as it used to.
@gjbadros
Copy link
Contributor Author

These build check failures look like an automation problem and not a problem with my changes, jfyi.

@gjbadros
Copy link
Contributor Author

gjbadros commented Jul 26, 2019 via email

@MartinHjelmare
Copy link
Member

The build failed due to an unrelated problem it seems. You could try rebasing the last commit and force pushing to force a new build.

Thanks for the feedback! I appreciate it. 👍

@gjbadros
Copy link
Contributor Author

gjbadros commented Jul 27, 2019 via email

@MartinHjelmare MartinHjelmare merged commit 7d68def into home-assistant:dev Jul 27, 2019
Dev automation moved this from Reviewer approved to Done Jul 27, 2019
@gjbadros
Copy link
Contributor Author

gjbadros commented Jul 27, 2019 via email

@balloob balloob mentioned this pull request Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants