Пример #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))
Пример #2
0
 def humanCommand(self):
     result = self._decoded.split(':')[0]
     if result:
         if result not in self.commands:
             LOGGER.critical('LGTV: unknown argument {}'.format(self._decoded))
             sys.exit(2)
     return result
Пример #3
0
 def _setAttributes(self, decoded, encoded):
     """The LG interface is a bit
     stupid: When sending, we send two characters for the command
     like ka or ma. But the answer only returns the second character,
     so we cannot easily find the corresponding full command"""
     if encoded is not None:
         parts = encoded.split(' ')
         if len(parts) < 3:
             self._decoded = ':'
             return
         self.status = parts[2][:2]
         cmd2 = parts[0]
         self.status = parts[2][:2]
         encodedValue = parts[2][2:]
         items = [x for x in self.commands.items() if x[1][1] == cmd2]
         if len(items) > 1:
             LOGGER.error('answer from LG matches more than 1 command: {}'.format(items))
         elif len(items) == 0:
             LOGGER.error('answer from LG matches no command: {}'.format(self.encoded))
         humanCommand = items[0][0]
         if encodedValue:
             decodedValue = self.values[humanCommand][encodedValue]
         else:
             decodedValue = 'None'
         self._decoded = ':'.join([humanCommand, decodedValue])
     else: # decoded
         self._decoded = decoded
         humanCommand = self.humanCommand()
         humanValue = self.value()
         if humanValue:
             encodedValue = [x[0] for x in self.values[humanCommand].items() if x[1] == humanValue][0]
         else:
             self.isQuestion = True
             encodedValue = 'ff'
     self._encoded = ' '.join([self.commands[humanCommand], self.setID, encodedValue])
Пример #4
0
 def humanCommand(self):
     result = self._decoded.split(':')[0]
     if result:
         if result not in self.commands:
             LOGGER.critical('LGTV: unknown argument {}'.format(
                 self._decoded))
             sys.exit(2)
     return result
Пример #5
0
 def errReceived(self, data):
     """got stderr from sispmctl"""
     for line in data.split('\n'):
         if not line:
             # we do not want to log the copyright...
             # what sense does it make to add that
             # to an error message?
             break
         LOGGER.error('Gembird: %s' % line)
Пример #6
0
 def start(self):
     """start channel NDR 90,3 loudly"""
     LOGGER.debug('morning.start')
     if self.wanted():
         self.denon.poweron().addCallback(
             self.denon.send, 'SIDBS/SAT').addCallback(
             self.denon.send, 'MV60')
         self.vdr.gotoChannel(None, 'NDR 90,3')
         self.lgtv.standby()
Пример #7
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))
Пример #8
0
 def errReceived(self, data):
     """got stderr from sispmctl"""
     for line in data.split('\n'):
         if not line:
             # we do not want to log the copyright...
             # what sense does it make to add that
             # to an error message?
             break
         LOGGER.error('Gembird: {}'.format(line))
Пример #9
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:
                 LOGGER.debug('closing vdr')
                 self.write('quit\n')
                 self.protocol.transport.loseConnection()
                 self.protocol = None
Пример #10
0
 def connect(self):
     """connect to serial port"""
     if not os.path.exists(self.device):
         self.connected = False
         LOGGER.info('LGTV: {} does not exist, waiting for 0.1 seconds'.format(self.device))
         reactor.callLater(0.1, self.connect)
     else:
         SerialPort(self, self.device, reactor)
         self.connected = True
         LOGGER.info('LGTV: connected to {}'.format(self.device))
Пример #11
0
 def end(self):
     """off to train"""
     LOGGER.debug('morning.end')
     if self.wanted():
         self.denon.standby(None)
         if self.vdr.prevChannel:
             self.vdr.gotoChannel(None, self.vdr.prevChannel)
         self.lgtv.standby(None)
     elif os.path.exists(self.silencer):
         os.remove(self.silencer)
Пример #12
0
 def connect(self):
     """connect to serial port"""
     if not os.path.exists(self.device):
         self.connected = False
         LOGGER.info(
             'LGTV: {} does not exist, waiting for 0.1 seconds'.format(
                 self.device))
         reactor.callLater(0.1, self.connect)
     else:
         SerialPort(self, self.device, reactor)
         self.connected = True
         LOGGER.info('LGTV: connected to {}'.format(self.device))
Пример #13
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)
Пример #14
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
     if not self.protocol:
         LOGGER.debug('opening vdr')
         point = TCP4ClientEndpoint(reactor, self.host, self.port)
         factory = ClientFactory()
         factory.protocol = VdrProtocol
         point.connect(factory).addCallback(gotProtocol)
         self.openDeferred = Deferred()
         result = self.openDeferred
     else:
         result = succeed(None)
     reactor.callLater(5, self.close)
     return result
Пример #15
0
 def _setAttributes(self, decoded, encoded):
     """The LG interface is a bit
     stupid: When sending, we send two characters for the command
     like ka or ma. But the answer only returns the second character,
     so we cannot easily find the corresponding full command"""
     if encoded is not None:
         parts = encoded.split(' ')
         if len(parts) < 3:
             self._decoded = ':'
             return
         self.status = parts[2][:2]
         cmd2 = parts[0]
         self.status = parts[2][:2]
         encodedValue = parts[2][2:]
         items = [x for x in self.commands.items() if x[1][1] == cmd2]
         if len(items) > 1:
             LOGGER.error(
                 'answer from LG matches more than 1 command: {}'.format(
                     items))
         elif len(items) == 0:
             LOGGER.error('answer from LG matches no command: {}'.format(
                 self.encoded))
         humanCommand = items[0][0]
         if encodedValue:
             decodedValue = self.values[humanCommand][encodedValue]
         else:
             decodedValue = 'None'
         self._decoded = ':'.join([humanCommand, decodedValue])
     else:  # decoded
         self._decoded = decoded
         humanCommand = self.humanCommand()
         humanValue = self.value()
         if humanValue:
             encodedValue = [
                 x[0] for x in self.values[humanCommand].items()
                 if x[1] == humanValue
             ][0]
         else:
             self.isQuestion = True
             encodedValue = 'ff'
     self._encoded = ' '.join(
         [self.commands[humanCommand], self.setID, encodedValue])
Пример #16
0
 def lineReceived(self, line):
     """we got a full line from vdr"""
     if 'p' in OPTIONS.debug:
         LOGGER.debug('READ from %s: %s' % (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']:
         LOGGER.error('from %s: %s' % (self.wrapper.name(), line))
     if self.wrapper.tasks.running:
         self.wrapper.tasks.gotAnswer(VdrMessage(line))
     else:
         LOGGER.error('vdr sent data without being asked:%s' % line)
Пример #17
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))
Пример #18
0
 def connectionLost(self, reason):
     """USB disconnect or similar"""
     self.connected = False
     LOGGER.error('LGTV lost connection: {}'.format(reason))
     reactor.callLater(5, self.connect)
Пример #19
0
 def gotNoProtocol(result):
     """something went wrong"""
     msg = "Pioneer: %s" % result.getErrorMessage()
     LOGGER.error(msg)
     raise Exception(msg)
Пример #20
0
 def connectionLost(self, reason):
     """USB disconnect or similar"""
     self.connected = False
     LOGGER.error('LGTV lost connection: {}'.format(reason))
     reactor.callLater(5, self.connect)
Пример #21
0
 def gotNoProtocol(result):
     """something went wrong"""
     msg = 'Pioneer: %s' % result.getErrorMessage()
     LOGGER.error(msg)
     raise Exception(msg)
Пример #22
0
 def changeVolume(self):
     """kitchen time"""
     LOGGER.debug('morning.changeVolume')
     if self.wanted():
         self.denon.send('MV42')
Пример #23
0
 def lineReceived(self, data):
     """we got a raw line from the lirc socket"""
     if 'p' in OPTIONS.debug:
         LOGGER.debug('READ from %s: %s' % (self.wrapper.name(), repr(data)))
     msg = self.wrapper.message(encoded=data)
     self.wrapper.hal.eventReceived(msg)
Пример #24
0
 def leaving(self):
     """off to train"""
     LOGGER.debug('morning.end')
     self.yamaha.standby(None)
     if self.vdr.prevChannel:
         self.vdr.gotoChannel(None, self.vdr.prevChannel)