Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/unifi/hub/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class UnifiConfig:

# Device tracker options

option_track_clients: list[str]
option_track_clients: bool
"""Config entry option to not track clients."""
option_track_wired_clients: list[str]
option_track_wired_clients: bool
"""Config entry option to not track wired clients."""
option_track_devices: bool
"""Config entry option to not track devices."""
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/unifi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def async_client_uptime_value_fn(hub: UnifiHub, client: Client) -> datetime:
@callback
def async_wired_client_allowed_fn(hub: UnifiHub, obj_id: str) -> bool:
"""Check if client is wired and allowed."""
if obj_id not in hub.config.option_supported_clients and (
not hub.config.option_track_clients or not hub.config.option_track_wired_clients
):
return False
client = hub.api.clients[obj_id]
if not client.is_wired or client.wired_rate_mbps <= 0:
return False
Expand Down
38 changes: 38 additions & 0 deletions tests/components/unifi/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
from homeassistant.components.unifi.const import (
CONF_ALLOW_BANDWIDTH_SENSORS,
CONF_ALLOW_UPTIME_SENSORS,
CONF_CLIENT_SOURCE,
CONF_DETECTION_TIME,
CONF_TRACK_CLIENTS,
CONF_TRACK_DEVICES,
CONF_TRACK_WIRED_CLIENTS,
DEFAULT_DETECTION_TIME,
DEVICE_STATES,
)
Expand Down Expand Up @@ -579,6 +581,42 @@ async def test_wired_client_speed_sensor(
assert hass.states.get("sensor.wired_client_link_speed").state == STATE_UNAVAILABLE


@pytest.mark.parametrize("config_entry_options", [{CONF_TRACK_CLIENTS: False}])
@pytest.mark.parametrize("client_payload", [[WIRED_CLIENT]])
@pytest.mark.usefixtures("config_entry_setup")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_wired_client_speed_sensor_tracking_disabled(
hass: HomeAssistant,
) -> None:
"""Verify wired client speed sensor is not created when track_clients is disabled."""
assert hass.states.get("sensor.wired_client_link_speed") is None


@pytest.mark.parametrize("config_entry_options", [{CONF_TRACK_WIRED_CLIENTS: False}])
@pytest.mark.parametrize("client_payload", [[WIRED_CLIENT]])
@pytest.mark.usefixtures("config_entry_setup")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_wired_client_speed_sensor_wired_tracking_disabled(
hass: HomeAssistant,
) -> None:
"""Verify wired client speed sensor is not created when track_wired_clients is disabled."""
assert hass.states.get("sensor.wired_client_link_speed") is None


@pytest.mark.parametrize(
"config_entry_options",
[{CONF_TRACK_CLIENTS: False, CONF_CLIENT_SOURCE: [WIRED_CLIENT["mac"]]}],
)
@pytest.mark.parametrize("client_payload", [[WIRED_CLIENT]])
@pytest.mark.usefixtures("config_entry_setup")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_wired_client_speed_sensor_supported_client_bypass(
hass: HomeAssistant,
) -> None:
"""Verify wired client speed sensor is created for supported clients even when tracking is disabled."""
assert hass.states.get("sensor.wired_client_link_speed").state == "1000"
Comment thread
RaHehl marked this conversation as resolved.


@pytest.mark.parametrize(
"config_entry_options",
[{CONF_ALLOW_BANDWIDTH_SENSORS: True, CONF_ALLOW_UPTIME_SENSORS: True}],
Expand Down