Skip to content

Commit

Permalink
Add VPN sensor and switch for Smlight integration (#126201)
Browse files Browse the repository at this point in the history
* Add vpn_status sensor

* update test fixures with new attributes

* Add vpn enabled switch

vpn strings

* Add vpn switch to test

* update snapshots

* Add vpn status to disabled by default test
  • Loading branch information
tl-sl authored Sep 18, 2024
1 parent 0281e95 commit 4f53ffc
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 6 deletions.
6 changes: 6 additions & 0 deletions homeassistant/components/smlight/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class SmBinarySensorEntityDescription(BinarySensorEntityDescription):
translation_key="ethernet",
value_fn=lambda x: x.ethernet,
),
SmBinarySensorEntityDescription(
key="vpn",
translation_key="vpn",
entity_registry_enabled_default=False,
value_fn=lambda x: x.vpn_status,
),
SmBinarySensorEntityDescription(
key="wifi",
translation_key="wifi",
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/smlight/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"internet": {
"name": "Internet"
},
"vpn": {
"name": "VPN"
},
"wifi": {
"name": "Wi-Fi"
}
Expand Down Expand Up @@ -116,6 +119,9 @@
},
"night_mode": {
"name": "LED night mode"
},
"vpn_enabled": {
"name": "VPN enabled"
}
},
"update": {
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/smlight/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class SmSwitchEntityDescription(SwitchEntityDescription):
setting=Settings.ZB_AUTOUPDATE,
state_fn=lambda x: x.auto_zigbee,
),
SmSwitchEntityDescription(
key="vpn_enabled",
translation_key="vpn_enabled",
setting=Settings.ENABLE_VPN,
entity_registry_enabled_default=False,
state_fn=lambda x: x.vpn_enabled,
),
]


Expand Down
1 change: 1 addition & 0 deletions tests/components/smlight/fixtures/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"sw_version": "v2.3.6",
"wifi_mode": 0,
"zb_flash_size": 704,
"zb_channel": 0,
"zb_hw": "CC2652P7",
"zb_ram_size": 152,
"zb_version": "20240314",
Expand Down
4 changes: 3 additions & 1 deletion tests/components/smlight/fixtures/sensors.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"wifi_status": 255,
"disable_leds": false,
"night_mode": true,
"auto_zigbee": false
"auto_zigbee": false,
"vpn_enabled": false,
"vpn_status": true
}
47 changes: 47 additions & 0 deletions tests/components/smlight/snapshots/test_binary_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,53 @@
'state': 'unknown',
})
# ---
# name: test_all_binary_sensors[binary_sensor.mock_title_vpn-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.mock_title_vpn',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
'original_icon': None,
'original_name': 'VPN',
'platform': 'smlight',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'vpn',
'unique_id': 'aa:bb:cc:dd:ee:ff_vpn',
'unit_of_measurement': None,
})
# ---
# name: test_all_binary_sensors[binary_sensor.mock_title_vpn-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'connectivity',
'friendly_name': 'Mock Title VPN',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.mock_title_vpn',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_all_binary_sensors[binary_sensor.mock_title_wi_fi-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
Expand Down
47 changes: 47 additions & 0 deletions tests/components/smlight/snapshots/test_switch.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,50 @@
'state': 'on',
})
# ---
# name: test_switch_setup[switch.mock_title_vpn_enabled-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.mock_title_vpn_enabled',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
'original_icon': None,
'original_name': 'VPN enabled',
'platform': 'smlight',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'vpn_enabled',
'unique_id': 'aa:bb:cc:dd:ee:ff-vpn_enabled',
'unit_of_measurement': None,
})
# ---
# name: test_switch_setup[switch.mock_title_vpn_enabled-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'switch',
'friendly_name': 'Mock Title VPN enabled',
}),
'context': <ANY>,
'entity_id': 'switch.mock_title_vpn_enabled',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
13 changes: 8 additions & 5 deletions tests/components/smlight/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ async def test_disabled_by_default_sensors(
"""Test wifi sensor is disabled by default ."""
await setup_integration(hass, mock_config_entry)

assert not hass.states.get("binary_sensor.mock_title_wi_fi")

assert (entry := entity_registry.async_get("binary_sensor.mock_title_wi_fi"))
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
for sensor in ("wi_fi", "vpn"):
assert not hass.states.get(f"binary_sensor.mock_title_{sensor}")

assert (
entry := entity_registry.async_get(f"binary_sensor.mock_title_{sensor}")
)
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION


async def test_internet_sensor_event(
Expand Down
18 changes: 18 additions & 0 deletions tests/components/smlight/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def platforms() -> list[Platform]:
return [Platform.SWITCH]


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_switch_setup(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
Expand All @@ -46,12 +47,29 @@ async def test_switch_setup(
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)


async def test_disabled_by_default_switch(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test vpn enabled switch is disabled by default ."""
await setup_integration(hass, mock_config_entry)

assert not hass.states.get("switch.mock_title_vpn_enabled")

assert (entry := entity_registry.async_get("switch.mock_title_vpn_enabled"))
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize(
("entity", "setting"),
[
("disable_leds", Settings.DISABLE_LEDS),
("led_night_mode", Settings.NIGHT_MODE),
("auto_zigbee_update", Settings.ZB_AUTOUPDATE),
("vpn_enabled", Settings.ENABLE_VPN),
],
)
async def test_switches(
Expand Down

0 comments on commit 4f53ffc

Please sign in to comment.