From 6c04e4f8ed5b5acaedc8c1413d9c7b673993dcb6 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Wed, 23 Sep 2026 16:35:43 +0200 Subject: [PATCH] Start the 5.0 integration when it is installed next to 4.x Version 5.0 uses the domain gree_custom and moves the 4.x devices over when it starts. Home Assistant only sets up an integration that has a config entry or a YAML key, and after an update through HACS gree_custom has neither. HACS also leaves custom_components/gree in place, so this version still runs after the update. async_setup now starts gree_custom when it is installed. Nothing happens when it is not. This makes the move to 5.0 work without user action for everyone who updates to this release first. --- custom_components/gree/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/custom_components/gree/__init__.py b/custom_components/gree/__init__.py index a5858931..49e73623 100644 --- a/custom_components/gree/__init__.py +++ b/custom_components/gree/__init__.py @@ -20,6 +20,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv from homeassistant.helpers.typing import ConfigType +from homeassistant.loader import IntegrationNotFound, async_get_integration +from homeassistant.setup import async_setup_component # Local imports from .const import ( @@ -44,6 +46,9 @@ PLATFORMS = [Platform.CLIMATE, Platform.SWITCH, Platform.NUMBER, Platform.SELECT, Platform.SENSOR] _LOGGER = logging.getLogger(__name__) +# Version 5 of this integration uses its own domain, see _start_successor() +SUCCESSOR_DOMAIN = "gree_custom" + # YAML configuration schema CLIMATE_SCHEMA = vol.Schema( { @@ -66,8 +71,30 @@ CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.All(cv.ensure_list, [CLIMATE_SCHEMA])}, extra=vol.ALLOW_EXTRA) +def _start_successor(hass: HomeAssistant, config: ConfigType) -> None: + """Start version 5 when it is installed next to this version. + + Version 5 uses the domain gree_custom and moves the devices of this + version over when it starts. Home Assistant only sets up an integration + that has a config entry or a YAML key, and after an update through HACS + gree_custom has neither yet. So this version starts it. + """ + + async def _setup() -> None: + try: + await async_get_integration(hass, SUCCESSOR_DOMAIN) + except IntegrationNotFound: + return + _LOGGER.info("Starting %s, which replaces this integration", SUCCESSOR_DOMAIN) + await async_setup_component(hass, SUCCESSOR_DOMAIN, config) + + hass.async_create_task(_setup()) + + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Gree component from yaml.""" + _start_successor(hass, config) + if DOMAIN not in config: return True