From fda817cb1d3a56d1d28ff28776dbc895ebaec6e2 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Tue, 27 Jan 2026 17:18:08 +0100 Subject: [PATCH] Fix deflection switch state for Fritz (#161669) --- homeassistant/components/fritz/switch.py | 3 +++ tests/components/fritz/const.py | 2 +- tests/components/fritz/snapshots/test_switch.ambr | 2 +- tests/components/fritz/test_switch.py | 7 ++++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/fritz/switch.py b/homeassistant/components/fritz/switch.py index 09e473d868a..a35bf65f23d 100644 --- a/homeassistant/components/fritz/switch.py +++ b/homeassistant/components/fritz/switch.py @@ -488,6 +488,9 @@ class FritzBoxDeflectionSwitch(FritzBoxBaseCoordinatorSwitch): async def _async_handle_turn_on_off(self, turn_on: bool) -> None: """Handle deflection switch.""" await self.coordinator.async_set_deflection_enable(self.deflection_id, turn_on) + deflection = self.coordinator.data["call_deflections"][self.deflection_id] + deflection["Enable"] = "1" if turn_on else "0" + self.async_write_ha_state() class FritzBoxProfileSwitch(FritzDeviceBase, SwitchEntity): diff --git a/tests/components/fritz/const.py b/tests/components/fritz/const.py index e2bb2ce048f..7e37e742046 100644 --- a/tests/components/fritz/const.py +++ b/tests/components/fritz/const.py @@ -967,7 +967,7 @@ MOCK_HOST_ATTRIBUTES_DATA = [ MOCK_CALL_DEFLECTION_DATA = { "X_AVM-DE_OnTel1": { "GetDeflections": { - "NewDeflectionList": "00fromAll+1234657890eImmediately" + "NewDeflectionList": "01fromAll+1234657890eImmediately" } } } diff --git a/tests/components/fritz/snapshots/test_switch.ambr b/tests/components/fritz/snapshots/test_switch.ambr index 600cc9838f5..ff1624daf7a 100644 --- a/tests/components/fritz/snapshots/test_switch.ambr +++ b/tests/components/fritz/snapshots/test_switch.ambr @@ -799,7 +799,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'off', + 'state': 'on', }) # --- # name: test_switch_setup[fc_data3][switch.mock_title_port_forward_test_port_mapping-entry] diff --git a/tests/components/fritz/test_switch.py b/tests/components/fritz/test_switch.py index 8410cf02162..f8cf719fb0b 100644 --- a/tests/components/fritz/test_switch.py +++ b/tests/components/fritz/test_switch.py @@ -293,7 +293,7 @@ async def test_switch_no_profile_entities_list( ) -> None: """Test Fritz!Tools switches with no profile entities.""" - entity_id = "sswitch.printer_internet_access" + entity_id = "switch.printer_internet_access" entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA) entry.add_to_hass(hass) @@ -364,6 +364,11 @@ async def test_switch_device_no_wan_access( "async_set_allow_wan_access", STATE_ON, ), + ( + "switch.mock_title_call_deflection_0", + "async_set_deflection_enable", + STATE_ON, + ), ], ) async def test_switch_turn_on_off(