Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -10,17 +10,13 @@ from tests.common import mock_coro, async_fire_time_changed
|
||||
|
||||
async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs):
|
||||
"""Test Alexa config should expose using prefs."""
|
||||
entity_conf = {
|
||||
'should_expose': False
|
||||
}
|
||||
await cloud_prefs.async_update(alexa_entity_configs={
|
||||
'light.kitchen': entity_conf
|
||||
})
|
||||
entity_conf = {"should_expose": False}
|
||||
await cloud_prefs.async_update(alexa_entity_configs={"light.kitchen": entity_conf})
|
||||
conf = alexa_config.AlexaConfig(hass, ALEXA_SCHEMA({}), cloud_prefs, None)
|
||||
|
||||
assert not conf.should_expose('light.kitchen')
|
||||
entity_conf['should_expose'] = True
|
||||
assert conf.should_expose('light.kitchen')
|
||||
assert not conf.should_expose("light.kitchen")
|
||||
entity_conf["should_expose"] = True
|
||||
assert conf.should_expose("light.kitchen")
|
||||
|
||||
|
||||
async def test_alexa_config_report_state(hass, cloud_prefs):
|
||||
@@ -31,8 +27,7 @@ async def test_alexa_config_report_state(hass, cloud_prefs):
|
||||
assert conf.should_report_state is False
|
||||
assert conf.is_reporting_states is False
|
||||
|
||||
with patch.object(conf, 'async_get_access_token',
|
||||
return_value=mock_coro("hello")):
|
||||
with patch.object(conf, "async_get_access_token", return_value=mock_coro("hello")):
|
||||
await cloud_prefs.async_update(alexa_report_state=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -57,11 +52,9 @@ def patch_sync_helper():
|
||||
to_update = []
|
||||
to_remove = []
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.cloud.alexa_config.SYNC_DELAY', 0
|
||||
), patch(
|
||||
'homeassistant.components.cloud.alexa_config.AlexaConfig._sync_helper',
|
||||
side_effect=mock_coro
|
||||
with patch("homeassistant.components.cloud.alexa_config.SYNC_DELAY", 0), patch(
|
||||
"homeassistant.components.cloud.alexa_config.AlexaConfig._sync_helper",
|
||||
side_effect=mock_coro,
|
||||
) as mock_helper:
|
||||
yield to_update, to_remove
|
||||
|
||||
@@ -76,63 +69,62 @@ async def test_alexa_update_expose_trigger_sync(hass, cloud_prefs):
|
||||
|
||||
with patch_sync_helper() as (to_update, to_remove):
|
||||
await cloud_prefs.async_update_alexa_entity_config(
|
||||
entity_id='light.kitchen', should_expose=True
|
||||
entity_id="light.kitchen", should_expose=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, utcnow())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert to_update == ['light.kitchen']
|
||||
assert to_update == ["light.kitchen"]
|
||||
assert to_remove == []
|
||||
|
||||
with patch_sync_helper() as (to_update, to_remove):
|
||||
await cloud_prefs.async_update_alexa_entity_config(
|
||||
entity_id='light.kitchen', should_expose=False
|
||||
entity_id="light.kitchen", should_expose=False
|
||||
)
|
||||
await cloud_prefs.async_update_alexa_entity_config(
|
||||
entity_id='binary_sensor.door', should_expose=True
|
||||
entity_id="binary_sensor.door", should_expose=True
|
||||
)
|
||||
await cloud_prefs.async_update_alexa_entity_config(
|
||||
entity_id='sensor.temp', should_expose=True
|
||||
entity_id="sensor.temp", should_expose=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_time_changed(hass, utcnow())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert sorted(to_update) == ['binary_sensor.door', 'sensor.temp']
|
||||
assert to_remove == ['light.kitchen']
|
||||
assert sorted(to_update) == ["binary_sensor.door", "sensor.temp"]
|
||||
assert to_remove == ["light.kitchen"]
|
||||
|
||||
|
||||
async def test_alexa_entity_registry_sync(hass, mock_cloud_login, cloud_prefs):
|
||||
"""Test Alexa config responds to entity registry."""
|
||||
alexa_config.AlexaConfig(
|
||||
hass, ALEXA_SCHEMA({}), cloud_prefs, hass.data['cloud'])
|
||||
alexa_config.AlexaConfig(hass, ALEXA_SCHEMA({}), cloud_prefs, hass.data["cloud"])
|
||||
|
||||
with patch_sync_helper() as (to_update, to_remove):
|
||||
hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'create',
|
||||
'entity_id': 'light.kitchen',
|
||||
})
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{"action": "create", "entity_id": "light.kitchen"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert to_update == ['light.kitchen']
|
||||
assert to_update == ["light.kitchen"]
|
||||
assert to_remove == []
|
||||
|
||||
with patch_sync_helper() as (to_update, to_remove):
|
||||
hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'remove',
|
||||
'entity_id': 'light.kitchen',
|
||||
})
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{"action": "remove", "entity_id": "light.kitchen"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert to_update == []
|
||||
assert to_remove == ['light.kitchen']
|
||||
assert to_remove == ["light.kitchen"]
|
||||
|
||||
with patch_sync_helper() as (to_update, to_remove):
|
||||
hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'update',
|
||||
'entity_id': 'light.kitchen',
|
||||
})
|
||||
hass.bus.async_fire(
|
||||
EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
{"action": "update", "entity_id": "light.kitchen"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert to_update == []
|
||||
@@ -144,10 +136,14 @@ async def test_alexa_update_report_state(hass, cloud_prefs):
|
||||
alexa_config.AlexaConfig(hass, ALEXA_SCHEMA({}), cloud_prefs, None)
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.cloud.alexa_config.AlexaConfig.'
|
||||
'async_sync_entities', side_effect=mock_coro) as mock_sync, patch(
|
||||
'homeassistant.components.cloud.alexa_config.'
|
||||
'AlexaConfig.async_enable_proactive_mode', side_effect=mock_coro):
|
||||
"homeassistant.components.cloud.alexa_config.AlexaConfig."
|
||||
"async_sync_entities",
|
||||
side_effect=mock_coro,
|
||||
) as mock_sync, patch(
|
||||
"homeassistant.components.cloud.alexa_config."
|
||||
"AlexaConfig.async_enable_proactive_mode",
|
||||
side_effect=mock_coro,
|
||||
):
|
||||
await cloud_prefs.async_update(alexa_report_state=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
Reference in new issue
Block a user