def tellstick_discover_new_devices(): """Discover new devices.""" devices = telldus.tdGetNumberOfDevices() logger.debug('[%s] - Found %s devices in telldus-core', self.__class__.__name__, devices) add_ctrl = self.nodeman.get_add_ctrl() for i in range(devices): deviceid = telldus.tdGetDeviceId(i) if deviceid: name = telldus.tdGetName(deviceid) methods = telldus.tdMethods(deviceid, self.ALL_METHODS) logger.debug( '[%s] - Found device id %s (%s) of type %s with methods : (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s)', self.__class__.__name__, deviceid, name, telldus.tdGetDeviceType(deviceid), 'TELLSTICK_TURNON', methods & self.TELLSTICK_TURNON, 'TELLSTICK_TURNOFF', methods & self.TELLSTICK_TURNOFF, 'TELLSTICK_DIM', methods & self.TELLSTICK_DIM, 'TELLSTICK_BELL', methods & self.TELLSTICK_BELL, 'TELLSTICK_EXECUTE', methods & self.TELLSTICK_EXECUTE, 'TELLSTICK_UP', methods & self.TELLSTICK_UP, 'TELLSTICK_DOWN', methods & self.TELLSTICK_DOWN, 'TELLSTICK_STOP', methods & self.TELLSTICK_STOP, ) add_comp = '%s__%s' % (self.uuid, self.get_hadd_from_tdev(deviceid)) #~ logger.debug('[%s] - Check node %s in %s', self.__class__.__name__, add_comp, self.nodeman.nodes) if add_comp not in self.nodeman.nodes: #add_comp = key hadd = HADD % (add_ctrl, self.get_hadd_from_tdev(deviceid)) compo_oid = '%s.device' % self.oid if methods & self.TELLSTICK_DIM: compo_oid = '%s.dimmer' % self.oid if methods & self.TELLSTICK_UP and methods & self.TELLSTICK_UP: compo_oid = '%s.shutter' % self.oid compo = self.add_component(compo_oid, add_comp, options=self.options) node = self.nodeman.create_node(add_comp, hadd, name=name) node.create_options(compo_oid) time.sleep(self.nodeman.slow_start) logger.debug('[%s] - Discover new component %s / node %s', self.__class__.__name__, compo, node) logger.debug('[%s] - Found components %s after discover', self.__class__.__name__, self.components)
def tellstick_learn(tdev): """learn a telldus device.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_LEARN: telldus.tdLearn(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_learn', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_execute(tdev, level): """execute a telldus device.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_EXECUTE: telldus.tdExecute(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_execute', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_dim(tdev, level): """Dim a telldus device. Level from 0 to 100.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_DIM: telldus.tdDim(tdev, int(level*2.55)) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_dim', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_turnoff(tdev): """Turn off a telldus device""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_TURNOFF: telldus.tdTurnOff(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_turnoff', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_dim(tdev, level): """Dim a telldus device. Level from 0 to 100.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_DIM: telldus.tdDim(tdev, int(level * 2.55)) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_dim', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_stop(tdev): """stop a telldus device""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_STOP: telldus.tdStop(tdev) time.sleep(self._lock_delay) elif methods & self.TELLSTICK_TURNOFF or methods & self.TELLSTICK_TURNON: #Emulate stop by resending self.tellstick_resend(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_stop', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_up(tdev): """up a telldus device.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_UP: telldus.tdUp(tdev) time.sleep(self._lock_delay) elif methods & self.TELLSTICK_TURNON: #Emulate up by turnon telldus.tdTurnOn(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_up', self.__class__.__name__) finally: self.tellstick_release()
def tellstick_discover_new_devices(): """Discover new devices.""" devices = telldus.tdGetNumberOfDevices() logger.debug('[%s] - Found %s devices in telldus-core', self.__class__.__name__, devices) add_ctrl = self.nodeman.get_add_ctrl() for i in range(devices): deviceid = telldus.tdGetDeviceId(i) if deviceid: name = telldus.tdGetName(deviceid) methods = telldus.tdMethods(deviceid, self.ALL_METHODS) logger.debug('[%s] - Found device id %s (%s) of type %s with methods : (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s) (%s : %s)', self.__class__.__name__, deviceid, name, telldus.tdGetDeviceType(deviceid), 'TELLSTICK_TURNON', methods & self.TELLSTICK_TURNON, 'TELLSTICK_TURNOFF', methods & self.TELLSTICK_TURNOFF, 'TELLSTICK_DIM', methods & self.TELLSTICK_DIM, 'TELLSTICK_BELL', methods & self.TELLSTICK_BELL, 'TELLSTICK_EXECUTE', methods & self.TELLSTICK_EXECUTE, 'TELLSTICK_UP', methods & self.TELLSTICK_UP, 'TELLSTICK_DOWN', methods & self.TELLSTICK_DOWN, 'TELLSTICK_STOP', methods & self.TELLSTICK_STOP, ) add_comp = '%s__%s' % (self.uuid, self.get_hadd_from_tdev(deviceid)) #~ logger.debug('[%s] - Check node %s in %s', self.__class__.__name__, add_comp, self.nodeman.nodes) if add_comp not in self.nodeman.nodes: #add_comp = key hadd = HADD%(add_ctrl,self.get_hadd_from_tdev(deviceid)) compo_oid = '%s.device'%self.oid if methods & self.TELLSTICK_DIM: compo_oid = '%s.dimmer'%self.oid if methods & self.TELLSTICK_UP and methods & self.TELLSTICK_UP: compo_oid = '%s.shutter'%self.oid compo = self.add_component(compo_oid, add_comp, options=self.options) node = self.nodeman.create_node(add_comp, hadd, name=name) node.create_options(compo_oid) time.sleep(self.nodeman.slow_start) logger.debug('[%s] - Discover new component %s / node %s', self.__class__.__name__, compo, node) logger.debug('[%s] - Found components %s after discover', self.__class__.__name__, self.components)
telldus.tdInit() devices = telldus.tdGetNumberOfDevices() print "Devices: %d\n" % devices allMethods = telldus.TELLSTICK_TURNON | telldus.TELLSTICK_TURNOFF | telldus.TELLSTICK_BELL | telldus.TELLSTICK_DIM for i in xrange(devices): deviceid = telldus.tdGetDeviceId(i) if deviceid: name = telldus.tdGetName(deviceid) print "%s - %s\n" % (deviceid, name) methods = telldus.tdMethods(deviceid, allMethods) if methods & telldus.TELLSTICK_TURNON: print " * TurnOn\n" telldus.tdTurnOn(deviceid) time.sleep(1) if methods & telldus.TELLSTICK_TURNOFF: print " * TurnOff\n" telldus.tdTurnOff(deviceid) time.sleep(1) if methods & telldus.TELLSTICK_BELL: print " * Bell\n" telldus.tdBell(deviceid) time.sleep(1)