def closeTelldus(self): log.info('Closing telldus') try: td.unregisterCallback(self.deviceCallbackId) except: log.warn('ignored error unregistering device callback') try: td.unregisterCallback(self.sensorCallbackId) except: log.warn('ignored error unregistering sensor callback') try: td.close() except: log.warn('ignored error closing td')
def close(self): return td.close()
while queue.full(): write("Queue is full", rc_switch, "8") time.sleep(1) queue.put(makeJobb(rc_switch, "Off", delay)) write("tdmod.SendOff(" + rc_switch + ")") write("Switches:" + rc_switch + " On at: " + z[3] + " and Off at: " + z[4] + " with delay:" + delay) write("------------------------------------------------------------") if start == 1 and debug == 1: write("Startup run ends") if start == 1: start_jobs.sort(key=itemgetter('On')) for job in start_jobs: startuprun(job['Rc_switch'], job['Group'], job['On'], job['Off']) write(job) start = 0 count = int(count) + 1 write("Going to sleep " + str(count)) time.sleep(60) write("Done sleeping") write("Waiting for threads to exit") ActionTimerExit = 1 write("High" + "Exiting program!") td.close()
# file: logger.py import td import time def logSensorEvent(protocol, model, id, dataType, value, timestamp, callbackId): # print a line for each event with time, sensor id, data type, value, protocoll, and model print '%s,%d,%d,%s,%s,%s' %(time.strftime("%Y-%m-%d,%H:%M:%S"), id, dataType, value, protocol, model) if __name__ == '__main__': # Intialize the communcation td.init( defaultMethods = td.TELLSTICK_TURNON | td.TELLSTICK_TURNOFF ) # Register callbacks callbackId = [] callbackId.append(td.registerSensorEvent(logSensorEvent)) # Run infinite loop try: while(1): time.sleep(1) except KeyboardInterrupt: for i in callbackId: # De-register callbacks td.unregisterCallback(i) # Close communication so telldus-core can do some cleanup. td.close() ## End logger.py