mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add diagnostics support to CPU Speed (#64745)
* Add diagnostics support to CPU Speed * Fix copy pasta error
This commit is contained in:
parent
88c9422b70
commit
22656f6082
17
homeassistant/components/cpuspeed/diagnostics.py
Normal file
17
homeassistant/components/cpuspeed/diagnostics.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
"""Diagnostics support for CPU Speed."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from cpuinfo import cpuinfo
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
info: dict[str, Any] = cpuinfo.get_cpu_info()
|
||||||
|
return info
|
36
tests/components/cpuspeed/test_diagnostics.py
Normal file
36
tests/components/cpuspeed/test_diagnostics.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
"""Tests for the diagnostics data provided by the CPU Speed integration."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSession,
|
||||||
|
init_integration: MockConfigEntry,
|
||||||
|
):
|
||||||
|
"""Test diagnostics."""
|
||||||
|
info = {
|
||||||
|
"hz_actual": (3200000001, 0),
|
||||||
|
"arch_string_raw": "aargh",
|
||||||
|
"brand_raw": "Intel Ryzen 7",
|
||||||
|
"hz_advertised": (3600000001, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.cpuspeed.diagnostics.cpuinfo.get_cpu_info",
|
||||||
|
return_value=info,
|
||||||
|
):
|
||||||
|
assert await get_diagnostics_for_config_entry(
|
||||||
|
hass, hass_client, init_integration
|
||||||
|
) == {
|
||||||
|
"hz_actual": [3200000001, 0],
|
||||||
|
"arch_string_raw": "aargh",
|
||||||
|
"brand_raw": "Intel Ryzen 7",
|
||||||
|
"hz_advertised": [3600000001, 0],
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user