def do_short_command(self, finished, equipment=None, state=0): log.msg('Setting {0} equipment to {1}'.format(equipment, state)) if equipment == 'LED': if int(state) == 0: self.led.set_off() print('BILL LED OFF') else: self.led.set_on() print('BILL LED ON') if equipment == 'MINTEMP': self.sensor.set_min_temp(state) print('- - - BILL MINTEMP') if equipment == 'MAXTEMP': self.sensor.set_max_temp(state) print('- - - BILL MAXTEMP') gsettings.sync() # upon completion post the result back self.factory.notify('equipment', { 'state': state, 'equipment': equipment }, device_id=self.info.id, device_key=self.info.key) finished.callback(devicehive.CommandResult('Completed'))
def do_update_led_state(self, finish_deferred, equipment=None, state=0): if equipment == 'LED': self.led_state = state self.status_notify() finish_deferred.callback(devicehive.CommandResult('Completed')) else: finish_deferred.errback( NotImplementedError( 'Unknown equipment {0}.'.format(equipment)))
def on_command(self, device_id, command, finished): if command.command == 'refresh': self.status_notify() finished.callback(devicehive.CommandResult('Completed')) return if command.command == 'setOutputSource': try: src = int(command.parameters['source']) res = setOutputSource("%.2d" % src) except ValueError, e: finished.errback(NotImplementedError('wrong parameter')) print "caught exeption while setting output source" print e return finished.callback(devicehive.CommandResult(res)) self.status_notify() return
def do_short_command(self, finished, equipment = None, state = 0): log.msg('Setting {0} equipment to {1}'.format(equipment, state)) if equipment == 'LED' : if int(state) == 0 : self.led.set_off() else: self.led.set_on() # upon completion post the result back self.factory.notify('equipment', {'state': state, 'equipment': 'LED'}, device_id = self.info.id, device_key = self.info.key) finished.callback(devicehive.CommandResult('Completed'))
def on_command(self, device_id, command, finished): cmd_name = command.command cmd_params = command.parameters if cmd_name == 'UpdateLedState': equipment = cmd_params['equipment'] state = cmd_params['state'] log.msg("<{0}> -> {1}.".format(equipment, state)) finished.calback(devicehive.CommandResult('Completed', 'OK')) else: finished.errback( NotImplementedError( 'Unknown command: <{0}> ignored.'.format(cmd_name)))
def do_set_command(self, finished, text=None): #self.lcd.write_string(text or '') Bill desactivate lcd finished.callback(devicehive.CommandResult('Completed'))
def command_finished(finish_d, par_echo_string): log.msg('Device async acomplished.') finish_d.callback( devicehive.CommandResult('Completed', par_echo_string))
def do_short_command(self, finished): log.msg('short command handle') finished.callback(devicehive.CommandResult('Completed'))
class SolarApp(object): implements(devicehive.interfaces.IProtoHandler) def __init__(self, config, delay=None): self.factory = None self.info = SolarInfo(config) self.connected = False self.io = IO() self.stopFlag = [] self.timer = [] if delay == None: self.updateDelay = 60.0 else: self.updateDelay = delay self.timer = task.LoopingCall(self.update) self.timer.start(self.updateDelay) def on_apimeta(self, websocket_server, server_time): pass def on_closing_connection(self): print "Closing connection, Finishing reactor" reactor.stop() def on_connection_failed(self, reason): print "Connection,failed. Finishing reactor" reactor.stop() def on_failure(self, device_id, reason): print "Failure, Finishing reactor" reactor.stop() def update(self): self.status_notify() def on_connected(self): def on_subscribe(result): self.connected = True self.update() def on_subsc(res): print '!!!! SUBSCRIBED' self.factory.subscribe(self.info.id, self.info.key).addCallback(on_subsc) def on_failed(reason): log.err('Failed to save device {0}. Reason: {1}.'.format( self.info, reason)) self.factory.device_save(self.info).addCallbacks( on_subscribe, on_failed) def on_command(self, device_id, command, finished): if command.command == 'refresh': self.status_notify() finished.callback(devicehive.CommandResult('Completed')) return if command.command == 'setOutputSource': try: src = int(command.parameters['source']) res = setOutputSource("%.2d" % src) except ValueError, e: finished.errback(NotImplementedError('wrong parameter')) print "caught exeption while setting output source" print e return finished.callback(devicehive.CommandResult(res)) self.status_notify() return if command.command == 'setLoad': loadname = command.parameters['name'] value = command.parameters['value'] try: self.io.setLoad(loadname, int(value)) except ValueError: finished.errback(NotImplementedError('wrong parameters')) print "caught exeption while setting output" return finished.callback(devicehive.CommandResult("EXEC OK")) if not ('silent' in command.parameters): self.status_notify() return finished.errback( NotImplementedError('Unknown command {0}.'.format( command.command)))