Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lm_sensors: fix invalid json if specified more than one chip #2226

Merged
merged 1 commit into from
Jan 12, 2024
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: 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
Loading