-
-
Notifications
You must be signed in to change notification settings - Fork 28.9k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dedup and clarify imported konnected config flows #32138
Conversation
This pull request needs to be manually signed off by @balloob before it can get merged. |
Hey there @heythisisnate, mind taking a look at this pull request as its been labeled with a integration ( |
LGTM |
Codecov Report
@@ Coverage Diff @@
## dev #32138 +/- ##
==========================================
- Coverage 94.74% 94.73% -0.01%
==========================================
Files 767 768 +1
Lines 55504 55619 +115
==========================================
+ Hits 52587 52693 +106
- Misses 2917 2926 +9
Continue to review full report at Codecov.
|
@frenck We need to make sure we update translations on the rc branch before release to pick up the changes from this PR. |
description_placeholders={"id": self.unique_id}, | ||
) | ||
|
||
# if we have ssdp discovered applicable host info use it |
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.
Do we really need this? If the user wants discovery help the user can use that approach instead of config yaml.
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.
After receiving feedback on the beta build I think we do need to support this use case. The legacy konnected component automatically discovered host info and then applied the config.yaml.
The config.yaml can be extensive for this integration so we shouldn't require users to abandon what they have. This flow makes for a smooth upgrade path existing konnected users.
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.
Ok.
if entry and ( | ||
entry.data[CONF_HOST] != self.data[CONF_HOST] | ||
or entry.data[CONF_PORT] != self.data[CONF_PORT] | ||
): | ||
# update an existing config entry if host info changes | ||
entry_data = copy.deepcopy(entry.data) | ||
entry_data.update(self.data) | ||
self.hass.config_entries.async_update_entry(entry, data=entry_data) |
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.
We can now pass the updates directly to self._abort_if_unique_id_configured
.
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.
cool - I'll swap over to this
options={}, | ||
) | ||
entry.add_to_hass(hass) | ||
hass.data[panel.DOMAIN] = { |
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.
It's better to set up the integration using the mock entry than to mock integration code. Whenever we mock integration code in tests of the integration, the tests become less robust.
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.
I understand. The panel module is well isolated from the rest of the integration and HA architecture - it just needs to parse and act upon passed in config entry data (which the integration also defines).
Bypassing the integration setup made it really clean to access, control, and assert behaviors based on the panel class methods. I think these tests might be an exception where directly mocking some workings of the integration shouldn't add maintenance overhead.
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.
That we need to mock this is a sign that it's not isolated.
We don't really care about what the panel is doing. We just care about what the result in the core is upon different input that the panel forwards. It's better to set up the integration and assert core state.
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.
Or if the info is flowing the other way, we assert that the library is called correctly.
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.
ok - will fix
} | ||
|
||
# confirm the device settings are saved in hass.data | ||
assert hass.data[panel.DOMAIN][panel.CONF_DEVICES] == { |
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.
Saving the data like this is just a detail which could change in the future. This isn't something we should assert.
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.
Are you referring to asserting that konnected integration data resides in hass.data
?
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.
Yes. 馃憤
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.
Got it - updating
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.
Updated in latest commits. There is still one reference to hass.data in these tests to get the instance of the AlarmPanel created when the integration is setup. This is essential to confirm that the data store is formatted correctly - a check I want to keep to ensure that no future code changes in this module break that data structure since it is utilized when setting up the platforms.
The last commit prior to this comment (9c355e4) was a minor change to reflect a key change used to identify the soon to be released pro board. It has no impact on existing equipment. |
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.
If we do these three types of changes, we'll no longer interact with the panel instance directly in the tests, making them more robust.
|
||
# confirm panel instance was created and configured | ||
# hass.data is the only mechanism to get a reference to the created panel instance | ||
device = hass.data[panel.DOMAIN][panel.CONF_DEVICES]["112233445566"]["panel"] | ||
await device.update_switch("1", 0) |
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.
update_switch
should be tested in konnected switch platform tests.
"state": None, | ||
"type": "door", | ||
}, | ||
assert device.stored_configuration == { |
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.
Instead we should assert that mock_panel.put_settings
is called with the correct configuration during device sync.
@@ -92,9 +93,6 @@ def mock_constructor(host, port, websession): | |||
options=device_options, |
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.
Instead of creating the data and options first and using that to create a mock entry, just pass the configuration to async_setup_component
. It will set up the integration and use the config yaml schemas of the integration before importing the config into a config entry.
If we had a single Directly accessing Are these changes FYI/suggestions or requirements for PR approval? If they are required I will make them but I would like to understand why these items are blocking this PR but identical test code was approved without issue in the recent konnected PR. That would have been a much more ideal time to overhaul testing architecture vs now when attempting to fix beta release bugs. |
It's ok to improve the tests in a future PR. We shouldn't add any new tests that are not robust though. As we said many times before, trying to get a huge PR like last PR merged is never a good idea since there will always be things that are missed. This is just confirmation. |
@MartinHjelmare Understood. I greatly appreciate the high standards you and the team are implementing. Thank you for all the help. |
* dedup config flows * use default (imported) options until user goes thru options flow * address pr feedback * correct key used to distinguish pro model
Proposed change
This PR addresses some of the UX concerns brought up in item 1 and 2 of #32076 and should be included in the 0.106 release.
Previously importing from configuration.yaml and ssdp discovery would result in two config flows being started. Now the ssdp discovered flow is aborted and it's host info utilized by the import flow. This more accurately mimics historical konnected component behavior where host info was discovered if not included in the configuration.yaml.
This PR also includes a small change to utilize imported configuration.yaml options until the user goes thru the options flow. This has no impact on Konnected panels that are being setup completely thru the config flow but it does allow for configuration.yaml based setups to be imported and utilized without forcing the user to run thru the options flow.
Type of change
Example entry for
configuration.yaml
:Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: