Fix CPUSpeed with missing info (#66339)

This commit is contained in:
Franck Nijhof
2022-02-11 13:30:42 -08:00
committed by Paulus Schoutsen
parent f3a3ff28f2
commit 646c56e0e9
2 changed files with 24 additions and 2 deletions
+22
View File
@@ -61,3 +61,25 @@ async def test_sensor(
assert state.attributes.get(ATTR_ARCH) == "aargh"
assert state.attributes.get(ATTR_BRAND) == "Intel Ryzen 7"
assert state.attributes.get(ATTR_HZ) == 3.6
async def test_sensor_partial_info(
hass: HomeAssistant,
mock_cpuinfo: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the CPU Speed sensor missing info."""
mock_config_entry.add_to_hass(hass)
# Pop some info from the mocked CPUSpeed
mock_cpuinfo.return_value.pop("brand_raw")
mock_cpuinfo.return_value.pop("arch_string_raw")
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.cpu_speed")
assert state
assert state.state == "3.2"
assert state.attributes.get(ATTR_ARCH) is None
assert state.attributes.get(ATTR_BRAND) is None