Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for streaming (push) history #85892

Merged
merged 39 commits into from
Jan 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
980b672
Add support for streaming (push) history
bdraco Jan 14, 2023
3095055
Update homeassistant/components/history/__init__.py
bdraco Jan 14, 2023
7fae8cd
merge filter
bdraco Jan 14, 2023
96566e9
Merge remote-tracking branch 'origin/history_stream' into history_stream
bdraco Jan 14, 2023
6ab7af6
expose new api
bdraco Jan 14, 2023
8017359
expose new api
bdraco Jan 14, 2023
9b4f96d
expose new api
bdraco Jan 14, 2023
9efca7b
expose new api
bdraco Jan 14, 2023
839b80e
coverage
bdraco Jan 14, 2023
170013a
tests
bdraco Jan 14, 2023
f7b7516
fixes
bdraco Jan 15, 2023
3c2ffdf
tweak
bdraco Jan 15, 2023
695b55b
tweak
bdraco Jan 15, 2023
9f7c13b
tweak
bdraco Jan 15, 2023
2c7c359
DRY
bdraco Jan 15, 2023
9886945
leaky
bdraco Jan 15, 2023
d05e8f6
Merge branch 'dev' into history_stream
bdraco Jan 15, 2023
3f49518
test for specific entities
bdraco Jan 15, 2023
f66d56e
test for specific entities
bdraco Jan 15, 2023
015dc5c
test for specific entities
bdraco Jan 15, 2023
ee1aab4
test for specific entities
bdraco Jan 15, 2023
86dced4
test for specific entities
bdraco Jan 15, 2023
0dd0e03
Merge remote-tracking branch 'origin/history_stream' into history_stream
bdraco Jan 15, 2023
f8399b3
cover
bdraco Jan 15, 2023
7e5e69c
cover
bdraco Jan 15, 2023
b7aad92
more cover
bdraco Jan 15, 2023
098489e
tweak
bdraco Jan 15, 2023
3a938c5
make sure it works before history starts
bdraco Jan 15, 2023
b163830
fix test
bdraco Jan 15, 2023
451283e
cover
bdraco Jan 15, 2023
e0d257a
tweak
bdraco Jan 15, 2023
d9c06a5
make sure we unsub on overflow
bdraco Jan 16, 2023
3209482
Update homeassistant/components/history/__init__.py
bdraco Jan 16, 2023
f0a56f5
Update homeassistant/components/history/__init__.py
bdraco Jan 16, 2023
3e5331a
fix race in test
bdraco Jan 16, 2023
dc2e823
Merge remote-tracking branch 'origin/history_stream' into history_stream
bdraco Jan 16, 2023
bad23c5
Merge branch 'dev' into history_stream
bdraco Jan 16, 2023
727e4e3
fix db executor access
bdraco Jan 16, 2023
191353d
relo above task creation
bdraco Jan 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests
  • Loading branch information
bdraco committed Jan 14, 2023
commit 170013a7795411ec8b0f33bed2fbb1d3adb1f378
101 changes: 101 additions & 0 deletions tests/components/history/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,62 @@ async def test_history_during_period_bad_end_time(recorder_mock, hass, hass_ws_c
assert response["error"]["code"] == "invalid_end_time"


async def test_history_during_period_with_use_include_order(
recorder_mock, hass, hass_ws_client
):
"""Test history_during_period."""
now = dt_util.utcnow()
sort_order = ["sensor.two", "sensor.four", "sensor.one"]
await async_setup_component(
hass,
"history",
{
history.DOMAIN: {
history.CONF_ORDER: True,
CONF_INCLUDE: {
CONF_ENTITIES: sort_order,
CONF_DOMAINS: ["sensor"],
},
}
},
)
await async_setup_component(hass, "sensor", {})
await async_recorder_block_till_done(hass)
hass.states.async_set("sensor.one", "on", attributes={"any": "attr"})
await async_recorder_block_till_done(hass)
hass.states.async_set("sensor.two", "off", attributes={"any": "attr"})
await async_recorder_block_till_done(hass)
hass.states.async_set("sensor.three", "off", attributes={"any": "changed"})
await async_recorder_block_till_done(hass)
hass.states.async_set("sensor.four", "off", attributes={"any": "again"})
await async_recorder_block_till_done(hass)
hass.states.async_set("switch.excluded", "off", attributes={"any": "again"})
await async_wait_recording_done(hass)

await async_wait_recording_done(hass)

client = await hass_ws_client()
await client.send_json(
{
"id": 1,
"type": "history/history_during_period",
"start_time": now.isoformat(),
"include_start_time_state": True,
"significant_changes_only": False,
"no_attributes": True,
"minimal_response": True,
}
)
response = await client.receive_json()
assert response["success"]
assert response["id"] == 1

assert list(response["result"]) == [
*sort_order,
"sensor.three",
]


async def test_history_stream_historical_only(recorder_mock, hass, hass_ws_client):
"""Test history stream."""
now = dt_util.utcnow()
Expand Down Expand Up @@ -1515,3 +1571,48 @@ async def test_history_stream_significant_domain_historical_only(
assert sensor_test_history[0]["a"] == {"temperature": "5"}
assert sensor_test_history[0]["lu"] == later.timestamp()
assert "lc" not in sensor_test_history[0] # skipped if the same a last_updated (lu)


async def test_history_stream_bad_start_time(recorder_mock, hass, hass_ws_client):
"""Test history stream bad state time."""
await async_setup_component(
hass,
"history",
{"history": {}},
)

client = await hass_ws_client()
await client.send_json(
{
"id": 1,
"type": "history/stream",
"start_time": "cats",
}
)
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == "invalid_start_time"


async def test_history_stream_bad_end_time(recorder_mock, hass, hass_ws_client):
"""Test history stream bad end time."""
now = dt_util.utcnow()

await async_setup_component(
hass,
"history",
{"history": {}},
)

client = await hass_ws_client()
await client.send_json(
{
"id": 1,
"type": "history/stream",
"start_time": now.isoformat(),
"end_time": "dogs",
}
)
response = await client.receive_json()
assert not response["success"]
assert response["error"]["code"] == "invalid_end_time"