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

Fix device host discovery in config flow #52

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion custom_components/dyson_local/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ async def _async_get_entry_data(
) -> Optional[str]:
"""Try connect and return config entry data."""
device = get_device(serial, credential, device_type)
saved_host = host
Copy link
Owner

Choose a reason for hiding this comment

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

Can you explain why this fixes the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During the config setup, if you leave the Host field empty it will get passed into this method as None. When this method discovers the host, it overrides the host variable because of the nonlocal host (line 224) and the config data that is returned will have a hard-coded host value. Instead of returning the discovered host, this change will return the passed in host value (None in this case).

Later on during the entry setup the code checks if the Host value is set - https://github.com/shenxn/ha-dyson/blob/main/custom_components/dyson_local/__init__.py#L107. If this value is None then the host will be discovered automatically which is what we want.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the explanation. Can you add some comments here since it's a little confusing.


# Find device using discovery
if not host:
Expand Down Expand Up @@ -250,7 +251,7 @@ def _callback(address: str) -> None:
CONF_CREDENTIAL: credential,
CONF_DEVICE_TYPE: device_type,
CONF_NAME: name,
CONF_HOST: host,
CONF_HOST: saved_host,
}


Expand Down