backend.when_sensor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A dosensor() 0 3 1
A when_sensor() 0 8 2
A main() 0 2 1
1
'''what to do when a sensor reading is broadcast'''
2
from helpers.queuehelper import QueueName
3
from backend.fcmapp import Component
4
5
SENSOR = Component('fullcycle')
6
7
def when_sensor(channel, method, properties, body):
8
    '''when there is a sensor reading'''
9
    try:
10
        print("[{0}] Received sensor reading".format(SENSOR.app.now()))
11
        message, sensorvalue = SENSOR.app.messagedecodesensor(body)
12
        dosensor(message, sensorvalue)
13
    except Exception as ex:
14
        SENSOR.app.logexception(ex)
15
16
def dosensor(message, sensorvalue):
17
    '''put the sensor in cache'''
18
    SENSOR.app.sensors.addknownsensor(sensorvalue)
19
20
def main():
21
    SENSOR.listeningqueue = SENSOR.app.listen_to_broadcast(QueueName.Q_SENSOR, when_sensor)
22
23
if __name__ == "__main__":
24
    main()
25