Coverage for janitoo_tellstick.bus : 56%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
"""
This file is part of Janitoo.
Janitoo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Janitoo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Janitoo. If not, see <http://www.gnu.org/licenses/>.
"""
# Set default logging handler to avoid "No handler found" warnings.
############################################################## #Check that we are in sync with the official command classes #Must be implemented for non-regression
##############################################################
"""A pseudo-bus to handle the tellstick """
""" :param int bus_id: the SMBus id (see Raspberry Pi documentation) :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer """
"""Turn on a telldus device""" pass
"""Turn off a telldus device""" pass
"""Dim a telldus device. Level from 0 to 255.""" pass
"""Learn a telldus device.""" pass
"""Bell a telldus device.""" pass
"""Execute a scene action.""" pass
"""Up a telldus device.""" pass
"""Down a telldus device.""" pass
"""Stop a telldus device.""" pass
"""Get a lock on the bus""" if self._tellstick_lock.acquire(blocking): return True return False
"""Release a lock on the bus""" self._tellstick_lock.release()
"""Get status of the lock""" return self._tellstick_lock.locked()
""" """
""" """ return hadd-1
""" """ logger.debug("[%s] - Receive callback from %s", self.__class__.__name__, device_id) return True
"""Start the bus""" except Exception: logger.exception('[%s] - Exception when starting bus %s', self.__class__.__name__, self.oid)
"""stop the bus""" except Exception: logger.exception('[%s] - Exception when stopping bus %s', self.__class__.__name__, self.oid)
"""Turn on a telldus device""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_TURNON: telldus.tdTurnOn(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_turnon', self.__class__.__name__) finally: self.tellstick_release()
"""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()
"""Dim a telldus device. Level from 0 to 255.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_TURNDIM: 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()
"""execute a telldus device. Level from 0 to 255.""" 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()
"""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) except Exception: logger.exception('[%s] - Exception when tellstick_up', self.__class__.__name__) finally: self.tellstick_release()
"""down a telldus device. Level from 0 to 255.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_DOWN: telldus.tdDown(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_down', self.__class__.__name__) finally: self.tellstick_release()
"""stop a telldus device. Level from 0 to 255.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_STOP: telldus.tdStop(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_stop', self.__class__.__name__) finally: self.tellstick_release()
"""bell a telldus device.""" self.tellstick_acquire() try: methods = telldus.tdMethods(tdev, self.ALL_METHODS) if methods & self.TELLSTICK_BELL: telldus.tdBell(tdev) time.sleep(self._lock_delay) except Exception: logger.exception('[%s] - Exception when tellstick_bell', self.__class__.__name__) finally: self.tellstick_release()
"""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()
"""Discover new devices.""" 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, ) #~ logger.debug('[%s] - Check node %s in %s', self.__class__.__name__, add_comp, 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)
"""We can't make a distinction between a switch, a remote controler, a door sensors or a light sensor. So we need to update it after discovering. """
|