From 537313a765cc00f3b7b260096fea6b1854dfc3d1 Mon Sep 17 00:00:00 2001 From: Laurent Ollagnier <56002070+lollagnier@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:06:41 +0100 Subject: [PATCH] On event, cast 'new' and 'old' field into a string Because, many events use theses fields and they use many differents formats. * ConnectivityChanged, old and new are boolean * ToolChange, old and new are integer (tool's index) * ZChange, old and new are float --- octoprint_influxdb/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/octoprint_influxdb/__init__.py b/octoprint_influxdb/__init__.py index c236793..6d996f0 100644 --- a/octoprint_influxdb/__init__.py +++ b/octoprint_influxdb/__init__.py @@ -20,6 +20,13 @@ if sys.version_info < (3, 0): ALLOWED_TYPES = (unicode,) + ALLOWED_TYPES + +# On events cast theses fields with the function in value +EVENT_CAST_FIELDS = { + 'new': str, + 'old': str +} + # host methods HOST_NODE = "node" HOST_FQDN = "fqdn" @@ -268,6 +275,10 @@ def on_event(self, event, payload): if not payload: payload = {} + + for field in payload: + if field in EVENT_CAST_FIELDS: + payload[field] = EVENT_CAST_FIELDS[field](payload[field]) self.influx_emit('events', payload, extra_tags={'type': event}) # state changes happen on events, so...