Fix CPUSpeed with missing info (#66339)
parent
8ff987d90c
commit
2f220b27d4
|
@ -81,8 +81,8 @@ class CPUSpeedSensor(SensorEntity):
|
|||
|
||||
if info:
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_ARCH: info["arch_string_raw"],
|
||||
ATTR_BRAND: info["brand_raw"],
|
||||
ATTR_ARCH: info.get("arch_string_raw"),
|
||||
ATTR_BRAND: info.get("brand_raw"),
|
||||
}
|
||||
if HZ_ADVERTISED in info:
|
||||
self._attr_extra_state_attributes[ATTR_HZ] = round(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue