Improve handling of call deflection switches in AVM Fritz!Tools (#127592)
improve handling of call_deflection switches
This commit is contained in:
parent
c28edb1117
commit
c043142b86
4 changed files with 181 additions and 37 deletions
|
@ -46,9 +46,7 @@ async def _async_deflection_entities_list(
|
|||
|
||||
_LOGGER.debug("Setting up %s switches", SWITCH_TYPE_DEFLECTION)
|
||||
|
||||
if (
|
||||
call_deflections := avm_wrapper.data.get("call_deflections")
|
||||
) is None or not isinstance(call_deflections, dict):
|
||||
if not (call_deflections := avm_wrapper.data["call_deflections"]):
|
||||
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
|
||||
return []
|
||||
|
||||
|
@ -72,7 +70,7 @@ async def _async_port_entities_list(
|
|||
# Query port forwardings and setup a switch for each forward for the current device
|
||||
resp = await avm_wrapper.async_get_num_port_mapping(avm_wrapper.device_conn_type)
|
||||
if not resp:
|
||||
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
|
||||
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_PORTFORWARD)
|
||||
return []
|
||||
|
||||
port_forwards_count: int = resp["NewPortMappingNumberOfEntries"]
|
||||
|
|
|
@ -904,6 +904,14 @@ MOCK_HOST_ATTRIBUTES_DATA = [
|
|||
},
|
||||
]
|
||||
|
||||
MOCK_CALL_DEFLECTION_DATA = {
|
||||
"X_AVM-DE_OnTel1": {
|
||||
"GetDeflections": {
|
||||
"NewDeflectionList": "<List><Item><DeflectionId>0</DeflectionId><Enable>0</Enable><Type>fromAll</Type><Number></Number><DeflectionToNumber>+1234657890</DeflectionToNumber><Mode>eImmediately</Mode><Outgoing></Outgoing><PhonebookID></PhonebookID></Item></List>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MOCK_USER_DATA = MOCK_CONFIG[DOMAIN][CONF_DEVICES][0]
|
||||
MOCK_USER_INPUT_ADVANCED = MOCK_USER_DATA
|
||||
MOCK_USER_INPUT_SIMPLE = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# serializer version: 1
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.mock_title_wi_fi_wifi_2_4ghz-entry]
|
||||
# name: test_switch_setup[fc_data0][switch.mock_title_wi_fi_wifi_2_4ghz-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -32,7 +32,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.mock_title_wi_fi_wifi_2_4ghz-state]
|
||||
# name: test_switch_setup[fc_data0][switch.mock_title_wi_fi_wifi_2_4ghz-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi (2.4Ghz)',
|
||||
|
@ -46,7 +46,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.mock_title_wi_fi_wifi_5ghz-entry]
|
||||
# name: test_switch_setup[fc_data0][switch.mock_title_wi_fi_wifi_5ghz-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -79,7 +79,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.mock_title_wi_fi_wifi_5ghz-state]
|
||||
# name: test_switch_setup[fc_data0][switch.mock_title_wi_fi_wifi_5ghz-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi (5Ghz)',
|
||||
|
@ -93,7 +93,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.printer_internet_access-entry]
|
||||
# name: test_switch_setup[fc_data0][switch.printer_internet_access-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -126,7 +126,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data0-expected_wifi_names0][switch.printer_internet_access-state]
|
||||
# name: test_switch_setup[fc_data0][switch.printer_internet_access-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'printer Internet Access',
|
||||
|
@ -140,7 +140,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.mock_title_wi_fi_wifi-entry]
|
||||
# name: test_switch_setup[fc_data1][switch.mock_title_wi_fi_wifi-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -173,7 +173,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.mock_title_wi_fi_wifi-state]
|
||||
# name: test_switch_setup[fc_data1][switch.mock_title_wi_fi_wifi-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi',
|
||||
|
@ -187,7 +187,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.mock_title_wi_fi_wifi2-entry]
|
||||
# name: test_switch_setup[fc_data1][switch.mock_title_wi_fi_wifi2-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -220,7 +220,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.mock_title_wi_fi_wifi2-state]
|
||||
# name: test_switch_setup[fc_data1][switch.mock_title_wi_fi_wifi2-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi2',
|
||||
|
@ -234,7 +234,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.printer_internet_access-entry]
|
||||
# name: test_switch_setup[fc_data1][switch.printer_internet_access-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -267,7 +267,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data1-expected_wifi_names1][switch.printer_internet_access-state]
|
||||
# name: test_switch_setup[fc_data1][switch.printer_internet_access-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'printer Internet Access',
|
||||
|
@ -281,7 +281,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.mock_title_wi_fi_wifi_2_4ghz-entry]
|
||||
# name: test_switch_setup[fc_data2][switch.mock_title_wi_fi_wifi_2_4ghz-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -314,7 +314,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.mock_title_wi_fi_wifi_2_4ghz-state]
|
||||
# name: test_switch_setup[fc_data2][switch.mock_title_wi_fi_wifi_2_4ghz-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi (2.4Ghz)',
|
||||
|
@ -328,7 +328,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.mock_title_wi_fi_wifi_5ghz-entry]
|
||||
# name: test_switch_setup[fc_data2][switch.mock_title_wi_fi_wifi_5ghz-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -361,7 +361,7 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.mock_title_wi_fi_wifi_5ghz-state]
|
||||
# name: test_switch_setup[fc_data2][switch.mock_title_wi_fi_wifi_5ghz-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi WiFi+ (5Ghz)',
|
||||
|
@ -375,7 +375,7 @@
|
|||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.printer_internet_access-entry]
|
||||
# name: test_switch_setup[fc_data2][switch.printer_internet_access-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
|
@ -408,7 +408,154 @@
|
|||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data2-expected_wifi_names2][switch.printer_internet_access-state]
|
||||
# name: test_switch_setup[fc_data2][switch.printer_internet_access-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'printer Internet Access',
|
||||
'icon': 'mdi:router-wireless-settings',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.printer_internet_access',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.mock_title_call_deflection_0-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': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.mock_title_call_deflection_0',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:phone-forward',
|
||||
'original_name': 'Call deflection 0',
|
||||
'platform': 'fritz',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '1C:ED:6F:12:34:11-call_deflection_0',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.mock_title_call_deflection_0-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'deflection_to_number': '+1234657890',
|
||||
'friendly_name': 'Mock Title Call deflection 0',
|
||||
'icon': 'mdi:phone-forward',
|
||||
'mode': 'Immediately',
|
||||
'number': None,
|
||||
'outgoing': None,
|
||||
'phonebook_id': None,
|
||||
'type': 'fromAll',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.mock_title_call_deflection_0',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.mock_title_wi_fi_mywifi-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': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.mock_title_wi_fi_mywifi',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:wifi',
|
||||
'original_name': 'Mock Title Wi-Fi MyWifi',
|
||||
'platform': 'fritz',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '1C:ED:6F:12:34:11-wi_fi_mywifi',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.mock_title_wi_fi_mywifi-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Title Wi-Fi MyWifi',
|
||||
'icon': 'mdi:wifi',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'switch.mock_title_wi_fi_mywifi',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.printer_internet_access-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': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'switch.printer_internet_access',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:router-wireless-settings',
|
||||
'original_name': 'printer Internet Access',
|
||||
'platform': 'fritz',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'AA:BB:CC:00:11:22_internet_access',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switch_setup[fc_data3][switch.printer_internet_access-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'printer Internet Access',
|
||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.const import Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import MOCK_FB_SERVICES, MOCK_USER_DATA
|
||||
from .const import MOCK_CALL_DEFLECTION_DATA, MOCK_FB_SERVICES, MOCK_USER_DATA
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
@ -169,24 +169,18 @@ MOCK_WLANCONFIGS_DIFF2_SSID: dict[str, dict] = {
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("fc_data", "expected_wifi_names"),
|
||||
("fc_data"),
|
||||
[
|
||||
(
|
||||
{**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_SAME_SSID},
|
||||
["WiFi (2.4Ghz)", "WiFi (5Ghz)"],
|
||||
),
|
||||
({**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_DIFF_SSID}, ["WiFi", "WiFi2"]),
|
||||
(
|
||||
{**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_DIFF2_SSID},
|
||||
["WiFi (2.4Ghz)", "WiFi+ (5Ghz)"],
|
||||
),
|
||||
({**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_SAME_SSID}),
|
||||
({**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_DIFF_SSID}),
|
||||
({**MOCK_FB_SERVICES, **MOCK_WLANCONFIGS_DIFF2_SSID}),
|
||||
({**MOCK_FB_SERVICES, **MOCK_CALL_DEFLECTION_DATA}),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_switch_setup(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
expected_wifi_names: list[str],
|
||||
fc_class_mock,
|
||||
fh_class_mock,
|
||||
snapshot: SnapshotAssertion,
|
||||
|
@ -199,7 +193,4 @@ async def test_switch_setup(
|
|||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
states = hass.states.async_all()
|
||||
assert len(states) == 3
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue