From 04e4b05ab0e08a4d4cc4b570a33fc375b1103feb Mon Sep 17 00:00:00 2001 From: rappenze Date: Wed, 4 Mar 2026 15:40:49 +0100 Subject: [PATCH] Fix handling of several thermostat QuickApp's in fibaro (#164344) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/fibaro/__init__.py | 7 ++- tests/components/fibaro/conftest.py | 62 +++++++++++++++++++++ tests/components/fibaro/test_climate.py | 28 ++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/fibaro/__init__.py b/homeassistant/components/fibaro/__init__.py index bde62b234dc..d56cd113e76 100644 --- a/homeassistant/components/fibaro/__init__.py +++ b/homeassistant/components/fibaro/__init__.py @@ -275,8 +275,11 @@ class FibaroController: # otherwise add the first visible device in the group # which is a hack, but solves a problem with FGT having # hidden compatibility devices before the real device - if last_climate_parent != device.parent_fibaro_id or ( - device.has_endpoint_id and last_endpoint != device.endpoint_id + # Second hack is for quickapps which have parent id 0 and no children + if ( + last_climate_parent != device.parent_fibaro_id + or (device.has_endpoint_id and last_endpoint != device.endpoint_id) + or device.parent_fibaro_id == 0 ): _LOGGER.debug("Handle separately") self.fibaro_devices[platform].append(device) diff --git a/tests/components/fibaro/conftest.py b/tests/components/fibaro/conftest.py index 952efbbb8ec..3949edb2c3a 100644 --- a/tests/components/fibaro/conftest.py +++ b/tests/components/fibaro/conftest.py @@ -286,6 +286,68 @@ def mock_thermostat_with_operating_mode() -> Mock: return climate +@pytest.fixture +def mock_thermostat_quickapp_1() -> Mock: + """Fixture for a thermostat.""" + climate = Mock() + climate.fibaro_id = 6 + climate.parent_fibaro_id = 0 + climate.has_endpoint_id = False + climate.name = "Test climate" + climate.room_id = 1 + climate.dead = False + climate.visible = True + climate.enabled = True + climate.type = "com.fibaro.hvacSystemHeat" + climate.base_type = "com.fibaro.hvacSystem" + climate.properties = {"manufacturer": ""} + climate.actions = {"setHeatingThermostatSetpoint": 1, "setThermostatMode": 1} + climate.supported_features = {} + climate.has_supported_operating_modes = False + climate.has_supported_thermostat_modes = True + climate.supported_thermostat_modes = ["Off", "Heat"] + climate.has_thermostat_mode = True + climate.thermostat_mode = "Heat" + climate.has_unit = False + climate.has_heating_thermostat_setpoint = False + climate.has_heating_thermostat_setpoint_future = False + value_mock = Mock() + value_mock.has_value = False + climate.value = value_mock + return climate + + +@pytest.fixture +def mock_thermostat_quickapp_2() -> Mock: + """Fixture for a thermostat.""" + climate = Mock() + climate.fibaro_id = 7 + climate.parent_fibaro_id = 0 + climate.has_endpoint_id = False + climate.name = "Test climate 2" + climate.room_id = 1 + climate.dead = False + climate.visible = True + climate.enabled = True + climate.type = "com.fibaro.hvacSystemHeat" + climate.base_type = "com.fibaro.hvacSystem" + climate.properties = {"manufacturer": ""} + climate.actions = {"setHeatingThermostatSetpoint": 1, "setThermostatMode": 1} + climate.supported_features = {} + climate.has_supported_operating_modes = False + climate.has_supported_thermostat_modes = True + climate.supported_thermostat_modes = ["Off", "Heat"] + climate.has_thermostat_mode = True + climate.thermostat_mode = "Heat" + climate.has_unit = False + climate.has_heating_thermostat_setpoint = False + climate.has_heating_thermostat_setpoint_future = False + value_mock = Mock() + value_mock.has_value = False + climate.value = value_mock + return climate + + @pytest.fixture def mock_fan_device() -> Mock: """Fixture for a fan endpoint of a thermostat device.""" diff --git a/tests/components/fibaro/test_climate.py b/tests/components/fibaro/test_climate.py index 339d9d23077..183a4333b60 100644 --- a/tests/components/fibaro/test_climate.py +++ b/tests/components/fibaro/test_climate.py @@ -41,6 +41,34 @@ async def test_climate_setup( ) +async def test_climate_setup_2_quickapps( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_fibaro_client: Mock, + mock_config_entry: MockConfigEntry, + mock_thermostat_quickapp_1: Mock, + mock_thermostat_quickapp_2: Mock, + mock_room: Mock, +) -> None: + """Test that the climate creates entities for more than one QuickApp.""" + + # Arrange + mock_fibaro_client.read_rooms.return_value = [mock_room] + mock_fibaro_client.read_devices.return_value = [ + mock_thermostat_quickapp_1, + mock_thermostat_quickapp_2, + ] + + with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.CLIMATE]): + # Act + await init_integration(hass, mock_config_entry) + # Assert + entry1 = entity_registry.async_get("climate.room_1_test_climate_6") + assert entry1 + entry2 = entity_registry.async_get("climate.room_1_test_climate_2_7") + assert entry2 + + async def test_hvac_mode_preset( hass: HomeAssistant, mock_fibaro_client: Mock,