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
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()
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)
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
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)
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)
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)
def changeVolume(self): """kitchen time""" LOGGER.debug('morning.changeVolume') if self.wanted(): self.denon.send('MV42')