mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 04:37:52 +00:00
Minor code improvement for KEF (#41885)
This commit is contained in:
parent
0e20bba40a
commit
d790de1346
@ -85,6 +85,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ip_mode(host):
|
||||||
|
"""Get the 'mode' used to retrieve the MAC address."""
|
||||||
|
try:
|
||||||
|
if ipaddress.ip_address(host).version == 6:
|
||||||
|
return "ip6"
|
||||||
|
return "ip"
|
||||||
|
except ValueError:
|
||||||
|
return "hostname"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up the KEF platform."""
|
"""Set up the KEF platform."""
|
||||||
if DOMAIN not in hass.data:
|
if DOMAIN not in hass.data:
|
||||||
@ -111,13 +121,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
sources,
|
sources,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
mode = get_ip_mode(host)
|
||||||
if ipaddress.ip_address(host).version == 6:
|
|
||||||
mode = "ip6"
|
|
||||||
else:
|
|
||||||
mode = "ip"
|
|
||||||
except ValueError:
|
|
||||||
mode = "hostname"
|
|
||||||
mac = await hass.async_add_executor_job(partial(get_mac_address, **{mode: host}))
|
mac = await hass.async_add_executor_job(partial(get_mac_address, **{mode: host}))
|
||||||
unique_id = f"kef-{mac}" if mac is not None else None
|
unique_id = f"kef-{mac}" if mac is not None else None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user