From 13737ff2e65cd952f29407df3ba23ad176a4ecfc Mon Sep 17 00:00:00 2001 From: Sab44 <64696149+Sab44@users.noreply.github.com> Date: Mon, 23 Feb 2026 11:01:58 +0100 Subject: [PATCH 01/19] Bump librehardwaremonitor-api to version 1.10.1 (#163572) --- .../libre_hardware_monitor/manifest.json | 2 +- .../libre_hardware_monitor/sensor.py | 40 ++++++++++++++----- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../libre_hardware_monitor/test_sensor.py | 38 ++++++++++++------ 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/libre_hardware_monitor/manifest.json b/homeassistant/components/libre_hardware_monitor/manifest.json index 7a5873fec60ef..943f03c65791d 100644 --- a/homeassistant/components/libre_hardware_monitor/manifest.json +++ b/homeassistant/components/libre_hardware_monitor/manifest.json @@ -7,5 +7,5 @@ "integration_type": "device", "iot_class": "local_polling", "quality_scale": "silver", - "requirements": ["librehardwaremonitor-api==1.9.1"] + "requirements": ["librehardwaremonitor-api==1.10.1"] } diff --git a/homeassistant/components/libre_hardware_monitor/sensor.py b/homeassistant/components/libre_hardware_monitor/sensor.py index c56bb75fc1075..ad00ee35aeaba 100644 --- a/homeassistant/components/libre_hardware_monitor/sensor.py +++ b/homeassistant/components/libre_hardware_monitor/sensor.py @@ -5,6 +5,7 @@ from typing import Any from librehardwaremonitor_api.model import LibreHardwareMonitorSensorData +from librehardwaremonitor_api.sensor_type import SensorType from homeassistant.components.sensor import SensorEntity, SensorStateClass from homeassistant.core import HomeAssistant, callback @@ -53,12 +54,8 @@ def __init__( super().__init__(coordinator) self._attr_name: str = sensor_data.name - self._attr_native_value: str | None = sensor_data.value - self._attr_extra_state_attributes: dict[str, Any] = { - STATE_MIN_VALUE: sensor_data.min, - STATE_MAX_VALUE: sensor_data.max, - } - self._attr_native_unit_of_measurement = sensor_data.unit + + self._set_state(coordinator.data.is_deprecated_version, sensor_data) self._attr_unique_id: str = f"{entry_id}_{sensor_data.sensor_id}" self._sensor_id: str = sensor_data.sensor_id @@ -70,15 +67,36 @@ def __init__( model=sensor_data.device_type, ) + def _set_state( + self, + is_deprecated_lhm_version: bool, + sensor_data: LibreHardwareMonitorSensorData, + ) -> None: + value = sensor_data.value + min_value = sensor_data.min + max_value = sensor_data.max + unit = sensor_data.unit + + if not is_deprecated_lhm_version and sensor_data.type == SensorType.THROUGHPUT: + # Temporary fix: convert the B/s value to KB/s to not break existing entries + # This will be migrated properly once SensorDeviceClass is introduced + value = f"{(float(value) / 1024):.1f}" if value else None + min_value = f"{(float(min_value) / 1024):.1f}" if min_value else None + max_value = f"{(float(max_value) / 1024):.1f}" if max_value else None + unit = "KB/s" + + self._attr_native_value: str | None = value + self._attr_extra_state_attributes: dict[str, Any] = { + STATE_MIN_VALUE: min_value, + STATE_MAX_VALUE: max_value, + } + self._attr_native_unit_of_measurement = unit + @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" if sensor_data := self.coordinator.data.sensor_data.get(self._sensor_id): - self._attr_native_value = sensor_data.value - self._attr_extra_state_attributes = { - STATE_MIN_VALUE: sensor_data.min, - STATE_MAX_VALUE: sensor_data.max, - } + self._set_state(self.coordinator.data.is_deprecated_version, sensor_data) else: self._attr_native_value = None diff --git a/requirements_all.txt b/requirements_all.txt index f527122145139..e469254aaf5a1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1416,7 +1416,7 @@ libpyfoscamcgi==0.0.9 libpyvivotek==0.6.1 # homeassistant.components.libre_hardware_monitor -librehardwaremonitor-api==1.9.1 +librehardwaremonitor-api==1.10.1 # homeassistant.components.mikrotik librouteros==3.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3b9d9810f4169..21cbf4d8c5743 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1250,7 +1250,7 @@ libpyfoscamcgi==0.0.9 libpyvivotek==0.6.1 # homeassistant.components.libre_hardware_monitor -librehardwaremonitor-api==1.9.1 +librehardwaremonitor-api==1.10.1 # homeassistant.components.mikrotik librouteros==3.2.0 diff --git a/tests/components/libre_hardware_monitor/test_sensor.py b/tests/components/libre_hardware_monitor/test_sensor.py index 8f4db123a493a..8f62f716234d5 100644 --- a/tests/components/libre_hardware_monitor/test_sensor.py +++ b/tests/components/libre_hardware_monitor/test_sensor.py @@ -130,26 +130,38 @@ async def test_sensor_invalid_auth_during_startup( assert all(state.state == STATE_UNAVAILABLE for state in unavailable_states) +@pytest.mark.parametrize( + ("object_id", "sensor_id", "new_value", "state_value"), + [ + ( + "gaming_pc_amd_ryzen_7_7800x3d_package_temperature", + "amdcpu-0-temperature-3", + "42.1", + "42.1", + ), + ( + "gaming_pc_nvidia_geforce_rtx_4080_super_gpu_pcie_tx_throughput", + "gpu-nvidia-0-throughput-1", + "792150000.0", + "773584.0", + ), + ], +) async def test_sensors_are_updated( hass: HomeAssistant, mock_lhm_client: AsyncMock, mock_config_entry: MockConfigEntry, freezer: FrozenDateTimeFactory, + object_id: str, + sensor_id: str, + new_value: str, + state_value: str, ) -> None: """Test sensors are updated with properly formatted values.""" await init_integration(hass, mock_config_entry) - entity_id = "sensor.gaming_pc_amd_ryzen_7_7800x3d_package_temperature" - state = hass.states.get(entity_id) - - assert state - assert state.state != STATE_UNAVAILABLE - assert state.state == "52.8" - updated_data = dict(mock_lhm_client.get_data.return_value.sensor_data) - updated_data["amdcpu-0-temperature-3"] = replace( - updated_data["amdcpu-0-temperature-3"], value="42.1" - ) + updated_data[sensor_id] = replace(updated_data[sensor_id], value=new_value) mock_lhm_client.get_data.return_value = replace( mock_lhm_client.get_data.return_value, sensor_data=MappingProxyType(updated_data), @@ -159,11 +171,11 @@ async def test_sensors_are_updated( async_fire_time_changed(hass) await hass.async_block_till_done() - state = hass.states.get(entity_id) + state = hass.states.get(f"sensor.{object_id}") assert state assert state.state != STATE_UNAVAILABLE - assert state.state == "42.1" + assert state.state == state_value async def test_sensor_state_is_unknown_when_no_sensor_data_is_provided( @@ -263,6 +275,7 @@ async def _mock_orphaned_device( if not sensor_id.startswith(removed_device) } ), + is_deprecated_version=False, ) return device_registry.async_get_or_create( @@ -287,6 +300,7 @@ async def test_integration_does_not_log_new_devices_on_first_refresh( } ), sensor_data=mock_lhm_client.get_data.return_value.sensor_data, + is_deprecated_version=False, ) with caplog.at_level(logging.WARNING): From 99bd66194d8e8d392b25b6af6f90fdd4bf678420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Mon, 23 Feb 2026 11:33:57 +0100 Subject: [PATCH 02/19] Add allow_none_value=True to MatterDiscoverySchema for electrical power attributes (#163195) Co-authored-by: TheJulianJES --- homeassistant/components/matter/sensor.py | 8 + .../matter/snapshots/test_sensor.ambr | 1376 ++++++++++++++--- tests/components/matter/test_sensor.py | 15 + 3 files changed, 1161 insertions(+), 238 deletions(-) diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index ac24ab7672462..b6965a5108b94 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -908,6 +908,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.ApparentPower, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -924,6 +925,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.ReactivePower, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -939,6 +941,7 @@ def _update_from_device(self) -> None: ), entity_class=MatterSensor, required_attributes=(clusters.ElectricalPowerMeasurement.Attributes.Voltage,), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -956,6 +959,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.RMSVoltage, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -973,6 +977,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.ApparentCurrent, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -990,6 +995,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.ActiveCurrent, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -1007,6 +1013,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.ReactiveCurrent, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -1024,6 +1031,7 @@ def _update_from_device(self) -> None: required_attributes=( clusters.ElectricalPowerMeasurement.Attributes.RMSCurrent, ), + allow_none_value=True, ), MatterDiscoverySchema( platform=Platform.SENSOR, diff --git a/tests/components/matter/snapshots/test_sensor.ambr b/tests/components/matter/snapshots/test_sensor.ambr index 211c85b3cacd3..dab69776fc166 100644 --- a/tests/components/matter/snapshots/test_sensor.ambr +++ b/tests/components/matter/snapshots/test_sensor.ambr @@ -1639,6 +1639,66 @@ 'state': '27.73', }) # --- +# name: test_sensors[aqara_thermostat_w500][sensor.floor_heating_thermostat_active_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.floor_heating_thermostat_active_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Active current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Active current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'active_current', + 'unique_id': '00000000000004D2-0000000000000064-MatterNodeDevice-0-ElectricalPowerMeasurementActiveCurrent-144-5', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[aqara_thermostat_w500][sensor.floor_heating_thermostat_active_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'Floor Heating Thermostat Active current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.floor_heating_thermostat_active_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_sensors[aqara_thermostat_w500][sensor.floor_heating_thermostat_energy-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -11661,19 +11721,13 @@ 'state': '0.0', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_appliance_energy_state-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_active_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ - 'options': list([ - 'offline', - 'online', - 'fault', - 'power_adjust_active', - 'paused', - ]), + 'state_class': , }), 'config_entry_id': , 'config_subentry_id': , @@ -11682,7 +11736,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_appliance_energy_state', + 'entity_id': 'sensor.evse_active_current', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -11690,43 +11744,44 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Appliance energy state', + 'object_id_base': 'Active current', 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'Appliance energy state', + 'original_name': 'Active current', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'esa_state', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ESAState-152-2', - 'unit_of_measurement': None, + 'translation_key': 'active_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementActiveCurrent-144-5', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_appliance_energy_state-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_active_current-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'enum', - 'friendly_name': 'evse Appliance energy state', - 'options': list([ - 'offline', - 'online', - 'fault', - 'power_adjust_active', - 'paused', - ]), + 'device_class': 'current', + 'friendly_name': 'evse Active current', + 'state_class': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_appliance_energy_state', + 'entity_id': 'sensor.evse_active_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'online', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_circuit_capacity-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_apparent_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -11741,7 +11796,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_circuit_capacity', + 'entity_id': 'sensor.evse_apparent_current', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -11749,7 +11804,7 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Circuit capacity', + 'object_id_base': 'Apparent current', 'options': dict({ 'sensor': dict({ 'suggested_display_precision': 2, @@ -11760,44 +11815,39 @@ }), 'original_device_class': , 'original_icon': None, - 'original_name': 'Circuit capacity', + 'original_name': 'Apparent current', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_circuit_capacity', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseCircuitCapacity-153-5', + 'translation_key': 'apparent_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementApparentCurrent-144-7', 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_circuit_capacity-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_apparent_current-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'current', - 'friendly_name': 'evse Circuit capacity', + 'friendly_name': 'evse Apparent current', 'state_class': , 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_circuit_capacity', + 'entity_id': 'sensor.evse_apparent_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '32.0', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_energy_optimization_opt_out-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_apparent_power-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ - 'options': list([ - 'no_opt_out', - 'local_opt_out', - 'grid_opt_out', - 'opt_out', - ]), + 'state_class': , }), 'config_entry_id': , 'config_subentry_id': , @@ -11806,7 +11856,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_energy_optimization_opt_out', + 'entity_id': 'sensor.evse_apparent_power', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -11814,64 +11864,55 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Energy optimization opt-out', + 'object_id_base': 'Apparent power', 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'Energy optimization opt-out', + 'original_name': 'Apparent power', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'esa_opt_out_state', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ESAOptOutState-152-7', - 'unit_of_measurement': None, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementApparentPower-144-10', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_energy_optimization_opt_out-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_apparent_power-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'enum', - 'friendly_name': 'evse Energy optimization opt-out', - 'options': list([ - 'no_opt_out', - 'local_opt_out', - 'grid_opt_out', - 'opt_out', - ]), + 'device_class': 'apparent_power', + 'friendly_name': 'evse Apparent power', + 'state_class': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_energy_optimization_opt_out', + 'entity_id': 'sensor.evse_apparent_power', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'no_opt_out', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_fault_state-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_appliance_energy_state-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ 'options': list([ - 'no_error', - 'meter_failure', - 'over_voltage', - 'under_voltage', - 'over_current', - 'contact_wet_failure', - 'contact_dry_failure', - 'power_loss', - 'power_quality', - 'pilot_short_circuit', - 'emergency_stop', - 'ev_disconnected', - 'wrong_power_supply', - 'live_neutral_swap', - 'over_temperature', - 'other', + 'offline', + 'online', + 'fault', + 'power_adjust_active', + 'paused', ]), }), 'config_entry_id': , @@ -11881,7 +11922,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_fault_state', + 'entity_id': 'sensor.evse_appliance_energy_state', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -11889,54 +11930,43 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Fault state', + 'object_id_base': 'Appliance energy state', 'options': dict({ }), 'original_device_class': , 'original_icon': None, - 'original_name': 'Fault state', + 'original_name': 'Appliance energy state', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_fault_state', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseFaultState-153-2', + 'translation_key': 'esa_state', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ESAState-152-2', 'unit_of_measurement': None, }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_fault_state-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_appliance_energy_state-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'enum', - 'friendly_name': 'evse Fault state', + 'friendly_name': 'evse Appliance energy state', 'options': list([ - 'no_error', - 'meter_failure', - 'over_voltage', - 'under_voltage', - 'over_current', - 'contact_wet_failure', - 'contact_dry_failure', - 'power_loss', - 'power_quality', - 'pilot_short_circuit', - 'emergency_stop', - 'ev_disconnected', - 'wrong_power_supply', - 'live_neutral_swap', - 'over_temperature', - 'other', + 'offline', + 'online', + 'fault', + 'power_adjust_active', + 'paused', ]), }), 'context': , - 'entity_id': 'sensor.evse_fault_state', + 'entity_id': 'sensor.evse_appliance_energy_state', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'no_error', + 'state': 'online', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_max_charge_current-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_circuit_capacity-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -11951,7 +11981,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_max_charge_current', + 'entity_id': 'sensor.evse_circuit_capacity', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -11959,7 +11989,7 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Max charge current', + 'object_id_base': 'Circuit capacity', 'options': dict({ 'sensor': dict({ 'suggested_display_precision': 2, @@ -11970,33 +12000,33 @@ }), 'original_device_class': , 'original_icon': None, - 'original_name': 'Max charge current', + 'original_name': 'Circuit capacity', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_max_charge_current', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseMaximumChargeCurrent-153-7', + 'translation_key': 'evse_circuit_capacity', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseCircuitCapacity-153-5', 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_max_charge_current-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_circuit_capacity-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'current', - 'friendly_name': 'evse Max charge current', + 'friendly_name': 'evse Circuit capacity', 'state_class': , 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_max_charge_current', + 'entity_id': 'sensor.evse_circuit_capacity', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '30.0', + 'state': '32.0', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_min_charge_current-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_effective_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -12011,7 +12041,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.evse_min_charge_current', + 'entity_id': 'sensor.evse_effective_current', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12019,7 +12049,7 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Min charge current', + 'object_id_base': 'Effective current', 'options': dict({ 'sensor': dict({ 'suggested_display_precision': 2, @@ -12030,33 +12060,33 @@ }), 'original_device_class': , 'original_icon': None, - 'original_name': 'Min charge current', + 'original_name': 'Effective current', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_min_charge_current', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseMinimumChargeCurrent-153-6', + 'translation_key': 'rms_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementRMSCurrent-144-12', 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_min_charge_current-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_effective_current-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'current', - 'friendly_name': 'evse Min charge current', + 'friendly_name': 'evse Effective current', 'state_class': , 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_min_charge_current', + 'entity_id': 'sensor.evse_effective_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '2.0', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_state_of_charge-entry] +# name: test_sensors[silabs_evse_charging][sensor.evse_effective_voltage-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -12070,8 +12100,8 @@ 'device_id': , 'disabled_by': None, 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.evse_state_of_charge', + 'entity_category': , + 'entity_id': 'sensor.evse_effective_voltage', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12079,18 +12109,468 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'State of charge', + 'object_id_base': 'Effective voltage', 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'State of charge', + 'original_name': 'Effective voltage', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_soc', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseStateOfCharge-153-48', + 'translation_key': 'rms_voltage', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementRMSVoltage-144-11', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_effective_voltage-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'voltage', + 'friendly_name': 'evse Effective voltage', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_effective_voltage', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy_optimization_opt_out-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'no_opt_out', + 'local_opt_out', + 'grid_opt_out', + 'opt_out', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_energy_optimization_opt_out', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy optimization opt-out', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy optimization opt-out', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'esa_opt_out_state', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ESAOptOutState-152-7', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy_optimization_opt_out-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'evse Energy optimization opt-out', + 'options': list([ + 'no_opt_out', + 'local_opt_out', + 'grid_opt_out', + 'opt_out', + ]), + }), + 'context': , + 'entity_id': 'sensor.evse_energy_optimization_opt_out', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'no_opt_out', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_fault_state-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'no_error', + 'meter_failure', + 'over_voltage', + 'under_voltage', + 'over_current', + 'contact_wet_failure', + 'contact_dry_failure', + 'power_loss', + 'power_quality', + 'pilot_short_circuit', + 'emergency_stop', + 'ev_disconnected', + 'wrong_power_supply', + 'live_neutral_swap', + 'over_temperature', + 'other', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_fault_state', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Fault state', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Fault state', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'evse_fault_state', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseFaultState-153-2', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_fault_state-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'evse Fault state', + 'options': list([ + 'no_error', + 'meter_failure', + 'over_voltage', + 'under_voltage', + 'over_current', + 'contact_wet_failure', + 'contact_dry_failure', + 'power_loss', + 'power_quality', + 'pilot_short_circuit', + 'emergency_stop', + 'ev_disconnected', + 'wrong_power_supply', + 'live_neutral_swap', + 'over_temperature', + 'other', + ]), + }), + 'context': , + 'entity_id': 'sensor.evse_fault_state', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'no_error', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_max_charge_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_max_charge_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Max charge current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Max charge current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'evse_max_charge_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseMaximumChargeCurrent-153-7', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_max_charge_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'evse Max charge current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_max_charge_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '30.0', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_min_charge_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_min_charge_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Min charge current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Min charge current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'evse_min_charge_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseMinimumChargeCurrent-153-6', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_min_charge_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'evse Min charge current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_min_charge_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2.0', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_reactive_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_reactive_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Reactive current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Reactive current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'reactive_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementReactiveCurrent-144-6', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_reactive_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'evse Reactive current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_reactive_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_reactive_power-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_reactive_power', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Reactive power', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Reactive power', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementReactivePower-144-9', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_reactive_power-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'reactive_power', + 'friendly_name': 'evse Reactive power', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_reactive_power', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_state_of_charge-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.evse_state_of_charge', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'State of charge', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'State of charge', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'evse_soc', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseStateOfCharge-153-48', 'unit_of_measurement': '%', }) # --- @@ -12133,41 +12613,101 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'User max charge current', + 'object_id_base': 'User max charge current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'User max charge current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'evse_user_max_charge_current', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseUserMaximumChargeCurrent-153-9', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_user_max_charge_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'evse User max charge current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_user_max_charge_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '32.0', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_voltage-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_voltage', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Voltage', 'options': dict({ 'sensor': dict({ - 'suggested_display_precision': 2, + 'suggested_display_precision': 0, }), 'sensor.private': dict({ - 'suggested_unit_of_measurement': , + 'suggested_unit_of_measurement': , }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'User max charge current', + 'original_name': 'Voltage', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'evse_user_max_charge_current', - 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-EnergyEvseUserMaximumChargeCurrent-153-9', - 'unit_of_measurement': , + 'translation_key': 'voltage', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalPowerMeasurementVoltage-144-4', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_evse_charging][sensor.evse_user_max_charge_current-state] +# name: test_sensors[silabs_evse_charging][sensor.evse_voltage-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'current', - 'friendly_name': 'evse User max charge current', + 'device_class': 'voltage', + 'friendly_name': 'evse Voltage', 'state_class': , - 'unit_of_measurement': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.evse_user_max_charge_current', + 'entity_id': 'sensor.evse_voltage', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '32.0', + 'state': 'unknown', }) # --- # name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_current_phase-entry] @@ -12467,25 +13007,255 @@ ]), }), 'context': , - 'entity_id': 'sensor.laundrywasher_operational_error', + 'entity_id': 'sensor.laundrywasher_operational_error', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'no_error', + }) +# --- +# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_operational_state-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'stopped', + 'running', + 'paused', + 'error', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.laundrywasher_operational_state', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Operational state', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Operational state', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'operational_state', + 'unique_id': '00000000000004D2-0000000000000038-MatterNodeDevice-1-OperationalState-96-4', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_operational_state-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'LaundryWasher Operational state', + 'options': list([ + 'stopped', + 'running', + 'paused', + 'error', + ]), + }), + 'context': , + 'entity_id': 'sensor.laundrywasher_operational_state', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'stopped', + }) +# --- +# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_power-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.laundrywasher_power', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Power', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Power', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000038-MatterNodeDevice-2-ElectricalPowerMeasurementWatt-144-8', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_power-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'power', + 'friendly_name': 'LaundryWasher Power', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.laundrywasher_power', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0.0', + }) +# --- +# name: test_sensors[silabs_light_switch][sensor.light_switch_example_current_switch_position-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.light_switch_example_current_switch_position', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Current switch position', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Current switch position', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'switch_current_position', + 'unique_id': '00000000000004D2-000000000000008E-MatterNodeDevice-2-SwitchCurrentPosition-59-1', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[silabs_light_switch][sensor.light_switch_example_current_switch_position-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Light switch example Current switch position', + 'state_class': , + }), + 'context': , + 'entity_id': 'sensor.light_switch_example_current_switch_position', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_active_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.water_heater_active_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Active current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Active current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'active_current', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementActiveCurrent-144-5', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_active_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'Water Heater Active current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.water_heater_active_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'no_error', + 'state': '0.1', }) # --- -# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_operational_state-entry] +# name: test_sensors[silabs_water_heater][sensor.water_heater_apparent_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ - 'options': list([ - 'stopped', - 'running', - 'paused', - 'error', - ]), + 'state_class': , }), 'config_entry_id': , 'config_subentry_id': , @@ -12493,8 +13263,8 @@ 'device_id': , 'disabled_by': None, 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.laundrywasher_operational_state', + 'entity_category': , + 'entity_id': 'sensor.water_heater_apparent_current', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12502,42 +13272,44 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Operational state', + 'object_id_base': 'Apparent current', 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'Operational state', + 'original_name': 'Apparent current', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'operational_state', - 'unique_id': '00000000000004D2-0000000000000038-MatterNodeDevice-1-OperationalState-96-4', - 'unit_of_measurement': None, + 'translation_key': 'apparent_current', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementApparentCurrent-144-7', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_operational_state-state] +# name: test_sensors[silabs_water_heater][sensor.water_heater_apparent_current-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'enum', - 'friendly_name': 'LaundryWasher Operational state', - 'options': list([ - 'stopped', - 'running', - 'paused', - 'error', - ]), + 'device_class': 'current', + 'friendly_name': 'Water Heater Apparent current', + 'state_class': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.laundrywasher_operational_state', + 'entity_id': 'sensor.water_heater_apparent_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'stopped', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_power-entry] +# name: test_sensors[silabs_water_heater][sensor.water_heater_apparent_power-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -12552,7 +13324,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.laundrywasher_power', + 'entity_id': 'sensor.water_heater_apparent_power', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12560,50 +13332,56 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Power', + 'object_id_base': 'Apparent power', 'options': dict({ 'sensor': dict({ 'suggested_display_precision': 2, }), 'sensor.private': dict({ - 'suggested_unit_of_measurement': , + 'suggested_unit_of_measurement': , }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'Power', + 'original_name': 'Apparent power', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, 'translation_key': None, - 'unique_id': '00000000000004D2-0000000000000038-MatterNodeDevice-2-ElectricalPowerMeasurementWatt-144-8', - 'unit_of_measurement': , + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementApparentPower-144-10', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_laundrywasher][sensor.laundrywasher_power-state] +# name: test_sensors[silabs_water_heater][sensor.water_heater_apparent_power-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'power', - 'friendly_name': 'LaundryWasher Power', + 'device_class': 'apparent_power', + 'friendly_name': 'Water Heater Apparent power', 'state_class': , - 'unit_of_measurement': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.laundrywasher_power', + 'entity_id': 'sensor.water_heater_apparent_power', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '0.0', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_light_switch][sensor.light_switch_example_current_switch_position-entry] +# name: test_sensors[silabs_water_heater][sensor.water_heater_appliance_energy_state-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ - 'state_class': , + 'options': list([ + 'offline', + 'online', + 'fault', + 'power_adjust_active', + 'paused', + ]), }), 'config_entry_id': , 'config_subentry_id': , @@ -12612,7 +13390,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.light_switch_example_current_switch_position', + 'entity_id': 'sensor.water_heater_appliance_energy_state', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12620,36 +13398,43 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Current switch position', + 'object_id_base': 'Appliance energy state', 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, - 'original_name': 'Current switch position', + 'original_name': 'Appliance energy state', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'switch_current_position', - 'unique_id': '00000000000004D2-000000000000008E-MatterNodeDevice-2-SwitchCurrentPosition-59-1', + 'translation_key': 'esa_state', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ESAState-152-2', 'unit_of_measurement': None, }) # --- -# name: test_sensors[silabs_light_switch][sensor.light_switch_example_current_switch_position-state] +# name: test_sensors[silabs_water_heater][sensor.water_heater_appliance_energy_state-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'friendly_name': 'Light switch example Current switch position', - 'state_class': , + 'device_class': 'enum', + 'friendly_name': 'Water Heater Appliance energy state', + 'options': list([ + 'offline', + 'online', + 'fault', + 'power_adjust_active', + 'paused', + ]), }), 'context': , - 'entity_id': 'sensor.light_switch_example_current_switch_position', + 'entity_id': 'sensor.water_heater_appliance_energy_state', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '0', + 'state': 'online', }) # --- -# name: test_sensors[silabs_water_heater][sensor.water_heater_active_current-entry] +# name: test_sensors[silabs_water_heater][sensor.water_heater_effective_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -12664,7 +13449,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.water_heater_active_current', + 'entity_id': 'sensor.water_heater_effective_current', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12672,7 +13457,7 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Active current', + 'object_id_base': 'Effective current', 'options': dict({ 'sensor': dict({ 'suggested_display_precision': 2, @@ -12683,45 +13468,39 @@ }), 'original_device_class': , 'original_icon': None, - 'original_name': 'Active current', + 'original_name': 'Effective current', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'active_current', - 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementActiveCurrent-144-5', + 'translation_key': 'rms_current', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementRMSCurrent-144-12', 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_water_heater][sensor.water_heater_active_current-state] +# name: test_sensors[silabs_water_heater][sensor.water_heater_effective_current-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'current', - 'friendly_name': 'Water Heater Active current', + 'friendly_name': 'Water Heater Effective current', 'state_class': , 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.water_heater_active_current', + 'entity_id': 'sensor.water_heater_effective_current', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '0.1', + 'state': 'unknown', }) # --- -# name: test_sensors[silabs_water_heater][sensor.water_heater_appliance_energy_state-entry] +# name: test_sensors[silabs_water_heater][sensor.water_heater_effective_voltage-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), 'area_id': None, 'capabilities': dict({ - 'options': list([ - 'offline', - 'online', - 'fault', - 'power_adjust_active', - 'paused', - ]), + 'state_class': , }), 'config_entry_id': , 'config_subentry_id': , @@ -12730,7 +13509,7 @@ 'disabled_by': None, 'domain': 'sensor', 'entity_category': , - 'entity_id': 'sensor.water_heater_appliance_energy_state', + 'entity_id': 'sensor.water_heater_effective_voltage', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -12738,40 +13517,41 @@ 'labels': set({ }), 'name': None, - 'object_id_base': 'Appliance energy state', + 'object_id_base': 'Effective voltage', 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 0, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': , + 'original_device_class': , 'original_icon': None, - 'original_name': 'Appliance energy state', + 'original_name': 'Effective voltage', 'platform': 'matter', 'previous_unique_id': None, 'suggested_object_id': None, 'supported_features': 0, - 'translation_key': 'esa_state', - 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ESAState-152-2', - 'unit_of_measurement': None, + 'translation_key': 'rms_voltage', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementRMSVoltage-144-11', + 'unit_of_measurement': , }) # --- -# name: test_sensors[silabs_water_heater][sensor.water_heater_appliance_energy_state-state] +# name: test_sensors[silabs_water_heater][sensor.water_heater_effective_voltage-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'device_class': 'enum', - 'friendly_name': 'Water Heater Appliance energy state', - 'options': list([ - 'offline', - 'online', - 'fault', - 'power_adjust_active', - 'paused', - ]), + 'device_class': 'voltage', + 'friendly_name': 'Water Heater Effective voltage', + 'state_class': , + 'unit_of_measurement': , }), 'context': , - 'entity_id': 'sensor.water_heater_appliance_energy_state', + 'entity_id': 'sensor.water_heater_effective_voltage', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'online', + 'state': 'unknown', }) # --- # name: test_sensors[silabs_water_heater][sensor.water_heater_energy_optimization_opt_out-entry] @@ -12950,6 +13730,126 @@ 'state': '23.0', }) # --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_reactive_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.water_heater_reactive_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Reactive current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Reactive current', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'reactive_current', + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementReactiveCurrent-144-6', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_reactive_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'Water Heater Reactive current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.water_heater_reactive_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_reactive_power-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.water_heater_reactive_power', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Reactive power', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Reactive power', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalPowerMeasurementReactivePower-144-9', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_reactive_power-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'reactive_power', + 'friendly_name': 'Water Heater Reactive power', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.water_heater_reactive_power', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_sensors[silabs_water_heater][sensor.water_heater_required_heating_energy-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/test_sensor.py b/tests/components/matter/test_sensor.py index 1b9768e54c5f2..4657931a0d790 100644 --- a/tests/components/matter/test_sensor.py +++ b/tests/components/matter/test_sensor.py @@ -824,3 +824,18 @@ async def test_valve( state = hass.states.get("sensor.mock_valve_auto_close_time") assert state assert state.state == "unknown" + + +@pytest.mark.parametrize("node_fixture", ["aqara_thermostat_w500"]) +async def test_aqara_thermostat_w500_entity_exists_and_unknown( + hass: HomeAssistant, + matter_client: MagicMock, + matter_node: MatterNode, +) -> None: + """Ensure the Aqara W500 entity is created and its state is unknown. + + This test helps prevent regressions if allow_none_value=True is removed. + """ + state = hass.states.get("sensor.floor_heating_thermostat_active_current") + assert state is not None + assert state.state == "unknown" From ea71c40b0a964abdc736595a1e2ba55f07f2a3b8 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Mon, 23 Feb 2026 11:45:55 +0100 Subject: [PATCH 03/19] Bump deebot-client to 18.0.0 (#163835) --- homeassistant/components/ecovacs/manifest.json | 2 +- homeassistant/components/ecovacs/vacuum.py | 6 +++--- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/ecovacs/manifest.json b/homeassistant/components/ecovacs/manifest.json index 424be24f529fc..abfa385e95bc2 100644 --- a/homeassistant/components/ecovacs/manifest.json +++ b/homeassistant/components/ecovacs/manifest.json @@ -7,5 +7,5 @@ "integration_type": "hub", "iot_class": "cloud_push", "loggers": ["sleekxmppfs", "sucks", "deebot_client"], - "requirements": ["py-sucks==0.9.11", "deebot-client==17.1.0"] + "requirements": ["py-sucks==0.9.11", "deebot-client==18.0.0"] } diff --git a/homeassistant/components/ecovacs/vacuum.py b/homeassistant/components/ecovacs/vacuum.py index 77d0093fb3b13..bfa1f164bf561 100644 --- a/homeassistant/components/ecovacs/vacuum.py +++ b/homeassistant/components/ecovacs/vacuum.py @@ -338,11 +338,11 @@ async def async_send_command( translation_placeholders={"name": name}, ) - if command in "spot_area": + if command == "spot_area": await self._device.execute_command( self._capability.clean.action.area( CleanMode.SPOT_AREA, - str(params["rooms"]), + params["rooms"], params.get("cleanings", 1), ) ) @@ -350,7 +350,7 @@ async def async_send_command( await self._device.execute_command( self._capability.clean.action.area( CleanMode.CUSTOM_AREA, - str(params["coordinates"]), + params["coordinates"], params.get("cleanings", 1), ) ) diff --git a/requirements_all.txt b/requirements_all.txt index e469254aaf5a1..53fc5143fc627 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -787,7 +787,7 @@ debugpy==1.8.17 decora-wifi==1.4 # homeassistant.components.ecovacs -deebot-client==17.1.0 +deebot-client==18.0.0 # homeassistant.components.ihc # homeassistant.components.ohmconnect diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 21cbf4d8c5743..7c086b3ec2cf4 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -696,7 +696,7 @@ dbus-fast==3.1.2 debugpy==1.8.17 # homeassistant.components.ecovacs -deebot-client==17.1.0 +deebot-client==18.0.0 # homeassistant.components.ihc # homeassistant.components.ohmconnect From 85eeac6812e9a1c3e20d81785c9b72344315fe32 Mon Sep 17 00:00:00 2001 From: kshypachov <128974084+kshypachov@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:52:05 +0200 Subject: [PATCH 04/19] Fix Matter energy sensor discovery when value is null (#162044) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ludovic BOUÉ --- homeassistant/components/matter/sensor.py | 2 + .../matter/snapshots/test_sensor.ambr | 180 ++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index b6965a5108b94..6a0273e05bba0 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -1047,6 +1047,7 @@ def _update_from_device(self) -> None: device_to_ha=lambda x: x.energy, ), entity_class=MatterSensor, + allow_none_value=True, required_attributes=( clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported, ), @@ -1066,6 +1067,7 @@ def _update_from_device(self) -> None: device_to_ha=lambda x: x.energy, ), entity_class=MatterSensor, + allow_none_value=True, required_attributes=( clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyExported, ), diff --git a/tests/components/matter/snapshots/test_sensor.ambr b/tests/components/matter/snapshots/test_sensor.ambr index dab69776fc166..fd3465d7b2c56 100644 --- a/tests/components/matter/snapshots/test_sensor.ambr +++ b/tests/components/matter/snapshots/test_sensor.ambr @@ -12146,6 +12146,126 @@ 'state': 'unknown', }) # --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_energy', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 3, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalEnergyMeasurementCumulativeEnergyImported-145-1', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'evse Energy', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_energy', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy_exported-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.evse_energy_exported', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy exported', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 3, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy exported', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'energy_exported', + 'unique_id': '00000000000004D2-0000000000000017-MatterNodeDevice-1-ElectricalEnergyMeasurementCumulativeEnergyExported-145-2', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_evse_charging][sensor.evse_energy_exported-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'evse Energy exported', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.evse_energy_exported', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_sensors[silabs_evse_charging][sensor.evse_energy_optimization_opt_out-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -13554,6 +13674,66 @@ 'state': 'unknown', }) # --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_energy-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.water_heater_energy', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 3, + }), + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-0000000000000039-MatterNodeDevice-2-ElectricalEnergyMeasurementCumulativeEnergyImported-145-1', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[silabs_water_heater][sensor.water_heater_energy-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Water Heater Energy', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.water_heater_energy', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_sensors[silabs_water_heater][sensor.water_heater_energy_optimization_opt_out-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ From bd6b8a812cc94071d659ab8fc0da507451caa906 Mon Sep 17 00:00:00 2001 From: Karl Beecken Date: Mon, 23 Feb 2026 13:07:19 +0100 Subject: [PATCH 05/19] Teltonika integration: add reauth config flow (#163712) --- .../components/teltonika/config_flow.py | 60 ++++++++++ .../components/teltonika/coordinator.py | 43 ++++++- .../components/teltonika/quality_scale.yaml | 2 +- .../components/teltonika/strings.json | 12 ++ tests/components/teltonika/conftest.py | 1 + .../components/teltonika/test_config_flow.py | 112 ++++++++++++++++++ tests/components/teltonika/test_sensor.py | 99 +++++++++++++++- 7 files changed, 321 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/teltonika/config_flow.py b/homeassistant/components/teltonika/config_flow.py index 3af1d28620c14..2d6f06bc35d88 100644 --- a/homeassistant/components/teltonika/config_flow.py +++ b/homeassistant/components/teltonika/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations +from collections.abc import Mapping import logging from typing import Any @@ -126,6 +127,65 @@ async def async_step_user( step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors ) + async def async_step_reauth( + self, entry_data: Mapping[str, Any] + ) -> ConfigFlowResult: + """Handle reauth when authentication fails.""" + return await self.async_step_reauth_confirm() + + async def async_step_reauth_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle reauth confirmation.""" + errors: dict[str, str] = {} + reauth_entry = self._get_reauth_entry() + + if user_input is not None: + data = { + CONF_HOST: reauth_entry.data[CONF_HOST], + CONF_USERNAME: user_input[CONF_USERNAME], + CONF_PASSWORD: user_input[CONF_PASSWORD], + CONF_VERIFY_SSL: reauth_entry.data.get(CONF_VERIFY_SSL, False), + } + try: + # Validate new credentials against the configured host + info = await validate_input(self.hass, data) + except CannotConnect: + errors["base"] = "cannot_connect" + except InvalidAuth: + errors["base"] = "invalid_auth" + except Exception: + _LOGGER.exception("Unexpected exception during reauth") + errors["base"] = "unknown" + else: + # Verify reauth is for the same device + await self.async_set_unique_id(info["device_id"]) + self._abort_if_unique_id_mismatch(reason="wrong_account") + + return self.async_update_reload_and_abort( + reauth_entry, + data_updates=user_input, + ) + + reauth_schema = vol.Schema( + { + vol.Required(CONF_USERNAME): str, + vol.Required(CONF_PASSWORD): str, + } + ) + + suggested = {**reauth_entry.data, **(user_input or {})} + + return self.async_show_form( + step_id="reauth_confirm", + data_schema=self.add_suggested_values_to_schema(reauth_schema, suggested), + errors=errors, + description_placeholders={ + "name": reauth_entry.title, + "host": reauth_entry.data[CONF_HOST], + }, + ) + async def async_step_dhcp( self, discovery_info: DhcpServiceInfo ) -> ConfigFlowResult: diff --git a/homeassistant/components/teltonika/coordinator.py b/homeassistant/components/teltonika/coordinator.py index 0604ca4cd542d..7d1a614d1414e 100644 --- a/homeassistant/components/teltonika/coordinator.py +++ b/homeassistant/components/teltonika/coordinator.py @@ -8,10 +8,11 @@ from aiohttp import ClientResponseError, ContentTypeError from teltasync import Teltasync, TeltonikaAuthenticationError, TeltonikaConnectionError +from teltasync.error_codes import TeltonikaErrorCode from teltasync.modems import Modems from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady +from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -23,6 +24,13 @@ _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(seconds=30) +AUTH_ERROR_CODES = frozenset( + { + TeltonikaErrorCode.UNAUTHORIZED_ACCESS, + TeltonikaErrorCode.LOGIN_FAILED, + TeltonikaErrorCode.INVALID_JWT_TOKEN, + } +) class TeltonikaDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): @@ -54,12 +62,12 @@ async def _async_setup(self) -> None: await self.client.get_device_info() system_info_response = await self.client.get_system_info() except TeltonikaAuthenticationError as err: - raise ConfigEntryError(f"Authentication failed: {err}") from err + raise ConfigEntryAuthFailed(f"Authentication failed: {err}") from err except (ClientResponseError, ContentTypeError) as err: - if isinstance(err, ClientResponseError) and err.status in (401, 403): - raise ConfigEntryError(f"Authentication failed: {err}") from err - if isinstance(err, ContentTypeError) and err.status == 403: - raise ConfigEntryError(f"Authentication failed: {err}") from err + if (isinstance(err, ClientResponseError) and err.status in (401, 403)) or ( + isinstance(err, ContentTypeError) and err.status == 403 + ): + raise ConfigEntryAuthFailed(f"Authentication failed: {err}") from err raise ConfigEntryNotReady(f"Failed to connect to device: {err}") from err except TeltonikaConnectionError as err: raise ConfigEntryNotReady(f"Failed to connect to device: {err}") from err @@ -81,9 +89,32 @@ async def _async_update_data(self) -> dict[str, Any]: try: # Get modems data using the teltasync library modems_response = await modems.get_status() + except TeltonikaAuthenticationError as err: + raise ConfigEntryAuthFailed(f"Authentication failed: {err}") from err + except (ClientResponseError, ContentTypeError) as err: + if (isinstance(err, ClientResponseError) and err.status in (401, 403)) or ( + isinstance(err, ContentTypeError) and err.status == 403 + ): + raise ConfigEntryAuthFailed(f"Authentication failed: {err}") from err + raise UpdateFailed(f"Error communicating with device: {err}") from err except TeltonikaConnectionError as err: raise UpdateFailed(f"Error communicating with device: {err}") from err + if not modems_response.success: + if modems_response.errors and any( + error.code in AUTH_ERROR_CODES for error in modems_response.errors + ): + raise ConfigEntryAuthFailed( + "Authentication failed: unauthorized access" + ) + + error_message = ( + modems_response.errors[0].error + if modems_response.errors + else "Unknown API error" + ) + raise UpdateFailed(f"Error communicating with device: {error_message}") + # Return only modems which are online modem_data: dict[str, Any] = {} if modems_response.data: diff --git a/homeassistant/components/teltonika/quality_scale.yaml b/homeassistant/components/teltonika/quality_scale.yaml index 329aa7f7b7867..c6b7d6b23c7ab 100644 --- a/homeassistant/components/teltonika/quality_scale.yaml +++ b/homeassistant/components/teltonika/quality_scale.yaml @@ -36,7 +36,7 @@ rules: integration-owner: done log-when-unavailable: todo parallel-updates: done - reauthentication-flow: todo + reauthentication-flow: done test-coverage: todo # Gold diff --git a/homeassistant/components/teltonika/strings.json b/homeassistant/components/teltonika/strings.json index 954f648f2ddab..f775e620035c8 100644 --- a/homeassistant/components/teltonika/strings.json +++ b/homeassistant/components/teltonika/strings.json @@ -23,6 +23,18 @@ "description": "A Teltonika device ({name}) was discovered at {host}. Enter the credentials to add it to Home Assistant.", "title": "Discovered Teltonika device" }, + "reauth_confirm": { + "data": { + "password": "[%key:common::config_flow::data::password%]", + "username": "[%key:common::config_flow::data::username%]" + }, + "data_description": { + "password": "[%key:component::teltonika::config::step::dhcp_confirm::data_description::password%]", + "username": "[%key:component::teltonika::config::step::dhcp_confirm::data_description::username%]" + }, + "description": "Update the credentials for {name}. The current host is {host}.", + "title": "Authentication failed for {name}" + }, "user": { "data": { "host": "[%key:common::config_flow::data::host%]", diff --git a/tests/components/teltonika/conftest.py b/tests/components/teltonika/conftest.py index db90e8b8230b4..f33293847cbee 100644 --- a/tests/components/teltonika/conftest.py +++ b/tests/components/teltonika/conftest.py @@ -90,6 +90,7 @@ def mock_modems() -> Generator[AsyncMock]: ModemStatusFull(**modem) for modem in device_data["modems_data"] ] mock_modems_instance.get_status.return_value = response_mock + response_mock.success = True # Mock is_online to return True for the modem mock_modems_class.is_online = MagicMock(return_value=True) diff --git a/tests/components/teltonika/test_config_flow.py b/tests/components/teltonika/test_config_flow.py index f6e6b605409d0..582de543fcbc3 100644 --- a/tests/components/teltonika/test_config_flow.py +++ b/tests/components/teltonika/test_config_flow.py @@ -406,3 +406,115 @@ async def test_validate_credentials_false( assert result["type"] is FlowResultType.FORM assert result["errors"] == {"base": "invalid_auth"} + + +async def test_reauth_flow_success( + hass: HomeAssistant, + mock_teltasync_client: MagicMock, + mock_setup_entry: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test successful reauth flow.""" + mock_config_entry.add_to_hass(hass) + + result = await mock_config_entry.start_reauth_flow(hass) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "reauth_confirm" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: "admin", + CONF_PASSWORD: "new_password", + }, + ) + + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "reauth_successful" + assert mock_config_entry.data[CONF_USERNAME] == "admin" + assert mock_config_entry.data[CONF_PASSWORD] == "new_password" + assert mock_config_entry.data[CONF_HOST] == "192.168.1.1" + + +@pytest.mark.parametrize( + ("side_effect", "expected_error"), + [ + (TeltonikaAuthenticationError("Invalid credentials"), "invalid_auth"), + (TeltonikaConnectionError("Connection failed"), "cannot_connect"), + (ValueError("Unexpected error"), "unknown"), + ], + ids=["invalid_auth", "cannot_connect", "unexpected_exception"], +) +async def test_reauth_flow_errors_with_recovery( + hass: HomeAssistant, + mock_teltasync_client: MagicMock, + mock_setup_entry: AsyncMock, + mock_config_entry: MockConfigEntry, + side_effect: Exception, + expected_error: str, +) -> None: + """Test reauth flow error handling with successful recovery.""" + mock_config_entry.add_to_hass(hass) + result = await mock_config_entry.start_reauth_flow(hass) + + mock_teltasync_client.get_device_info.side_effect = side_effect + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: "admin", + CONF_PASSWORD: "bad_password", + }, + ) + + assert result["type"] is FlowResultType.FORM + assert result["errors"] == {"base": expected_error} + assert result["step_id"] == "reauth_confirm" + + mock_teltasync_client.get_device_info.side_effect = None + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: "admin", + CONF_PASSWORD: "new_password", + }, + ) + + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "reauth_successful" + assert mock_config_entry.data[CONF_USERNAME] == "admin" + assert mock_config_entry.data[CONF_PASSWORD] == "new_password" + assert mock_config_entry.data[CONF_HOST] == "192.168.1.1" + + +async def test_reauth_flow_wrong_account( + hass: HomeAssistant, + mock_teltasync_client: MagicMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test reauth flow aborts when device serial doesn't match.""" + mock_config_entry.add_to_hass(hass) + result = await mock_config_entry.start_reauth_flow(hass) + + device_info = MagicMock() + device_info.device_name = "RUTX50 Different" + device_info.device_identifier = "DIFFERENT1234567890" + mock_teltasync_client.get_device_info = AsyncMock(return_value=device_info) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: "admin", + CONF_PASSWORD: "password", + }, + ) + + await hass.async_block_till_done() + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "wrong_account" diff --git a/tests/components/teltonika/test_sensor.py b/tests/components/teltonika/test_sensor.py index 1d7b1b18d618e..65c306c957709 100644 --- a/tests/components/teltonika/test_sensor.py +++ b/tests/components/teltonika/test_sensor.py @@ -3,10 +3,15 @@ from datetime import timedelta from unittest.mock import AsyncMock, MagicMock +from aiohttp import ClientResponseError from freezegun.api import FrozenDateTimeFactory +import pytest from syrupy.assertion import SnapshotAssertion -from teltasync import TeltonikaConnectionError +from teltasync import TeltonikaAuthenticationError, TeltonikaConnectionError +from teltasync.error_codes import TeltonikaErrorCode +from homeassistant.components.teltonika.const import DOMAIN +from homeassistant.config_entries import SOURCE_REAUTH from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -91,3 +96,95 @@ async def test_sensor_update_failure_and_recovery( state = hass.states.get("sensor.rutx50_test_internal_modem_rssi") assert state is not None assert state.state == "-63" + + +@pytest.mark.parametrize( + ("side_effect", "expect_reauth"), + [ + (TeltonikaAuthenticationError("Invalid credentials"), True), + ( + ClientResponseError( + request_info=MagicMock(), + history=(), + status=401, + message="Unauthorized", + headers={}, + ), + True, + ), + ( + ClientResponseError( + request_info=MagicMock(), + history=(), + status=500, + message="Server error", + headers={}, + ), + False, + ), + ], + ids=["auth_exception", "http_auth_error", "http_non_auth_error"], +) +async def test_sensor_update_exception_paths( + hass: HomeAssistant, + mock_modems: AsyncMock, + init_integration: MockConfigEntry, + freezer: FrozenDateTimeFactory, + side_effect: Exception, + expect_reauth: bool, +) -> None: + """Test auth and non-auth exceptions during updates.""" + mock_modems.get_status.side_effect = side_effect + + freezer.tick(timedelta(seconds=31)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + state = hass.states.get("sensor.rutx50_test_internal_modem_rssi") + assert state is not None + assert state.state == "unavailable" + + has_reauth = any( + flow["handler"] == DOMAIN and flow["context"]["source"] == SOURCE_REAUTH + for flow in hass.config_entries.flow.async_progress() + ) + assert has_reauth is expect_reauth + + +@pytest.mark.parametrize( + ("error_code", "expect_reauth"), + [ + (TeltonikaErrorCode.UNAUTHORIZED_ACCESS, True), + (999, False), + ], + ids=["api_auth_error", "api_non_auth_error"], +) +async def test_sensor_update_unsuccessful_response_paths( + hass: HomeAssistant, + mock_modems: AsyncMock, + init_integration: MockConfigEntry, + freezer: FrozenDateTimeFactory, + error_code: int, + expect_reauth: bool, +) -> None: + """Test unsuccessful API response handling.""" + mock_modems.get_status.side_effect = None + mock_modems.get_status.return_value = MagicMock( + success=False, + data=None, + errors=[MagicMock(code=error_code, error="API error")], + ) + + freezer.tick(timedelta(seconds=31)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + state = hass.states.get("sensor.rutx50_test_internal_modem_rssi") + assert state is not None + assert state.state == "unavailable" + + has_reauth = any( + flow["handler"] == DOMAIN and flow["context"]["source"] == SOURCE_REAUTH + for flow in hass.config_entries.flow.async_progress() + ) + assert has_reauth is expect_reauth From 9d54236f7d41f5e0fab1fd2d295a385f6d94e625 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 13:12:11 +0100 Subject: [PATCH 06/19] Add integration_type hub to waqi (#163754) --- homeassistant/components/waqi/manifest.json | 1 + homeassistant/generated/integrations.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/waqi/manifest.json b/homeassistant/components/waqi/manifest.json index cb04bd7d6acba..4fe09bc714392 100644 --- a/homeassistant/components/waqi/manifest.json +++ b/homeassistant/components/waqi/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@joostlek"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/waqi", + "integration_type": "service", "iot_class": "cloud_polling", "loggers": ["aiowaqi"], "requirements": ["aiowaqi==3.1.0"] diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index eee3c6adb4149..d95c9d7a2ed31 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -7637,7 +7637,7 @@ }, "waqi": { "name": "World Air Quality Index (WAQI)", - "integration_type": "hub", + "integration_type": "service", "config_flow": true, "iot_class": "cloud_polling" }, From fe377befa6bc9a6d5d86bcbc690026b8eebbcf99 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 13:12:40 +0100 Subject: [PATCH 07/19] Add integration_type hub to wallbox (#163752) --- homeassistant/components/wallbox/manifest.json | 1 + homeassistant/generated/integrations.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/wallbox/manifest.json b/homeassistant/components/wallbox/manifest.json index cda1f0ced3d55..a326fcba8e548 100644 --- a/homeassistant/components/wallbox/manifest.json +++ b/homeassistant/components/wallbox/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@hesselonline"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/wallbox", + "integration_type": "device", "iot_class": "cloud_polling", "loggers": ["wallbox"], "requirements": ["wallbox==0.9.0"] diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index d95c9d7a2ed31..4cac5bc64a23b 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -7631,7 +7631,7 @@ }, "wallbox": { "name": "Wallbox", - "integration_type": "hub", + "integration_type": "device", "config_flow": true, "iot_class": "cloud_polling" }, From cf5733de97857f95856173a0b2475bf2acffbe12 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 13:16:37 +0100 Subject: [PATCH 08/19] Add integration_type device to tilt_pi (#163667) --- homeassistant/components/tilt_pi/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/tilt_pi/manifest.json b/homeassistant/components/tilt_pi/manifest.json index 94c6b7ade8660..00c837e7b3223 100644 --- a/homeassistant/components/tilt_pi/manifest.json +++ b/homeassistant/components/tilt_pi/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@michaelheyman"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tilt_pi", + "integration_type": "hub", "iot_class": "local_polling", "quality_scale": "bronze", "requirements": ["tilt-pi==0.2.1"] From 77a56a3e602f017dfe157bbd1e0fc62dee54e66f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 13:17:02 +0100 Subject: [PATCH 09/19] Add integration_type device to smart_meter_texas (#163398) --- homeassistant/components/smart_meter_texas/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/smart_meter_texas/manifest.json b/homeassistant/components/smart_meter_texas/manifest.json index 8bf44fbed152c..a8397da06795e 100644 --- a/homeassistant/components/smart_meter_texas/manifest.json +++ b/homeassistant/components/smart_meter_texas/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@grahamwetzler"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/smart_meter_texas", + "integration_type": "hub", "iot_class": "cloud_polling", "loggers": ["smart_meter_texas"], "requirements": ["smart-meter-texas==0.5.5"] From 0f6a3a83286f2bd4917206841b9d00acd2d80bed Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 13:17:31 +0100 Subject: [PATCH 10/19] Add integration_type service to snapcast (#163401) --- homeassistant/components/snapcast/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/snapcast/manifest.json b/homeassistant/components/snapcast/manifest.json index 80d3b6cd49139..21358156455fa 100644 --- a/homeassistant/components/snapcast/manifest.json +++ b/homeassistant/components/snapcast/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@luar123"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/snapcast", + "integration_type": "hub", "iot_class": "local_push", "loggers": ["construct", "snapcast"], "requirements": ["snapcast==2.3.7"] From 6299e8cb7758a9caf2eea9dd67835a8fefebfa35 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Mon, 23 Feb 2026 06:29:20 -0600 Subject: [PATCH 11/19] Add support for current sensors to egauge integration (#163728) --- homeassistant/components/egauge/sensor.py | 16 ++++- tests/components/egauge/conftest.py | 3 + .../egauge/snapshots/test_sensor.ambr | 59 ++++++++++++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/egauge/sensor.py b/homeassistant/components/egauge/sensor.py index 2abd1c6886d65..743bc34a42973 100644 --- a/homeassistant/components/egauge/sensor.py +++ b/homeassistant/components/egauge/sensor.py @@ -13,7 +13,12 @@ SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import UnitOfElectricPotential, UnitOfEnergy, UnitOfPower +from homeassistant.const import ( + UnitOfElectricCurrent, + UnitOfElectricPotential, + UnitOfEnergy, + UnitOfPower, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -59,6 +64,15 @@ class EgaugeSensorEntityDescription(SensorEntityDescription): available_fn=lambda data, register: register in data.measurements, supported_fn=lambda register_info: register_info.type == RegisterType.VOLTAGE, ), + EgaugeSensorEntityDescription( + key="current", + device_class=SensorDeviceClass.CURRENT, + state_class=SensorStateClass.MEASUREMENT, + native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, + native_value_fn=lambda data, register: data.measurements[register], + available_fn=lambda data, register: register in data.measurements, + supported_fn=lambda register_info: register_info.type == RegisterType.CURRENT, + ), ) diff --git a/tests/components/egauge/conftest.py b/tests/components/egauge/conftest.py index c78ee0a723321..d12a10a5c178e 100644 --- a/tests/components/egauge/conftest.py +++ b/tests/components/egauge/conftest.py @@ -66,6 +66,7 @@ def mock_egauge_client() -> Generator[MagicMock]: name="Temp", type=RegisterType.TEMPERATURE, idx=2, did=None ), "L1": RegisterInfo(name="L1", type=RegisterType.VOLTAGE, idx=3, did=None), + "S1": RegisterInfo(name="S1", type=RegisterType.CURRENT, idx=4, did=None), } # Dynamic measurements @@ -74,12 +75,14 @@ def mock_egauge_client() -> Generator[MagicMock]: "Solar": -2500.0, "Temp": 45.0, "L1": 123.4, + "S1": 1.2, } client.get_current_counters.return_value = { "Grid": 450000000.0, # 125 kWh in Ws "Solar": 315000000.0, # 87.5 kWh in Ws "Temp": 0.0, "L1": 12345678.0, + "S1": 12345.0, } yield client diff --git a/tests/components/egauge/snapshots/test_sensor.ambr b/tests/components/egauge/snapshots/test_sensor.ambr index 9a939b1419d75..74b3d029b60f3 100644 --- a/tests/components/egauge/snapshots/test_sensor.ambr +++ b/tests/components/egauge/snapshots/test_sensor.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_sensors.10 +# name: test_sensors.12 DeviceRegistryEntrySnapshot({ 'area_id': None, 'config_entries': , @@ -204,6 +204,63 @@ 'state': '123.4', }) # --- +# name: test_sensors[sensor.egauge_home_s1_current-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.egauge_home_s1_current', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Current', + 'platform': 'egauge', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ABC123456_S1_current', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[sensor.egauge_home_s1_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'egauge-home S1 Current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.egauge_home_s1_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1.2', + }) +# --- # name: test_sensors[sensor.egauge_home_solar_energy-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ From 74a3f4bbb9cdc8a68497bc81d523599c946d4c1c Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 23 Feb 2026 14:03:43 +0100 Subject: [PATCH 12/19] Bump securetar to 2026.2.0 (#163226) --- homeassistant/backup_restore.py | 24 +-- homeassistant/components/backup/const.py | 2 + homeassistant/components/backup/manager.py | 25 ++- homeassistant/components/backup/manifest.json | 2 +- homeassistant/components/backup/util.py | 154 ++++++++---------- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/backup/test_manager.py | 30 ++-- tests/components/backup/test_util.py | 28 +++- tests/test_backup_restore.py | 18 -- 13 files changed, 131 insertions(+), 162 deletions(-) diff --git a/homeassistant/backup_restore.py b/homeassistant/backup_restore.py index 4d309469017a2..6800851c182cb 100644 --- a/homeassistant/backup_restore.py +++ b/homeassistant/backup_restore.py @@ -4,7 +4,6 @@ from collections.abc import Iterable from dataclasses import dataclass -import hashlib import json import logging from pathlib import Path @@ -40,17 +39,6 @@ class RestoreBackupFileContent: restore_homeassistant: bool -def password_to_key(password: str) -> bytes: - """Generate a AES Key from password. - - Matches the implementation in supervisor.backups.utils.password_to_key. - """ - key: bytes = password.encode() - for _ in range(100): - key = hashlib.sha256(key).digest() - return key[:16] - - def restore_backup_file_content(config_dir: Path) -> RestoreBackupFileContent | None: """Return the contents of the restore backup file.""" instruction_path = config_dir.joinpath(RESTORE_BACKUP_FILE) @@ -96,15 +84,14 @@ def _extract_backup( """Extract the backup file to the config directory.""" with ( TemporaryDirectory() as tempdir, - securetar.SecureTarFile( + securetar.SecureTarArchive( restore_content.backup_file_path, - gzip=False, mode="r", ) as ostf, ): - ostf.extractall( + ostf.tar.extractall( path=Path(tempdir, "extracted"), - members=securetar.secure_path(ostf), + members=securetar.secure_path(ostf.tar), filter="fully_trusted", ) backup_meta_file = Path(tempdir, "extracted", "backup.json") @@ -126,10 +113,7 @@ def _extract_backup( f"homeassistant.tar{'.gz' if backup_meta['compressed'] else ''}", ), gzip=backup_meta["compressed"], - key=password_to_key(restore_content.password) - if restore_content.password is not None - else None, - mode="r", + password=restore_content.password, ) as istf: istf.extractall( path=Path(tempdir, "homeassistant"), diff --git a/homeassistant/components/backup/const.py b/homeassistant/components/backup/const.py index 3d6e6fc45b577..131acf99a802e 100644 --- a/homeassistant/components/backup/const.py +++ b/homeassistant/components/backup/const.py @@ -33,3 +33,5 @@ "home-assistant_v2.db", "home-assistant_v2.db-wal", ] + +SECURETAR_CREATE_VERSION = 2 diff --git a/homeassistant/components/backup/manager.py b/homeassistant/components/backup/manager.py index cba09a078c1a5..909225f5bded3 100644 --- a/homeassistant/components/backup/manager.py +++ b/homeassistant/components/backup/manager.py @@ -20,13 +20,9 @@ from typing import IO, TYPE_CHECKING, Any, Protocol, TypedDict, cast import aiohttp -from securetar import SecureTarFile, atomic_contents_add +from securetar import SecureTarArchive, atomic_contents_add -from homeassistant.backup_restore import ( - RESTORE_BACKUP_FILE, - RESTORE_BACKUP_RESULT_FILE, - password_to_key, -) +from homeassistant.backup_restore import RESTORE_BACKUP_FILE, RESTORE_BACKUP_RESULT_FILE from homeassistant.const import __version__ as HAVERSION from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import ( @@ -60,6 +56,7 @@ EXCLUDE_DATABASE_FROM_BACKUP, EXCLUDE_FROM_BACKUP, LOGGER, + SECURETAR_CREATE_VERSION, ) from .models import ( AddonInfo, @@ -1858,20 +1855,22 @@ def is_excluded_by_filter(path: PurePath) -> bool: return False - outer_secure_tarfile = SecureTarFile( - tar_file_path, "w", gzip=False, bufsize=BUF_SIZE - ) - with outer_secure_tarfile as outer_secure_tarfile_tarfile: + with SecureTarArchive( + tar_file_path, + "w", + bufsize=BUF_SIZE, + create_version=SECURETAR_CREATE_VERSION, + password=password, + ) as outer_secure_tarfile: raw_bytes = json_bytes(backup_data) fileobj = io.BytesIO(raw_bytes) tar_info = tarfile.TarInfo(name="./backup.json") tar_info.size = len(raw_bytes) tar_info.mtime = int(time.time()) - outer_secure_tarfile_tarfile.addfile(tar_info, fileobj=fileobj) - with outer_secure_tarfile.create_inner_tar( + outer_secure_tarfile.tar.addfile(tar_info, fileobj=fileobj) + with outer_secure_tarfile.create_tar( "./homeassistant.tar.gz", gzip=True, - key=password_to_key(password) if password is not None else None, ) as core_tar: atomic_contents_add( tar_file=core_tar, diff --git a/homeassistant/components/backup/manifest.json b/homeassistant/components/backup/manifest.json index 7b128dbecd0d9..0c1db47c05f7d 100644 --- a/homeassistant/components/backup/manifest.json +++ b/homeassistant/components/backup/manifest.json @@ -8,6 +8,6 @@ "integration_type": "service", "iot_class": "calculated", "quality_scale": "internal", - "requirements": ["cronsim==2.7", "securetar==2025.2.1"], + "requirements": ["cronsim==2.7", "securetar==2026.2.0"], "single_config_entry": true } diff --git a/homeassistant/components/backup/util.py b/homeassistant/components/backup/util.py index 9dfcb36783d10..c5899315524f7 100644 --- a/homeassistant/components/backup/util.py +++ b/homeassistant/components/backup/util.py @@ -8,7 +8,6 @@ from dataclasses import dataclass, replace from io import BytesIO import json -import os from pathlib import Path, PurePath from queue import SimpleQueue import tarfile @@ -16,9 +15,14 @@ from typing import IO, Any, cast import aiohttp -from securetar import SecureTarError, SecureTarFile, SecureTarReadError +from securetar import ( + SecureTarArchive, + SecureTarError, + SecureTarFile, + SecureTarReadError, + SecureTarRootKeyContext, +) -from homeassistant.backup_restore import password_to_key from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.util import dt as dt_util @@ -29,7 +33,7 @@ ) from homeassistant.util.json import JsonObjectType, json_loads_object -from .const import BUF_SIZE, LOGGER +from .const import BUF_SIZE, LOGGER, SECURETAR_CREATE_VERSION from .models import AddonInfo, AgentBackup, Folder @@ -132,17 +136,23 @@ def suggested_filename(backup: AgentBackup) -> str: def validate_password(path: Path, password: str | None) -> bool: - """Validate the password.""" - with tarfile.open(path, "r:", bufsize=BUF_SIZE) as backup_file: + """Validate the password. + + This assumes every inner tar is encrypted with the same secure tar version and + same password. + """ + with SecureTarArchive( + path, "r", bufsize=BUF_SIZE, password=password + ) as backup_file: compressed = False ha_tar_name = "homeassistant.tar" try: - ha_tar = backup_file.extractfile(ha_tar_name) + ha_tar = backup_file.tar.extractfile(ha_tar_name) except KeyError: compressed = True ha_tar_name = "homeassistant.tar.gz" try: - ha_tar = backup_file.extractfile(ha_tar_name) + ha_tar = backup_file.tar.extractfile(ha_tar_name) except KeyError: LOGGER.error("No homeassistant.tar or homeassistant.tar.gz found") return False @@ -150,13 +160,12 @@ def validate_password(path: Path, password: str | None) -> bool: with SecureTarFile( path, # Not used gzip=compressed, - key=password_to_key(password) if password is not None else None, - mode="r", + password=password, fileobj=ha_tar, ): # If we can read the tar file, the password is correct return True - except tarfile.ReadError: + except tarfile.ReadError, SecureTarReadError: LOGGER.debug("Invalid password") return False except Exception: # noqa: BLE001 @@ -168,22 +177,23 @@ def validate_password_stream( input_stream: IO[bytes], password: str | None, ) -> None: - """Decrypt a backup.""" - with ( - tarfile.open(fileobj=input_stream, mode="r|", bufsize=BUF_SIZE) as input_tar, - ): - for obj in input_tar: + """Validate the password. + + This assumes every inner tar is encrypted with the same secure tar version and + same password. + """ + with SecureTarArchive( + fileobj=input_stream, + mode="r", + bufsize=BUF_SIZE, + streaming=True, + password=password, + ) as input_archive: + for obj in input_archive.tar: if not obj.name.endswith((".tar", ".tgz", ".tar.gz")): continue - istf = SecureTarFile( - None, # Not used - gzip=False, - key=password_to_key(password) if password is not None else None, - mode="r", - fileobj=input_tar.extractfile(obj), - ) - with istf.decrypt(obj) as decrypted: - if istf.securetar_header.plaintext_size is None: + with input_archive.extract_tar(obj) as decrypted: + if decrypted.plaintext_size is None: raise UnsupportedSecureTarVersion try: decrypted.read(1) # Read a single byte to trigger the decryption @@ -212,21 +222,25 @@ def decrypt_backup( password: str | None, on_done: Callable[[Exception | None], None], minimum_size: int, - nonces: NonceGenerator, + key_context: SecureTarRootKeyContext, ) -> None: """Decrypt a backup.""" error: Exception | None = None try: try: with ( - tarfile.open( - fileobj=input_stream, mode="r|", bufsize=BUF_SIZE - ) as input_tar, + SecureTarArchive( + fileobj=input_stream, + mode="r", + bufsize=BUF_SIZE, + streaming=True, + password=password, + ) as input_archive, tarfile.open( fileobj=output_stream, mode="w|", bufsize=BUF_SIZE ) as output_tar, ): - _decrypt_backup(backup, input_tar, output_tar, password) + _decrypt_backup(backup, input_archive, output_tar) except (DecryptError, SecureTarError, tarfile.TarError) as err: LOGGER.warning("Error decrypting backup: %s", err) error = err @@ -248,19 +262,18 @@ def decrypt_backup( def _decrypt_backup( backup: AgentBackup, - input_tar: tarfile.TarFile, + input_archive: SecureTarArchive, output_tar: tarfile.TarFile, - password: str | None, ) -> None: """Decrypt a backup.""" expected_archives = _get_expected_archives(backup) - for obj in input_tar: + for obj in input_archive.tar: # We compare with PurePath to avoid issues with different path separators, # for example when backup.json is added as "./backup.json" object_path = PurePath(obj.name) if object_path == PurePath("backup.json"): # Rewrite the backup.json file to indicate that the backup is decrypted - if not (reader := input_tar.extractfile(obj)): + if not (reader := input_archive.tar.extractfile(obj)): raise DecryptError metadata = json_loads_object(reader.read()) metadata["protected"] = False @@ -272,21 +285,15 @@ def _decrypt_backup( prefix, _, suffix = object_path.name.partition(".") if suffix not in ("tar", "tgz", "tar.gz"): LOGGER.debug("Unknown file %s will not be decrypted", obj.name) - output_tar.addfile(obj, input_tar.extractfile(obj)) + output_tar.addfile(obj, input_archive.tar.extractfile(obj)) continue if prefix not in expected_archives: LOGGER.debug("Unknown inner tar file %s will not be decrypted", obj.name) - output_tar.addfile(obj, input_tar.extractfile(obj)) + output_tar.addfile(obj, input_archive.tar.extractfile(obj)) continue - istf = SecureTarFile( - None, # Not used - gzip=False, - key=password_to_key(password) if password is not None else None, - mode="r", - fileobj=input_tar.extractfile(obj), - ) - with istf.decrypt(obj) as decrypted: - if (plaintext_size := istf.securetar_header.plaintext_size) is None: + with input_archive.extract_tar(obj) as decrypted: + # Guard against SecureTar v1 which doesn't store plaintext size + if (plaintext_size := decrypted.plaintext_size) is None: raise UnsupportedSecureTarVersion decrypted_obj = copy.deepcopy(obj) decrypted_obj.size = plaintext_size @@ -300,7 +307,7 @@ def encrypt_backup( password: str | None, on_done: Callable[[Exception | None], None], minimum_size: int, - nonces: NonceGenerator, + key_context: SecureTarRootKeyContext, ) -> None: """Encrypt a backup.""" error: Exception | None = None @@ -310,11 +317,16 @@ def encrypt_backup( tarfile.open( fileobj=input_stream, mode="r|", bufsize=BUF_SIZE ) as input_tar, - tarfile.open( - fileobj=output_stream, mode="w|", bufsize=BUF_SIZE - ) as output_tar, + SecureTarArchive( + fileobj=output_stream, + mode="w", + bufsize=BUF_SIZE, + streaming=True, + root_key_context=key_context, + create_version=SECURETAR_CREATE_VERSION, + ) as output_archive, ): - _encrypt_backup(backup, input_tar, output_tar, password, nonces) + _encrypt_backup(backup, input_tar, output_archive) except (EncryptError, SecureTarError, tarfile.TarError) as err: LOGGER.warning("Error encrypting backup: %s", err) error = err @@ -337,9 +349,7 @@ def encrypt_backup( def _encrypt_backup( backup: AgentBackup, input_tar: tarfile.TarFile, - output_tar: tarfile.TarFile, - password: str | None, - nonces: NonceGenerator, + output_archive: SecureTarArchive, ) -> None: """Encrypt a backup.""" inner_tar_idx = 0 @@ -357,29 +367,20 @@ def _encrypt_backup( updated_metadata_b = json.dumps(metadata).encode() metadata_obj = copy.deepcopy(obj) metadata_obj.size = len(updated_metadata_b) - output_tar.addfile(metadata_obj, BytesIO(updated_metadata_b)) + output_archive.tar.addfile(metadata_obj, BytesIO(updated_metadata_b)) continue prefix, _, suffix = object_path.name.partition(".") if suffix not in ("tar", "tgz", "tar.gz"): LOGGER.debug("Unknown file %s will not be encrypted", obj.name) - output_tar.addfile(obj, input_tar.extractfile(obj)) + output_archive.tar.addfile(obj, input_tar.extractfile(obj)) continue if prefix not in expected_archives: LOGGER.debug("Unknown inner tar file %s will not be encrypted", obj.name) continue - istf = SecureTarFile( - None, # Not used - gzip=False, - key=password_to_key(password) if password is not None else None, - mode="r", - fileobj=input_tar.extractfile(obj), - nonce=nonces.get(inner_tar_idx), + output_archive.import_tar( + input_tar.extractfile(obj), obj, derived_key_id=inner_tar_idx ) inner_tar_idx += 1 - with istf.encrypt(obj) as encrypted: - encrypted_obj = copy.deepcopy(obj) - encrypted_obj.size = encrypted.encrypted_size - output_tar.addfile(encrypted_obj, encrypted) @dataclass(kw_only=True) @@ -391,21 +392,6 @@ class _CipherWorkerStatus: writer: AsyncIteratorWriter -class NonceGenerator: - """Generate nonces for encryption.""" - - def __init__(self) -> None: - """Initialize the generator.""" - self._nonces: dict[int, bytes] = {} - - def get(self, index: int) -> bytes: - """Get a nonce for the given index.""" - if index not in self._nonces: - # Generate a new nonce for the given index - self._nonces[index] = os.urandom(16) - return self._nonces[index] - - class _CipherBackupStreamer: """Encrypt or decrypt a backup.""" @@ -417,7 +403,7 @@ class _CipherBackupStreamer: str | None, Callable[[Exception | None], None], int, - NonceGenerator, + SecureTarRootKeyContext, ], None, ] @@ -435,7 +421,7 @@ def __init__( self._hass = hass self._open_stream = open_stream self._password = password - self._nonces = NonceGenerator() + self._key_context = SecureTarRootKeyContext(password) def size(self) -> int: """Return the maximum size of the decrypted or encrypted backup.""" @@ -466,7 +452,7 @@ def on_done(error: Exception | None) -> None: self._password, on_done, self.size(), - self._nonces, + self._key_context, ], ) worker_status = _CipherWorkerStatus( diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 6e45cb30c21c5..d9e007e149c7b 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -64,7 +64,7 @@ python-slugify==8.0.4 PyTurboJPEG==1.8.0 PyYAML==6.0.3 requests==2.32.5 -securetar==2025.2.1 +securetar==2026.2.0 SQLAlchemy==2.0.41 standard-aifc==3.13.0 standard-telnetlib==3.13.0 diff --git a/pyproject.toml b/pyproject.toml index 1b97a7e7faa35..bd0837031bf8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,7 +71,7 @@ dependencies = [ "python-slugify==8.0.4", "PyYAML==6.0.3", "requests==2.32.5", - "securetar==2025.2.1", + "securetar==2026.2.0", "SQLAlchemy==2.0.41", "standard-aifc==3.13.0", "standard-telnetlib==3.13.0", diff --git a/requirements.txt b/requirements.txt index 001c32437edc6..9491c87273908 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,7 +47,7 @@ python-slugify==8.0.4 PyTurboJPEG==1.8.0 PyYAML==6.0.3 requests==2.32.5 -securetar==2025.2.1 +securetar==2026.2.0 SQLAlchemy==2.0.41 standard-aifc==3.13.0 standard-telnetlib==3.13.0 diff --git a/requirements_all.txt b/requirements_all.txt index 53fc5143fc627..02857f99d12ee 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2859,7 +2859,7 @@ screenlogicpy==0.10.2 scsgate==0.1.0 # homeassistant.components.backup -securetar==2025.2.1 +securetar==2026.2.0 # homeassistant.components.sendgrid sendgrid==6.8.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7c086b3ec2cf4..180361f2ca51d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2410,7 +2410,7 @@ satel-integra==0.3.7 screenlogicpy==0.10.2 # homeassistant.components.backup -securetar==2025.2.1 +securetar==2026.2.0 # homeassistant.components.emulated_kasa # homeassistant.components.sense diff --git a/tests/components/backup/test_manager.py b/tests/components/backup/test_manager.py index 67cc4e1b3e772..73cb98d7fd343 100644 --- a/tests/components/backup/test_manager.py +++ b/tests/components/backup/test_manager.py @@ -24,7 +24,7 @@ from freezegun.api import FrozenDateTimeFactory import pytest -from securetar import SecureTarFile +from securetar import SecureTarArchive, SecureTarFile from homeassistant.components.backup import ( DOMAIN, @@ -49,7 +49,6 @@ RestoreBackupState, WrittenBackup, ) -from homeassistant.components.backup.util import password_to_key from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STARTED from homeassistant.core import CoreState, HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -671,8 +670,7 @@ async def test_initiate_backup( with SecureTarFile( fileobj=core_tar_io, gzip=True, - key=password_to_key(password) if password is not None else None, - mode="r", + password=password, ) as core_tar: assert set(core_tar.getnames()) == expected_files @@ -3312,7 +3310,7 @@ async def test_restore_backup_file_error( @pytest.mark.usefixtures("mock_ha_version") @pytest.mark.parametrize( - ("commands", "agent_ids", "password", "protected_backup", "inner_tar_key"), + ("commands", "agent_ids", "password", "protected_backup", "inner_tar_password"), [ ( [], @@ -3326,7 +3324,7 @@ async def test_restore_backup_file_error( ["backup.local", "test.remote"], "hunter2", {"backup.local": True, "test.remote": True}, - password_to_key("hunter2"), + "hunter2", ), ( [ @@ -3371,7 +3369,7 @@ async def test_restore_backup_file_error( ["backup.local", "test.remote"], "hunter2", {"backup.local": True, "test.remote": False}, - password_to_key("hunter2"), # Local agent is protected + "hunter2", # Local agent is protected ), ( [ @@ -3386,7 +3384,7 @@ async def test_restore_backup_file_error( ["backup.local", "test.remote"], "hunter2", {"backup.local": True, "test.remote": True}, - password_to_key("hunter2"), + "hunter2", ), ( [ @@ -3416,7 +3414,7 @@ async def test_restore_backup_file_error( ["test.remote"], "hunter2", {"test.remote": True}, - password_to_key("hunter2"), + "hunter2", ), ( [ @@ -3431,7 +3429,7 @@ async def test_restore_backup_file_error( ["test.remote"], "hunter2", {"test.remote": False}, - password_to_key("hunter2"), # Temporary backup protected when password set + "hunter2", # Temporary backup protected when password set ), ], ) @@ -3443,7 +3441,7 @@ async def test_initiate_backup_per_agent_encryption( agent_ids: list[str], password: str | None, protected_backup: dict[str, bool], - inner_tar_key: bytes | None, + inner_tar_password: str | None, ) -> None: """Test generate backup where encryption is selectively set on agents.""" await setup_backup_integration(hass, remote_agents=["test.remote"]) @@ -3479,7 +3477,11 @@ async def test_initiate_backup_per_agent_encryption( with ( patch("pathlib.Path.open", mock_open(read_data=b"test")), - patch("securetar.SecureTarFile.create_inner_tar") as mock_create_inner_tar, + patch( + "securetar.SecureTarArchive.__init__", + autospec=True, + wraps=SecureTarArchive.__init__, + ) as mock_secure_tar_archive, ): await ws_client.send_json_auto_id( { @@ -3504,7 +3506,9 @@ async def test_initiate_backup_per_agent_encryption( await hass.async_block_till_done() - mock_create_inner_tar.assert_called_once_with(ANY, gzip=True, key=inner_tar_key) + assert mock_secure_tar_archive.mock_calls[0] == call( + ANY, ANY, "w", bufsize=4194304, create_version=2, password=inner_tar_password + ) result = await ws_client.receive_json() assert result["event"] == { diff --git a/tests/components/backup/test_util.py b/tests/components/backup/test_util.py index 0190979306752..021a33dcb32bc 100644 --- a/tests/components/backup/test_util.py +++ b/tests/components/backup/test_util.py @@ -160,15 +160,25 @@ def test_validate_password( @pytest.mark.parametrize("password", [None, "hunter2"]) -@pytest.mark.parametrize("secure_tar_side_effect", [tarfile.ReadError, Exception]) +@pytest.mark.parametrize( + ("secure_tar_side_effect", "expected_message"), + [ + (tarfile.ReadError, "Invalid password"), + (securetar.SecureTarReadError, "Invalid password"), + (Exception, "Unexpected error validating password"), + ], +) def test_validate_password_with_error( - password: str | None, secure_tar_side_effect: type[Exception] + password: str | None, + secure_tar_side_effect: type[Exception], + expected_message: str, + caplog: pytest.LogCaptureFixture, ) -> None: """Test validating a password.""" mock_path = Mock() with ( - patch("homeassistant.components.backup.util.tarfile.open"), + patch("securetar.tarfile.open"), patch( "homeassistant.components.backup.util.SecureTarFile", ) as mock_secure_tar, @@ -176,19 +186,21 @@ def test_validate_password_with_error( mock_secure_tar.return_value.__enter__.side_effect = secure_tar_side_effect assert validate_password(mock_path, password) is False + assert expected_message in caplog.text -def test_validate_password_no_homeassistant() -> None: + +def test_validate_password_no_homeassistant(caplog: pytest.LogCaptureFixture) -> None: """Test validating a password.""" mock_path = Mock() with ( - patch("homeassistant.components.backup.util.tarfile.open") as mock_open_tar, + patch("securetar.tarfile.open") as mock_open_tar, ): - mock_open_tar.return_value.__enter__.return_value.extractfile.side_effect = ( - KeyError - ) + mock_open_tar.return_value.extractfile.side_effect = KeyError assert validate_password(mock_path, "hunter2") is False + assert "No homeassistant.tar or homeassistant.tar.gz found" in caplog.text + @pytest.mark.parametrize( ("addons", "padding_size", "decrypted_backup"), diff --git a/tests/test_backup_restore.py b/tests/test_backup_restore.py index 2d66e90be5e81..1e16c91e5a73e 100644 --- a/tests/test_backup_restore.py +++ b/tests/test_backup_restore.py @@ -463,21 +463,3 @@ def test_remove_backup_file_after_restore( "error_type": None, "success": True, } - - -@pytest.mark.parametrize( - ("password", "expected"), - [ - ("test", b"\xf0\x9b\xb9\x1f\xdc,\xff\xd5x\xd6\xd6\x8fz\x19.\x0f"), - ("lorem ipsum...", b"#\xe0\xfc\xe0\xdb?_\x1f,$\rQ\xf4\xf5\xd8\xfb"), - ], -) -def test_pw_to_key(password: str | None, expected: bytes | None) -> None: - """Test password to key conversion.""" - assert backup_restore.password_to_key(password) == expected - - -def test_pw_to_key_none() -> None: - """Test password to key conversion.""" - with pytest.raises(AttributeError): - backup_restore.password_to_key(None) From cdb92a54b00a2e160c963b8a5520c40c8f0e113b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Mon, 23 Feb 2026 14:38:37 +0100 Subject: [PATCH 13/19] Fix Matter speaker mute toggle (#161128) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/matter/switch.py | 56 +++++++++++------------ tests/components/matter/test_switch.py | 53 +++++++++++++++++++++ 2 files changed, 81 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/matter/switch.py b/homeassistant/components/matter/switch.py index ee906662de50a..7c125763703b4 100644 --- a/homeassistant/components/matter/switch.py +++ b/homeassistant/components/matter/switch.py @@ -46,30 +46,42 @@ async def async_setup_entry( class MatterSwitchEntityDescription(SwitchEntityDescription, MatterEntityDescription): """Describe Matter Switch entities.""" + inverted: bool = False + class MatterSwitch(MatterEntity, SwitchEntity): """Representation of a Matter switch.""" + entity_description: MatterSwitchEntityDescription _platform_translation_key = "switch" + def _get_command_for_value(self, value: bool) -> ClusterCommand: + """Get the appropriate command for the desired value. + + Applies inversion if needed (e.g., for inverted logic like mute). + """ + send_value = not value if self.entity_description.inverted else value + return ( + clusters.OnOff.Commands.On() + if send_value + else clusters.OnOff.Commands.Off() + ) + async def async_turn_on(self, **kwargs: Any) -> None: """Turn switch on.""" - await self.send_device_command( - clusters.OnOff.Commands.On(), - ) + await self.send_device_command(self._get_command_for_value(True)) async def async_turn_off(self, **kwargs: Any) -> None: """Turn switch off.""" - await self.send_device_command( - clusters.OnOff.Commands.Off(), - ) + await self.send_device_command(self._get_command_for_value(False)) @callback def _update_from_device(self) -> None: """Update from device.""" - self._attr_is_on = self.get_matter_attribute_value( - self._entity_info.primary_attribute - ) + value = self.get_matter_attribute_value(self._entity_info.primary_attribute) + if self.entity_description.inverted: + value = not value + self._attr_is_on = value class MatterGenericCommandSwitch(MatterSwitch): @@ -121,9 +133,7 @@ async def send_device_command( @dataclass(frozen=True, kw_only=True) -class MatterGenericCommandSwitchEntityDescription( - SwitchEntityDescription, MatterEntityDescription -): +class MatterGenericCommandSwitchEntityDescription(MatterSwitchEntityDescription): """Describe Matter Generic command Switch entities.""" # command: a custom callback to create the command to send to the device @@ -133,9 +143,7 @@ class MatterGenericCommandSwitchEntityDescription( @dataclass(frozen=True, kw_only=True) -class MatterNumericSwitchEntityDescription( - SwitchEntityDescription, MatterEntityDescription -): +class MatterNumericSwitchEntityDescription(MatterSwitchEntityDescription): """Describe Matter Numeric Switch entities.""" @@ -146,11 +154,10 @@ class MatterNumericSwitch(MatterSwitch): async def _async_set_native_value(self, value: bool) -> None: """Update the current value.""" + send_value: Any = value if value_convert := self.entity_description.ha_to_device: send_value = value_convert(value) - await self.write_attribute( - value=send_value, - ) + await self.write_attribute(value=send_value) async def async_turn_on(self, **kwargs: Any) -> None: """Turn switch on.""" @@ -248,19 +255,12 @@ def _update_from_device(self) -> None: ), MatterDiscoverySchema( platform=Platform.SWITCH, - entity_description=MatterNumericSwitchEntityDescription( + entity_description=MatterSwitchEntityDescription( key="MatterMuteToggle", translation_key="speaker_mute", - device_to_ha={ - True: False, # True means volume is on, so HA should show mute as off - False: True, # False means volume is off (muted), so HA should show mute as on - }.get, - ha_to_device={ - False: True, # HA showing mute as off means volume is on, so send True - True: False, # HA showing mute as on means volume is off (muted), so send False - }.get, + inverted=True, ), - entity_class=MatterNumericSwitch, + entity_class=MatterSwitch, required_attributes=(clusters.OnOff.Attributes.OnOff,), device_type=(device_types.Speaker,), ), diff --git a/tests/components/matter/test_switch.py b/tests/components/matter/test_switch.py index 4155901fa8be7..e89f3fc7fe63c 100644 --- a/tests/components/matter/test_switch.py +++ b/tests/components/matter/test_switch.py @@ -232,3 +232,56 @@ async def test_evse_sensor( ), timed_request_timeout_ms=3000, ) + + +@pytest.mark.parametrize("node_fixture", ["mock_speaker"]) +async def test_speaker_mute_uses_onoff_commands( + hass: HomeAssistant, + matter_client: MagicMock, + matter_node: MatterNode, +) -> None: + """Test speaker mute switch uses On/Off commands instead of attribute writes.""" + + state = hass.states.get("switch.mock_speaker_mute") + assert state + assert state.state == "off" + + await hass.services.async_call( + "switch", + "turn_on", + {"entity_id": "switch.mock_speaker_mute"}, + blocking=True, + ) + + assert matter_client.send_device_command.call_count == 1 + assert matter_client.send_device_command.call_args == call( + node_id=matter_node.node_id, + endpoint_id=1, + command=clusters.OnOff.Commands.Off(), + ) + + set_node_attribute(matter_node, 1, 6, 0, False) + await trigger_subscription_callback(hass, matter_client) + state = hass.states.get("switch.mock_speaker_mute") + assert state + assert state.state == "on" + + await hass.services.async_call( + "switch", + "turn_off", + {"entity_id": "switch.mock_speaker_mute"}, + blocking=True, + ) + + assert matter_client.send_device_command.call_count == 2 + assert matter_client.send_device_command.call_args == call( + node_id=matter_node.node_id, + endpoint_id=1, + command=clusters.OnOff.Commands.On(), + ) + + set_node_attribute(matter_node, 1, 6, 0, True) + await trigger_subscription_callback(hass, matter_client) + state = hass.states.get("switch.mock_speaker_mute") + assert state + assert state.state == "off" From e1667bd5c6cb0b743cf2da97f199b75f4e3dee95 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:02:10 +0100 Subject: [PATCH 14/19] Increase request timeout from 10 to 20s in FRITZ!SmartHome (#163818) --- homeassistant/components/fritzbox/coordinator.py | 1 + tests/components/fritzbox/test_init.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/fritzbox/coordinator.py b/homeassistant/components/fritzbox/coordinator.py index fcbea2d0265c2..756264f5e35f9 100644 --- a/homeassistant/components/fritzbox/coordinator.py +++ b/homeassistant/components/fritzbox/coordinator.py @@ -63,6 +63,7 @@ async def async_setup(self) -> None: host=self.config_entry.data[CONF_HOST], user=self.config_entry.data[CONF_USERNAME], password=self.config_entry.data[CONF_PASSWORD], + timeout=20, ) try: diff --git a/tests/components/fritzbox/test_init.py b/tests/components/fritzbox/test_init.py index 489e5e19588d3..8d2ffcc4db566 100644 --- a/tests/components/fritzbox/test_init.py +++ b/tests/components/fritzbox/test_init.py @@ -44,7 +44,7 @@ async def test_setup(hass: HomeAssistant, fritz: Mock) -> None: assert entries[0].data[CONF_USERNAME] == "fake_user" assert fritz.call_count == 1 assert fritz.call_args_list == [ - call(host="10.0.0.1", password="fake_pass", user="fake_user") + call(host="10.0.0.1", password="fake_pass", user="fake_user", timeout=20) ] From 5e3d2bec6845da6e1a56b2a001545f562744cfef Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 15:18:54 +0100 Subject: [PATCH 15/19] Add integration_type device to sia (#163393) --- homeassistant/components/sia/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/sia/manifest.json b/homeassistant/components/sia/manifest.json index a6b612a8acff0..19d6f07dca2be 100644 --- a/homeassistant/components/sia/manifest.json +++ b/homeassistant/components/sia/manifest.json @@ -4,6 +4,7 @@ "codeowners": ["@eavanvalkenburg"], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/sia", + "integration_type": "hub", "iot_class": "local_push", "loggers": ["pysiaalarm"], "requirements": ["pysiaalarm==3.2.2"] From 80936497ce279891d17364718c05c8d558dd9297 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Feb 2026 15:55:15 +0100 Subject: [PATCH 16/19] Add Zinvolt integration (#163449) --- .strict-typing | 1 + CODEOWNERS | 2 + homeassistant/components/zinvolt/__init__.py | 47 ++++++++ .../components/zinvolt/config_flow.py | 63 ++++++++++ homeassistant/components/zinvolt/const.py | 3 + .../components/zinvolt/coordinator.py | 50 ++++++++ .../components/zinvolt/manifest.json | 12 ++ .../components/zinvolt/quality_scale.yaml | 70 +++++++++++ homeassistant/components/zinvolt/sensor.py | 82 +++++++++++++ homeassistant/components/zinvolt/strings.json | 29 +++++ homeassistant/generated/config_flows.py | 1 + homeassistant/generated/integrations.json | 6 + mypy.ini | 10 ++ requirements_all.txt | 3 + requirements_test_all.txt | 3 + tests/components/zinvolt/__init__.py | 13 +++ tests/components/zinvolt/conftest.py | 57 +++++++++ tests/components/zinvolt/const.py | 3 + .../zinvolt/fixtures/batteries.json | 9 ++ .../zinvolt/fixtures/current_state.json | 51 ++++++++ .../zinvolt/snapshots/test_init.ambr | 32 +++++ .../zinvolt/snapshots/test_sensor.ambr | 52 +++++++++ tests/components/zinvolt/test_config_flow.py | 110 ++++++++++++++++++ tests/components/zinvolt/test_init.py | 27 +++++ tests/components/zinvolt/test_sensor.py | 27 +++++ 25 files changed, 763 insertions(+) create mode 100644 homeassistant/components/zinvolt/__init__.py create mode 100644 homeassistant/components/zinvolt/config_flow.py create mode 100644 homeassistant/components/zinvolt/const.py create mode 100644 homeassistant/components/zinvolt/coordinator.py create mode 100644 homeassistant/components/zinvolt/manifest.json create mode 100644 homeassistant/components/zinvolt/quality_scale.yaml create mode 100644 homeassistant/components/zinvolt/sensor.py create mode 100644 homeassistant/components/zinvolt/strings.json create mode 100644 tests/components/zinvolt/__init__.py create mode 100644 tests/components/zinvolt/conftest.py create mode 100644 tests/components/zinvolt/const.py create mode 100644 tests/components/zinvolt/fixtures/batteries.json create mode 100644 tests/components/zinvolt/fixtures/current_state.json create mode 100644 tests/components/zinvolt/snapshots/test_init.ambr create mode 100644 tests/components/zinvolt/snapshots/test_sensor.ambr create mode 100644 tests/components/zinvolt/test_config_flow.py create mode 100644 tests/components/zinvolt/test_init.py create mode 100644 tests/components/zinvolt/test_sensor.py diff --git a/.strict-typing b/.strict-typing index f2bef7f82dd71..34a51978216c4 100644 --- a/.strict-typing +++ b/.strict-typing @@ -612,6 +612,7 @@ homeassistant.components.yale_smart_alarm.* homeassistant.components.yalexs_ble.* homeassistant.components.youtube.* homeassistant.components.zeroconf.* +homeassistant.components.zinvolt.* homeassistant.components.zodiac.* homeassistant.components.zone.* homeassistant.components.zwave_js.* diff --git a/CODEOWNERS b/CODEOWNERS index 9b34dc9c5e03e..e99fe9da6f635 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1959,6 +1959,8 @@ build.json @home-assistant/supervisor /tests/components/zha/ @dmulcahey @adminiuga @puddly @TheJulianJES /homeassistant/components/zimi/ @markhannon /tests/components/zimi/ @markhannon +/homeassistant/components/zinvolt/ @joostlek +/tests/components/zinvolt/ @joostlek /homeassistant/components/zodiac/ @JulienTant /tests/components/zodiac/ @JulienTant /homeassistant/components/zone/ @home-assistant/core diff --git a/homeassistant/components/zinvolt/__init__.py b/homeassistant/components/zinvolt/__init__.py new file mode 100644 index 0000000000000..bd20e4f96672a --- /dev/null +++ b/homeassistant/components/zinvolt/__init__.py @@ -0,0 +1,47 @@ +"""The Zinvolt integration.""" + +from __future__ import annotations + +import asyncio + +from zinvolt import ZinvoltClient +from zinvolt.exceptions import ZinvoltError + +from homeassistant.const import CONF_ACCESS_TOKEN, Platform +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.aiohttp_client import async_get_clientsession + +from .coordinator import ZinvoltConfigEntry, ZinvoltDeviceCoordinator + +_PLATFORMS: list[Platform] = [Platform.SENSOR] + + +async def async_setup_entry(hass: HomeAssistant, entry: ZinvoltConfigEntry) -> bool: + """Set up Zinvolt from a config entry.""" + session = async_get_clientsession(hass) + client = ZinvoltClient(entry.data[CONF_ACCESS_TOKEN], session=session) + + try: + batteries = await client.get_batteries() + except ZinvoltError as err: + raise ConfigEntryNotReady from err + + coordinators: dict[str, ZinvoltDeviceCoordinator] = {} + tasks = [] + for battery in batteries: + coordinator = ZinvoltDeviceCoordinator(hass, entry, client, battery.identifier) + tasks.append(coordinator.async_config_entry_first_refresh()) + coordinators[battery.identifier] = coordinator + await asyncio.gather(*tasks) + + entry.runtime_data = coordinators + + await hass.config_entries.async_forward_entry_setups(entry, _PLATFORMS) + + return True + + +async def async_unload_entry(hass: HomeAssistant, entry: ZinvoltConfigEntry) -> bool: + """Unload a config entry.""" + return await hass.config_entries.async_unload_platforms(entry, _PLATFORMS) diff --git a/homeassistant/components/zinvolt/config_flow.py b/homeassistant/components/zinvolt/config_flow.py new file mode 100644 index 0000000000000..f16b26917a4e4 --- /dev/null +++ b/homeassistant/components/zinvolt/config_flow.py @@ -0,0 +1,63 @@ +"""Config flow for the Zinvolt integration.""" + +from __future__ import annotations + +import logging +from typing import Any + +import jwt +import voluptuous as vol +from zinvolt import ZinvoltClient +from zinvolt.exceptions import ZinvoltAuthenticationError, ZinvoltError + +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult +from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL, CONF_PASSWORD +from homeassistant.helpers.aiohttp_client import async_get_clientsession + +from .const import DOMAIN + +_LOGGER = logging.getLogger(__name__) + + +class ZinvoltConfigFlow(ConfigFlow, domain=DOMAIN): + """Handle a config flow for Zinvolt.""" + + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle the initial step.""" + errors: dict[str, str] = {} + if user_input is not None: + session = async_get_clientsession(self.hass) + client = ZinvoltClient(session=session) + try: + token = await client.login( + user_input[CONF_EMAIL], user_input[CONF_PASSWORD] + ) + except ZinvoltAuthenticationError: + errors["base"] = "invalid_auth" + except ZinvoltError: + errors["base"] = "cannot_connect" + except Exception: + _LOGGER.exception("Unexpected exception") + errors["base"] = "unknown" + else: + # Extract the user ID from the JWT token's 'sub' field + decoded_token = jwt.decode(token, options={"verify_signature": False}) + user_id = decoded_token["sub"] + await self.async_set_unique_id(user_id) + self._abort_if_unique_id_configured() + return self.async_create_entry( + title=user_input[CONF_EMAIL], data={CONF_ACCESS_TOKEN: token} + ) + + return self.async_show_form( + step_id="user", + data_schema=vol.Schema( + { + vol.Required(CONF_EMAIL): str, + vol.Required(CONF_PASSWORD): str, + } + ), + errors=errors, + ) diff --git a/homeassistant/components/zinvolt/const.py b/homeassistant/components/zinvolt/const.py new file mode 100644 index 0000000000000..87e3bfd2da15a --- /dev/null +++ b/homeassistant/components/zinvolt/const.py @@ -0,0 +1,3 @@ +"""Constants for the Zinvolt integration.""" + +DOMAIN = "zinvolt" diff --git a/homeassistant/components/zinvolt/coordinator.py b/homeassistant/components/zinvolt/coordinator.py new file mode 100644 index 0000000000000..b495af767985e --- /dev/null +++ b/homeassistant/components/zinvolt/coordinator.py @@ -0,0 +1,50 @@ +"""Coordinator for Zinvolt.""" + +from datetime import timedelta +import logging + +from zinvolt import ZinvoltClient +from zinvolt.exceptions import ZinvoltError +from zinvolt.models import BatteryState + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed + +from .const import DOMAIN + +_LOGGER = logging.getLogger(__name__) + +type ZinvoltConfigEntry = ConfigEntry[dict[str, ZinvoltDeviceCoordinator]] + + +class ZinvoltDeviceCoordinator(DataUpdateCoordinator[BatteryState]): + """Class for Zinvolt devices.""" + + def __init__( + self, + hass: HomeAssistant, + config_entry: ZinvoltConfigEntry, + client: ZinvoltClient, + battery_id: str, + ) -> None: + """Initialize the Zinvolt device.""" + super().__init__( + hass, + _LOGGER, + config_entry=config_entry, + name=f"Zinvolt {battery_id}", + update_interval=timedelta(minutes=5), + ) + self._battery_id = battery_id + self._client = client + + async def _async_update_data(self) -> BatteryState: + """Update data from Zinvolt.""" + try: + return await self._client.get_battery_status(self._battery_id) + except ZinvoltError as err: + raise UpdateFailed( + translation_key="update_failed", + translation_domain=DOMAIN, + ) from err diff --git a/homeassistant/components/zinvolt/manifest.json b/homeassistant/components/zinvolt/manifest.json new file mode 100644 index 0000000000000..c50e82cf41366 --- /dev/null +++ b/homeassistant/components/zinvolt/manifest.json @@ -0,0 +1,12 @@ +{ + "domain": "zinvolt", + "name": "Zinvolt", + "codeowners": ["@joostlek"], + "config_flow": true, + "documentation": "https://www.home-assistant.io/integrations/zinvolt", + "integration_type": "hub", + "iot_class": "cloud_polling", + "loggers": ["zinvolt"], + "quality_scale": "bronze", + "requirements": ["zinvolt==0.1.0"] +} diff --git a/homeassistant/components/zinvolt/quality_scale.yaml b/homeassistant/components/zinvolt/quality_scale.yaml new file mode 100644 index 0000000000000..413995615f0cd --- /dev/null +++ b/homeassistant/components/zinvolt/quality_scale.yaml @@ -0,0 +1,70 @@ +rules: + # Bronze + action-setup: + status: exempt + comment: There are no custom actions + appropriate-polling: done + brands: done + common-modules: done + config-flow-test-coverage: done + config-flow: done + dependency-transparency: done + docs-actions: + status: exempt + comment: There are no custom actions + docs-high-level-description: done + docs-installation-instructions: done + docs-removal-instructions: done + entity-event-setup: + status: exempt + comment: Entities do not explicitly subscribe to events + entity-unique-id: done + has-entity-name: done + runtime-data: done + test-before-configure: done + test-before-setup: done + unique-config-entry: done + + # Silver + action-exceptions: todo + config-entry-unloading: done + docs-configuration-parameters: + status: exempt + comment: There are no configuration parameters + docs-installation-parameters: todo + entity-unavailable: done + integration-owner: done + log-when-unavailable: done + parallel-updates: todo + reauthentication-flow: todo + test-coverage: todo + + # Gold + devices: done + diagnostics: todo + discovery-update-info: todo + discovery: todo + docs-data-update: todo + docs-examples: todo + docs-known-limitations: todo + docs-supported-devices: todo + docs-supported-functions: todo + docs-troubleshooting: todo + docs-use-cases: todo + dynamic-devices: todo + entity-category: todo + entity-device-class: todo + entity-disabled-by-default: todo + entity-translations: done + exception-translations: todo + icon-translations: todo + reconfiguration-flow: todo + repair-issues: + status: exempt + comment: There are no repairable issues + stale-devices: todo + + # Platinum + async-dependency: done + inject-websession: done + strict-typing: done diff --git a/homeassistant/components/zinvolt/sensor.py b/homeassistant/components/zinvolt/sensor.py new file mode 100644 index 0000000000000..3084783be6bb9 --- /dev/null +++ b/homeassistant/components/zinvolt/sensor.py @@ -0,0 +1,82 @@ +"""Sensor platform for Zinvolt integration.""" + +from collections.abc import Callable +from dataclasses import dataclass + +from zinvolt.models import BatteryState + +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorEntityDescription, +) +from homeassistant.const import PERCENTAGE, EntityCategory +from homeassistant.core import HomeAssistant +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from .const import DOMAIN +from .coordinator import ZinvoltConfigEntry, ZinvoltDeviceCoordinator + + +@dataclass(kw_only=True, frozen=True) +class ZinvoltBatteryStateDescription(SensorEntityDescription): + """Sensor description for Zinvolt battery state.""" + + value_fn: Callable[[BatteryState], float] + + +SENSORS: tuple[ZinvoltBatteryStateDescription, ...] = ( + ZinvoltBatteryStateDescription( + key="state_of_charge", + entity_category=EntityCategory.DIAGNOSTIC, + device_class=SensorDeviceClass.BATTERY, + native_unit_of_measurement=PERCENTAGE, + value_fn=lambda state: state.current_power.state_of_charge, + ), +) + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ZinvoltConfigEntry, + async_add_entities: AddConfigEntryEntitiesCallback, +) -> None: + """Initialize the entries.""" + + async_add_entities( + ZinvoltBatteryStateSensor(coordinator, description) + for description in SENSORS + for coordinator in entry.runtime_data.values() + ) + + +class ZinvoltBatteryStateSensor( + CoordinatorEntity[ZinvoltDeviceCoordinator], SensorEntity +): + """Zinvolt battery state sensor.""" + + _attr_has_entity_name = True + entity_description: ZinvoltBatteryStateDescription + + def __init__( + self, + coordinator: ZinvoltDeviceCoordinator, + description: ZinvoltBatteryStateDescription, + ) -> None: + """Initialize the sensor.""" + super().__init__(coordinator) + self.entity_description = description + self._attr_unique_id = f"{coordinator.data.serial_number}.{description.key}" + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, coordinator.data.serial_number)}, + manufacturer="Zinvolt", + name=coordinator.data.name, + serial_number=coordinator.data.serial_number, + ) + + @property + def native_value(self) -> float: + """Return the state of the sensor.""" + return self.entity_description.value_fn(self.coordinator.data) diff --git a/homeassistant/components/zinvolt/strings.json b/homeassistant/components/zinvolt/strings.json new file mode 100644 index 0000000000000..62b36f97b5fbb --- /dev/null +++ b/homeassistant/components/zinvolt/strings.json @@ -0,0 +1,29 @@ +{ + "config": { + "abort": { + "already_configured": "[%key:common::config_flow::abort::already_configured_account%]" + }, + "error": { + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", + "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "unknown": "[%key:common::config_flow::error::unknown%]" + }, + "step": { + "user": { + "data": { + "email": "[%key:common::config_flow::data::email%]", + "password": "[%key:common::config_flow::data::password%]" + }, + "data_description": { + "email": "The email of your Zinvolt account.", + "password": "The password of your Zinvolt account." + } + } + } + }, + "exceptions": { + "update_failed": { + "message": "An error occurred while updating the Zinvolt integration." + } + } +} diff --git a/homeassistant/generated/config_flows.py b/homeassistant/generated/config_flows.py index 2ea23986e9048..9218aa12d5f94 100644 --- a/homeassistant/generated/config_flows.py +++ b/homeassistant/generated/config_flows.py @@ -824,6 +824,7 @@ "zeversolar", "zha", "zimi", + "zinvolt", "zodiac", "zwave_js", "zwave_me", diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index 4cac5bc64a23b..face6cb24e4a7 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -8062,6 +8062,12 @@ "config_flow": true, "iot_class": "local_push" }, + "zinvolt": { + "name": "Zinvolt", + "integration_type": "hub", + "config_flow": true, + "iot_class": "cloud_polling" + }, "zodiac": { "integration_type": "hub", "config_flow": true, diff --git a/mypy.ini b/mypy.ini index 814b8ce0402b7..8afddd21a562b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5879,6 +5879,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.zinvolt.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.zodiac.*] check_untyped_defs = true disallow_incomplete_defs = true diff --git a/requirements_all.txt b/requirements_all.txt index 02857f99d12ee..1699cfc251308 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3349,6 +3349,9 @@ zhong-hong-hvac==1.0.13 # homeassistant.components.ziggo_mediabox_xl ziggo-mediabox-xl==1.1.0 +# homeassistant.components.zinvolt +zinvolt==0.1.0 + # homeassistant.components.zoneminder zm-py==0.5.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 180361f2ca51d..bf29d72849847 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2813,6 +2813,9 @@ zeversolar==0.3.2 # homeassistant.components.zha zha==0.0.90 +# homeassistant.components.zinvolt +zinvolt==0.1.0 + # homeassistant.components.zwave_js zwave-js-server-python==0.68.0 diff --git a/tests/components/zinvolt/__init__.py b/tests/components/zinvolt/__init__.py new file mode 100644 index 0000000000000..7befc059ec2a1 --- /dev/null +++ b/tests/components/zinvolt/__init__.py @@ -0,0 +1,13 @@ +"""Tests for the Zinvolt integration.""" + +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry + + +async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: + """Method for setting up the component.""" + config_entry.add_to_hass(hass) + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() diff --git a/tests/components/zinvolt/conftest.py b/tests/components/zinvolt/conftest.py new file mode 100644 index 0000000000000..c7d07427b4a79 --- /dev/null +++ b/tests/components/zinvolt/conftest.py @@ -0,0 +1,57 @@ +"""Common fixtures for the Zinvolt tests.""" + +from collections.abc import Generator +from unittest.mock import AsyncMock, patch + +import pytest +from zinvolt.models import BatteryListResponse, BatteryState + +from homeassistant.components.zinvolt.const import DOMAIN +from homeassistant.const import CONF_ACCESS_TOKEN + +from .const import TOKEN + +from tests.common import MockConfigEntry, load_fixture + + +@pytest.fixture +def mock_setup_entry() -> Generator[AsyncMock]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.zinvolt.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry + + +@pytest.fixture +def mock_config_entry() -> MockConfigEntry: + """Mock config entry.""" + return MockConfigEntry( + domain=DOMAIN, + title="test@test.com", + unique_id="a0226b8f-98fe-4524-b369-272b466b8797", + data={CONF_ACCESS_TOKEN: TOKEN}, + ) + + +@pytest.fixture +def mock_zinvolt_client() -> Generator[AsyncMock]: + """Mock Zinvolt client.""" + with ( + patch( + "homeassistant.components.zinvolt.ZinvoltClient", autospec=True + ) as mock_client, + patch( + "homeassistant.components.zinvolt.config_flow.ZinvoltClient", + new=mock_client, + ), + ): + client = mock_client.return_value + client.login.return_value = TOKEN + client.get_batteries.return_value = BatteryListResponse.from_json( + load_fixture("batteries.json", DOMAIN) + ).batteries + client.get_battery_status.return_value = BatteryState.from_json( + load_fixture("current_state.json", DOMAIN) + ) + yield client diff --git a/tests/components/zinvolt/const.py b/tests/components/zinvolt/const.py new file mode 100644 index 0000000000000..b61911baa2953 --- /dev/null +++ b/tests/components/zinvolt/const.py @@ -0,0 +1,3 @@ +"""Constants for the Zinvolt tests.""" + +TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vZXZhLWJhY2tvZmZpY2Uub25tb29ubHkuYXBwL2FwaS9wdWJsaWMvdjIvbG9naW4iLCJpYXQiOjE3NjA3OTM0NjEsIm5iZiI6MTc2MDc5MzQ2MSwianRpIjoiYjY5U0J4bVVscU5WcmlKQyIsInN1YiI6ImEwMjI2YjhmLTk4ZmUtNDUyNC1iMzY5LTI3MmI0NjZiODc5NyIsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjciLCJkZXZpY2VzIjpbeyJzZXJpYWxfbnVtYmVyIjoiQUxHMDAxMTI0MTAwMTA3Iiwic3VwcGxpZXIiOiJhbHBoYWVzcyIsImRldmljZWFibGVfdHlwZSI6IkFwcFxcTW9kZWxzXFxCYWxjb255QmF0dGVyeSJ9XSwibmFtZSI6IkludGVncmF0aW9uIE5hbWUiLCJhYmlsaXRpZXMiOlsiYXBpOnB1YmxpYyJdfQ.UumLlVUkGBHnO0ZVtpfENy-edf_d5LV4gOctNan2M5w" diff --git a/tests/components/zinvolt/fixtures/batteries.json b/tests/components/zinvolt/fixtures/batteries.json new file mode 100644 index 0000000000000..4746c40c3be45 --- /dev/null +++ b/tests/components/zinvolt/fixtures/batteries.json @@ -0,0 +1,9 @@ +{ + "batteries": [ + { + "id": "a0226fa5-bfdf-4192-9dd5-81d0ad085f29", + "name": "Zinvolt Batterij", + "serial_number": "ALG001124100107" + } + ] +} diff --git a/tests/components/zinvolt/fixtures/current_state.json b/tests/components/zinvolt/fixtures/current_state.json new file mode 100644 index 0000000000000..36e5e5b29429e --- /dev/null +++ b/tests/components/zinvolt/fixtures/current_state.json @@ -0,0 +1,51 @@ +{ + "sn": "ALG001124100107", + "name": "Zinvolt Batterij", + "longitude": 4.8936, + "latitude": 52.3792, + "onlineStatus": "ONLINE", + "currentPower": { + "soc": 4, + "coc": 0.04, + "pbt": 0, + "ppv": 0, + "pso": 0, + "onGrid": true, + "onlineStatus": "ONLINE", + "smp": 800, + "isDormancy": false + }, + "smartMode": "DYNAMIC", + "globalSettings": { + "maxOutput": 800, + "maxOutputLimit": 800, + "maxOutputUnlocked": false, + "batHighCap": 100, + "batUseCap": 25, + "maxChargePower": 900, + "feedModePower": { + "modeType": "FIXED", + "fixedPower": 200, + "pvFeedLimitPower": 800, + "equips": [] + }, + "haveElectricityPrices": true, + "standbyTime": 60 + }, + "tips": [], + "bpd": 493, + "updating": { + "units": [] + }, + "statistic": { + "co2": 0, + "saveAmount": 0, + "totalCapacity": 0 + }, + "isShowStatistic": false, + "meterReaders": [], + "isHomeDisplay": false, + "dynamicPriceStatus": "CONFIGURED", + "dynamicStrategyStatus": "CONFIGURED", + "remindManualSocCalibration": true +} diff --git a/tests/components/zinvolt/snapshots/test_init.ambr b/tests/components/zinvolt/snapshots/test_init.ambr new file mode 100644 index 0000000000000..54e89898d1a88 --- /dev/null +++ b/tests/components/zinvolt/snapshots/test_init.ambr @@ -0,0 +1,32 @@ +# serializer version: 1 +# name: test_device + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'config_entries_subentries': , + 'configuration_url': None, + 'connections': set({ + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'zinvolt', + 'ALG001124100107', + ), + }), + 'labels': set({ + }), + 'manufacturer': 'Zinvolt', + 'model': None, + 'model_id': None, + 'name': 'Zinvolt Batterij', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': 'ALG001124100107', + 'sw_version': None, + 'via_device_id': None, + }) +# --- diff --git a/tests/components/zinvolt/snapshots/test_sensor.ambr b/tests/components/zinvolt/snapshots/test_sensor.ambr new file mode 100644 index 0000000000000..77d2d510d48e5 --- /dev/null +++ b/tests/components/zinvolt/snapshots/test_sensor.ambr @@ -0,0 +1,52 @@ +# serializer version: 1 +# name: test_all_entities[sensor.zinvolt_batterij_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.zinvolt_batterij_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery', + 'platform': 'zinvolt', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'ALG001124100107.state_of_charge', + 'unit_of_measurement': '%', + }) +# --- +# name: test_all_entities[sensor.zinvolt_batterij_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'battery', + 'friendly_name': 'Zinvolt Batterij Battery', + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.zinvolt_batterij_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '4.0', + }) +# --- diff --git a/tests/components/zinvolt/test_config_flow.py b/tests/components/zinvolt/test_config_flow.py new file mode 100644 index 0000000000000..4e37ed8f061c1 --- /dev/null +++ b/tests/components/zinvolt/test_config_flow.py @@ -0,0 +1,110 @@ +"""Test the Zinvolt config flow.""" + +from unittest.mock import AsyncMock + +import pytest +from zinvolt.exceptions import ZinvoltAuthenticationError, ZinvoltError + +from homeassistant.components.zinvolt.const import DOMAIN +from homeassistant.config_entries import SOURCE_USER +from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL, CONF_PASSWORD +from homeassistant.core import HomeAssistant +from homeassistant.data_entry_flow import FlowResultType + +from .const import TOKEN + +from tests.common import MockConfigEntry + + +@pytest.mark.usefixtures("mock_zinvolt_client") +async def test_full_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: + """Test the full flow.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + assert result["type"] is FlowResultType.FORM + assert result["errors"] == {} + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_EMAIL: "test@test.com", + CONF_PASSWORD: "yes", + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == "test@test.com" + assert result["data"] == {CONF_ACCESS_TOKEN: TOKEN} + assert result["result"].unique_id == "a0226b8f-98fe-4524-b369-272b466b8797" + assert len(mock_setup_entry.mock_calls) == 1 + + +@pytest.mark.parametrize( + ("exception", "error"), + [ + (ZinvoltAuthenticationError, "invalid_auth"), + (ZinvoltError, "cannot_connect"), + (Exception, "unknown"), + ], +) +async def test_form_errors( + hass: HomeAssistant, + mock_zinvolt_client: AsyncMock, + mock_setup_entry: AsyncMock, + exception: Exception, + error: str, +) -> None: + """Test we handle invalid auth.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + + mock_zinvolt_client.login.side_effect = exception + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_EMAIL: "test@test.com", + CONF_PASSWORD: "yes", + }, + ) + + assert result["type"] is FlowResultType.FORM + assert result["errors"] == {"base": error} + + mock_zinvolt_client.login.side_effect = None + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_EMAIL: "test@test.com", + CONF_PASSWORD: "yes", + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert len(mock_setup_entry.mock_calls) == 1 + + +@pytest.mark.usefixtures("mock_zinvolt_client") +async def test_duplicate_entry( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Test we handle duplicate entries.""" + mock_config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_EMAIL: "test@test.com", + CONF_PASSWORD: "yes", + }, + ) + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" diff --git a/tests/components/zinvolt/test_init.py b/tests/components/zinvolt/test_init.py new file mode 100644 index 0000000000000..825caca10c665 --- /dev/null +++ b/tests/components/zinvolt/test_init.py @@ -0,0 +1,27 @@ +"""Test the Zinvolt initialization.""" + +from unittest.mock import AsyncMock + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.zinvolt.const import DOMAIN +from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr + +from . import setup_integration + +from tests.common import MockConfigEntry + + +async def test_device( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + mock_config_entry: MockConfigEntry, + mock_zinvolt_client: AsyncMock, + snapshot: SnapshotAssertion, +) -> None: + """Test the Zinvolt device.""" + await setup_integration(hass, mock_config_entry) + device = device_registry.async_get_device({(DOMAIN, "ALG001124100107")}) + assert device + assert device == snapshot diff --git a/tests/components/zinvolt/test_sensor.py b/tests/components/zinvolt/test_sensor.py new file mode 100644 index 0000000000000..20e5e5c029b10 --- /dev/null +++ b/tests/components/zinvolt/test_sensor.py @@ -0,0 +1,27 @@ +"""Tests for the Zinvolt sensor.""" + +from unittest.mock import AsyncMock, patch + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from . import setup_integration + +from tests.common import MockConfigEntry, snapshot_platform + + +async def test_all_entities( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + mock_zinvolt_client: AsyncMock, + mock_config_entry: MockConfigEntry, + entity_registry: er.EntityRegistry, +) -> None: + """Test all entities.""" + with patch("homeassistant.components.zinvolt._PLATFORMS", [Platform.SENSOR]): + await setup_integration(hass, mock_config_entry) + + await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) From f3042741bf69d0642297f6a469964a5962ab241f Mon Sep 17 00:00:00 2001 From: Sab44 <64696149+Sab44@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:57:17 +0100 Subject: [PATCH 17/19] Deprecate Libre Hardware Monitor versions below v0.9.5 (#163838) --- .../libre_hardware_monitor/__init__.py | 21 ++++++- .../libre_hardware_monitor/coordinator.py | 13 ++++- .../libre_hardware_monitor/strings.json | 6 ++ .../libre_hardware_monitor/test_sensor.py | 56 ++++++++++++++++++- 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/libre_hardware_monitor/__init__.py b/homeassistant/components/libre_hardware_monitor/__init__.py index 2a94cda9bac2f..5f4b50353523e 100644 --- a/homeassistant/components/libre_hardware_monitor/__init__.py +++ b/homeassistant/components/libre_hardware_monitor/__init__.py @@ -6,7 +6,11 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers import ( + device_registry as dr, + entity_registry as er, + issue_registry as ir, +) from .const import DOMAIN from .coordinator import ( @@ -80,6 +84,21 @@ async def async_setup_entry( lhm_coordinator = LibreHardwareMonitorCoordinator(hass, config_entry) await lhm_coordinator.async_config_entry_first_refresh() + if lhm_coordinator.data.is_deprecated_version: + issue_id = f"deprecated_api_{config_entry.entry_id}" + ir.async_create_issue( + hass, + DOMAIN, + issue_id, + breaks_in_ha_version="2026.9.0", + is_fixable=False, + severity=ir.IssueSeverity.WARNING, + translation_key="deprecated_api", + translation_placeholders={ + "lhm_releases_url": "https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/releases" + }, + ) + config_entry.runtime_data = lhm_coordinator await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) diff --git a/homeassistant/components/libre_hardware_monitor/coordinator.py b/homeassistant/components/libre_hardware_monitor/coordinator.py index 2e68541c3e82c..e39fa270e991f 100644 --- a/homeassistant/components/libre_hardware_monitor/coordinator.py +++ b/homeassistant/components/libre_hardware_monitor/coordinator.py @@ -21,7 +21,7 @@ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import device_registry as dr, issue_registry as ir from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.device_registry import DeviceEntry from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -50,7 +50,7 @@ def __init__( config_entry=config_entry, update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL), ) - + self._entry_id = config_entry.entry_id self._api = LibreHardwareMonitorClient( host=config_entry.data[CONF_HOST], port=config_entry.data[CONF_PORT], @@ -59,13 +59,14 @@ def __init__( session=async_create_clientsession(hass), ) device_entries: list[DeviceEntry] = dr.async_entries_for_config_entry( - registry=dr.async_get(self.hass), config_entry_id=config_entry.entry_id + registry=dr.async_get(self.hass), config_entry_id=self._entry_id ) self._previous_devices: dict[DeviceId, DeviceName] = { DeviceId(next(iter(device.identifiers))[1]): DeviceName(device.name) for device in device_entries if device.identifiers and device.name } + self._is_deprecated_version: bool | None = None async def _async_update_data(self) -> LibreHardwareMonitorData: try: @@ -80,6 +81,12 @@ async def _async_update_data(self) -> LibreHardwareMonitorData: except LibreHardwareMonitorNoDevicesError as err: raise UpdateFailed("No sensor data available, will retry") from err + # Check whether user has upgraded LHM from a deprecated version while the integration is running + if self._is_deprecated_version and not lhm_data.is_deprecated_version: + # Clear deprecation issue + ir.async_delete_issue(self.hass, DOMAIN, f"deprecated_api_{self._entry_id}") + self._is_deprecated_version = lhm_data.is_deprecated_version + await self._async_handle_changes_in_devices( dict(lhm_data.main_device_ids_and_names) ) diff --git a/homeassistant/components/libre_hardware_monitor/strings.json b/homeassistant/components/libre_hardware_monitor/strings.json index c5ff86e446c06..a029a818ab948 100644 --- a/homeassistant/components/libre_hardware_monitor/strings.json +++ b/homeassistant/components/libre_hardware_monitor/strings.json @@ -33,5 +33,11 @@ } } } + }, + "issues": { + "deprecated_api": { + "description": "Your version of Libre Hardware Monitor is deprecated and may not provide stable sensor data. To fix this issue:\n\n1. Download version 0.9.5 or later from {lhm_releases_url}\n2. Close Libre Hardware Monitor on your computer\n3. Install or extract the new version and start Libre Hardware Monitor again (you might have to re-enable the remote web server)\n4. Home Assistant will detect the new version and this issue will clear automatically", + "title": "Deprecated Libre Hardware Monitor version" + } } } diff --git a/tests/components/libre_hardware_monitor/test_sensor.py b/tests/components/libre_hardware_monitor/test_sensor.py index 8f62f716234d5..04fa222ff0c5e 100644 --- a/tests/components/libre_hardware_monitor/test_sensor.py +++ b/tests/components/libre_hardware_monitor/test_sensor.py @@ -27,7 +27,11 @@ from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers import ( + device_registry as dr, + entity_registry as er, + issue_registry as ir, +) from homeassistant.helpers.device_registry import DeviceEntry from . import init_integration @@ -312,3 +316,53 @@ async def test_integration_does_not_log_new_devices_on_first_refresh( if record.name.startswith("homeassistant.components.libre_hardware_monitor") ] assert len(libre_hardware_monitor_logs) == 0 + + +async def test_non_deprecated_version_does_not_raise_issue( + hass: HomeAssistant, + mock_lhm_client: AsyncMock, + mock_config_entry: MockConfigEntry, + issue_registry: ir.IssueRegistry, +) -> None: + """Test that a non-deprecated Libre Hardware Monitor version does not raise an issue.""" + await init_integration(hass, mock_config_entry) + + assert ( + DOMAIN, + f"deprecated_api_{mock_config_entry.entry_id}", + ) not in issue_registry.issues + + +async def test_deprecated_version_raises_issue_and_is_removed_after_update( + hass: HomeAssistant, + mock_lhm_client: AsyncMock, + mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, + issue_registry: ir.IssueRegistry, +) -> None: + """Test that a deprecated Libre Hardware Monitor version raises an issue that is removed after updating.""" + mock_lhm_client.get_data.return_value = replace( + mock_lhm_client.get_data.return_value, + is_deprecated_version=True, + ) + + await init_integration(hass, mock_config_entry) + + assert ( + DOMAIN, + f"deprecated_api_{mock_config_entry.entry_id}", + ) in issue_registry.issues + + mock_lhm_client.get_data.return_value = replace( + mock_lhm_client.get_data.return_value, + is_deprecated_version=False, + ) + + freezer.tick(timedelta(DEFAULT_SCAN_INTERVAL)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + assert ( + DOMAIN, + f"deprecated_api_{mock_config_entry.entry_id}", + ) not in issue_registry.issues From ac65163ebb4943a64a25f05b64215706e93d7d78 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Mon, 23 Feb 2026 15:58:54 +0100 Subject: [PATCH 18/19] Bump forecast-solar to v5.0.0 (#163841) --- homeassistant/components/forecast_solar/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/forecast_solar/manifest.json b/homeassistant/components/forecast_solar/manifest.json index 66796a44dc485..65df6a8828a9f 100644 --- a/homeassistant/components/forecast_solar/manifest.json +++ b/homeassistant/components/forecast_solar/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/forecast_solar", "integration_type": "service", "iot_class": "cloud_polling", - "requirements": ["forecast-solar==4.2.0"] + "requirements": ["forecast-solar==5.0.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 1699cfc251308..1245f6544cfad 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1003,7 +1003,7 @@ fnv-hash-fast==1.6.0 foobot_async==1.0.0 # homeassistant.components.forecast_solar -forecast-solar==4.2.0 +forecast-solar==5.0.0 # homeassistant.components.fortios fortiosapi==1.0.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bf29d72849847..bdb759243c95b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -888,7 +888,7 @@ fnv-hash-fast==1.6.0 foobot_async==1.0.0 # homeassistant.components.forecast_solar -forecast-solar==4.2.0 +forecast-solar==5.0.0 # homeassistant.components.freebox freebox-api==1.3.0 From dfb17c2187267587b8cc0d0c36777f83f7e4e65a Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 23 Feb 2026 16:15:44 +0100 Subject: [PATCH 19/19] Add configurable panel properties to frontend (#162742) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Petar Petrov --- homeassistant/components/frontend/__init__.py | 104 +++++++- tests/components/frontend/test_init.py | 237 ++++++++++++++++++ 2 files changed, 333 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index f487064cafd54..e8ab7acae4a24 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -18,7 +18,7 @@ from homeassistant.components import onboarding, websocket_api from homeassistant.components.http import KEY_HASS, HomeAssistantView, StaticPathConfig -from homeassistant.components.websocket_api import ActiveConnection +from homeassistant.components.websocket_api import ERR_NOT_FOUND, ActiveConnection from homeassistant.config import async_hass_config_yaml from homeassistant.const import ( CONF_MODE, @@ -78,6 +78,16 @@ THEMES_SAVE_DELAY = 60 DATA_THEMES_STORE: HassKey[Store] = HassKey("frontend_themes_store") DATA_THEMES: HassKey[dict[str, Any]] = HassKey("frontend_themes") + +PANELS_STORAGE_KEY = f"{DOMAIN}_panels" +PANELS_STORAGE_VERSION = 1 +PANELS_SAVE_DELAY = 10 +DATA_PANELS_STORE: HassKey[Store[dict[str, dict[str, Any]]]] = HassKey( + "frontend_panels_store" +) +DATA_PANELS_CONFIG: HassKey[dict[str, dict[str, Any]]] = HassKey( + "frontend_panels_config" +) DATA_DEFAULT_THEME = "frontend_default_theme" DATA_DEFAULT_DARK_THEME = "frontend_default_dark_theme" DEFAULT_THEME = "default" @@ -312,9 +322,11 @@ def __init__( self.sidebar_default_visible = sidebar_default_visible @callback - def to_response(self) -> PanelResponse: + def to_response( + self, config_override: dict[str, Any] | None = None + ) -> PanelResponse: """Panel as dictionary.""" - return { + response: PanelResponse = { "component_name": self.component_name, "icon": self.sidebar_icon, "title": self.sidebar_title, @@ -324,6 +336,18 @@ def to_response(self) -> PanelResponse: "require_admin": self.require_admin, "config_panel_domain": self.config_panel_domain, } + if config_override: + if "require_admin" in config_override: + response["require_admin"] = config_override["require_admin"] + if config_override.get("show_in_sidebar") is False: + response["title"] = None + response["icon"] = None + else: + if "icon" in config_override: + response["icon"] = config_override["icon"] + if "title" in config_override: + response["title"] = config_override["title"] + return response @bind_hass @@ -415,12 +439,24 @@ def _frontend_root(dev_repo_path: str | None) -> pathlib.Path: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the serving of the frontend.""" await async_setup_frontend_storage(hass) + + panels_store = hass.data[DATA_PANELS_STORE] = Store[dict[str, dict[str, Any]]]( + hass, PANELS_STORAGE_VERSION, PANELS_STORAGE_KEY + ) + loaded: Any = await panels_store.async_load() + if not isinstance(loaded, dict): + if loaded is not None: + _LOGGER.warning("Ignoring invalid panel storage data") + loaded = {} + hass.data[DATA_PANELS_CONFIG] = loaded + websocket_api.async_register_command(hass, websocket_get_icons) websocket_api.async_register_command(hass, websocket_get_panels) websocket_api.async_register_command(hass, websocket_get_themes) websocket_api.async_register_command(hass, websocket_get_translations) websocket_api.async_register_command(hass, websocket_get_version) websocket_api.async_register_command(hass, websocket_subscribe_extra_js) + websocket_api.async_register_command(hass, websocket_update_panel) hass.http.register_view(ManifestJSONView()) conf = config.get(DOMAIN, {}) @@ -559,6 +595,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: ) async_register_built_in_panel(hass, "profile") + async_register_built_in_panel(hass, "notfound") @callback def async_change_listener( @@ -883,11 +920,18 @@ def websocket_get_panels( ) -> None: """Handle get panels command.""" user_is_admin = connection.user.is_admin - panels = { - panel_key: panel.to_response() - for panel_key, panel in connection.hass.data[DATA_PANELS].items() - if user_is_admin or not panel.require_admin - } + panels_config = hass.data[DATA_PANELS_CONFIG] + panels: dict[str, PanelResponse] = {} + for panel_key, panel in connection.hass.data[DATA_PANELS].items(): + config_override = panels_config.get(panel_key) + require_admin = ( + config_override.get("require_admin", panel.require_admin) + if config_override + else panel.require_admin + ) + if not user_is_admin and require_admin: + continue + panels[panel_key] = panel.to_response(config_override) connection.send_message(websocket_api.result_message(msg["id"], panels)) @@ -986,6 +1030,50 @@ def cancel_subscription() -> None: connection.send_message(websocket_api.result_message(msg["id"])) +@websocket_api.websocket_command( + { + vol.Required("type"): "frontend/update_panel", + vol.Required("url_path"): str, + vol.Optional("title"): vol.Any(cv.string, None), + vol.Optional("icon"): vol.Any(cv.icon, None), + vol.Optional("require_admin"): vol.Any(cv.boolean, None), + vol.Optional("show_in_sidebar"): vol.Any(cv.boolean, None), + } +) +@websocket_api.require_admin +@websocket_api.async_response +async def websocket_update_panel( + hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any] +) -> None: + """Handle update panel command.""" + url_path: str = msg["url_path"] + + if url_path not in hass.data.get(DATA_PANELS, {}): + connection.send_error(msg["id"], ERR_NOT_FOUND, "Panel not found") + return + + panels_config = hass.data[DATA_PANELS_CONFIG] + panel_config = dict(panels_config.get(url_path, {})) + + for key in ("title", "icon", "require_admin", "show_in_sidebar"): + if key in msg: + if (value := msg[key]) is None: + panel_config.pop(key, None) + else: + panel_config[key] = value + + if panel_config: + panels_config[url_path] = panel_config + else: + panels_config.pop(url_path, None) + + hass.data[DATA_PANELS_STORE].async_delay_save( + lambda: hass.data[DATA_PANELS_CONFIG], PANELS_SAVE_DELAY + ) + hass.bus.async_fire(EVENT_PANELS_UPDATED) + connection.send_result(msg["id"]) + + class PanelResponse(TypedDict): """Represent the panel response type.""" diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index b13dd999ec996..dc5a8cbabd08e 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -1209,3 +1209,240 @@ async def test_setup_with_development_pr_unexpected_error( await hass.async_block_till_done() assert "Unexpected error downloading PR #12345" in caplog.text + + +async def test_update_panel( + hass: HomeAssistant, ws_client: MockHAClientWebSocket +) -> None: + """Test frontend/update_panel command.""" + # Verify initial state + await ws_client.send_json({"id": 1, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["light"]["icon"] == "mdi:lamps" + assert msg["result"]["light"]["title"] == "light" + assert msg["result"]["light"]["require_admin"] is False + + # Update the light panel + events = async_capture_events(hass, EVENT_PANELS_UPDATED) + await ws_client.send_json( + { + "id": 2, + "type": "frontend/update_panel", + "url_path": "light", + "title": "My Lights", + "icon": "mdi:lightbulb", + "require_admin": True, + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + assert len(events) == 1 + + # Verify the panel was updated + await ws_client.send_json({"id": 3, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["light"]["icon"] == "mdi:lightbulb" + assert msg["result"]["light"]["title"] == "My Lights" + assert msg["result"]["light"]["require_admin"] is True + + +async def test_update_panel_partial( + hass: HomeAssistant, ws_client: MockHAClientWebSocket +) -> None: + """Test that partial updates only change specified properties.""" + # Update only title + await ws_client.send_json( + { + "id": 1, + "type": "frontend/update_panel", + "url_path": "climate", + "title": "HVAC", + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + + # Verify only title changed, others kept defaults + await ws_client.send_json({"id": 2, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["climate"]["title"] == "HVAC" + assert msg["result"]["climate"]["icon"] == "mdi:home-thermometer" + assert msg["result"]["climate"]["require_admin"] is False + assert msg["result"]["climate"]["default_visible"] is False + + +async def test_update_panel_not_found(ws_client: MockHAClientWebSocket) -> None: + """Test that non-existent panels are rejected.""" + await ws_client.send_json( + { + "id": 1, + "type": "frontend/update_panel", + "url_path": "nonexistent", + "title": "Does Not Exist", + } + ) + msg = await ws_client.receive_json() + assert not msg["success"] + assert msg["error"]["code"] == "not_found" + + +async def test_update_panel_requires_admin( + hass: HomeAssistant, + ws_client: MockHAClientWebSocket, + hass_admin_user: MockUser, +) -> None: + """Test that non-admin users cannot update panels.""" + hass_admin_user.groups = [] + + await ws_client.send_json( + { + "id": 1, + "type": "frontend/update_panel", + "url_path": "light", + "title": "My Lights", + } + ) + msg = await ws_client.receive_json() + assert not msg["success"] + + +@pytest.mark.usefixtures("ignore_frontend_deps") +async def test_update_panel_persists( + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + hass_storage: dict[str, Any], +) -> None: + """Test that panel config is loaded from storage on startup.""" + hass_storage["frontend_panels"] = { + "key": "frontend_panels", + "version": 1, + "data": { + "light": { + "title": "Saved Lights", + "icon": "mdi:lamp", + "require_admin": True, + }, + }, + } + + assert await async_setup_component(hass, "frontend", {}) + client = await hass_ws_client(hass) + + await client.send_json({"id": 1, "type": "get_panels"}) + msg = await client.receive_json() + assert msg["result"]["light"]["title"] == "Saved Lights" + assert msg["result"]["light"]["icon"] == "mdi:lamp" + assert msg["result"]["light"]["require_admin"] is True + + # Verify other panels still have defaults + assert msg["result"]["climate"]["title"] == "climate" + assert msg["result"]["climate"]["icon"] == "mdi:home-thermometer" + + +async def test_update_panel_reset_param( + hass: HomeAssistant, ws_client: MockHAClientWebSocket +) -> None: + """Test that setting a param to None resets it to the original value.""" + # First set a custom icon + await ws_client.send_json( + { + "id": 1, + "type": "frontend/update_panel", + "url_path": "security", + "icon": "mdi:shield", + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + + await ws_client.send_json({"id": 2, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["security"]["icon"] == "mdi:shield" + + # Reset icon by setting to None — should restore original + await ws_client.send_json( + { + "id": 3, + "type": "frontend/update_panel", + "url_path": "security", + "icon": None, + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + + await ws_client.send_json({"id": 4, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["security"]["icon"] == "mdi:security" + + +async def test_update_panel_hide_sidebar( + hass: HomeAssistant, ws_client: MockHAClientWebSocket +) -> None: + """Test that show_in_sidebar=false clears title and icon like lovelace.""" + # Verify initial state has title and icon + await ws_client.send_json({"id": 1, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["light"]["title"] == "light" + assert msg["result"]["light"]["icon"] == "mdi:lamps" + + # Hide from sidebar + await ws_client.send_json( + { + "id": 2, + "type": "frontend/update_panel", + "url_path": "light", + "show_in_sidebar": False, + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + + # Title and icon should be None + await ws_client.send_json({"id": 3, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["light"]["title"] is None + assert msg["result"]["light"]["icon"] is None + + # Show in sidebar again by resetting show_in_sidebar + await ws_client.send_json( + { + "id": 4, + "type": "frontend/update_panel", + "url_path": "light", + "show_in_sidebar": None, + } + ) + msg = await ws_client.receive_json() + assert msg["success"] + + # Title and icon should be restored + await ws_client.send_json({"id": 5, "type": "get_panels"}) + msg = await ws_client.receive_json() + assert msg["result"]["light"]["title"] == "light" + assert msg["result"]["light"]["icon"] == "mdi:lamps" + + +async def test_panels_config_invalid_storage( + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + hass_storage: dict[str, Any], + caplog: pytest.LogCaptureFixture, +) -> None: + """Test that corrupted panel storage is ignored with a warning.""" + hass_storage["frontend_panels"] = { + "key": "frontend_panels", + "version": 1, + "data": "not_a_dict", + } + + assert await async_setup_component(hass, "frontend", {}) + assert "Ignoring invalid panel storage data" in caplog.text + + client = await hass_ws_client(hass) + + # Panels should still load with defaults + await client.send_json({"id": 1, "type": "get_panels"}) + msg = await client.receive_json() + assert msg["result"]["light"]["title"] == "light" + assert msg["result"]["light"]["icon"] == "mdi:lamps"