From f2726527f2c8e0a575720e6352b812dd30b2a232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Moreno?= Date: Tue, 25 Jul 2023 09:55:05 +0200 Subject: [PATCH] Create zwave_js repair issue instead of warning log entry (#95997) Co-authored-by: Martin Hjelmare --- homeassistant/components/zwave_js/climate.py | 23 +++++++++++++--- .../components/zwave_js/strings.json | 11 ++++++++ tests/components/zwave_js/test_climate.py | 27 ++++++++++++++----- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index cb027f32e0a..327db05cb00 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -37,6 +37,7 @@ from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemper from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.util.unit_conversion import TemperatureConverter from .const import DATA_CLIENT, DOMAIN, LOGGER @@ -502,13 +503,27 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): preset_mode_value = self._hvac_presets.get(preset_mode) if preset_mode_value is None: raise ValueError(f"Received an invalid preset mode: {preset_mode}") - # Dry and Fan preset modes are deprecated as of 2023.8 - # Use Dry and Fan HVAC modes instead + # Dry and Fan preset modes are deprecated as of Home Assistant 2023.8. + # Please use Dry and Fan HVAC modes instead. if preset_mode_value in (ThermostatMode.DRY, ThermostatMode.FAN): LOGGER.warning( - "Dry and Fan preset modes are deprecated and will be removed in a future release. " - "Use the corresponding Dry and Fan HVAC modes instead" + "Dry and Fan preset modes are deprecated and will be removed in Home Assistant 2024.2. " + "Please use the corresponding Dry and Fan HVAC modes instead" ) + async_create_issue( + self.hass, + DOMAIN, + f"dry_fan_presets_deprecation_{self.entity_id}", + breaks_in_ha_version="2024.2.0", + is_fixable=True, + is_persistent=True, + severity=IssueSeverity.WARNING, + translation_key="dry_fan_presets_deprecation", + translation_placeholders={ + "entity_id": self.entity_id, + }, + ) + await self._async_set_value(self._current_mode, preset_mode_value) diff --git a/homeassistant/components/zwave_js/strings.json b/homeassistant/components/zwave_js/strings.json index 3b86cbdd5a4..934307947d8 100644 --- a/homeassistant/components/zwave_js/strings.json +++ b/homeassistant/components/zwave_js/strings.json @@ -150,6 +150,17 @@ "invalid_server_version": { "title": "Newer version of Z-Wave JS Server needed", "description": "The version of Z-Wave JS Server you are currently running is too old for this version of Home Assistant. Please update the Z-Wave JS Server to the latest version to fix this issue." + }, + "dry_fan_presets_deprecation": { + "title": "Dry and Fan preset modes will be removed: {entity_id}", + "fix_flow": { + "step": { + "confirm": { + "title": "Dry and Fan preset modes will be removed: {entity_id}", + "description": "You are using the Dry or Fan preset modes in your entity `{entity_id}`.\n\nDry and Fan preset modes are deprecated and will be removed. Please update your automations to use the corresponding Dry and Fan **HVAC modes** instead.\n\nClick on SUBMIT below once you have manually fixed this issue." + } + } + } } }, "services": { diff --git a/tests/components/zwave_js/test_climate.py b/tests/components/zwave_js/test_climate.py index 753c107c2ee..23d34c131b8 100644 --- a/tests/components/zwave_js/test_climate.py +++ b/tests/components/zwave_js/test_climate.py @@ -40,6 +40,7 @@ from homeassistant.const import ( ATTR_TEMPERATURE, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import issue_registry as ir from .common import ( CLIMATE_AIDOO_HVAC_UNIT_ENTITY, @@ -722,14 +723,14 @@ async def test_thermostat_dry_and_fan_both_hvac_mode_and_preset( ] -async def test_thermostat_warning_when_setting_dry_preset( +async def test_thermostat_raise_repair_issue_and_warning_when_setting_dry_preset( hass: HomeAssistant, client, climate_airzone_aidoo_control_hvac_unit, integration, caplog: pytest.LogCaptureFixture, ) -> None: - """Test warning when setting Dry preset.""" + """Test raise of repair issue and warning when setting Dry preset.""" state = hass.states.get(CLIMATE_AIDOO_HVAC_UNIT_ENTITY) assert state @@ -743,20 +744,27 @@ async def test_thermostat_warning_when_setting_dry_preset( blocking=True, ) + issue_id = f"dry_fan_presets_deprecation_{CLIMATE_AIDOO_HVAC_UNIT_ENTITY}" + issue_registry = ir.async_get(hass) + + assert issue_registry.async_get_issue( + domain=DOMAIN, + issue_id=issue_id, + ) assert ( - "Dry and Fan preset modes are deprecated and will be removed in a future release. Use the corresponding Dry and Fan HVAC modes instead" + "Dry and Fan preset modes are deprecated and will be removed in Home Assistant 2024.2. Please use the corresponding Dry and Fan HVAC modes instead" in caplog.text ) -async def test_thermostat_warning_when_setting_fan_preset( +async def test_thermostat_raise_repair_issue_and_warning_when_setting_fan_preset( hass: HomeAssistant, client, climate_airzone_aidoo_control_hvac_unit, integration, caplog: pytest.LogCaptureFixture, ) -> None: - """Test warning when setting Fan preset.""" + """Test raise of repair issue and warning when setting Fan preset.""" state = hass.states.get(CLIMATE_AIDOO_HVAC_UNIT_ENTITY) assert state @@ -770,7 +778,14 @@ async def test_thermostat_warning_when_setting_fan_preset( blocking=True, ) + issue_id = f"dry_fan_presets_deprecation_{CLIMATE_AIDOO_HVAC_UNIT_ENTITY}" + issue_registry = ir.async_get(hass) + + assert issue_registry.async_get_issue( + domain=DOMAIN, + issue_id=issue_id, + ) assert ( - "Dry and Fan preset modes are deprecated and will be removed in a future release. Use the corresponding Dry and Fan HVAC modes instead" + "Dry and Fan preset modes are deprecated and will be removed in Home Assistant 2024.2. Please use the corresponding Dry and Fan HVAC modes instead" in caplog.text )