Add number parsing for OpenHardwareMonitor (#39030)
This commit is contained in:
parent
c9a4deb118
commit
8af64456ec
3 changed files with 24 additions and 8 deletions
|
@ -77,6 +77,11 @@ class OpenHardwareMonitorDevice(Entity):
|
||||||
"""Return the state attributes of the sun."""
|
"""Return the state attributes of the sun."""
|
||||||
return self.attributes
|
return self.attributes
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def parse_number(cls, string):
|
||||||
|
"""In some locales a decimal numbers uses ',' instead of '.'."""
|
||||||
|
return string.replace(",", ".")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the device from a new JSON object."""
|
"""Update the device from a new JSON object."""
|
||||||
self._data.update()
|
self._data.update()
|
||||||
|
@ -89,12 +94,16 @@ class OpenHardwareMonitorDevice(Entity):
|
||||||
values = array[path_number]
|
values = array[path_number]
|
||||||
|
|
||||||
if path_index == len(self.path) - 1:
|
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(
|
_attributes.update(
|
||||||
{
|
{
|
||||||
"name": values[OHM_NAME],
|
"name": values[OHM_NAME],
|
||||||
STATE_MIN_VALUE: values[OHM_MIN].split(" ")[0],
|
STATE_MIN_VALUE: self.parse_number(
|
||||||
STATE_MAX_VALUE: values[OHM_MAX].split(" ")[0],
|
values[OHM_MIN].split(" ")[0]
|
||||||
|
),
|
||||||
|
STATE_MAX_VALUE: self.parse_number(
|
||||||
|
values[OHM_MAX].split(" ")[0]
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,15 @@ class TestOpenHardwareMonitorSetup(unittest.TestCase):
|
||||||
assert len(entities) == 38
|
assert len(entities) == 38
|
||||||
|
|
||||||
state = self.hass.states.get(
|
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 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"
|
||||||
|
|
6
tests/fixtures/openhardwaremonitor.json
vendored
6
tests/fixtures/openhardwaremonitor.json
vendored
|
@ -91,9 +91,9 @@
|
||||||
"id": 12,
|
"id": 12,
|
||||||
"Text": "CPU Core #2",
|
"Text": "CPU Core #2",
|
||||||
"Children": [],
|
"Children": [],
|
||||||
"Min": "29.0 °C",
|
"Min": "29,0 °C",
|
||||||
"Value": "30.0 °C",
|
"Value": "30,0 °C",
|
||||||
"Max": "61.0 °C",
|
"Max": "61,0 °C",
|
||||||
"ImageURL": "images/transparent.png"
|
"ImageURL": "images/transparent.png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue