Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions homeassistant/components/sensor/cpuspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
ATTR_HZ = 'GHz Advertised'
ATTR_ARCH = 'arch'

HZ_ACTUAL_RAW = 'hz_actual_raw'
HZ_ADVERTISED_RAW = 'hz_advertised_raw'

DEFAULT_NAME = 'CPU speed'

ICON = 'mdi:pulse'
Expand Down Expand Up @@ -66,12 +69,17 @@ def unit_of_measurement(self):
def device_state_attributes(self):
"""Return the state attributes."""
if self.info is not None:
return {
attrs = {
ATTR_ARCH: self.info['arch'],
ATTR_BRAND: self.info['brand'],
ATTR_HZ: round(self.info['hz_advertised_raw'][0]/10**9, 2)
}

if HZ_ADVERTISED_RAW in self.info:
attrs[ATTR_HZ] = round(
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't duplicate the state in state attributes. I think we should remove this here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it's not the same key. Read too fast. 🤦‍♂️

self.info[HZ_ADVERTISED_RAW][0] / 10 ** 9, 2
)
return attrs

@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
Expand All @@ -82,4 +90,9 @@ def update(self):
from cpuinfo import cpuinfo

self.info = cpuinfo.get_cpu_info()
self._state = round(float(self.info['hz_actual_raw'][0])/10**9, 2)
if HZ_ACTUAL_RAW in self.info:
self._state = round(
float(self.info[HZ_ACTUAL_RAW][0]) / 10 ** 9, 2
)
else:
self._state = None