Skip to content

Use DeviceInfo in velbus#58622

Merged
bdraco merged 10 commits intohome-assistant:devfrom
epenet:deviceinfo-velbus
Nov 8, 2021
Merged

Use DeviceInfo in velbus#58622
bdraco merged 10 commits intohome-assistant:devfrom
epenet:deviceinfo-velbus

Conversation

@epenet
Copy link
Copy Markdown
Contributor

@epenet epenet commented Oct 28, 2021

Proposed change

Use DeviceInfo in velbus.
Split out from #58445 to give opportunity for code owners to review.

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)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

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

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @cereal2nd, @brefra, mind taking a look at this pull request as it has been labeled with an integration (velbus) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Oct 28, 2021
Comment on lines 181 to 183
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this one. This integration is not strictly typed, we don't have to change this right now. I rather see it being fixed than moved over into newer structures while ignoring typing.

Copy link
Copy Markdown
Contributor

@cereal2nd cereal2nd Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all parts in this tuple are strings, so the only problem is that we have a 3 part tuple instead of a 2 part?
if thats the case we can safely remove the ' self._channel.get_module_serial()' part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the identifiers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we safely remove that? This changes the resulting identifier? Doesn't this require to migrated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has a migration of this kind been implemented in another component that I can get inspiration from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, then we keep the original identifiers and remove the type hint on the method -> DeviceInfo

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Oct 28, 2021
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a material change in the identifier ?

Copy link
Copy Markdown
Member

@frenck frenck Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also: #58622 (comment)
I needs migration imho

Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one needs to have its identifier migrated since there is a material change here.

@epenet epenet marked this pull request as draft October 28, 2021 20:44
@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Oct 28, 2021

This one needs to have its identifier migrated since there is a material change here.

Agreed, but is there an example out there?
Maybe it's just a question of having two identifiers for a certain amount of time, and removing the old identifier in a future release?

@bdraco
Copy link
Copy Markdown
Member

bdraco commented Oct 28, 2021

Agreed, but is there an example out there?

git grep 'async_update_device('

@cereal2nd
Copy link
Copy Markdown
Contributor

Here is the migration code, to migrate from the old to the new format

    # Migrate device indentifiers
    dev_reg = await async_get_registry(hass)
    devices: list[DeviceEntry] = device_registry.async_entries_for_config_entry(
        dev_reg, entry.entry_id
    )
    for device in devices:
        old_identifier = list(next(iter(device.identifiers)))
        if len(old_identifier) > 2:
            new_identifier = {
                (old_identifier.pop(0), old_identifier.pop(0))
            }
            _LOGGER.debug(
                "migrate identifier '%s' to '%s'", device.identifiers, new_identifier
            )
            dev_reg.async_update_device(device.id, new_identifiers=new_identifier)

@epenet epenet marked this pull request as ready for review November 2, 2021 09:40
@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 2, 2021

Here is the migration code, to migrate from the old to the new format

Thanks @cereal2nd, I've added it to the initialisation routine.

@cereal2nd
Copy link
Copy Markdown
Contributor

@bdraco can you have a look at the latest changes?

Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks like it will work, but we should add a test since migrations are always high risk operations.

@cereal2nd
Copy link
Copy Markdown
Contributor

@epenet can you look in writing a testcase? i have no idea where to start

@cereal2nd cereal2nd mentioned this pull request Nov 6, 2021
22 tasks
@epenet epenet force-pushed the deviceinfo-velbus branch from 62abba1 to 58f055a Compare November 8, 2021 10:35
@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 8, 2021

@cereal2nd / @bdraco I have added the tests for migration in test_init.py.
I have also refactored the config flow tests to move the constants to const.py and the fixtures to conftest.py

Copy link
Copy Markdown
Member

@bdraco bdraco 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. One small comment above 👍

Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to go if CI passes 👍

collecting ... 
 tests/components/velbus/test_config_flow.py ✓✓✓✓                                                                                                           67% ██████▋   
 tests/components/velbus/test_init.py ✓✓                                                                                                                   100% ██████████

Results (0.28s):
       6 passed

@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 8, 2021

CI passed :)

@bdraco bdraco merged commit 089353e into home-assistant:dev Nov 8, 2021
@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 8, 2021

Thanks @bdraco

@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2021
@epenet epenet deleted the deviceinfo-velbus branch November 10, 2021 14:42
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.

6 participants