File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 160160]
161161"""
162162
163+ import re
163164from collections import OrderedDict
164165from fnmatch import fnmatch
165- from json import JSONDecodeError , loads
166+ from json import loads
166167
167168STRING_NOT_INSTALLED = "not installed"
168169
@@ -191,6 +192,7 @@ def post_config_hook(self):
191192 self .sensor_placeholders = [x for x in placeholders if x != "name" ]
192193 self .format_sensor = self .py3 .update_placeholder_formats (self .format_sensor , format_sensor )
193194
195+ self .pattern = re .compile (r'^}\n{$' , re .MULTILINE )
194196 self .first_run = True
195197
196198 if self .chips :
@@ -228,15 +230,13 @@ def post_config_hook(self):
228230 def _get_lm_sensors_data (self ):
229231 output = self .py3 .command_output (self .lm_sensors_command )
230232 temporary = OrderedDict ()
231- chunk = ""
232-
233- for line in output .splitlines ():
234- chunk += line
235- try :
236- temporary .update (loads (chunk ))
237- chunk = ""
238- except JSONDecodeError :
239- continue
233+
234+ for chunk in self .pattern .split (output .strip ()):
235+ if not chunk .startswith ("{" ):
236+ chunk = "{" + chunk
237+ if not chunk .endswith ("}" ):
238+ chunk = chunk + "}"
239+ temporary .update (loads (chunk ))
240240
241241 return temporary
242242
You can’t perform that action at this time.
0 commit comments