mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add basic system health data to the recorder (#71086)
This commit is contained in:
parent
f14bc1cece
commit
66a21e0bc3
@ -53,6 +53,13 @@ class RunHistory:
|
|||||||
"""Return the time the recorder started recording states."""
|
"""Return the time the recorder started recording states."""
|
||||||
return self._recording_start
|
return self._recording_start
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first(self) -> RecorderRuns:
|
||||||
|
"""Get the first run."""
|
||||||
|
if runs_by_timestamp := self._run_history.runs_by_timestamp:
|
||||||
|
return next(iter(runs_by_timestamp.values()))
|
||||||
|
return self.current
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current(self) -> RecorderRuns:
|
def current(self) -> RecorderRuns:
|
||||||
"""Get the current run."""
|
"""Get the current run."""
|
||||||
|
8
homeassistant/components/recorder/strings.json
Normal file
8
homeassistant/components/recorder/strings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"system_health": {
|
||||||
|
"info": {
|
||||||
|
"oldest_recorder_run": "Oldest Run Start Time",
|
||||||
|
"current_recorder_run": "Current Run Start Time"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
homeassistant/components/recorder/system_health.py
Normal file
24
homeassistant/components/recorder/system_health.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
"""Provide info to system health."""
|
||||||
|
|
||||||
|
from homeassistant.components import system_health
|
||||||
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
|
||||||
|
from . import get_instance
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_register(
|
||||||
|
hass: HomeAssistant, register: system_health.SystemHealthRegistration
|
||||||
|
) -> None:
|
||||||
|
"""Register system health callbacks."""
|
||||||
|
register.async_register_info(system_health_info)
|
||||||
|
|
||||||
|
|
||||||
|
async def system_health_info(hass: HomeAssistant):
|
||||||
|
"""Get info for the info page."""
|
||||||
|
instance = get_instance(hass)
|
||||||
|
run_history = instance.run_history
|
||||||
|
return {
|
||||||
|
"oldest_recorder_run": run_history.first.start,
|
||||||
|
"current_recorder_run": run_history.current.start,
|
||||||
|
}
|
8
homeassistant/components/recorder/translations/en.json
Normal file
8
homeassistant/components/recorder/translations/en.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"system_health": {
|
||||||
|
"info": {
|
||||||
|
"current_recorder_run": "Current Run Start Time",
|
||||||
|
"oldest_recorder_run": "Oldest Run Start Time"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
tests/components/recorder/test_system_health.py
Normal file
38
tests/components/recorder/test_system_health.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"""Test recorder system health."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from homeassistant.components.recorder import get_instance
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from .common import async_wait_recording_done
|
||||||
|
|
||||||
|
from tests.common import SetupRecorderInstanceT, get_system_health_info
|
||||||
|
|
||||||
|
|
||||||
|
async def test_recorder_system_health(hass, recorder_mock):
|
||||||
|
"""Test recorder system health."""
|
||||||
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
|
await async_wait_recording_done(hass)
|
||||||
|
info = await get_system_health_info(hass, "recorder")
|
||||||
|
instance = get_instance(hass)
|
||||||
|
assert info == {
|
||||||
|
"current_recorder_run": instance.run_history.current.start,
|
||||||
|
"oldest_recorder_run": instance.run_history.first.start,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_recorder_system_health_crashed_recorder_runs_table(
|
||||||
|
hass: HomeAssistant, async_setup_recorder_instance: SetupRecorderInstanceT
|
||||||
|
):
|
||||||
|
"""Test recorder system health with crashed recorder runs table."""
|
||||||
|
with patch("homeassistant.components.recorder.run_history.RunHistory.load_from_db"):
|
||||||
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
|
instance = await async_setup_recorder_instance(hass)
|
||||||
|
await async_wait_recording_done(hass)
|
||||||
|
info = await get_system_health_info(hass, "recorder")
|
||||||
|
assert info == {
|
||||||
|
"current_recorder_run": instance.run_history.current.start,
|
||||||
|
"oldest_recorder_run": instance.run_history.current.start,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user