added traffic light id;

This commit is contained in:
Marco Zeisler 2021-05-17 18:17:53 +02:00
parent 731d6a564a
commit f581863e14

View File

@ -16,6 +16,8 @@ class TrafficLight:
GREEN = 0 GREEN = 0
RED = 1 RED = 1
# id of traffic light
tlid: str
# time between switches in seconds # time between switches in seconds
switching_time: int switching_time: int
# timestamp of last switch # timestamp of last switch
@ -29,7 +31,11 @@ class TrafficLight:
# stores runner thread # stores runner thread
_t: threading.Thread _t: threading.Thread
def __init__(self, switching_time: int = SWITCHING_TIME, starting_color: Color = Color.RED): def __init__(self,
tlid: str,
switching_time: int = SWITCHING_TIME,
starting_color: Color = Color.RED):
self.tlid = tlid
self.switching_time = switching_time self.switching_time = switching_time
self._starting_color = starting_color self._starting_color = starting_color
@ -56,10 +62,9 @@ class TrafficLight:
@circuit(failure_threshold=10, expected_exception=ConnectionError) @circuit(failure_threshold=10, expected_exception=ConnectionError)
def send_status_update(self): def send_status_update(self):
# TODO inform the message broker about the current status # TODO inform the message broker about the current status
print(self.current_color, self.last_switch) print(self.tlid, self.current_color, self.last_switch)
if __name__ == '__main__': if __name__ == '__main__':
tl1 = TrafficLight(3) tl1 = TrafficLight(tlid='tl1')
tl1.start() tl1.start()