Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def MotionTimeEventsHandler(json_events):
- global timeOfLastEvent
- global motionTimer
- error = 0
- index = 0
- newEvent = ""
- for event in json_events:
- newEvent = event
- data = event['data']
- if data['sensor_type'] == "Control4-Motion":
- try:
- if data['target'] in motionTimer:
- motionTime = datetime.datetime.fromtimestamp(float(data['epoch'])) - motionTimer[data['target']]
- else:
- motionTime = 0
- motionTimer[data['target']] = datetime.datetime.fromtimestamp(float(data['epoch']))
- #print(data['target'] + " time off is: " + str(timeOff))
- #going to write this event so we want to change it to make it fit the build.
- newEvent['data']['message'] = '%d' % (motionTime)
- if data['message'] == "ON":
- newEvent['data']['sensor_type'] = "MotionTimeOFF"
- newEvent['data']['state'] = "OFF"
- else:
- newEvent['data']['sensor_type'] = "MotionTimeON"
- newEvent['data']['state'] = "ON"
- json_events.append(newEvent)
- except Exception as e:
- error = 1
- #Do nothing at all...
- #Not sure what I would need to do here since this will error everytime it starts up
- #Due to being the first time having some off and on already...
- #end of type if
- #end of loop
- self.influxdb_publisher.write_casas_events(json_events)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement