Google: Report all states on activating report state (#27312)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-10-08 09:58:36 -07:00
1 parent 0cfd0388d6
commit a51e0d7a5f
3 files changed
+54 -6

No files matched your search

@@ -1,17 +1,38 @@
"""Test Google report state."""
from unittest.mock import patch
from homeassistant.components.google_assistant.report_state import (
async_enable_report_state,
)
from homeassistant.components.google_assistant import report_state
from homeassistant.util.dt import utcnow
from . import BASIC_CONFIG
from tests.common import mock_coro
from tests.common import mock_coro, async_fire_time_changed
async def test_report_state(hass):
"""Test report state works."""
unsub = async_enable_report_state(hass, BASIC_CONFIG)
hass.states.async_set("light.ceiling", "off")
hass.states.async_set("switch.ac", "on")
with patch.object(
BASIC_CONFIG, "async_report_state", side_effect=mock_coro
) as mock_report, patch.object(report_state, "INITIAL_REPORT_DELAY", 0):
unsub = report_state.async_enable_report_state(hass, BASIC_CONFIG)
async_fire_time_changed(hass, utcnow())
await hass.async_block_till_done()
# Test that enabling report state does a report on all entities
assert len(mock_report.mock_calls) == 1
assert mock_report.mock_calls[0][1][0] == {
"devices": {
"states": {
"light.ceiling": {"on": False, "online": True},
"switch.ac": {"on": True, "online": True},
}
}
}
with patch.object(
BASIC_CONFIG, "async_report_state", side_effect=mock_coro