Zeroconf lowercase (#44675)
This commit is contained in:
parent
b290a8b5a1
commit
c7bf7b32a2
5 changed files with 48 additions and 20 deletions
|
@ -4,7 +4,7 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/brother",
|
||||
"codeowners": ["@bieniu"],
|
||||
"requirements": ["brother==0.1.20"],
|
||||
"zeroconf": [{"type": "_printer._tcp.local.", "name":"Brother*"}],
|
||||
"zeroconf": [{ "type": "_printer._tcp.local.", "name": "brother*" }],
|
||||
"config_flow": true,
|
||||
"quality_scale": "platinum"
|
||||
}
|
||||
|
|
|
@ -284,22 +284,30 @@ async def _async_start_zeroconf_browser(hass, zeroconf):
|
|||
# likely bad homekit data
|
||||
return
|
||||
|
||||
if "name" in info:
|
||||
lowercase_name = info["name"].lower()
|
||||
else:
|
||||
lowercase_name = None
|
||||
|
||||
if "macaddress" in info.get("properties", {}):
|
||||
uppercase_mac = info["properties"]["macaddress"].upper()
|
||||
else:
|
||||
uppercase_mac = None
|
||||
|
||||
for entry in zeroconf_types[service_type]:
|
||||
if len(entry) > 1:
|
||||
if "macaddress" in entry:
|
||||
if "properties" not in info:
|
||||
continue
|
||||
if "macaddress" not in info["properties"]:
|
||||
continue
|
||||
if not fnmatch.fnmatch(
|
||||
info["properties"]["macaddress"], entry["macaddress"]
|
||||
):
|
||||
continue
|
||||
if "name" in entry:
|
||||
if "name" not in info:
|
||||
continue
|
||||
if not fnmatch.fnmatch(info["name"], entry["name"]):
|
||||
continue
|
||||
if (
|
||||
uppercase_mac is not None
|
||||
and "macaddress" in entry
|
||||
and not fnmatch.fnmatch(uppercase_mac, entry["macaddress"])
|
||||
):
|
||||
continue
|
||||
if (
|
||||
lowercase_name is not None
|
||||
and "name" in entry
|
||||
and not fnmatch.fnmatch(lowercase_name, entry["name"])
|
||||
):
|
||||
continue
|
||||
|
||||
hass.add_job(
|
||||
hass.config_entries.flow.async_init(
|
||||
|
|
|
@ -116,7 +116,7 @@ ZEROCONF = {
|
|||
"_printer._tcp.local.": [
|
||||
{
|
||||
"domain": "brother",
|
||||
"name": "Brother*"
|
||||
"name": "brother*"
|
||||
}
|
||||
],
|
||||
"_spotify-connect._tcp.local.": [
|
||||
|
|
|
@ -33,6 +33,22 @@ def documentation_url(value: str) -> str:
|
|||
return value
|
||||
|
||||
|
||||
def verify_lowercase(value: str):
|
||||
"""Verify a value is lowercase."""
|
||||
if value.lower() != value:
|
||||
raise vol.Invalid("Value needs to be lowercase")
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def verify_uppercase(value: str):
|
||||
"""Verify a value is uppercase."""
|
||||
if value.upper() != value:
|
||||
raise vol.Invalid("Value needs to be uppercase")
|
||||
|
||||
return value
|
||||
|
||||
|
||||
MANIFEST_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("domain"): str,
|
||||
|
@ -45,8 +61,8 @@ MANIFEST_SCHEMA = vol.Schema(
|
|||
vol.Schema(
|
||||
{
|
||||
vol.Required("type"): str,
|
||||
vol.Optional("macaddress"): str,
|
||||
vol.Optional("name"): str,
|
||||
vol.Optional("macaddress"): vol.All(str, verify_uppercase),
|
||||
vol.Optional("name"): vol.All(str, verify_lowercase),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
|
|
@ -242,13 +242,17 @@ async def test_zeroconf_match(hass, mock_zeroconf):
|
|||
handlers[0](
|
||||
zeroconf,
|
||||
"_http._tcp.local.",
|
||||
"shelly108._http._tcp.local.",
|
||||
"Shelly108._http._tcp.local.",
|
||||
ServiceStateChange.Added,
|
||||
)
|
||||
|
||||
with patch.dict(
|
||||
zc_gen.ZEROCONF,
|
||||
{"_http._tcp.local.": [{"domain": "shelly", "name": "shelly*"}]},
|
||||
{
|
||||
"_http._tcp.local.": [
|
||||
{"domain": "shelly", "name": "shelly*", "macaddress": "FFAADD*"}
|
||||
]
|
||||
},
|
||||
clear=True,
|
||||
), patch.object(
|
||||
hass.config_entries.flow, "async_init"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue