Use has_template property from lib in Fritz!SmartHome (#89152)
parent
0f5c49c7be
commit
d4cc4a343d
|
@ -2,7 +2,6 @@
|
|||
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
|
||||
|
@ -44,14 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
CONF_CONNECTIONS: fritz,
|
||||
}
|
||||
|
||||
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
|
||||
has_templates = await hass.async_add_executor_job(fritz.has_templates)
|
||||
LOGGER.debug("enable smarthome templates: %s", has_templates)
|
||||
|
||||
coordinator = FritzboxDataUpdateCoordinator(hass, entry, has_templates)
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import Mock, call, patch
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
||||
from pyfritzhome import LoginError
|
||||
import pytest
|
||||
|
@ -170,7 +169,7 @@ async def test_coordinator_update_after_reboot(
|
|||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert fritz().update_devices.call_count == 2
|
||||
assert fritz().update_templates.call_count == 2
|
||||
assert fritz().update_templates.call_count == 1
|
||||
assert fritz().get_devices.call_count == 1
|
||||
assert fritz().get_templates.call_count == 1
|
||||
assert fritz().login.call_count == 2
|
||||
|
@ -270,17 +269,3 @@ async def test_raise_config_entry_not_ready_when_offline(hass: HomeAssistant) ->
|
|||
entries = hass.config_entries.async_entries()
|
||||
config_entry = entries[0]
|
||||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_disable_smarthome_templates(hass: HomeAssistant, fritz: Mock) -> None:
|
||||
"""Test smarthome templates are disabled."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
fritz().update_templates.side_effect = [ParseError(), ""]
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert fritz().update_templates.call_count == 1
|
||||
|
|
Loading…
Reference in New Issue