Load json for mqtt callbacks
This commit is contained in:
parent
41dfa6b262
commit
357906fcd1
|
@ -1,3 +1,9 @@
|
|||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import ujson as json
|
||||
|
||||
|
||||
def sensor(cls):
|
||||
Sensor.register(cls)
|
||||
|
||||
|
@ -60,6 +66,11 @@ class Sensor(object):
|
|||
|
||||
@classmethod
|
||||
def run_mqtt_callback(cls, mqtt_topic, data):
|
||||
try:
|
||||
data = json.loads(data)
|
||||
except ValueError:
|
||||
print("Could not parse data {}".format(data))
|
||||
|
||||
if mqtt_topic in cls._mqtt_callbacks:
|
||||
cls._mqtt_callbacks[mqtt_topic](data)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue