-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 config flow to panasonic_viera component #33829
Conversation
The lint job fails now because access mode has changed on some files. Eg: Please revert those changes. |
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.
Please add tests for the config flow. It needs 100% coverage. The scaffold script should help you get started with those tests. More examples is eg the hue integration config flow tests.
So, I think I just finished to add the suggested changes and refactoring. However, I still need to create the tests. Any resources to help me on that? |
|
I think I learned how to create and run tests. However, I couldn't manage to replace the RemoteControl class with a Mock class. This is what I have right now: def get_mock_remote(host="1.2.3.4", encrypted=False, app_id=None, encryption_key=None):
"""Return a mock remote."""
mock_remote = Mock()
mock_remote._host = host
mock_remote._type = TV_TYPE_ENCRYPTED if encrypted else TV_TYPE_NONENCRYPTED
mock_remote._app_id = app_id
mock_remote._enc_key = encryption_key
return mock_remote
async def test_flow_encrypted(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form" # passes
assert result["step_id"] == "user" # passes
mock_remote = get_mock_remote(encrypted=True)
with patch("panasonic_viera.RemoteControl", return_value=mock_remote,), patch(
"homeassistant.components.panasonic_viera.async_setup", return_value=True,
), patch(
"homeassistant.components.panasonic_viera.async_setup_entry", return_value=True,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_HOST: "1.2.3.4", CONF_NAME: DEFAULT_NAME},
)
assert result2["type"] == "form"
assert result2["step_id"] == "pairing" # returns AssertionError: assert 'user'
assert result2["errors"] == {} # returns AssertionError: assert {'base': 'not_connected'} (There are other tests, of course, this is only the first example) |
The target for the patch needs to patch where the name is used not where it's defined. Ie: https://docs.python.org/3/library/unittest.mock.html#where-to-patch |
I think everything's fine now. Working on the docs. |
I made a pull request on the documentation repo: home-assistant/home-assistant.io#12843 |
Documentation approved! :D |
Oof... I guess everything is working now! |
This sounds weird:
The user should not need to complete the flow on every restart if the device has already been set up. |
Oh, it sounded very ambiguous. I was talking about the first restart after changing configuration.yaml After that the config entry is saved and it sets itself up automatically (unless the user modifies the config for the entity) |
I really don't know why Azure is reporting translation errors when the only file I changed was |
ok, I screwed everything up |
I think I was able to fix everything... Thankfully, I had made a copy of the integration before pushing, just to make sure I had a backup. However, I didn't do the same with the tests, but I was able to get a conflicted copy and remove the conflicts; at least I got a chance to review and re-organize some of the code... @MartinHjelmare |
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 might be possible to make the config flow more DRY by using some error handler helper like we did in the media player platform. But I think this can be a job for a future PR. It's fine like this. Just one comment.
Now 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.
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.
Just one more question?
done! |
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.
Thanks!
Oh, I also updated the docs to resolve conflicts that were being reported with the original branch (I don't know If you have writing permissions there) |
We have a very good team for the docs that will review your PR there. |
I'd like to thank you a lot, @MartinHjelmare for helping me with this. I must admit that at first I felt a bit intimated by all the changes that were asked, but it was worth it. As I have already said, this is the first time I ever contribute to the source code of a such a big project as Home Assistant (I'm 14 y/o btw, don't blame me), so it was very... exciting. Looking forward to contributing even more in the future! thank you 😊 |
oh, ok! They were very fast when I created the pull request so it really shouldn't take long |
Cheers, good job and welcome to the community! 🎉 |
Thanks for your work @joogps. How do I use the send_key service? |
First of all, thank you! :) Second of all, the |
@ramondunker I created the pull request: #34398 |
Breaking change
The only breaking change for existing users is that the YAML configuration isn't based on a platform anymore, so instead of this:
They'll need to use this:
The latter supports multiple configurations. Also, after restarting Home Assistant, the user will be prompted to finish configuration and pairing through a config flow.
Proposed change
As an update to #33433, this pull request adds encryption support for the
panasonic_viera
component through YAML or the UI, via a config flow. I also rearranged the code, fixed a few stability issues and upgraded requirements.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: