From ade4badfa02439d623d2bc6b2c73a7fdce459173 Mon Sep 17 00:00:00 2001 From: flavien Date: Fri, 25 Apr 2025 20:28:36 +0200 Subject: [PATCH] fix --- __init__.py | 6 ++---- coordinator.py | 7 +++++-- manifest.json | 7 +++---- sensor.py | 10 +++++++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index ed00a87..8daddf2 100644 --- a/__init__.py +++ b/__init__.py @@ -7,10 +7,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType): return True async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "sensor") - ) + await hass.config_entries.async_forward_entry_setups(entry, ["sensor"]) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): - return await hass.config_entries.async_forward_entry_unload(entry, "sensor") + return await hass.config_entries.async_unload_platforms(entry, ["sensor"]) diff --git a/coordinator.py b/coordinator.py index 2cbec9f..f0bef12 100644 --- a/coordinator.py +++ b/coordinator.py @@ -20,8 +20,11 @@ class LinkyTarifCoordinator(DataUpdateCoordinator): self._ieee = ieee async def _async_update_data(self): - zha_storage = self.hass.data["zha"] - app_ctrl = zha_storage.gateway.application + try: + zha_gateway = self.hass.data["zha"] + app_ctrl = zha_gateway.application_controller + except (AttributeError, KeyError) as e: + raise UpdateFailed(f"ZHA Gateway not ready: {e}") device = app_ctrl.get_device(types.EUI64.convert(self._ieee)) if not device: diff --git a/manifest.json b/manifest.json index a0407b7..3077084 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,7 @@ "name": "Linky Tarif Sensor", "version": "1.0.0", "config_flow": true, - "documentation": "https://github.com/yourusername/linky_tarif", + "documentation": "https://git.flavien.ovh/flavien/linky_tarif", "requirements": [], - "dependencies": ["zha"], - "codeowners": ["@yourusername"] -} + "dependencies": ["zha"] +} \ No newline at end of file diff --git a/sensor.py b/sensor.py index f15e159..19ca0ff 100644 --- a/sensor.py +++ b/sensor.py @@ -3,6 +3,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity import DeviceInfo +from homeassistant.exceptions import ConfigEntryNotReady from .coordinator import LinkyTarifCoordinator from .const import DOMAIN, CONF_IEEE, CONF_INTERVAL @@ -13,7 +14,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e ieee=entry.data[CONF_IEEE], interval=entry.options.get(CONF_INTERVAL, 300), ) - await coordinator.async_config_entry_first_refresh() + + try: + await coordinator.async_refresh() + if coordinator.last_update_success is False: + raise ConfigEntryNotReady + except Exception: + raise ConfigEntryNotReady + async_add_entities([LinkyTarifSensor(coordinator)]) class LinkyTarifSensor(SensorEntity):