Skip to content

Commit

Permalink
Evita ImportError su HA 2024.4 e precedenti; fix #44
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualdj committed Jun 1, 2024
1 parent 4f2248d commit c04386e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions custom_components/pun_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit c04386e

Please sign in to comment.