-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Use dataclass properties in hue discovery #60598
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
Changes from 3 commits
d235cd8
4ccd15e
fad0772
fd254e1
27f0320
f64994b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -194,26 +194,28 @@ async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowRes | |||||
| """ | ||||||
| # Filter out non-Hue bridges #1 | ||||||
| if ( | ||||||
| discovery_info.get(ssdp.ATTR_UPNP_MANUFACTURER_URL) | ||||||
| discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER_URL) | ||||||
| not in HUE_MANUFACTURERURL | ||||||
| ): | ||||||
| return self.async_abort(reason="not_hue_bridge") | ||||||
|
|
||||||
| # Filter out non-Hue bridges #2 | ||||||
| if any( | ||||||
| name in discovery_info.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "") | ||||||
| name in discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "") | ||||||
| for name in HUE_IGNORED_BRIDGE_NAMES | ||||||
| ): | ||||||
| return self.async_abort(reason="not_hue_bridge") | ||||||
|
|
||||||
| if ( | ||||||
| not discovery_info.get(ssdp.ATTR_SSDP_LOCATION) | ||||||
| or ssdp.ATTR_UPNP_SERIAL not in discovery_info | ||||||
| ): | ||||||
| if ssdp.ATTR_UPNP_SERIAL not in discovery_info.upnp: | ||||||
| return self.async_abort(reason="not_hue_bridge") | ||||||
|
|
||||||
| host = urlparse(discovery_info.ssdp_location).hostname | ||||||
| if not host: | ||||||
| return self.async_abort(reason="not_hue_bridge") | ||||||
|
|
||||||
| host = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]).hostname | ||||||
| bridge = await self._get_bridge(host, discovery_info[ssdp.ATTR_UPNP_SERIAL]) | ||||||
| bridge = await self._get_bridge( | ||||||
| str(host), discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL] | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial thought also, but
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, my dev machine is on python 3.10... might be that urlparse changed between py versions...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the docs the namedtuple ParseResult either have a str or None value so not bytes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha! I think I found the root cause... I have a similar issue in
If the first argument of urlparse is I'll see if I can clean this up better.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are 100% right. The documentation doesn't match wil reality and the type is indeed AnyStr, yikes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have reworked this, and added an extra test for an invalid hostname.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. Mypy happy now ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the tests pass. I think this is good to merge. |
||||||
| ) | ||||||
|
|
||||||
| await self.async_set_unique_id(bridge.id) | ||||||
| self._abort_if_unique_id_configured( | ||||||
|
|
@@ -232,8 +234,8 @@ async def async_step_zeroconf( | |||||
| host is already configured and delegate to the import step if not. | ||||||
| """ | ||||||
| bridge = await self._get_bridge( | ||||||
| discovery_info[zeroconf.ATTR_HOST], | ||||||
| discovery_info[zeroconf.ATTR_PROPERTIES]["bridgeid"], | ||||||
| discovery_info.host, | ||||||
| discovery_info.properties["bridgeid"], | ||||||
| ) | ||||||
|
|
||||||
| await self.async_set_unique_id(bridge.id) | ||||||
|
|
@@ -253,7 +255,7 @@ async def async_step_homekit( | |||||
| as the unique identifier. Therefore, this method uses discovery without | ||||||
| a unique ID. | ||||||
| """ | ||||||
| self.bridge = await self._get_bridge(discovery_info[zeroconf.ATTR_HOST]) | ||||||
| self.bridge = await self._get_bridge(discovery_info.host) | ||||||
| await self._async_handle_discovery_without_unique_id() | ||||||
| return await self.async_step_link() | ||||||
|
|
||||||
|
|
||||||

Uh oh!
There was an error while loading. Please reload this page.