class Switch(): """ This class is used to control Servo motors """ def __init__(self, name, adress): """ Parameters ---------- name : string DESCRIPTION : It is the name of the train adress : int DESCRIPTION This is the address on which it was programmed biais_id : int DESCRIPTION Allows you to choose which servomotor will be used Returns ------- None. """ self.name = name self.adress = adress self.biais_id = 1 if not isinstance(self.biais_id, int): raise TypeError("biais_id must be an int but got " + str(self.biais_id)) if self.biais_id not in [1, 2]: raise ValueError("biais_id must be an 1 or 2 but got " + str(self.biais_id)) if not isinstance(name, str): raise TypeError(" name must be a str but got " + str(name)) if not isinstance(adress, int): raise TypeError("adress must be an integer but got " + str(adress)) #if adress not in range(101, 126): #raise RuntimeError("""The address must be between 101 and 125 but got """+str(adress)) self.dccobject = DCCObject(name, adress) def _get_biais(self): """ Returns ------- TYPE DESCRIPTION : Returns the current state of the switch """ if self.biais_id == 1: return biais1, self.dccobject.f1, self.dccobject.f_light elif self.biais_id == 2: return biais2, self.dccobject.f2 def _set_biais(self, arguments): """ Parameters ---------- arguments : array arguments[0] : int DESCRIPTION : represents the num of the servo motor we would like pilote arguments[1] : bool DESCRIPTION : change the state of the switch Returns ------- None. """ self.biais_id = arguments[0] if not isinstance(arguments[1], bool): raise TypeError(" var must me a boolean but got " + str(arguments[1])) if self.biais_id == 1: self.dccobject.f1 = arguments[1] self.dccobject.f_light = arguments[1] elif self.biais_id == 2: self.dccobject.f2 = arguments[1] self.dccobject.reverse() biais = property(_get_biais, _set_biais)
class Train(): """ Train class """ def __init__(self, name, adress): """ this function takes a name and an address (an integer # 0) as parameters to create a train and register it on the controller """ if not isinstance(name, str): raise TypeError(" name must be a str but got " + str(name)) if not isinstance(adress, int): raise TypeError("adress must be an integer but got " + str(adress)) if adress not in range(1, 100): raise RuntimeError("""The address must be between 1 and 127 but got """ + str(adress)) self.dccobject = DCCObject(name, adress) def faster(self): """ Increase 1 speed step""" self.dccobject.faster() def reverse(self): """Change the direction""" self.dccobject.reverse() def slower(self): """Reduce the speed""" self.dccobject.slower() def __repr__(self): return self.dccobject.__repr__() def _get_speed(self): """ Returns the current speed of the train """ return self.dccobject.speed def _set_speed(self, new_speed): """ change the speed""" self.dccobject.speed = new_speed speed = property(_get_speed, _set_speed) def _get_f_light(self): """Returns the current state of fl """ return self.dccobject.fl def _set_f_light(self, var): """ change the state of fl """ self.dccobject.fl = var f_light = property(_get_f_light, _set_f_light) def _get_f1(self): """Returns the current state of f1 """ return self.dccobject.f1 def _set_f1(self, var): """ change the state of f1 """ self.dccobject.f1 = var f1 = property(_get_f1, _set_f1) def _get_f2(self): """Returns the current state of f1 """ return self.dccobject.f1 def _set_f2(self, var): """ change the state of f1 """ self.dccobject.f2 = var f2 = property(_get_f2, _set_f2) def _get_f3(self): """Returns the current state of f1 """ return self.dccobject.f3 def _set_f3(self, var): """ change the state of f1 """ self.dccobject.f3 = var f3 = property(_get_f3, _set_f3) def _get_f4(self): """Returns the current state of f1 """ return self.dccobject.f4 def _set_f4(self, var): """ change the state of f1 """ self.dccobject.f4 = var f4 = property(_get_f4, _set_f4)