mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add test helper for cloud status updates (#100993)
* Add helper for cloud status updates * Move import
This commit is contained in:
parent
25a80cd46f
commit
8b5bfd8cee
@ -67,7 +67,10 @@ from homeassistant.helpers import (
|
|||||||
restore_state as rs,
|
restore_state as rs,
|
||||||
storage,
|
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.json import JSONEncoder, _orjson_default_encoder
|
||||||
from homeassistant.helpers.typing import ConfigType, StateType
|
from homeassistant.helpers.typing import ConfigType, StateType
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
@ -1443,3 +1446,17 @@ def async_get_persistent_notifications(
|
|||||||
) -> dict[str, pn.Notification]:
|
) -> dict[str, pn.Notification]:
|
||||||
"""Get the current persistent notifications."""
|
"""Get the current persistent notifications."""
|
||||||
return pn._async_get_or_create_notifications(hass)
|
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)
|
||||||
|
@ -11,11 +11,7 @@ from withings_api import NotifyListResponse
|
|||||||
from withings_api.common import AuthFailedException, NotifyAppli, UnauthorizedException
|
from withings_api.common import AuthFailedException, NotifyAppli, UnauthorizedException
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.cloud import (
|
from homeassistant.components.cloud import CloudNotAvailable
|
||||||
SIGNAL_CLOUD_CONNECTION_STATE,
|
|
||||||
CloudConnectionState,
|
|
||||||
CloudNotAvailable,
|
|
||||||
)
|
|
||||||
from homeassistant.components.webhook import async_generate_url
|
from homeassistant.components.webhook import async_generate_url
|
||||||
from homeassistant.components.withings import CONFIG_SCHEMA, async_setup
|
from homeassistant.components.withings import CONFIG_SCHEMA, async_setup
|
||||||
from homeassistant.components.withings.const import CONF_USE_WEBHOOK, DOMAIN
|
from homeassistant.components.withings.const import CONF_USE_WEBHOOK, DOMAIN
|
||||||
@ -26,7 +22,6 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, HomeAssistant
|
from homeassistant.core import CoreState, HomeAssistant
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import call_webhook, setup_integration
|
from . import call_webhook, setup_integration
|
||||||
@ -35,6 +30,7 @@ from .conftest import USER_ID, WEBHOOK_ID
|
|||||||
from tests.common import (
|
from tests.common import (
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
async_fire_time_changed,
|
async_fire_time_changed,
|
||||||
|
async_mock_cloud_connection_status,
|
||||||
load_json_object_fixture,
|
load_json_object_fixture,
|
||||||
)
|
)
|
||||||
from tests.components.cloud import mock_cloud
|
from tests.components.cloud import mock_cloud
|
||||||
@ -506,16 +502,12 @@ async def test_cloud_disconnect(
|
|||||||
|
|
||||||
assert withings.async_notify_subscribe.call_count == 6
|
assert withings.async_notify_subscribe.call_count == 6
|
||||||
|
|
||||||
async_dispatcher_send(
|
async_mock_cloud_connection_status(hass, False)
|
||||||
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_DISCONNECTED
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert withings.async_notify_revoke.call_count == 3
|
assert withings.async_notify_revoke.call_count == 3
|
||||||
|
|
||||||
async_dispatcher_send(
|
async_mock_cloud_connection_status(hass, True)
|
||||||
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_CONNECTED
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert withings.async_notify_subscribe.call_count == 12
|
assert withings.async_notify_subscribe.call_count == 12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user