From 9e043e73ee73bc8a80d01cea58a1e5ded0d440ef Mon Sep 17 00:00:00 2001 From: "A. Gideonse" Date: Sun, 29 Nov 2026 09:25:04 +0100 Subject: [PATCH] Fix heating states values for Indevolt devices (#194975) --- .../components/indevolt/binary_sensor.py | 12 +++++ tests/components/indevolt/fixtures/gen_2.json | 12 ++--- .../indevolt/snapshots/test_diagnostics.ambr | 12 ++--- .../components/indevolt/test_binary_sensor.py | 48 +++++++++++++++++++ 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/indevolt/binary_sensor.py b/homeassistant/components/indevolt/binary_sensor.py index e91b3dfb7cd5..bff9ced232f4 100644 --- a/homeassistant/components/indevolt/binary_sensor.py +++ b/homeassistant/components/indevolt/binary_sensor.py @@ -49,6 +49,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.MAIN_HEATING_STATE, generation=(2,), + on_value=1, + off_value=0, translation_key="main_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -56,6 +58,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.PACK_1_HEATING_STATE, generation=(2,), + on_value=1, + off_value=0, translation_key="battery_pack_1_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -63,6 +67,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.PACK_2_HEATING_STATE, generation=(2,), + on_value=1, + off_value=0, translation_key="battery_pack_2_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -70,6 +76,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.PACK_3_HEATING_STATE, generation=(2,), + on_value=1, + off_value=0, translation_key="battery_pack_3_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -77,6 +85,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.PACK_4_HEATING_STATE, generation=(2,), + on_value=1, + off_value=0, translation_key="battery_pack_4_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -84,6 +94,8 @@ BINARY_SENSORS: Final = ( IndevoltBinarySensorEntityDescription( key=IndevoltBattery.PACK_5_HEATING_STATE, generation=(2,), + on_value=1001, + off_value=1000, translation_key="battery_pack_5_electric_heating_state", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, diff --git a/tests/components/indevolt/fixtures/gen_2.json b/tests/components/indevolt/fixtures/gen_2.json index 01723ac2271c..9b9de19692f4 100644 --- a/tests/components/indevolt/fixtures/gen_2.json +++ b/tests/components/indevolt/fixtures/gen_2.json @@ -24,12 +24,12 @@ "6006": 380.58, "6007": 338.07, "7120": 1001, - "9080": 1000, - "9096": 1000, - "9112": 1001, - "9128": 1000, - "9144": 1001, - "9279": 1000, + "9080": 1, + "9096": 1, + "9112": 0, + "9128": 1, + "9144": 0, + "9279": 1001, "11016": 0, "2600": 1200, "2612": 50.0, diff --git a/tests/components/indevolt/snapshots/test_diagnostics.ambr b/tests/components/indevolt/snapshots/test_diagnostics.ambr index 471bb8836931..9dfe7d670852 100644 --- a/tests/components/indevolt/snapshots/test_diagnostics.ambr +++ b/tests/components/indevolt/snapshots/test_diagnostics.ambr @@ -138,15 +138,15 @@ '9058': 51.1, '9068': 25.0, '9070': '**REDACTED**', - '9080': 1000, + '9080': 1, '9085': 31.5, - '9096': 1000, + '9096': 1, '9101': 32.8, - '9112': 1001, + '9112': 0, '9117': 31.9, - '9128': 1000, + '9128': 1, '9133': 33.0, - '9144': 1001, + '9144': 0, '9149': 94, '9152': 125, '9153': 51.4, @@ -158,7 +158,7 @@ '9216': 24.9, '9218': '**REDACTED**', '9270': 31.2, - '9279': 1000, + '9279': 1001, }), 'device': dict({ 'firmware_version': '1.2.3', diff --git a/tests/components/indevolt/test_binary_sensor.py b/tests/components/indevolt/test_binary_sensor.py index fcfb75766757..92aacb6ff253 100644 --- a/tests/components/indevolt/test_binary_sensor.py +++ b/tests/components/indevolt/test_binary_sensor.py @@ -4,6 +4,7 @@ from datetime import timedelta from unittest.mock import AsyncMock, patch from freezegun.api import FrozenDateTimeFactory +from indevolt_api import IndevoltBattery import pytest from pytest_homeassistant.common import ( MockConfigEntry, @@ -32,6 +33,15 @@ METER_DISCONNECTED_VALUE = 1001 ENTITY_ID_GEN2 = "binary_sensor.cms_sf2000_meter_connected" +HEATING_STATE_VALUES = ( + (IndevoltBattery.MAIN_HEATING_STATE, 1, 0), + (IndevoltBattery.PACK_1_HEATING_STATE, 1, 0), + (IndevoltBattery.PACK_2_HEATING_STATE, 1, 0), + (IndevoltBattery.PACK_3_HEATING_STATE, 1, 0), + (IndevoltBattery.PACK_4_HEATING_STATE, 1, 0), + (IndevoltBattery.PACK_5_HEATING_STATE, 1001, 1000), +) + @pytest.mark.usefixtures("entity_registry_enabled_by_default") @pytest.mark.parametrize("generation", [1, 2], indirect=True) @@ -87,6 +97,44 @@ async def test_meter_connected_state_changes( assert state.state == STATE_UNKNOWN +@pytest.mark.usefixtures("entity_registry_enabled_by_default") +@pytest.mark.parametrize("generation", [2], indirect=True) +@pytest.mark.parametrize(("key", "on_value", "off_value"), HEATING_STATE_VALUES) +async def test_heating_state_values( + hass: HomeAssistant, + mock_indevolt: AsyncMock, + mock_config_entry: MockConfigEntry, + entity_registry: er.EntityRegistry, + key: str, + on_value: int, + off_value: int, +) -> None: + """Test the device values used for heating state binary sensors.""" + await setup_integration(hass, mock_config_entry) + + entity_entry = next( + entry + for entry in er.async_entries_for_config_entry( + entity_registry, mock_config_entry.entry_id + ) + if entry.unique_id.endswith(key) + ) + + mock_indevolt.fetch_data.return_value[key] = on_value + await hass.config_entries.async_reload(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert (state := hass.states.get(entity_entry.entity_id)) is not None + assert state.state == STATE_ON + + mock_indevolt.fetch_data.return_value[key] = off_value + await hass.config_entries.async_reload(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert (state := hass.states.get(entity_entry.entity_id)) is not None + assert state.state == STATE_OFF + + @pytest.mark.usefixtures("entity_registry_enabled_by_default") @pytest.mark.parametrize("generation", [2], indirect=True) async def test_binary_sensor_availability(