Skip to content

Commit

Permalink
lm_sensors module: fix invalid json if specified more than one chip (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lasers authored Jan 12, 2024
1 parent 2f81ae9 commit 4a15090
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions py3status/modules/lm_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
]
"""

from collections import OrderedDict
from fnmatch import fnmatch
from json import loads

Expand Down Expand Up @@ -194,12 +195,12 @@ def post_config_hook(self):

if self.chips:
lm_sensors_data = self._get_lm_sensors_data()
chips = set()
chips = OrderedDict()
for _filter in self.chips:
for chip_name in lm_sensors_data:
if fnmatch(chip_name, _filter):
chips.add(_filter)
self.lm_sensors_command += chips
chips[_filter] = None
self.lm_sensors_command += OrderedDict.keys(chips)

self.sensors = {"list": [], "name": {}, "sensors": self.sensors}

Expand All @@ -225,7 +226,17 @@ def post_config_hook(self):
self.thresholds_man.remove("auto.input")

def _get_lm_sensors_data(self):
return loads(self.py3.command_output(self.lm_sensors_command))
output = self.py3.command_output(self.lm_sensors_command)
temporary = OrderedDict()

for chunk in output.strip().split("}\n{"):
if not chunk.startswith("{"):
chunk = "{" + chunk
if not chunk.endswith("}"):
chunk = chunk + "}"
temporary.update(loads(chunk))

return temporary

def lm_sensors(self):
lm_sensors_data = self._get_lm_sensors_data()
Expand Down

0 comments on commit 4a15090

Please sign in to comment.