Add test helper for cloud status updates (#100993)

* Add helper for cloud status updates

* Move import
pull/101013/head
Joost Lekkerkerker 2023-09-27 17:08:51 +02:00 committed by GitHub
parent 25a80cd46f
commit 8b5bfd8cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View File

@ -67,7 +67,10 @@ from homeassistant.helpers import (
restore_state as rs,
storage,
)
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.json import JSONEncoder, _orjson_default_encoder
from homeassistant.helpers.typing import ConfigType, StateType
from homeassistant.setup import setup_component
@ -1443,3 +1446,17 @@ def async_get_persistent_notifications(
) -> dict[str, pn.Notification]:
"""Get the current persistent notifications."""
return pn._async_get_or_create_notifications(hass)
def async_mock_cloud_connection_status(hass: HomeAssistant, connected: bool) -> None:
"""Mock a signal the cloud disconnected."""
from homeassistant.components.cloud import (
SIGNAL_CLOUD_CONNECTION_STATE,
CloudConnectionState,
)
if connected:
state = CloudConnectionState.CLOUD_CONNECTED
else:
state = CloudConnectionState.CLOUD_DISCONNECTED
async_dispatcher_send(hass, SIGNAL_CLOUD_CONNECTION_STATE, state)

View File

@ -11,11 +11,7 @@ from withings_api import NotifyListResponse
from withings_api.common import AuthFailedException, NotifyAppli, UnauthorizedException
from homeassistant import config_entries
from homeassistant.components.cloud import (
SIGNAL_CLOUD_CONNECTION_STATE,
CloudConnectionState,
CloudNotAvailable,
)
from homeassistant.components.cloud import CloudNotAvailable
from homeassistant.components.webhook import async_generate_url
from homeassistant.components.withings import CONFIG_SCHEMA, async_setup
from homeassistant.components.withings.const import CONF_USE_WEBHOOK, DOMAIN
@ -26,7 +22,6 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STARTED,
)
from homeassistant.core import CoreState, HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.util import dt as dt_util
from . import call_webhook, setup_integration
@ -35,6 +30,7 @@ from .conftest import USER_ID, WEBHOOK_ID
from tests.common import (
MockConfigEntry,
async_fire_time_changed,
async_mock_cloud_connection_status,
load_json_object_fixture,
)
from tests.components.cloud import mock_cloud
@ -506,16 +502,12 @@ async def test_cloud_disconnect(
assert withings.async_notify_subscribe.call_count == 6
async_dispatcher_send(
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_DISCONNECTED
)
async_mock_cloud_connection_status(hass, False)
await hass.async_block_till_done()
assert withings.async_notify_revoke.call_count == 3
async_dispatcher_send(
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_CONNECTED
)
async_mock_cloud_connection_status(hass, True)
await hass.async_block_till_done()
assert withings.async_notify_subscribe.call_count == 12