Migrate CPUSpeed to new entity naming style (#75080)

This commit is contained in:
Franck Nijhof 2022-07-20 11:31:17 +02:00 committed by GitHub
parent b62ebbe974
commit 05d2b955ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -7,8 +7,11 @@ from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import FREQUENCY_GIGAHERTZ
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
ATTR_BRAND = "brand"
ATTR_HZ = "ghz_advertised"
ATTR_ARCH = "arch"
@ -30,12 +33,16 @@ class CPUSpeedSensor(SensorEntity):
"""Representation of a CPU sensor."""
_attr_icon = "mdi:pulse"
_attr_name = "CPU Speed"
_attr_has_entity_name = True
_attr_native_unit_of_measurement = FREQUENCY_GIGAHERTZ
def __init__(self, entry: ConfigEntry) -> None:
"""Initialize the CPU sensor."""
self._attr_unique_id = entry.entry_id
self._attr_device_info = DeviceInfo(
name="CPU Speed",
identifiers={(DOMAIN, entry.entry_id)},
)
def update(self) -> None:
"""Get the latest data and updates the state."""