Example #1
0
    def test_api(self, crossbar):
        publish_opt = PublishOptions(exclude_me=False)

        @register('api.api.rpc')
        def rpc():
            self.rpc_called = True

        @subscribe('api.api.event')
        def sub():
            self.sub_called = True

        with pytest.raises(NotRunningError):
            call('api.api.rpc')

        with pytest.raises(NotRunningError):
            publish('api.api.event', options=publish_opt)

        assert not self.rpc_called
        assert not self.sub_called

        run()

        call('api.api.rpc')
        publish('api.api.event', options=publish_opt)
        sleep(0.1)  # Dirty way to wait for on_event to be called...

        assert self.rpc_called
        assert self.sub_called
Example #2
0
    def test_api(self, crossbar):
        publish_opt = PublishOptions(exclude_me=False)

        @register('api.api.rpc')
        def rpc():
            self.rpc_called = True

        @subscribe('api.api.event')
        def sub():
            self.sub_called = True

        with pytest.raises(NotRunningError):
            call('api.api.rpc')

        with pytest.raises(NotRunningError):
            publish('api.api.event', options=publish_opt)

        assert not self.rpc_called
        assert not self.sub_called

        run()

        call('api.api.rpc')
        publish('api.api.event', options=publish_opt)
        sleep(0.1)  # Dirty way to wait for on_event to be called...

        assert self.rpc_called
        assert self.sub_called
Example #3
0
 def update(self):
     """ load the websocket with updated info """
     if not self.kpro.status:  # if kpro is down try to reconnect
         self.kpro.find_and_connect()
     self.odo.save(self.kpro.vss["kmh"])
     self.style.update(self.kpro.tps)
     publish(
         "data",
         {
             "bat": self.kpro.bat,
             "gear": self.kpro.gear,
             "iat": self.kpro.iat[self.iat_unit],
             "tps": self.kpro.tps,
             "ect": self.kpro.ect[self.ect_unit],
             "rpm": self.kpro.rpm,
             "vss": self.kpro.vss[self.vss_unit],
             "o2": self.kpro.o2[self.o2_unit],
             "cam": self.kpro.cam,
             "mil": self.kpro.mil,
             "fan": self.kpro.fanc,
             "bksw": self.kpro.bksw,
             "flr": self.kpro.flr,
             "eth": self.kpro.eth,
             "scs": self.kpro.scs,
             "fmw": self.kpro.firmware,
             "map": self.kpro.map[self.map_unit],
             "an0": self.an0_formula(
                 self.kpro.analog_input(0))[self.an0_unit],
             "an1": self.an1_formula(
                 self.kpro.analog_input(1))[self.an1_unit],
             "an2": self.an2_formula(
                 self.kpro.analog_input(2))[self.an2_unit],
             "an3": self.an3_formula(
                 self.kpro.analog_input(3))[self.an3_unit],
             "an4": self.an4_formula(
                 self.kpro.analog_input(4))[self.an4_unit],
             "an5": self.an5_formula(
                 self.kpro.analog_input(5))[self.an5_unit],
             "an6": self.an6_formula(
                 self.kpro.analog_input(6))[self.an6_unit],
             "an7": self.an7_formula(
                 self.kpro.analog_input(7))[self.an7_unit],
             "time": self.time.get_time(),
             "odo": self.odo.get_mileage()[self.odo_unit],
             "style": self.style.status,
             "ver": __version__,
         },
     )
Example #4
0
 def _reset(self):
     self.setup_file.reset_setup()
     publish(
         "refresh")  # refresh the frontend so the new changes are applied
     self._load_user_preferences()  # refresh the backend too
Example #5
0
 def _save(self, new_setup):
     self.setup_file.save_setup(new_setup)
     self.setup_file.rotate_screen(new_setup["screen"]["rotate"])
     publish(
         "refresh")  # refresh the frontend so the new changes are applied
     self._load_user_preferences()  # refresh the backend too
Example #6
0
 publish(
     'com.app.idea', {
         'bat': kpro.bat(),
         'gear': kpro.gear(),
         'iat': kpro.iat().setdefault(iat_unit, 'celsius'),
         'tps': kpro.tps(),
         'ect': kpro.ect().setdefault(ect_unit, 'celsius'),
         'rpm': kpro.rpm(),
         'vss': kpro.vss().setdefault(vss_unit, 'kmh'),
         'o2': kpro.o2().setdefault(o2_unit, 'afr'),
         'cam': kpro.cam(),
         'mil': kpro.mil(),
         'bksw': kpro.bksw(),
         'flr': kpro.flr(),
         'map': kpro.map().setdefault(map_unit, 'bar'),
         'eth': kpro.eth(),
         'an0': an0_formula(kpro.analog_input(0)).setdefault(
             an0_unit, 'volts'),
         'an1': an1_formula(kpro.analog_input(1)).setdefault(
             an1_unit, 'volts'),
         'an2': an2_formula(kpro.analog_input(2)).setdefault(
             an2_unit, 'volts'),
         'an3': an3_formula(kpro.analog_input(3)).setdefault(
             an3_unit, 'volts'),
         'an4': an4_formula(kpro.analog_input(4)).setdefault(
             an4_unit, 'volts'),
         'an5': an5_formula(kpro.analog_input(5)).setdefault(
             an5_unit, 'volts'),
         'an6': an6_formula(kpro.analog_input(6)).setdefault(
             an6_unit, 'volts'),
         'an7': an7_formula(kpro.analog_input(7)).setdefault(
             an7_unit, 'volts'),
         'time': time.get_time(),
         'odo': odo.get_mileage(),
     })
Example #7
0
while True:
    odo.save(kpro.vss()['kmh'])
    publish(
        'data', {
            'bat': kpro.bat(),
            'gear': kpro.gear(),
            'iat': kpro.iat()[iat_unit],
            'tps': kpro.tps(),
            'ect': kpro.ect()[ect_unit],
            'rpm': kpro.rpm(),
            'vss': kpro.vss()[vss_unit],
            'o2': kpro.o2()[o2_unit],
            'cam': kpro.cam(),
            'mil': kpro.mil(),
            'fan': kpro.fanc(),
            'bksw': kpro.bksw(),
            'flr': kpro.flr(),
            'eth': kpro.eth(),
            'map': kpro.map()[map_unit],
            'an0': an0_formula(kpro.analog_input(0))[an0_unit],
            'an1': an1_formula(kpro.analog_input(1))[an1_unit],
            'an2': an2_formula(kpro.analog_input(2))[an2_unit],
            'an3': an3_formula(kpro.analog_input(3))[an3_unit],
            'an4': an4_formula(kpro.analog_input(4))[an4_unit],
            'an5': an5_formula(kpro.analog_input(5))[an5_unit],
            'an6': an6_formula(kpro.analog_input(6))[an6_unit],
            'an7': an7_formula(kpro.analog_input(7))[an7_unit],
            'time': time.get_time(),
            'odo': odo.get_mileage()[odo_unit],
        })
    sleep(0.1)
Example #8
0
 publish(
     'com.app.idea', {
         'bat': random.uniform(0, 15),
         'map': {
             'bar': random.uniform(0, 2),
             'mbar': random.uniform(0, 2),
             'psi': random.uniform(0, 2)
         },
         'gear': random.randint(0, 6),
         'iat': {
             'celsius': random.randint(0, 50),
             'fahrenheit': random.randint(0, 50)
         },
         'tps': random.randint(0, 100),
         'ect': {
             'celsius': random.randint(0, 50),
             'fahrenheit': random.randint(0, 50)
         },
         'rpm': random.randint(0, 9000),
         'vss': {
             'kmh': random.randint(0, 200),
             'mph': random.randint(0, 200)
         },
         'o2': {
             'afr': random.uniform(0, 20),
             'lambda': random.uniform(0, 1)
         },
         'cam': random.randint(0, 50),
         'mil': random.choice([True, False]),
         'bksw': random.choice([True, False]),
         'an0': Formula.psi_to_bar(
             Formula.ebay_150_psi(random.uniform(0, 5))),
         'an1': Formula.autometer_2246(random.uniform(0, 5)),
         'an2': random.uniform(0, 5),
         'an3': random.uniform(0, 5),
         'an4': random.uniform(0, 5),
         'an5': random.uniform(0, 5),
         'an6': random.uniform(0, 5),
         'an7': random.uniform(0, 5),
         'di4': random.randint(0, 1),
         'di5': random.randint(0, 1),
         'di6': random.randint(0, 1),
         'di12': random.randint(0, 1),
         'di21': random.randint(0, 1),
         'di17': random.randint(0, 1),
         'di27': random.randint(0, 1),
         'di22': random.randint(0, 1),
         'time': time.get_time(),
         'odo': odo.get_mileage(),
         'ai0': Formula.vdo_323_057(random.uniform(0, 5)),
         'ai1': Formula.civic_eg_fuel_tank(random.uniform(0, 5)),
         'ai2': random.uniform(0, 5),
         'ai3': random.uniform(0, 5),
         'ai4': random.uniform(0, 5),
         'ai5': random.uniform(0, 5),
         'ai6': random.uniform(0, 5),
         'ai7': random.uniform(0, 5),
     })
 publish('com.app.idea', {'bat': random.uniform(0, 15),
                          'map': {'bar': random.uniform(0, 2), 'mbar': random.uniform(0, 2), 'psi': random.uniform(0, 2)},
                          'gear': random.randint(0, 6),
                          'iat': {'celsius': random.randint(0, 50), 'fahrenheit': random.randint(0, 50)},
                          'tps': random.randint(0, 100),
                          'ect': {'celsius': random.randint(0, 50), 'fahrenheit': random.randint(0, 50)},
                          'rpm': random.randint(0, 9000),
                          'vss': {'kmh': random.randint(0, 200), 'mph': random.randint(0, 200)},
                          'o2': {'afr': random.uniform(0, 20), 'lambda': random.uniform(0, 1)},
                          'cam': random.randint(0, 50),
                          'mil': random.choice([True, False]),
                          'bksw': random.choice([True, False]),
                          'an0': Formula.psi_to_bar(Formula.ebay_150_psi(random.uniform(0, 5))),
                          'an1': Formula.autometer_2246(random.uniform(0, 5)),
                          'an2': random.uniform(0, 5),
                          'an3': random.uniform(0, 5),
                          'an4': random.uniform(0, 5),
                          'an5': random.uniform(0, 5),
                          'an6': random.uniform(0, 5),
                          'an7': random.uniform(0, 5),
                          'di4': random.randint(0, 1),
                          'di5': random.randint(0, 1),
                          'di6': random.randint(0, 1),
                          'di12': random.randint(0, 1),
                          'di21': random.randint(0, 1),
                          'di17': random.randint(0, 1),
                          'di27': random.randint(0, 1),
                          'di22': random.randint(0, 1),
                          'time': time.get_time(),
                          'odo': odo.get_mileage(),
                          'ai0': Formula.vdo_323_057(random.uniform(0, 5)),
                          'ai1': Formula.civic_eg_fuel_tank(random.uniform(0, 5)),
                          'ai2': random.uniform(0, 5),
                          'ai3': random.uniform(0, 5),
                          'ai4': random.uniform(0, 5),
                          'ai5': random.uniform(0, 5),
                          'ai6': random.uniform(0, 5),
                          'ai7': random.uniform(0, 5),
                          })
Example #10
0
 publish(
     "data",
     {
         "bat": kpro.bat(),
         "gear": kpro.gear(),
         "iat": kpro.iat()[iat_unit],
         "tps": kpro.tps(),
         "ect": kpro.ect()[ect_unit],
         "rpm": kpro.rpm(),
         "vss": kpro.vss()[vss_unit],
         "o2": kpro.o2()[o2_unit],
         "cam": kpro.cam(),
         "mil": kpro.mil(),
         "fan": kpro.fanc(),
         "bksw": kpro.bksw(),
         "flr": kpro.flr(),
         "eth": kpro.eth(),
         "scs": kpro.scs(),
         "fmw": kpro.firmware(),
         "map": kpro.map()[map_unit],
         "an0": an0_formula(kpro.analog_input(0))[an0_unit],
         "an1": an1_formula(kpro.analog_input(1))[an1_unit],
         "an2": an2_formula(kpro.analog_input(2))[an2_unit],
         "an3": an3_formula(kpro.analog_input(3))[an3_unit],
         "an4": an4_formula(kpro.analog_input(4))[an4_unit],
         "an5": an5_formula(kpro.analog_input(5))[an5_unit],
         "an6": an6_formula(kpro.analog_input(6))[an6_unit],
         "an7": an7_formula(kpro.analog_input(7))[an7_unit],
         "time": time.get_time(),
         "odo": odo.get_mileage()[odo_unit],
         "style": style.status,
         "ver": __version__,
     },
 )
Example #11
0
 publish(
     "com.app.idea",
     {
         "bat": random.uniform(0, 15),
         "map": {
             "bar": random.uniform(0, 2),
             "mbar": random.uniform(0, 2),
             "psi": random.uniform(0, 2),
         },
         "gear": random.randint(0, 6),
         "iat": {
             "celsius": random.randint(0, 50),
             "fahrenheit": random.randint(0, 50),
         },
         "tps": random.randint(0, 100),
         "ect": {
             "celsius": random.randint(0, 50),
             "fahrenheit": random.randint(0, 50),
         },
         "rpm": random.randint(0, 9000),
         "vss": {"kmh": random.randint(0, 200), "mph": random.randint(0, 200)},
         "o2": {"afr": random.uniform(0, 20), "lambda": random.uniform(0, 1)},
         "cam": random.randint(0, 50),
         "mil": random.choice([True, False]),
         "bksw": random.choice([True, False]),
         "an0": Formula.psi_to_bar(Formula.ebay_150_psi(random.uniform(0, 5))),
         "an1": Formula.autometer_2246(random.uniform(0, 5)),
         "an2": random.uniform(0, 5),
         "an3": random.uniform(0, 5),
         "an4": random.uniform(0, 5),
         "an5": random.uniform(0, 5),
         "an6": random.uniform(0, 5),
         "an7": random.uniform(0, 5),
         "di4": random.randint(0, 1),
         "di5": random.randint(0, 1),
         "di6": random.randint(0, 1),
         "di12": random.randint(0, 1),
         "di21": random.randint(0, 1),
         "di17": random.randint(0, 1),
         "di27": random.randint(0, 1),
         "di22": random.randint(0, 1),
         "time": time.get_time(),
         "odo": odo.get_mileage(),
         "ai0": Formula.vdo_323_057(random.uniform(0, 5)),
         "ai1": Formula.civic_eg_fuel_tank(random.uniform(0, 5)),
         "ai2": random.uniform(0, 5),
         "ai3": random.uniform(0, 5),
         "ai4": random.uniform(0, 5),
         "ai5": random.uniform(0, 5),
         "ai6": random.uniform(0, 5),
         "ai7": random.uniform(0, 5),
     },
 )
Example #12
0
while True:
    odo.save(kpro.vss()['kmh'])
    publish('data', {'bat': kpro.bat(),
                     'gear': kpro.gear(),
                     'iat': kpro.iat()[iat_unit],
                     'tps': kpro.tps(),
                     'ect': kpro.ect()[ect_unit],
                     'rpm': kpro.rpm(),
                     'vss': kpro.vss()[vss_unit],
                     'o2': kpro.o2()[o2_unit],
                     'cam': kpro.cam(),
                     'mil': kpro.mil(),
                     'fan': kpro.fanc(),
                     'bksw': kpro.bksw(),
                     'flr': kpro.flr(),
                     'eth': kpro.eth(),
                     'map': kpro.map()[map_unit],
                     'an0': an0_formula(kpro.analog_input(0))[an0_unit],
                     'an1': an1_formula(kpro.analog_input(1))[an1_unit],
                     'an2': an2_formula(kpro.analog_input(2))[an2_unit],
                     'an3': an3_formula(kpro.analog_input(3))[an3_unit],
                     'an4': an4_formula(kpro.analog_input(4))[an4_unit],
                     'an5': an5_formula(kpro.analog_input(5))[an5_unit],
                     'an6': an6_formula(kpro.analog_input(6))[an6_unit],
                     'an7': an7_formula(kpro.analog_input(7))[an7_unit],
                     'time': time.get_time(),
                     'odo': odo.get_mileage()[odo_unit],
                     })
    sleep(0.1)