Move netatmo dataclass registrations (#65052)
This commit is contained in:
parent
de7f1e793a
commit
0a2f57e4f8
9 changed files with 27 additions and 23 deletions
|
@ -55,9 +55,6 @@ async def async_setup_entry(
|
|||
"""Set up the Netatmo camera platform."""
|
||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||
|
||||
await data_handler.register_data_class(
|
||||
CAMERA_DATA_CLASS_NAME, CAMERA_DATA_CLASS_NAME, None
|
||||
)
|
||||
data_class = data_handler.data.get(CAMERA_DATA_CLASS_NAME)
|
||||
|
||||
if not data_class or not data_class.raw_data:
|
||||
|
|
|
@ -124,9 +124,6 @@ async def async_setup_entry(
|
|||
"""Set up the Netatmo energy platform."""
|
||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||
|
||||
await data_handler.register_data_class(
|
||||
CLIMATE_TOPOLOGY_CLASS_NAME, CLIMATE_TOPOLOGY_CLASS_NAME, None
|
||||
)
|
||||
climate_topology = data_handler.data.get(CLIMATE_TOPOLOGY_CLASS_NAME)
|
||||
|
||||
if not climate_topology or climate_topology.raw_data == {}:
|
||||
|
|
|
@ -74,7 +74,7 @@ class NetatmoDataClass:
|
|||
name: str
|
||||
interval: int
|
||||
next_scan: float
|
||||
subscriptions: list[CALLBACK_TYPE]
|
||||
subscriptions: list[CALLBACK_TYPE | None]
|
||||
|
||||
|
||||
class NetatmoDataHandler:
|
||||
|
@ -105,6 +105,18 @@ class NetatmoDataHandler:
|
|||
)
|
||||
)
|
||||
|
||||
await asyncio.gather(
|
||||
*[
|
||||
self.register_data_class(data_class, data_class, None)
|
||||
for data_class in (
|
||||
CLIMATE_TOPOLOGY_CLASS_NAME,
|
||||
CAMERA_DATA_CLASS_NAME,
|
||||
WEATHERSTATION_DATA_CLASS_NAME,
|
||||
HOMECOACH_DATA_CLASS_NAME,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
async def async_update(self, event_time: datetime) -> None:
|
||||
"""
|
||||
Update device.
|
||||
|
@ -172,7 +184,7 @@ class NetatmoDataHandler:
|
|||
self,
|
||||
data_class_name: str,
|
||||
data_class_entry: str,
|
||||
update_callback: CALLBACK_TYPE,
|
||||
update_callback: CALLBACK_TYPE | None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Register data class."""
|
||||
|
|
|
@ -34,10 +34,6 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the Netatmo camera light platform."""
|
||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||
|
||||
await data_handler.register_data_class(
|
||||
CAMERA_DATA_CLASS_NAME, CAMERA_DATA_CLASS_NAME, None
|
||||
)
|
||||
data_class = data_handler.data.get(CAMERA_DATA_CLASS_NAME)
|
||||
|
||||
if not data_class or data_class.raw_data == {}:
|
||||
|
|
|
@ -37,9 +37,6 @@ async def async_setup_entry(
|
|||
"""Set up the Netatmo energy platform schedule selector."""
|
||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||
|
||||
await data_handler.register_data_class(
|
||||
CLIMATE_TOPOLOGY_CLASS_NAME, CLIMATE_TOPOLOGY_CLASS_NAME, None
|
||||
)
|
||||
climate_topology = data_handler.data.get(CLIMATE_TOPOLOGY_CLASS_NAME)
|
||||
|
||||
if not climate_topology or climate_topology.raw_data == {}:
|
||||
|
|
|
@ -386,7 +386,6 @@ async def async_setup_entry(
|
|||
WEATHERSTATION_DATA_CLASS_NAME,
|
||||
HOMECOACH_DATA_CLASS_NAME,
|
||||
):
|
||||
await data_handler.register_data_class(data_class_name, data_class_name, None)
|
||||
data_class = data_handler.data.get(data_class_name)
|
||||
|
||||
if data_class and data_class.raw_data:
|
||||
|
|
|
@ -364,7 +364,7 @@ async def test_camera_reconnect_webhook(hass, config_entry):
|
|||
await simulate_webhook(hass, webhook_id, response)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert fake_post_hits == 5
|
||||
assert fake_post_hits == 8
|
||||
|
||||
calls = fake_post_hits
|
||||
|
||||
|
@ -446,7 +446,7 @@ async def test_setup_component_no_devices(hass, config_entry):
|
|||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert fake_post_hits == 1
|
||||
assert fake_post_hits == 4
|
||||
|
||||
|
||||
async def test_camera_image_raises_exception(hass, config_entry, requests_mock):
|
||||
|
@ -491,4 +491,4 @@ async def test_camera_image_raises_exception(hass, config_entry, requests_mock):
|
|||
await camera.async_get_image(hass, camera_entity_indoor)
|
||||
|
||||
assert excinfo.value.args == ("Unable to get image",)
|
||||
assert fake_post_hits == 6
|
||||
assert fake_post_hits == 9
|
||||
|
|
|
@ -112,7 +112,7 @@ async def test_setup_component_with_config(hass, config_entry):
|
|||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert fake_post_hits == 3
|
||||
assert fake_post_hits == 9
|
||||
mock_impl.assert_called_once()
|
||||
mock_webhook.assert_called_once()
|
||||
|
||||
|
@ -354,7 +354,7 @@ async def test_setup_component_with_delay(hass, config_entry):
|
|||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_post_request.call_count == 5
|
||||
assert mock_post_request.call_count == 8
|
||||
|
||||
mock_impl.assert_called_once()
|
||||
mock_webhook.assert_not_called()
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.const import ATTR_ENTITY_ID, CONF_WEBHOOK_ID
|
|||
|
||||
from .common import FAKE_WEBHOOK_ACTIVATION, selected_platforms, simulate_webhook
|
||||
|
||||
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
||||
|
||||
|
||||
async def test_light_setup_and_services(hass, config_entry, netatmo_auth):
|
||||
"""Test setup and services."""
|
||||
|
@ -89,7 +91,11 @@ async def test_setup_component_no_devices(hass, config_entry):
|
|||
"""Fake error during requesting backend data."""
|
||||
nonlocal fake_post_hits
|
||||
fake_post_hits += 1
|
||||
return "{}"
|
||||
return AiohttpClientMockResponse(
|
||||
method="POST",
|
||||
url=kwargs["url"],
|
||||
json={},
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth"
|
||||
|
@ -115,7 +121,7 @@ async def test_setup_component_no_devices(hass, config_entry):
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert fake_post_hits == 1
|
||||
assert fake_post_hits == 4
|
||||
|
||||
assert hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue