Skip to content

Use dataclass for MqttServiceInfo#60191

Merged
emontnemery merged 2 commits intohome-assistant:devfrom
epenet:mqtt-service-info
Nov 23, 2021
Merged

Use dataclass for MqttServiceInfo#60191
emontnemery merged 2 commits intohome-assistant:devfrom
epenet:mqtt-service-info

Conversation

@epenet
Copy link
Copy Markdown
Contributor

@epenet epenet commented Nov 23, 2021

Breaking change

MQTT discovery now uses a dataclass instead of a dictionary object.
Access using __getitem__ will fail in version 2022.6.
Please use <cls>.<name> instead.

Proposed change

MQTT discovery now uses a dataclass instead of a dictionary object.
Access using __getitem__ will fail in version 2022.6.
Please use <cls>.<name> instead.

Linked to this comment in the architecture discussion home-assistant/architecture#662 (comment)

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

Comment on lines +115 to +119
report(
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; this will fail in version 2022.6",
exclude_integrations={"mqtt"},
error_if_core=False,
)
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 think it is ok to use WARNING (not DEBUG) straight away for usb as there is only one core component and the PRs for these are ready on my machine:

  • tasmota

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery 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

@emontnemery emontnemery merged commit 3b0d984 into home-assistant:dev Nov 23, 2021
@epenet epenet deleted the mqtt-service-info branch November 23, 2021 08:04
@MartinHjelmare
Copy link
Copy Markdown
Member

We need to update the infrastructure for flows, data_entry_flow etc, first before merging these.

@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 23, 2021

@MartinHjelmare does this need reverting?

data_entry_flow.py should not require amends (the discovery steps are not called by the UI)

config_entries.py is ready for this:

async def async_step_dhcp(
self, discovery_info: DhcpServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle a flow initialized by DHCP discovery."""
return await self.async_step_discovery(cast(dict, discovery_info))

helpers/config_entry_flow.py is ready for this also:

async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
"""Handle a flow initialized by dhcp discovery."""
if self._async_in_progress() or self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
await self.async_set_unique_id(self._domain)
return await self.async_step_confirm()

Components can continue using discovery_info[ATTR]

@epenet
Copy link
Copy Markdown
Contributor Author

epenet commented Nov 23, 2021

I will add BaseServiceInfo inheritance in a new PR as soon as #60136 is merged

@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 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