Example #1
0
 def lineReceived(self, line):
     """we got a full line from Pioneer"""
     logDebug(self, "p", "READ from {}: {}".format(self.wrapper.name(), repr(line)))
     if self.wrapper.tasks.running:
         self.wrapper.tasks.gotAnswer(PioneerMessage(line))
     else:
         LOGGER.error("Pioneer sent data without being asked:{}".format(line))
Example #2
0
 def lineReceived(self, line):
     """we got a full line from Yamaha"""
     msg = Serializer.defaultInputHandler(self.wrapper, line)
     logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(),
                                                   repr(line)))
     #        msg = YamahaMessage(line)
     self.status[msg.command()] = msg.value()
Example #3
0
 def close(self):
     """close connection if open"""
     if self.protocol:
         if not (self.tasks.running or self.tasks.queued):
             if elapsedSince(self.tasks.allRequests[-1].sendTime) > self.closeTimeout - 1:
                 logDebug(self, None, 'closing Yamaha')
                 self.protocol.transport.loseConnection()
                 self.protocol = None
Example #4
0
 def close(self):
     """close connection if open"""
     if self.protocol:
         if not (self.tasks.running or self.tasks.queued):
             if elapsedSince(self.tasks.allRequests[-1].sendTime
                             ) > self.closeTimeout - 1:
                 logDebug(self, None, 'closing Yamaha')
                 self.protocol.transport.loseConnection()
                 self.protocol = None
Example #5
0
 def lineReceived(self, line):
     """we got a full line from Pioneer"""
     logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(),
                                                   repr(line)))
     if self.wrapper.tasks.running:
         self.wrapper.tasks.gotAnswer(PioneerMessage(line))
     else:
         LOGGER.error(
             'Pioneer sent data without being asked:{}'.format(line))
Example #6
0
 def startKodi(dummyResult):
     """start kodi"""
     if  self.kodiProcess:
         return
     environ = dict(os.environ)
     environ['DISPLAY'] = ':0'
     environ['HOME'] = '/home/wr'
     self.kodiProcess = subprocess.Popen(["kodi", "-fs"], env=environ)
     logDebug(self, None, 'started kodi process {}'.format(self.kodiProcess.pid))
Example #7
0
 def close(self):
     """close connection if open"""
     if self.protocol:
         if not (self.tasks.running or self.tasks.queued):
             if elapsedSince(self.tasks.allRequests[-1].sendTime) > self.closeTimeout - 1:
                 logDebug(self, None, 'closing vdr after closeTimeout {}'.format(self.closeTimeout))
                 self.write('quit\n')
                 self.protocol.transport.loseConnection()
                 self.protocol = None
Example #8
0
 def _toggle1(result):
     """result ends in NOT_SUSPENDED or SUSPEND_NORMAL"""
     if result.value().endswith(' NOT_SUSPENDED'):
         return self.send('plug softhddevice susp').addCallback(_remoteOff).addCallback(startKodi)
     elif result.value().endswith(' SUSPEND_NORMAL'):
         if self.kodiProcess:
             logDebug(self, None, 'killing kodi process {}'.format(self.kodiProcess.pid))
             self.kodiProcess.kill() # would be nice to terminate cleanly
             _ = self.kodiProcess.wait()
             self.kodiProcess = None
         subprocess.Popen(['killall', '-9', 'kodi.bin']).wait()
         reactor.callLater(7, self.send, 'plug softhddevice resu')
         return self.send('remo on')
     else:
         LOGGER.error('plug softhddevice stat returns unexpected answer:{}'.format(repr(result)))
         return succeed(None)
Example #9
0
 def open(self):
     """open connection if not open"""
     def gotProtocol(result):
         """now we have a a connection, save it"""
         self.protocol = result
         self.protocol.wrapper = self
         self.ping()
     if not self.protocol:
         logDebug(self, None, 'opening Yamaha')
         point = TCP4ClientEndpoint(reactor, self.host, self.port)
         factory = ClientFactory()
         factory.protocol = YamahaProtocol
         result = point.connect(factory).addCallback(gotProtocol)
     else:
         result = succeed(None)
     reactor.callLater(self.closeTimeout, self.close)
     return result
Example #10
0
    def open(self):
        """open connection if not open"""
        def gotProtocol(result):
            """now we have a a connection, save it"""
            self.protocol = result
            self.protocol.wrapper = self
            self.ping()

        if not self.protocol:
            logDebug(self, None, 'opening Yamaha')
            point = TCP4ClientEndpoint(reactor, self.host, self.port)
            factory = ClientFactory()
            factory.protocol = YamahaProtocol
            result = point.connect(factory).addCallback(gotProtocol)
        else:
            result = succeed(None)
        reactor.callLater(self.closeTimeout, self.close)
        return result
Example #11
0
 def lineReceived(self, line):
     """we got a full line from vdr"""
     logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(), repr(line)))
     if line.startswith('221 '):
         # this is an error because we should have
         # closed the connection ourselves after a
         # much shorter timeout than the server timeout
         LOGGER.error('vdr closes connection, timeout')
         self.wrapper.close()
         return
     if line.startswith('220 '):
         self.wrapper.openDeferred.callback(None)
         return
     if line.split(' ')[0] not in ['250', '354', '550', '900', '910', '911']:
         LOGGER.error('from {}: {}'.format(self.wrapper.name(), line))
     if self.wrapper.tasks.running:
         self.wrapper.tasks.gotAnswer(VdrMessage(line))
     else:
         LOGGER.error('vdr sent data without being asked:{}'.format(line))
Example #12
0
 def ping(self):
     """keep connection alive or the yamaha closes it"""
     logDebug(self, None, 'pinging Yamaha')
     self.write('@SYS:INPNAMEPHONO=PHONO\r\n')
     reactor.callLater(10, self.ping)
Example #13
0
    def lineReceived(self, line):
        """we got a full line from Yamaha"""
        msg = Serializer.defaultInputHandler(self.wrapper, line)
        logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(), repr(line)))
#        msg = YamahaMessage(line)
        self.status[msg.command()] = msg.value()
Example #14
0
 def ping(self):
     """keep connection alive or the yamaha closes it"""
     logDebug(self, None, 'pinging Yamaha')
     self.write('@SYS:INPNAMEPHONO=PHONO\r\n')
     reactor.callLater(10, self.ping)
Example #15
0
 def lineReceived(self, data):
     """we got a raw line from the lirc socket"""
     logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(),
                                                   repr(data)))
     msg = self.wrapper.message(encoded=data)
     self.wrapper.hal.eventReceived(msg)
Example #16
0
 def gotProtocol(result):
     """now we have a connection"""
     self.protocol = result
     self.protocol.wrapper = self
     logDebug(self, None, 'got lirc protocol')
Example #17
0
 def lineReceived(self, data):
     """we got a raw line from the lirc socket"""
     logDebug(self, 'p', 'READ from {}: {}'.format(self.wrapper.name(), repr(data)))
     msg = self.wrapper.message(encoded=data)
     self.wrapper.hal.eventReceived(msg)
Example #18
0
 def gotProtocol(result):
     """now we have a connection"""
     self.protocol = result
     self.protocol.wrapper = self
     logDebug(self, None, 'got lirc protocol')