diff --git a/homeassistant/components/freebox/router.py b/homeassistant/components/freebox/router.py index ed2fbcf1e8311..710ea26151e2d 100644 --- a/homeassistant/components/freebox/router.py +++ b/homeassistant/components/freebox/router.py @@ -72,7 +72,9 @@ async def get_hosts_list_if_supported( supports_hosts: bool = True fbx_devices: list[dict[str, Any]] = [] try: - fbx_devices = await fbx_api.lan.get_hosts_list() or [] + fbx_devices_pub = await fbx_api.lan.get_hosts_list("pub") or [] + fbx_devices_wifiguest = await fbx_api.lan.get_hosts_list("wifiguest") or [] + fbx_devices = fbx_devices_pub + fbx_devices_wifiguest except HttpRequestError as err: if ( (matcher := re.search(r"Request failed \(APIResponse: (.+)\)", str(err))) diff --git a/tests/components/freebox/conftest.py b/tests/components/freebox/conftest.py index cf520043755ef..1bf2e12398c78 100644 --- a/tests/components/freebox/conftest.py +++ b/tests/components/freebox/conftest.py @@ -17,6 +17,7 @@ DATA_HOME_SET_VALUE, DATA_LAN_GET_HOSTS_LIST, DATA_LAN_GET_HOSTS_LIST_MODE_BRIDGE, + DATA_LAN_GET_HOSTS_WIFIGUEST_LIST, DATA_STORAGE_GET_DISKS, DATA_STORAGE_GET_RAIDS, DATA_SYSTEM_GET_CONFIG, @@ -77,8 +78,16 @@ def mock_router(mock_device_registry_devices): instance = service_mock.return_value instance.open = AsyncMock() instance.system.get_config = AsyncMock(return_value=DATA_SYSTEM_GET_CONFIG) + # device_tracker - instance.lan.get_hosts_list = AsyncMock(return_value=DATA_LAN_GET_HOSTS_LIST) + # instance.lan.get_hosts_list = AsyncMock(return_value=DATA_LAN_GET_HOSTS_LIST) + def get_hosts_list(interface): + if interface == "pub": + return DATA_LAN_GET_HOSTS_LIST + elif interface == "wifiguest": + return DATA_LAN_GET_HOSTS_WIFIGUEST_LIST + + instance.lan.get_hosts_list = AsyncMock(side_effect=get_hosts_list) # sensor instance.call.get_calls_log = AsyncMock(return_value=DATA_CALL_GET_CALLS_LOG) instance.storage.get_disks = AsyncMock(return_value=DATA_STORAGE_GET_DISKS) diff --git a/tests/components/freebox/const.py b/tests/components/freebox/const.py index 5211b793918ba..265c46f6e422b 100644 --- a/tests/components/freebox/const.py +++ b/tests/components/freebox/const.py @@ -26,6 +26,9 @@ # device_tracker DATA_LAN_GET_HOSTS_LIST = load_json_array_fixture("freebox/lan_get_hosts_list.json") +DATA_LAN_GET_HOSTS_WIFIGUEST_LIST = load_json_array_fixture( + "freebox/lan_get_hosts_wifiguest_list.json" +) DATA_LAN_GET_HOSTS_LIST_MODE_BRIDGE = load_json_object_fixture( "freebox/lan_get_hosts_list_bridge.json" ) diff --git a/tests/components/freebox/fixtures/lan_get_hosts_wifiguest_list.json b/tests/components/freebox/fixtures/lan_get_hosts_wifiguest_list.json new file mode 100644 index 0000000000000..2560614236b2d --- /dev/null +++ b/tests/components/freebox/fixtures/lan_get_hosts_wifiguest_list.json @@ -0,0 +1,35 @@ +[ + { + "l2ident": { + "id": "d0:23:db:36:15:aa", + "type": "mac_address" + }, + "active": true, + "id": "ether-d0:23:db:36:15:aa", + "last_time_reachable": 1360669498, + "persistent": true, + "names": [ + { + "name": "iPhone-r0ro", + "source": "dhcp" + } + ], + "vendor_name": "Apple, Inc.", + "host_type": "smartphone", + "interface": "wifiguest", + "l3connectivities": [ + { + "addr": "192.168.69.20", + "active": true, + "af": "ipv4", + "reachable": true, + "last_activity": 1360669498, + "last_time_reachable": 1360669498 + } + ], + "reachable": true, + "last_activity": 1360669498, + "primary_name_manual": true, + "primary_name": "iPhone r0ro" + } +] diff --git a/tests/components/freebox/test_device_tracker.py b/tests/components/freebox/test_device_tracker.py index 405166d6ba26a..c8bffa38583e9 100644 --- a/tests/components/freebox/test_device_tracker.py +++ b/tests/components/freebox/test_device_tracker.py @@ -21,14 +21,14 @@ async def test_router_mode( """Test get_hosts_list invoqued multiple times if freebox into router mode.""" await setup_platform(hass, DEVICE_TRACKER_DOMAIN) - assert router().lan.get_hosts_list.call_count == 1 + assert router().lan.get_hosts_list.call_count == 2 # Simulate an update freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass) await hass.async_block_till_done() - assert router().lan.get_hosts_list.call_count == 2 + assert router().lan.get_hosts_list.call_count == 4 async def test_bridge_mode( diff --git a/tests/components/freebox/test_router.py b/tests/components/freebox/test_router.py index 623f595e1adef..6de5b72e5a60d 100644 --- a/tests/components/freebox/test_router.py +++ b/tests/components/freebox/test_router.py @@ -35,7 +35,9 @@ async def test_get_hosts_list_if_supported( assert supports_hosts is True # List must not be empty; but it's content depends on how many unit tests are executed... assert fbx_devices + assert len(fbx_devices) == 5 assert "d633d0c8-958c-43cc-e807-d881b076924b" in str(fbx_devices) + assert "iPhone-r0ro" in str(fbx_devices) async def test_get_hosts_list_if_supported_bridge(