This commit is contained in:
Flavien Haas 2025-04-25 20:28:36 +02:00
parent f85beb29e1
commit ade4badfa0
4 changed files with 19 additions and 11 deletions

View File

@ -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"])

View File

@ -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:

View File

@ -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"]
}

View File

@ -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):