Exemplo n.º 1
0
 def async_matching_domains(self, info_with_desc: CaseInsensitiveDict) -> set[str]:
     """Find domains matching the passed CaseInsensitiveDict."""
     assert self._match_by_key is not None
     domains = set()
     for key, matchers_by_key in self._match_by_key.items():
         if not (match_value := info_with_desc.get(key)):
             continue
         for domain, matcher in matchers_by_key.get(match_value, []):
             if domain in domains:
                 continue
             if all(info_with_desc.get(k) == v for (k, v) in matcher.items()):
                 domains.add(domain)
Exemplo n.º 2
0
 def _async_matching_domains(self, info_with_req: CaseInsensitiveDict) -> set[str]:
     domains = set()
     for domain, matchers in self._integration_matchers.items():
         for matcher in matchers:
             if all(info_with_req.get(k) == v for (k, v) in matcher.items()):
                 domains.add(domain)
     return domains
Exemplo n.º 3
0
def discovery_info_from_headers_and_description(
    combined_headers: CaseInsensitiveDict,
    info_desc: Mapping[str, Any],
) -> SsdpServiceInfo:
    """Convert headers and description to discovery_info."""
    ssdp_usn = combined_headers["usn"]
    ssdp_st = combined_headers.get("st")
    if isinstance(info_desc, CaseInsensitiveDict):
        upnp_info = {**info_desc.as_dict()}
    else:
        upnp_info = {**info_desc}

    # Increase compatibility: depending on the message type,
    # either the ST (Search Target, from M-SEARCH messages)
    # or NT (Notification Type, from NOTIFY messages) header is mandatory
    if not ssdp_st:
        ssdp_st = combined_headers["nt"]

    # Ensure UPnP "udn" is set
    if ATTR_UPNP_UDN not in upnp_info:
        if udn := _udn_from_usn(ssdp_usn):
            upnp_info[ATTR_UPNP_UDN] = udn