Cleanup isinstance checks in zeroconf (#100090)
This commit is contained in:
parent
f4a7bb47fe
commit
791482406c
1 changed files with 10 additions and 7 deletions
|
@ -11,7 +11,7 @@ from ipaddress import IPv4Address, IPv6Address
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Final, cast
|
from typing import TYPE_CHECKING, Any, Final, cast
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from zeroconf import (
|
from zeroconf import (
|
||||||
|
@ -303,6 +303,7 @@ def _match_against_data(
|
||||||
if key not in match_data:
|
if key not in match_data:
|
||||||
return False
|
return False
|
||||||
match_val = matcher[key]
|
match_val = matcher[key]
|
||||||
|
if TYPE_CHECKING:
|
||||||
assert isinstance(match_val, str)
|
assert isinstance(match_val, str)
|
||||||
|
|
||||||
if not _memorized_fnmatch(match_data[key], match_val):
|
if not _memorized_fnmatch(match_data[key], match_val):
|
||||||
|
@ -485,11 +486,13 @@ class ZeroconfDiscovery:
|
||||||
continue
|
continue
|
||||||
if ATTR_PROPERTIES in matcher:
|
if ATTR_PROPERTIES in matcher:
|
||||||
matcher_props = matcher[ATTR_PROPERTIES]
|
matcher_props = matcher[ATTR_PROPERTIES]
|
||||||
|
if TYPE_CHECKING:
|
||||||
assert isinstance(matcher_props, dict)
|
assert isinstance(matcher_props, dict)
|
||||||
if not _match_against_props(matcher_props, props):
|
if not _match_against_props(matcher_props, props):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
matcher_domain = matcher["domain"]
|
matcher_domain = matcher["domain"]
|
||||||
|
if TYPE_CHECKING:
|
||||||
assert isinstance(matcher_domain, str)
|
assert isinstance(matcher_domain, str)
|
||||||
context = {
|
context = {
|
||||||
"source": config_entries.SOURCE_ZEROCONF,
|
"source": config_entries.SOURCE_ZEROCONF,
|
||||||
|
@ -516,11 +519,11 @@ def async_get_homekit_discovery(
|
||||||
|
|
||||||
Return the domain to forward the discovery data to
|
Return the domain to forward the discovery data to
|
||||||
"""
|
"""
|
||||||
if not (model := props.get(HOMEKIT_MODEL_LOWER) or props.get(HOMEKIT_MODEL_UPPER)):
|
if not (
|
||||||
|
model := props.get(HOMEKIT_MODEL_LOWER) or props.get(HOMEKIT_MODEL_UPPER)
|
||||||
|
) or not isinstance(model, str):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
assert isinstance(model, str)
|
|
||||||
|
|
||||||
for split_str in _HOMEKIT_MODEL_SPLITS:
|
for split_str in _HOMEKIT_MODEL_SPLITS:
|
||||||
key = (model.split(split_str))[0] if split_str else model
|
key = (model.split(split_str))[0] if split_str else model
|
||||||
if discovery := homekit_model_lookups.get(key):
|
if discovery := homekit_model_lookups.get(key):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue