Verify that the MAC address that Fully Kiosk reported is usable (#94887)
parent
723f6d35b0
commit
0c66ccebd1
|
@ -9,6 +9,18 @@ from .const import DOMAIN
|
||||||
from .coordinator import FullyKioskDataUpdateCoordinator
|
from .coordinator import FullyKioskDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
def valid_global_mac_address(mac: str | None) -> bool:
|
||||||
|
"""Check if a MAC address is valid, non-locally administered address."""
|
||||||
|
if not isinstance(mac, str):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
first_octet = int(mac.split(":")[0], 16)
|
||||||
|
# If the second least-significant bit is set, it's a locally administered address, should not be used as an ID
|
||||||
|
return not bool(first_octet & 0x2)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class FullyKioskEntity(CoordinatorEntity[FullyKioskDataUpdateCoordinator], Entity):
|
class FullyKioskEntity(CoordinatorEntity[FullyKioskDataUpdateCoordinator], Entity):
|
||||||
"""Defines a Fully Kiosk Browser entity."""
|
"""Defines a Fully Kiosk Browser entity."""
|
||||||
|
|
||||||
|
@ -25,7 +37,9 @@ class FullyKioskEntity(CoordinatorEntity[FullyKioskDataUpdateCoordinator], Entit
|
||||||
sw_version=coordinator.data["appVersionName"],
|
sw_version=coordinator.data["appVersionName"],
|
||||||
configuration_url=f"http://{coordinator.data['ip4']}:2323",
|
configuration_url=f"http://{coordinator.data['ip4']}:2323",
|
||||||
)
|
)
|
||||||
if "Mac" in coordinator.data and coordinator.data["Mac"]:
|
if "Mac" in coordinator.data and valid_global_mac_address(
|
||||||
|
coordinator.data["Mac"]
|
||||||
|
):
|
||||||
device_info["connections"] = {
|
device_info["connections"] = {
|
||||||
(CONNECTION_NETWORK_MAC, coordinator.data["Mac"])
|
(CONNECTION_NETWORK_MAC, coordinator.data["Mac"])
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ from fullykiosk import FullyKioskError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.fully_kiosk.const import DOMAIN
|
from homeassistant.components.fully_kiosk.const import DOMAIN
|
||||||
|
from homeassistant.components.fully_kiosk.entity import valid_global_mac_address
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -134,3 +135,11 @@ async def test_multiple_kiosk_with_empty_mac(
|
||||||
assert device2
|
assert device2
|
||||||
|
|
||||||
assert device1 != device2
|
assert device1 != device2
|
||||||
|
|
||||||
|
|
||||||
|
async def test_valid_global_mac_address() -> None:
|
||||||
|
"""Test valid_global_mac_address function."""
|
||||||
|
assert valid_global_mac_address("a1:bb:cc:dd:ee:ff")
|
||||||
|
assert not valid_global_mac_address("02:00:00:00:00:00")
|
||||||
|
assert not valid_global_mac_address(None)
|
||||||
|
assert not valid_global_mac_address("foobar")
|
||||||
|
|
Loading…
Reference in New Issue