async def go(LOOP):
            stop_name = "De Brouckère"
            lines_filter = [(5, 1)]
            custom_session = aiohttp.ClientSession()

            APIClient = MockAPIClient()

            service = STIBService(APIClient)
            exception = "Unraised"
            try:
                passages = await service.get_passages(stop_name,
                                                      lines_filter,
                                                      now=datetime.datetime(
                                                          2020,
                                                          1,
                                                          28,
                                                          hour=23,
                                                          minute=59,
                                                          second=52))
            except NoScheduleFromAPIException as e:
                exception = "Raised"
                passages = e.get_next_passages()
            self.assertEqual(exception, "Raised")
            self.assertGreaterEqual(len(passages), 1)
            self.assertEqual(passages[0]['expected_arrival_time'],
                             '2020-01-29T00:06:31')
Exemple #2
0
        async def go(LOOP):
            stop_name = "scherdemael"
            lines_filter = [(46, "Glibert")]

            APIClient = MockAPIClient()

            service = STIBService(APIClient)
            print(await service.get_passages(stop_name, lines_filter))
        async def go(LOOP):
            stop_name = "foobar"

            APIClient = MockAPIClient()

            service = STIBService(APIClient)
            res = "No exception raised"
            try:
                passages = await service.get_passages(stop_name)
            except InvalidStopNameException as e:
                res = "InvalidStopNameException raised!"

            self.assertEqual(res, "InvalidStopNameException raised!")
        async def go(LOOP):
            stop_name = "scherdemael"
            lines_filter = [(46, "Glibert")]
            custom_session = aiohttp.ClientSession()

            APIClient = MockAPIClient()

            service = STIBService(APIClient)
            passages = await service.get_passages(stop_name, lines_filter)

            print(json.dumps(passages))

            await custom_session.close()
        async def go(LOOP):
            result = "Integration test Succeded!"
            try:
                stop_name = "Saint-Denis"
                custom_session = aiohttp.ClientSession()

                APIClient = STIBAPIClient(LOOP, custom_session, CLIENT_ID, CLIENT_SECRET)

                service = STIBService(APIClient)
                print(await service.get_passages(stop_name, lang_message='fr', lang_stop_name='fr'))
            except:
                result = "Integration test Failed!"

            self.assertEqual(result, "Integration test Succeded!")
Exemple #6
0
async def go(LOOP):
    stop_name = "Scherdemael"
    lines_filter = [(46, "Glibert")]
    custom_session = aiohttp.ClientSession()
    APIClient = STIBAPIClient(LOOP, custom_session, CLIENT_ID, CLIENT_SECRET)
    service = STIBService(APIClient)
    print(await service.get_passages(stop_name, lines_filter, max_passages=3))

    shapefile_service = ShapefileService(APIClient)

    scherdemael = await shapefile_service.get_stop_infos(stop_name)
    print(scherdemael.get_lines())
    # doesn't really make sense to specify a filter but hey... you can
    print(scherdemael.get_lines(lines_filter))
    print(scherdemael.get_lines_with_destinations(lines_filter))

    await custom_session.close()
Exemple #7
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up this integration using UI.
    entry has the following data:
    {
        CONF_CLIENT_ID_KEY: user_input[CONF_CLIENT_ID_KEY],
        CONF_CLIENT_SECRET_KEY: user_input[CONF_CLIENT_SECRET_KEY],
        CONF_LANG: user_input[CONF_LANG],
        "uid": this_uid,
        "stop_name": stop_name,
        "lines_filter": lines_filter,
        "max_passages": max_passages
    }
    """
    if hass.data.get(DOMAIN) is None or hass.data.get(DOMAIN).get(
            "service") is None:
        client_id = entry.data.get(CONF_CLIENT_ID_KEY)
        client_secret = entry.data.get(CONF_CLIENT_SECRET_KEY)
        session = async_get_clientsession(hass)
        client = STIBAPIClient(loop=hass.loop,
                               session=session,
                               client_id=client_id,
                               client_secret=client_secret)
        if await client.async_get_access_token() is None:
            raise InvalidAuth
        service = STIBService(client)
        hass.data.setdefault(DOMAIN, {"service": service})
        _LOGGER.info(STARTUP_MESSAGE)

    service = hass.data.get(DOMAIN).get("service")

    sensor = STIBMVIBPublicTransportSensor(
        service=service,
        stop_name=entry.data.get(CONF_STOP_NAME),
        main_direction=entry.data.get(CONF_MAIN_DIRECTION),
        monitored_lines=entry.options.get(CONF_MONITORED_LINES),
        max_passages=entry.options.get(CONF_MAX_PASSAGES),
        lang=entry.data.get(CONF_LANG))

    if not sensor.is_init:
        raise PlatformNotReady

    hass.data[DOMAIN][entry.data["uid"]] = sensor

    entry.add_update_listener(async_reload_entry)
    return True
Exemple #8
0
        async def go(LOOP):
            stop_name = "Scherdemael"
            lines_filter = [(104, 1)]
            custom_session = aiohttp.ClientSession()

            APIClient = MockAPIClient()

            service = STIBService(APIClient)

            hasRaised = False
            try:
                await service.get_passages(stop_name,
                                           lines_filter,
                                           lang=('fr', 'fr'))
            except InvalidLineFilterException:
                hasRaised = True

            self.assertTrue(hasRaised)
Exemple #9
0
        async def go(LOOP):
            stop_name = "Scherdemael"
            lines_filter = [(46, 1)]
            custom_session = aiohttp.ClientSession()

            APIClient = MockAPIClient()

            service = STIBService(APIClient)
            passages = await service.get_passages(stop_name,
                                                  lines_filter,
                                                  lang=('fr', 'fr'))

            now = datetime.datetime.now()
            delta1 = datetime.timedelta(minutes=3, seconds=25)
            delta2 = datetime.timedelta(minutes=13, seconds=22)

            # Check message
            self.assertEqual(passages[0]["message"], "foofr")
            self.assertEqual(passages[1]["message"], "")