Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zeroconf discovery support to Brother Printer integration #30959

Merged
merged 14 commits into from Jan 22, 2020
Merged

Add zeroconf discovery support to Brother Printer integration #30959

merged 14 commits into from Jan 22, 2020

Conversation

bieniu
Copy link
Member

@bieniu bieniu commented Jan 18, 2020

Breaking Change:

None

Description:

This PR adds zeroconf discovery support to Brother Printer integration.

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

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

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

return self.async_abort(reason="connection_error")

try:
if "Brother" not in user_input["name"]:
Copy link
Member

Choose a reason for hiding this comment

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

this is very weird code. Just do something like this pleaes:

if "Brother" not in user_input.get("name"):

Also, do you want to check that it starts with, or is "Two Brothers on the fourth floor" ok too ?

# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context.update(
{
CONF_HOST: host,
Copy link
Member

Choose a reason for hiding this comment

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

Please don't set the host in context. If it's for using the flow, just store it on self

"""Handle a flow initiated by zeroconf."""
try:
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
brother = Brother(self.context.get(CONF_HOST))
Copy link
Member

Choose a reason for hiding this comment

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

Why are we making this connection again? We should just keep this object around from async_step_zeroconf ?

if user_input is not None:

# Check if already configured
await self.async_set_unique_id(brother.serial.lower())
Copy link
Member

Choose a reason for hiding this comment

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

You already did this in the previous step .

}
)
return self.async_show_form(
step_id="zeroconf_confirm",
Copy link
Member

Choose a reason for hiding this comment

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

Don't render forms for other steps. Instead return await self.async_step_zeroconf_confirm()

homeassistant/components/brother/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/brother/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/brother/config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/brother/test_config_flow.py Outdated Show resolved Hide resolved
Copy link
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!

@balloob balloob merged commit 4c27d6b into home-assistant:dev Jan 22, 2020
@lock lock bot locked and limited conversation to collaborators Jan 24, 2020
@bieniu bieniu deleted the brother-discovery branch January 31, 2020 09:23
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.

None yet

4 participants