From c86c522eb194053e0b1e38cdd0923c6c3bdc7a70 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sun, 23 Aug 2020 18:44:11 +0200 Subject: [PATCH] Upgrade py-cpuinfo to 7.0.0 (#39155) --- .../components/cpuspeed/manifest.json | 2 +- homeassistant/components/cpuspeed/sensor.py | 26 +++++++++---------- requirements_all.txt | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/cpuspeed/manifest.json b/homeassistant/components/cpuspeed/manifest.json index 3cd4be6f9d3..ced8344ee55 100644 --- a/homeassistant/components/cpuspeed/manifest.json +++ b/homeassistant/components/cpuspeed/manifest.json @@ -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"] } diff --git a/homeassistant/components/cpuspeed/sensor.py b/homeassistant/components/cpuspeed/sensor.py index 34e9c5fee25..4f352900012 100644 --- a/homeassistant/components/cpuspeed/sensor.py +++ b/homeassistant/components/cpuspeed/sensor.py @@ -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 diff --git a/requirements_all.txt b/requirements_all.txt index 8fdc47ccc8a..10f37a99d6d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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