mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add VPN sensor and switch for Smlight integration (#126201)
* 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
This commit is contained in:
parent
0281e95f2e
commit
4f53ffcd9c
@ -39,6 +39,12 @@ SENSORS = [
|
||||
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",
|
||||
|
@ -49,6 +49,9 @@
|
||||
"internet": {
|
||||
"name": "Internet"
|
||||
},
|
||||
"vpn": {
|
||||
"name": "VPN"
|
||||
},
|
||||
"wifi": {
|
||||
"name": "Wi-Fi"
|
||||
}
|
||||
@ -116,6 +119,9 @@
|
||||
},
|
||||
"night_mode": {
|
||||
"name": "LED night mode"
|
||||
},
|
||||
"vpn_enabled": {
|
||||
"name": "VPN enabled"
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
|
@ -54,6 +54,13 @@ SWITCHES: list[SmSwitchEntityDescription] = [
|
||||
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,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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',
|
||||
})
|
||||
# ---
|
||||
|
@ -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")
|
||||
for sensor in ("wi_fi", "vpn"):
|
||||
assert not hass.states.get(f"binary_sensor.mock_title_{sensor}")
|
||||
|
||||
assert (entry := entity_registry.async_get("binary_sensor.mock_title_wi_fi"))
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
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(
|
||||
|
@ -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,
|
||||
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user