1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Add number parsing for OpenHardwareMonitor (#39030)

This commit is contained in:
fillefilip8 2020-09-06 20:49:54 +02:00 committed by GitHub
parent c9a4deb118
commit 8af64456ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View File

@ -77,6 +77,11 @@ class OpenHardwareMonitorDevice(Entity):
"""Return the state attributes of the sun."""
return self.attributes
@classmethod
def parse_number(cls, string):
"""In some locales a decimal numbers uses ',' instead of '.'."""
return string.replace(",", ".")
def update(self):
"""Update the device from a new JSON object."""
self._data.update()
@ -89,12 +94,16 @@ class OpenHardwareMonitorDevice(Entity):
values = array[path_number]
if path_index == len(self.path) - 1:
self.value = values[OHM_VALUE].split(" ")[0]
self.value = self.parse_number(values[OHM_VALUE].split(" ")[0])
_attributes.update(
{
"name": values[OHM_NAME],
STATE_MIN_VALUE: values[OHM_MIN].split(" ")[0],
STATE_MAX_VALUE: values[OHM_MAX].split(" ")[0],
STATE_MIN_VALUE: self.parse_number(
values[OHM_MIN].split(" ")[0]
),
STATE_MAX_VALUE: self.parse_number(
values[OHM_MAX].split(" ")[0]
),
}
)

View File

@ -41,8 +41,15 @@ class TestOpenHardwareMonitorSetup(unittest.TestCase):
assert len(entities) == 38
state = self.hass.states.get(
"sensor.test_pc_intel_core_i7_7700_clocks_bus_speed"
"sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_1"
)
assert state is not None
assert state.state == "100"
assert state.state == "31.0"
state = self.hass.states.get(
"sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_2"
)
assert state is not None
assert state.state == "30.0"

View File

@ -91,9 +91,9 @@
"id": 12,
"Text": "CPU Core #2",
"Children": [],
"Min": "29.0 °C",
"Value": "30.0 °C",
"Max": "61.0 °C",
"Min": "29,0 °C",
"Value": "30,0 °C",
"Max": "61,0 °C",
"ImageURL": "images/transparent.png"
},
{