-
Currently DiscoveryInfoType = Dict[str, Any] In class ZeroconfServiceInfo(TypedDict):
"""Prepared info from mDNS entries."""
host: str
port: int | None
hostname: str
type: str
name: str
properties: dict[str, Any] While this doesn't cause any issue in python, if we adjust the signature of I propose that we change Linked PR: home-assistant/core#59503 |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 13 replies
-
Very much +1 to typing this better. OTOH I'm afraid that discovery infos for different things contain quite different things and unifying all of it might be a bit of work. |
Beta Was this translation helpful? Give feedback.
-
I've investigated this further, and it does look like it doesn't make sense to unify.
I am not sure (yet) what ServiceInfo would look like for hassio and ssdp, but I am happy to investigate it further (maybe with |
Beta Was this translation helpful? Give feedback.
-
I like this too. I think we can subclass the `SsdpServiceInfo` to include the UPnP details once they have been retrieved from the device (`ATTR_UPNP*` keys). That would make it more obvious what details are available when the discovery info is used.
|
Beta Was this translation helpful? Give feedback.
-
Also, it might be useful to have all of these discovery infos derive from a common class that includes one element, `unique_id`, that can be used in triggered config flows. But I'm not familiar with all the discovery types to say if this is feasible.
|
Beta Was this translation helpful? Give feedback.
-
I think it's potentially a little off topic for this exact topic, but @epenet said it would be good to mention here. Although not strictly part of using class inheritance for DiscoveryInfoType we have started to more heavility user await self.async_set_unique_id(
discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID]
) vs await self.async_set_unique_id(discovery_info["properties]["id"]) I haven't been able to find the historical motivation for
I don't think (2) is common, and we handle codebase wide changes all the time so i'm not entirely convinved this was a motivator. (1) feels like the common case, but I wonder if What have I got against ATTR const (crucially, specifically in well typed code)?
So I guess the question I want to ask after considering these points is:
I don't have the answers to this, but especially after realising it makes the IDE experience worse, I thought it was an interesting conversation to have. |
Beta Was this translation helpful? Give feedback.
-
This has now been implemented for zeroconf => home-assistant/core#60206 |
Beta Was this translation helpful? Give feedback.
-
This has been implemented. |
Beta Was this translation helpful? Give feedback.
This has been implemented.