Skip to content

Commit

Permalink
Add Freebox wifiguest devices
Browse files Browse the repository at this point in the history
  • Loading branch information
slecache committed Apr 3, 2024
1 parent 535da48 commit a86eb22
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/freebox/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
11 changes: 10 additions & 1 deletion tests/components/freebox/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/components/freebox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
4 changes: 2 additions & 2 deletions tests/components/freebox/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions tests/components/freebox/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a86eb22

Please sign in to comment.