Use has_template property from lib in Fritz!SmartHome (#89152)

pull/90137/head
Michael 2023-03-21 21:33:33 +01:00 committed by GitHub
parent 0f5c49c7be
commit d4cc4a343d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 25 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from xml.etree.ElementTree import ParseError
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
from pyfritzhome.devicetypes.fritzhomeentitybase import FritzhomeEntityBase from pyfritzhome.devicetypes.fritzhomeentitybase import FritzhomeEntityBase
@ -44,14 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
CONF_CONNECTIONS: fritz, CONF_CONNECTIONS: fritz,
} }
try: has_templates = await hass.async_add_executor_job(fritz.has_templates)
await hass.async_add_executor_job(fritz.update_templates) LOGGER.debug("enable smarthome templates: %s", has_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) coordinator = FritzboxDataUpdateCoordinator(hass, entry, has_templates)

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from unittest.mock import Mock, call, patch from unittest.mock import Mock, call, patch
from xml.etree.ElementTree import ParseError
from pyfritzhome import LoginError from pyfritzhome import LoginError
import pytest import pytest
@ -170,7 +169,7 @@ async def test_coordinator_update_after_reboot(
assert await hass.config_entries.async_setup(entry.entry_id) assert await hass.config_entries.async_setup(entry.entry_id)
assert fritz().update_devices.call_count == 2 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_devices.call_count == 1
assert fritz().get_templates.call_count == 1 assert fritz().get_templates.call_count == 1
assert fritz().login.call_count == 2 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() entries = hass.config_entries.async_entries()
config_entry = entries[0] config_entry = entries[0]
assert config_entry.state is ConfigEntryState.SETUP_ERROR 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