Пример #1
0
class BrickletRemote:
    def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
        self.bricklet = RemoteSwitch(uid, connection)
        self.uid = uid
        self.switch_id = switch_id
        self.ip = ip
        self._logging_daemon = logging_daemon
        self._queue = queue
        self._logging_daemon.debug(
            'Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid)

    @staticmethod
    def status(number):
        return -99

    def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d):

        self.bricklet.set_repeats(5)

        func = {
            "b switch": self.bricklet.switch_socket_b,
            "a switch": self.bricklet.switch_socket_a,
        }.get(arg_b)

        if func is not None:

            func(int(arg_c), int(arg_d), switch_to)

            self._logging_daemon.debug(
                'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" , geschaltet %s %s %s, SOLL = %s , '
                % (self.uid, arg_b, arg_c, arg_d, switch_to))
            tmp_json = json.dumps({
                "usage": "switch_changed_status",
                "ip": self.ip,
                "id": self.switch_id,
                "value": switch_to
            })
            for consumer in self._queue:
                consumer(tmp_json)
                self._logging_daemon.info(
                    'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" Relais %s %s %s, send %s -> SocketServer'
                    ' Warteschlange ' %
                    (self.uid, arg_b, arg_c, arg_d, switch_to))
Пример #2
0
class BrickletRemote:
    def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
        self.bricklet = RemoteSwitch(uid, connection)
        self.uid = uid
        self.switch_id = switch_id
        self.ip = ip
        self._logging_daemon = logging_daemon
        self._queue = queue
        self._logging_daemon.debug('Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid)

    @staticmethod
    def status(number):
        return -99

    def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d):

        self.bricklet.set_repeats(5)

        func = {
            "b switch" : self.bricklet.switch_socket_b,
            "a switch" : self.bricklet.switch_socket_a,
        }.get(arg_b)

        if func is not None:

            func(int(arg_c), int(arg_d), switch_to)

            self._logging_daemon.debug(
                'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" , geschaltet %s %s %s, SOLL = %s , ' %
                (self.uid, arg_b, arg_c, arg_d, switch_to))
            tmp_json = json.dumps({
                "usage": "switch_changed_status",
                "ip": self.ip,
                "id": self.switch_id,
                "value": switch_to
            })
            for consumer in self._queue:
                consumer(tmp_json)
                self._logging_daemon.info(
                    'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" Relais %s %s %s, send %s -> SocketServer'
                    ' Warteschlange ' % (self.uid, arg_b, arg_c, arg_d, switch_to))