Skip to content

Enhance Dynalite Integration after review#31760

Merged
MartinHjelmare merged 62 commits into
home-assistant:devfrom
ziv1234:dev
Feb 21, 2020
Merged

Enhance Dynalite Integration after review#31760
MartinHjelmare merged 62 commits into
home-assistant:devfrom
ziv1234:dev

Conversation

@ziv1234
Copy link
Copy Markdown
Contributor

@ziv1234 ziv1234 commented Feb 12, 2020

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • [ x] Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@ziv1234 ziv1234 mentioned this pull request Feb 12, 2020
9 tasks
@MartinHjelmare MartinHjelmare changed the title Dynalite Integration - fixes per Martin Hjelmare's asks Enhance Dynalite Integration after review Feb 12, 2020
@MartinHjelmare MartinHjelmare self-assigned this Feb 12, 2020
@codecov

This comment has been minimized.

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 13, 2020

all tests pass now include coverage. Should be ready to merge as this is just a code quality change. No functionality is affected

Copy link
Copy Markdown
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.

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.

Comment thread tests/components/dynalite/test_config_flow.py Outdated
Comment thread tests/components/dynalite/test_config_flow.py Outdated
Comment thread tests/components/dynalite/test_init.py Outdated
Comment thread tests/components/dynalite/test_init.py Outdated
Comment thread tests/components/dynalite/test_light.py Outdated
Comment thread tests/components/dynalite/test_light.py Outdated
Comment thread homeassistant/components/dynalite/light.py Outdated
Comment thread homeassistant/components/dynalite/light.py Outdated
Comment thread homeassistant/components/dynalite/bridge.py Outdated
Comment thread homeassistant/components/dynalite/config_flow.py Outdated
Comment thread tests/components/dynalite/test_init.py Outdated
Comment thread homeassistant/components/dynalite/config_flow.py Outdated
Comment thread tests/components/dynalite/test_init.py Outdated
Comment thread tests/components/dynalite/test_init.py Outdated
Comment thread tests/components/dynalite/test_init.py
Comment thread tests/components/dynalite/test_init.py Outdated
@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 18, 2020

The problem is that it only updates if there are more items there.

What do you mean?

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

@MartinHjelmare
Copy link
Copy Markdown
Member

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.

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 18, 2020

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

Comment thread tests/components/dynalite/test_config_flow.py
Copy link
Copy Markdown
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.

Looks good! Nice work!

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 18, 2020

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

@frenck
Copy link
Copy Markdown
Member

frenck commented Feb 21, 2020

The host isn't a unique ID? It can change...
So you are using host as the unique ID and want to update it with the same thing that is the unique ID? That will never work 🤷‍♂

For example, when if you run multiple on different ports and the same host? Proxies?

IMHO, a unique ID should not be used here.

@MartinHjelmare
Copy link
Copy Markdown
Member

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.

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 21, 2020

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?

@frenck
Copy link
Copy Markdown
Member

frenck commented Feb 21, 2020

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:

https://github.com/home-assistant/home-assistant/blob/dd8597cb46c5e788995e1ea56b87dfbaf43ca51c/homeassistant/components/wled/__init__.py#L64-L68

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 21, 2020

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?

@MartinHjelmare
Copy link
Copy Markdown
Member

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.

@MartinHjelmare MartinHjelmare added this to the 0.106.0 milestone Feb 21, 2020
@MartinHjelmare
Copy link
Copy Markdown
Member

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.

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 21, 2020

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?

@MartinHjelmare
Copy link
Copy Markdown
Member

@MartinHjelmare
Copy link
Copy Markdown
Member

Can we merge here now, and further changes can go in a future PR?

@MartinHjelmare
Copy link
Copy Markdown
Member

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.

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 21, 2020

done. created PR home-assistant/home-assistant.io#12157

@ziv1234
Copy link
Copy Markdown
Contributor Author

ziv1234 commented Feb 21, 2020

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

@MartinHjelmare MartinHjelmare merged commit 36db302 into home-assistant:dev Feb 21, 2020
balloob pushed a commit that referenced this pull request Feb 22, 2020
* 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>
@lock lock Bot locked and limited conversation to collaborators Feb 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants