Enhance Dynalite Integration after review#31760
Conversation
This comment has been minimized.
This comment has been minimized.
|
all tests pass now include coverage. Should be ready to merge as this is just a code quality change. No functionality is affected |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Please always use the core interfaces in the tests, and never the integration interfaces directly. Doing this will make the tests more robust, and we'll be able to change the implementation without changing the tests as long as the result in the core remains the same.
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
changed test_init to use the core methods
not updates.items() <= entry.data.items() wouldn't it only work if there are more items in the new config? Anyway, if the DATA_CONFIGS pattern is ok, I can easily implement it correctly. Will do so now, so please let me know whether or not to push |
|
I think that will just check if the existing data is the same as the updates and not update if it's the same. I think we should use my suggested approach and not do anything extra. |
sure. done |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Looks good! Nice work!
Thanks! Appreciate all the work you did. Learned a lot about Home Assistant. Now I can add the switch and cover platforms in another pull request after this one is merged |
|
The host isn't a unique ID? It can change... For example, when if you run multiple on different ports and the same host? Proxies? IMHO, a unique ID should not be used here. |
|
This is just a unique id for the config entry not the entities. The config entry would need to be replaced anyway if the host would change. Otherwise the integration would stop working. |
|
The host is the most constant thing. This is the IP of the gateway. There is more info in the config entry so I update it with the same host and the rest of the data. You can see what I put on the issue I opened. Is there another place in has to store persistent data? |
|
I've seen your issue @ziv1234. I think this has mainly to do with existing entries, that don't have a unique ID registered yet, but are in the registry. You can solve that by updating the entry on entry setup, like so: |
|
maybe i misunderstood something, but it seems like they are handling something else. In wled they are looking at an entry that doesn't have unique_id so they configure one for it. In my case, all entries will have unique_id, but they will be running with a different data (entry.data) which is what I expected to update. In dynalite, I use entry.data["host"] as the unique_id, but the other parameters (port, areas / devices, etc.) could change, so would expect to keep the unique_id and update it. It works, but the problem is that it requires and extra restart of HA. Is there something I should do differently here? |
|
The config entry will be updated immediately before aborting the config flow when checking for unique config entry id. If you need to take some action in the integration when the config entry data is updated, I think you have to register a listener. https://developers.home-assistant.io/docs/config_entries_options_flow_handler#signal-updates I think this listener is required if the config entry already has been loaded when the update happens. |
|
Marking this for 0.106 since the first PR for this integration was merged before beta cut and this PR is cleaning up many things about the first PR. |
|
ok. will start thinking about how to implement the signal update one. It makes sense. Is there a way to ask home assistant to unload and reload an entry? |
|
Yes, |
|
Can we merge here now, and further changes can go in a future PR? |
|
Btw, we need to update the docs, since we removed some config items. Please link a docs PR in the PR description. Then we can merge. |
|
done. created PR home-assistant/home-assistant.io#12157 |
|
we can merge now. i believe that the change to use reload_entry could be tricky, and the problem only happens when changing configuration.yaml, which shouldn't happen often after the initial setup |
* fixes per Martin Hjelmare * pylint fix * final fixes per request * fixed unit tests for new config flow * Added unit-tests to increase coverage. at 97% now * Added unit tests for 100% coverage of component * removed configured_host function and updated config_flow unit tests * added a pylint directive since it tells me by mistake DOMAIN is not used * fixed path (removed __init__) * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fixed the test as we moved from schedule_update_... to async_schedule * Update homeassistant/components/dynalite/bridge.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed context from config_flow changed test_init to use the core methods * moved test_light to also use the core interfaces * moved to config_entries.async_unload * additional fixes for the tests * pylint fix and removed unnecessary code * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * added break in loop * removed last mock_coro reference pylint fix * added coverage for try_connect * added check for a successful connection before bridge.async_setup succeeds also added a "nowait" config option (default False) that avoids this check * changed log level * fixed accidental chmod I did * fixed accidental change * not storing config in bridge * not patching asyncio * moved CONFIG_SCHEMA into component * moved all logs to start capitalized (and revised some of them) * moved test_config_flow to not patch the DynaliteBridge * also took DynaliteBridge patching out of test_init * removed NO_WAIT * fixes to SCHEMA * changed _ in multi-word CONF moved imports to component const.py * removed tries * removed redundant tests * fixed some small change i broke in the library. only version update * fixed rewuirements * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_light.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/dynalite/test_config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed HIDDEN_ENTITY removed hass in test fixture * black fixes * removed final piece of hidden_entity from light fix in the library updated config flow so if the entry is already set but with a different config, calls async_update_entry * removed DATA_CONFIGS - no longer necessary * pylint fixes * added coverage * use abort in config_flow * test update * removed logs * test that update actually updates the entry Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Breaking change
Proposed change
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional 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: