Skip to content

Commit

Permalink
ensure strings are not published to the message bus from ecobee driver
Browse files Browse the repository at this point in the history
  • Loading branch information
cmromo committed Jul 18, 2024
1 parent 72c330d commit 67ea014
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/core/PlatformDriverAgent/platform_driver/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

utils.setup_logging()
_log = logging.getLogger(__name__)
__version__ = '4.3.4'
__version__ = '4.3.5'


PROMETHEUS_METRICS_FILE = "/opt/packages/prometheus_exporter/scrape_files/scrape_metrics.prom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ def _set_point(self, point_name, value, **kwargs):
if register.readable:
return register.get_state(self.thermostat_data)

def _ensure_no_string(self, results):
"""
Ensure that all values in the results dictionary are not strings
:param results: dictionary of results to check
:return: dictionary with all string values converted to floats
"""
new_results = {}
for key, value_list in results.items():
if not isinstance(value_list, list):
value_list = [value_list]
for value in value_list:
if not isinstance(value, float):
try:
new_results[key] = float(value)
except ValueError:
_log.warning(f"Could not convert value {value} to float for point {key}")
pass
return new_results

def _scrape_all(self):
"""
Fetch point data for all configured points
Expand Down Expand Up @@ -467,6 +486,7 @@ def _scrape_all(self):
result.update(register_data)
else:
result[register.point_name] = register_data
result = self._ensure_no_string(result)
return result


Expand Down

0 comments on commit 67ea014

Please sign in to comment.