Skip to content

Use zeroconf attributes in elgato#58958

Merged
frenck merged 3 commits intohome-assistant:devfrom
epenet:zeroconf-elgato
Nov 15, 2021
Merged

Use zeroconf attributes in elgato#58958
frenck merged 3 commits intohome-assistant:devfrom
epenet:zeroconf-elgato

Conversation

@epenet
Copy link
Copy Markdown
Contributor

@epenet epenet commented Nov 2, 2021

Proposed change

Use zeroconf attributes in elgato

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 @frenck, mind taking a look at this pull request as it has been labeled with an integration (elgato) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)


async def async_step_zeroconf(self, discovery_info: dict[str, Any]) -> FlowResult:
async def async_step_zeroconf(
self, discovery_info: DiscoveryInfoType
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.

Or maybe it would it be better to use zeroconf.HaServiceInfo ?

Suggested change
self, discovery_info: DiscoveryInfoType
self, discovery_info: zeroconf.HaServiceInfo

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.

Actually, it’s unsafe to override a method with a more specific argument type, as it violates the Liskov substitution principle. For return types, it’s unsafe to override a method with a more general return type.

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.

I think we should adjust the upstream method typing for this in a second-round (once all integrations have been adjusted to ZeroconfServiceInfo).

Copy link
Copy Markdown
Contributor Author

@epenet epenet Nov 10, 2021

Choose a reason for hiding this comment

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

If we want to go ahead with this, why do it in a second pass? If @bdraco agrees, I can adjust async_step_zeroconf right away in config_entries.py. From my initial attempt, we just need to add a cast from ZeroconfServiceInfo to DiscoveryInfoType in the default implementation:

    async def async_step_zeroconf(
        self, discovery_info: ZeroconfServiceInfo
    ) -> data_entry_flow.FlowResult:
        """Handle a flow initialized by Zeroconf discovery."""
        return await self.async_step_discovery(cast(DiscoveryInfoType, discovery_info))

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 just run some extra tests, and I think it might be easier to first change the result type to ZeroconfServiceInfo in config_entries.py, and then finish the "pass" on all the components.
If we do it now, then less code to change to satisfy mypy

I'll prepare a separate PR for this.

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.

PR created #59503

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.

Rebased following the merge of PR 59503

@cereal2nd cereal2nd mentioned this pull request Nov 8, 2021
22 tasks
@epenet epenet mentioned this pull request Nov 10, 2021
22 tasks
@epenet epenet marked this pull request as draft November 10, 2021 07:49
@epenet epenet marked this pull request as ready for review November 10, 2021 14:47
@epenet epenet marked this pull request as draft November 11, 2021 09:54
@epenet epenet marked this pull request as ready for review November 15, 2021 18:02
Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @epenet 👍

@frenck frenck merged commit ce9385d into home-assistant:dev Nov 15, 2021
@epenet epenet deleted the zeroconf-elgato branch November 15, 2021 21:34
natekspencer pushed a commit to natekspencer/home-assistant-core that referenced this pull request Nov 16, 2021
Co-authored-by: epenet <epenet@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2021
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.

4 participants