Package: scclib
Developing with scclibClient computer library for S.C.I.L.E.R. systemThis is the library to create devices to work together with the SCILER systemInstallationpip install withpip install scclibUsing this libraryimport lib withfrom scclib.device import Devicecreate a class that extendsDevicein order to do this:implementgetStatus()which should return a dictionary of the current statusimplementperformInstruction(action)which should return a boolean of whether the instruction can be performed, where action has:instruction: string with the name of the instructionvalue: any type with a value specific for this instructioncomponent_id: string with the name of the component for which the instruction is meant (can be undefined)implementtest()which returns nothing, this method should do something visible so the operator can test this device works correctlyimplementreset()which returns nothing, this method should make the device return to its starting state so that the escape room can be started againcreate a constructor which calls the constructor ofDevicewithsuper(config, logger)where:config is a dictionary which has keys:id: this is the id of a device. Write it in camelCase, e.g. "controlBoard".host: the IP address of the host for the broker, formatted as a string.portthe port of the host for the broker, formatted as a number.labels: these are the labels to which this device should also subscribe, labels is an array of strings,logger is a function(date, level, message) in which an own logger is implemented wheredateis an Date objectlevelis one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal'messageis a custom string containing more informationit should also add event listeners to GPIO for all input components.implementmain()which should callstart(loop, stop)with an optional event loop and ending function.Now in your class which implementsDeviceyou can call:log(level, message)which logs using the logger provided inDevicewhere level one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal' and message custom string containing more informationstatusChanged()which can be called to signal toDevicethat the status is changed, this will send a new status to SCILERTo now start the systeminitialize the device in your main program and calldevice.main()Exampleimportosfromscclib.deviceimportDeviceclassDisplay(Device):def__init__(self):two_up=os.path.abspath(os.path.join(__file__,".."))rel_path="display_config.json"abs_file_path=os.path.join(two_up,rel_path)abs_file_path=os.path.abspath(os.path.realpath(abs_file_path))config=open(file=abs_file_path)super().__init__(config)self.hint=""defget_status(self):return{"hint":self.hint}defperform_instruction(self,action):instruction=action.get("instruction")ifinstruction=="hint":self.show_hint(action)else:returnFalse,actionreturnTrue,Nonedeftest(self):self.hint="test"print(self.hint)self.status_changed()defshow_hint(self,data):self.hint=data.get("value")print(self.hint)self.status_changed()defreset(self):self.hint=""self.status_changed()defmain(self):self.start()if__name__=="__main__":device=Display()device.main()wheredisplay_config.jsonis{"id":"display","description":"Display can print hints","host":"192.168.178.82","labels":["hint"],"port":1883}example ofmain()with loop and stop:defloop(self):previous=self.get_sliders_analog_reading()whileTrue:positions=self.get_sliders_analog_reading()ifprevious!=positions:self.status_changed()previous=positionsdefmain(self):self.setup_events()self.start(loop=self.loop,stop=GPIO.cleanup)LicenseThis library is licensed with GNU GPL v3, seeLICENSE.md.