Move template check into fritzbox entry setup (#83863)
* move template check into entry setup * use else in try-except blockpull/83871/head
parent
22e5d86324
commit
41041cb673
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
||||
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
||||
from pyfritzhome.devicetypes.fritzhomeentitybase import FritzhomeEntityBase
|
||||
|
@ -43,7 +44,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
CONF_CONNECTIONS: fritz,
|
||||
}
|
||||
|
||||
coordinator = FritzboxDataUpdateCoordinator(hass, entry)
|
||||
try:
|
||||
await hass.async_add_executor_job(fritz.update_templates)
|
||||
except ParseError:
|
||||
LOGGER.debug("Disable smarthome templates")
|
||||
has_templates = False
|
||||
else:
|
||||
LOGGER.debug("Enable smarthome templates")
|
||||
has_templates = True
|
||||
|
||||
coordinator = FritzboxDataUpdateCoordinator(hass, entry, has_templates)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
||||
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
||||
from pyfritzhome.devicetypes import FritzhomeTemplate
|
||||
|
@ -30,17 +29,14 @@ class FritzboxDataUpdateCoordinator(DataUpdateCoordinator[FritzboxCoordinatorDat
|
|||
|
||||
configuration_url: str
|
||||
|
||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, entry: ConfigEntry, has_templates: bool
|
||||
) -> None:
|
||||
"""Initialize the Fritzbox Smarthome device coordinator."""
|
||||
self.entry = entry
|
||||
self.fritz: Fritzhome = hass.data[DOMAIN][self.entry.entry_id][CONF_CONNECTIONS]
|
||||
self.configuration_url = self.fritz.get_prefixed_host()
|
||||
self.has_templates = True
|
||||
try:
|
||||
hass.async_add_executor_job(self.fritz.update_templates)
|
||||
except ParseError:
|
||||
LOGGER.info("Disable smarthome templates")
|
||||
self.has_templates = False
|
||||
self.has_templates = has_templates
|
||||
|
||||
super().__init__(
|
||||
hass,
|
||||
|
|
Loading…
Reference in New Issue