Improve parsing when missing values
The sound module may not be available so the parse function fails. This commit makes the parsing function more generic by giving a list of metrics to retreive in order. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
53758081d8
commit
bb65a7c6b6
1 changed files with 4 additions and 3 deletions
|
@ -30,14 +30,15 @@ def parse_sensor_values(data):
|
||||||
"""
|
"""
|
||||||
Input line: <humidity>,<temperature>,<sound>
|
Input line: <humidity>,<temperature>,<sound>
|
||||||
Output structure:
|
Output structure:
|
||||||
data = {
|
{
|
||||||
'humidity': <humidity>,
|
'humidity': <humidity>,
|
||||||
'temperature': <temperature>,
|
'temperature': <temperature>,
|
||||||
'sound': <sound>
|
'sound': <sound>
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
humidity, temperature, sound = data.decode('utf-8').strip().split(',')
|
metrics = ['humidity', 'temperature', 'sound']
|
||||||
return {'humidity': humidity, 'temperature': temperature, 'sound': sound}
|
values = data.decode('utf-8').strip().split(',')
|
||||||
|
return dict(zip(metrics, values))
|
||||||
|
|
||||||
|
|
||||||
def connect_mqtt(config):
|
def connect_mqtt(config):
|
||||||
|
|
Loading…
Reference in a new issue