Upgrade py-cpuinfo to 7.0.0 (#39155)

This commit is contained in:
Fabian Affolter 2020-08-23 18:44:11 +02:00 committed by GitHub
parent 7874711936
commit c86c522eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View File

@ -2,6 +2,6 @@
"domain": "cpuspeed",
"name": "CPU Speed",
"documentation": "https://www.home-assistant.io/integrations/cpuspeed",
"requirements": ["py-cpuinfo==5.0.0"],
"requirements": ["py-cpuinfo==7.0.0"],
"codeowners": ["@fabaff"]
}

View File

@ -11,12 +11,12 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
ATTR_BRAND = "Brand"
ATTR_HZ = "GHz Advertised"
ATTR_BRAND = "brand"
ATTR_HZ = "ghz_advertised"
ATTR_ARCH = "arch"
HZ_ACTUAL_RAW = "hz_actual_raw"
HZ_ADVERTISED_RAW = "hz_advertised_raw"
HZ_ACTUAL = "hz_actual"
HZ_ADVERTISED = "hz_advertised"
DEFAULT_NAME = "CPU speed"
@ -30,7 +30,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CPU speed sensor."""
name = config[CONF_NAME]
add_entities([CpuSpeedSensor(name)], True)
@ -38,7 +37,7 @@ class CpuSpeedSensor(Entity):
"""Representation of a CPU sensor."""
def __init__(self, name):
"""Initialize the sensor."""
"""Initialize the CPU sensor."""
self._name = name
self._state = None
self.info = None
@ -62,10 +61,12 @@ class CpuSpeedSensor(Entity):
def device_state_attributes(self):
"""Return the state attributes."""
if self.info is not None:
attrs = {ATTR_ARCH: self.info["arch"], ATTR_BRAND: self.info["brand"]}
if HZ_ADVERTISED_RAW in self.info:
attrs[ATTR_HZ] = round(self.info[HZ_ADVERTISED_RAW][0] / 10 ** 9, 2)
attrs = {
ATTR_ARCH: self.info["arch_string_raw"],
ATTR_BRAND: self.info["brand_raw"],
}
if HZ_ADVERTISED in self.info:
attrs[ATTR_HZ] = round(self.info[HZ_ADVERTISED][0] / 10 ** 9, 2)
return attrs
@property
@ -75,9 +76,8 @@ class CpuSpeedSensor(Entity):
def update(self):
"""Get the latest data and updates the state."""
self.info = cpuinfo.get_cpu_info()
if HZ_ACTUAL_RAW in self.info:
self._state = round(float(self.info[HZ_ACTUAL_RAW][0]) / 10 ** 9, 2)
if HZ_ACTUAL in self.info:
self._state = round(float(self.info[HZ_ACTUAL][0]) / 10 ** 9, 2)
else:
self._state = None

View File

@ -1157,7 +1157,7 @@ py-august==0.25.0
py-canary==0.5.0
# homeassistant.components.cpuspeed
py-cpuinfo==5.0.0
py-cpuinfo==7.0.0
# homeassistant.components.melissa
py-melissa-climate==2.0.0