mirror of
https://github.com/home-assistant/core.git
synced 2026-04-20 10:07:12 +00:00
Set proper state for the internet_access switches in FRITZ!Box Tools (#167767)
This commit is contained in:
@@ -453,10 +453,13 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
||||
if not attributes.get("MACAddress"):
|
||||
continue
|
||||
|
||||
wan_access_result = None
|
||||
if (wan_access := attributes.get("X_AVM-DE_WANAccess")) is not None:
|
||||
wan_access_result = "granted" in wan_access
|
||||
else:
|
||||
wan_access_result = None
|
||||
# wan_access can be "granted", "denied", "unknown" or "error"
|
||||
if "granted" in wan_access:
|
||||
wan_access_result = True
|
||||
elif "denied" in wan_access:
|
||||
wan_access_result = False
|
||||
|
||||
hosts[attributes["MACAddress"]] = Device(
|
||||
name=attributes["HostName"],
|
||||
|
||||
@@ -333,30 +333,42 @@ async def test_switch_no_mesh_wifi_uplink(
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
|
||||
async def test_switch_device_no_wan_access(
|
||||
@pytest.mark.parametrize(
|
||||
("wan_access_data", "expected_state"),
|
||||
[
|
||||
(None, STATE_UNAVAILABLE),
|
||||
("unknown", STATE_UNAVAILABLE),
|
||||
("error", STATE_UNAVAILABLE),
|
||||
("granted", STATE_ON),
|
||||
("denied", STATE_OFF),
|
||||
],
|
||||
)
|
||||
async def test_switch_device_wan_access(
|
||||
hass: HomeAssistant,
|
||||
fc_class_mock,
|
||||
fh_class_mock,
|
||||
fs_class_mock,
|
||||
wan_access_data: str | None,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test Fritz!Tools switches when device has no WAN access."""
|
||||
"""Test Fritz!Tools switches have proper WAN access state."""
|
||||
|
||||
entity_id = "switch.printer_internet_access"
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
attributes = [
|
||||
{k: v for k, v in host.items() if k != "X_AVM-DE_WANAccess"}
|
||||
for host in MOCK_HOST_ATTRIBUTES_DATA
|
||||
]
|
||||
attributes = deepcopy(MOCK_HOST_ATTRIBUTES_DATA)
|
||||
for host in attributes:
|
||||
host["X_AVM-DE_WANAccess"] = wan_access_data
|
||||
|
||||
fh_class_mock.get_hosts_attributes = MagicMock(return_value=attributes)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert state.state == expected_state
|
||||
|
||||
|
||||
async def test_switch_device_no_ip_address(
|
||||
|
||||
Reference in New Issue
Block a user