-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
Add abode config entries and device registry #26699
Add abode config entries and device registry #26699
Conversation
Hey @frenck, what type of documentation would I need to create? The setup configuration settings if using the .yaml file hasn’t changed. I looked at a few other components that support config entires and didn’t really see anything I needed to add. Perhaps just a note it can be added via the Integrations UI now? Let me know and I’ll definitely get it taken care of! Thanks. |
@shred86 The documentation page needs a frontmatter option: As for this PR, please add unit tests. Config flows require unit tests. |
Ah okay, thanks. Just created a pull request with the updated documentation (home-assistant/home-assistant.io#10467). I’ll try to add unit tests soon. Unfortunately I’m fairly new to Python and will be fairly busy for the next two weeks. |
Unfortunately I'm struggling with unit tests. If there's any guidance/documentation specific to writing unit tests for Home Assistant, please let me know. The basics of using the unittest module in python makes sense, but I'm not having much luck in understanding how they're written for Home Assistant, or more specifically how to execute async unit tests. I'll keep at it to try and figure it out, but any assistance would be appreciated. |
Read the pytest docs. Read a blog on unit testing eg this one: We want all new tests to be standalone pytest test functions. See existing tests eg: |
Added unit test for config flows. I used the SimpliSafe component as a reference. I think I covered all the test cases needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a fix for this issue. Previously, when setup_hass_events
was being called, it would execute hass.bus.listen_once(EVENT_HOMEASSISTANT_START, startup)
. This is why it was only working after a reboot since it was waiting for the EVENT_HOMEASSISTANT_STARTUP
event to fire. I couldn't think of any reason not to simply call the startup
function when setup_hass_events
is called (except for the case where polling is enabled), so that's what the changes reflect in addition to making the code async. The function setup_hass_events
should only be called during initial HA start or when the abode component is added, so there shouldn't ever be a situation where it's called twice.
@MartinHjelmare Thanks for review. Most of these make sense but there's a few I'll have to do some digging around to figure out. Thought I understood what |
Regarding suggestions, you can do either. If you commit the suggestion directly in github, you should pull from remote before you do local changes and push again. |
Just made a new commit with fixes to all the suggestions. Marked everything as resolved that I verified was corrected. |
Please solve the merge conflict. |
Another commit with fixes to all the suggestions. Also realized the unit test wasn't actually doing what I thought it was - should be fixed now and added another test case for the updated exception handling. I'm not sure why there is a branch merge conflict. I haven't touched the manifest.json file but it looks like there's a mismatch between |
I don't think the merge conflict will resolve itself. |
Another commit to fix the code review suggestions. I also updated the manifest.json - I have no idea why it's flagging a branch conflict for me adding:
I took the latest manifest.json from the dev branch and only added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to delete this - corrected on the next commit.
Edit: Sorry, thought it would reference the line. It's line 67 in __init__.py
: vol.Optional(CONF_NAME): cv.string,
And line 21: CONF_NAME
, line 35: NOTIFICATION_ID = "abode_notification"
and line 36 NOTIFICATION_ID = "abode_notification"
.
None of these constants are being used and will be removed:
EVENT_ABODE_ALARM = "abode_alarm"
EVENT_ABODE_ALARM_END = "abode_alarm_end"
EVENT_ABODE_AUTOMATION = "abode_automation"
EVENT_ABODE_FAULT = "abode_panel_fault"
EVENT_ABODE_RESTORE = "abode_panel_restore"
If the dev branch changes the same file as we change here and git can't resolve, there will be a merge conflict. The manifest.json file on dev branch was changed three days ago. We need to solve that merge conflict by rebasing on latest dev branch and specify how to solve the conflict. |
Rebased and committed some small changes I mentioned above. Additionally, updated the original post in this PR with the break changing and updated the PR for the documentation. I've also fixed the issue with switches being added as switches and lights from Abode which I'll include in the next commit along with some minor reorganizing of the imports to adhere to the style guidelines. Edit: Re-working |
Added option to enable polling to config flow UI. Personally, I think we can just get rid of polling since cloud push is obviously much faster and less demand on abode's servers, but I suppose it's worth keeping in the event someone needs to use it. I added the label "Polling (not recommended)" to make it fairly clear it shouldn't be used normally. I think a better option might be to remove the option from the UI and only allow enabling polling through the configuration.yaml. However, I tried reworking config_flow.py but ran into issues with getting exceptions to assert properly when moving the credential testing to a separate function. I'll continue trying to work it. Additionally, pylint is complaining about
Not entirely sure how to clear that up as it's failing CI tests. |
Hopefully that is the last commit. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I noticed that the coverage isn't 100% for the config flow module.
Added additional tests to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
Thanks for all the help @MartinHjelmare - I learned a ton in this process which I realize comes at the expense of your time fixing all my errors. I started learning python/programming primarily to help contribute to Home Assistant. I'm hoping to continue learn and contribute where I can. Cheers. |
Noticed one minor issue - there is no Edit: Just found out on the discord channel that it will automatically be added at midnight. |
Breaking Changes:
This PR removes the following configuration variables:
name
,exclude
andlights
, which were all previously optional. Existing users of the abode integration that use these configuration variables will have to remove them from the configuration.yaml file. Entities that users wish to disable can be done from the Entity Registry in the Configuration UI.Description:
Adds config entry and entity registry support for the Abode component. This implementation will create a config entry if a user has added the abode component configured via the configuration.yaml file. The entity registry unique ID is based on
device_id
from Abode (no devices in Abode should ever have the same device_id).Tested on my Abode setup which includes sensors and lights.
Docs PR:
home-assistant/home-assistant.io#10467
Checklist:
tox
. Your PR cannot be merged unless tests passIf the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
by runningpython3 -m script.gen_requirements_all
..coveragerc
.