diff --git a/j1939/electronic_control_unit.py b/j1939/electronic_control_unit.py index 520531b..8b28bee 100644 --- a/j1939/electronic_control_unit.py +++ b/j1939/electronic_control_unit.py @@ -219,6 +219,13 @@ def remove_bus(self): """ self._bus = None + def remove_notifier(self): + """Remove the notifier from the ECU. + """ + for listener in self._listeners: + self._notifier.remove_listener(listener) + self._notifier = None + def send_pgn(self, data_page, pdu_format, pdu_specific, priority, src_address, data, time_limit=0, frame_format=FrameFormat.FEFF): """send a pgn :param int data_page: data page diff --git a/test/test_ecu.py b/test/test_ecu.py index 4744a45..f326303 100644 --- a/test/test_ecu.py +++ b/test/test_ecu.py @@ -1,10 +1,10 @@ import time +import can import j1939 from test_helpers.feeder import Feeder from test_helpers.conftest import feeder - def receive(feeder): feeder.ecu.subscribe(on_message) feeder.inject_messages_into_ecu() @@ -165,3 +165,24 @@ def test_broadcast_send_long(feeder): feeder.send(pdu, 144, pdu[1]) +def test_add_bus(feeder): + """ + Test adding and removing a bus to the ECU + """ + bus = can.interface.Bus(interface="virtual", channel=1) + feeder.ecu.add_bus(bus) + assert feeder.ecu._bus == bus + feeder.ecu.remove_bus() + assert feeder.ecu._bus == None + +def test_add_notfier(feeder): + """ + Test adding and removing a notifier to the ECU + """ + bus = can.interface.Bus(interface="virtual", channel=1) + feeder.ecu.add_bus(bus) + notifier = can.Notifier(bus=bus, listeners=[]) + feeder.ecu.add_notifier(notifier) + assert feeder.ecu._notifier == notifier + feeder.ecu.remove_notifier() + assert feeder.ecu._notifier == None \ No newline at end of file