From c04386e7573d3773f93502d66fc1b52c39ec808f Mon Sep 17 00:00:00 2001 From: virtualdj Date: Sat, 1 Jun 2024 14:36:20 +0200 Subject: [PATCH] Evita ImportError su HA 2024.4 e precedenti; fix #44 --- custom_components/pun_sensor/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/custom_components/pun_sensor/__init__.py b/custom_components/pun_sensor/__init__.py index 7cfe098..ef2d9ff 100644 --- a/custom_components/pun_sensor/__init__.py +++ b/custom_components/pun_sensor/__init__.py @@ -17,10 +17,14 @@ UpdateFailed, ) from homeassistant.helpers.event import async_track_point_in_time, async_call_later -from homeassistant.setup import SetupPhases, async_pause_setup import homeassistant.util.dt as dt_util from zoneinfo import ZoneInfo +from awesomeversion.awesomeversion import AwesomeVersion +from homeassistant.const import __version__ as HA_VERSION +if (AwesomeVersion(HA_VERSION) >= AwesomeVersion("2024.5.0")): + from homeassistant.setup import SetupPhases, async_pause_setup + from .const import ( DOMAIN, PUN_FASCIA_MONO, @@ -47,10 +51,11 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool: """Impostazione dell'integrazione da configurazione Home Assistant""" - # Carica le dipendenze di holidays in background - with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES): - await hass.async_add_import_executor_job(holidays.IT) - + # Carica le dipendenze di holidays in background per evitare errori nel log + if (AwesomeVersion(HA_VERSION) >= AwesomeVersion("2024.5.0")): + with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES): + await hass.async_add_import_executor_job(holidays.IT) + # Salva il coordinator nella configurazione coordinator = PUNDataUpdateCoordinator(hass, config) hass.data.setdefault(DOMAIN, {})[config.entry_id] = coordinator