def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Entur public transport sensor.""" from enturclient import EnturPublicTransportData from enturclient.consts import CONF_NAME as API_NAME expand = config.get(CONF_EXPAND_PLATFORMS) line_whitelist = config.get(CONF_WHITELIST_LINES) name = config.get(CONF_NAME) show_on_map = config.get(CONF_SHOW_ON_MAP) stop_ids = config.get(CONF_STOP_IDS) stops = [s for s in stop_ids if "StopPlace" in s] quays = [s for s in stop_ids if "Quay" in s] data = EnturPublicTransportData(API_CLIENT_NAME, stops, quays, expand, line_whitelist) data.update() proxy = EnturProxy(data) entities = [] for item in data.all_stop_places_quays(): try: given_name = "{} {}".format( name, data.get_stop_info(item)[API_NAME]) except KeyError: given_name = "{} {}".format(name, item) entities.append( EnturPublicTransportSensor(proxy, given_name, item, show_on_map)) add_entities(entities, True)
async def print_train_delay(self): async with aiohttp.ClientSession() as client: stop_id = f'NSR:StopPlace:{self.config.stop_id}' stops = [stop_id] data = EnturPublicTransportData( client_name=self.config.entur_client_id, stops=stops, omit_non_boarding=True, number_of_departures=10, web_session=client) await data.update() train = data.get_stop_info(stop_id) dindex = 0 for index, call in enumerate(train.estimated_calls): # print(f'|{call.front_display}|') # for d in self.destinations: # print(f'destination: |{d}|') if dindex < 5 and call.front_display in self.config.destinations: # or (1 == 1): old_pos = self.collection.departure_list[dindex].pos departure = Departure(call.front_display, call.aimed_departure_time, call.delay_in_min, old_pos) self.collection.departure_list[dindex] = departure dindex += 1 # else: # print(f'Skipped train departure |{call.front_display}|, dindex {dindex}') while dindex < 5: self.collection.departure_list[dindex] = Departure( "", "", 0, 0) dindex += 1
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Entur public transport sensor.""" expand = config[CONF_EXPAND_PLATFORMS] line_whitelist = config[CONF_WHITELIST_LINES] name = config[CONF_NAME] show_on_map = config[CONF_SHOW_ON_MAP] stop_ids = config[CONF_STOP_IDS] omit_non_boarding = config[CONF_OMIT_NON_BOARDING] number_of_departures = config[CONF_NUMBER_OF_DEPARTURES] stops = [s for s in stop_ids if "StopPlace" in s] quays = [s for s in stop_ids if "Quay" in s] data = EnturPublicTransportData( API_CLIENT_NAME, stops=stops, quays=quays, line_whitelist=line_whitelist, omit_non_boarding=omit_non_boarding, number_of_departures=number_of_departures, web_session=async_get_clientsession(hass), ) if expand: await data.expand_all_quays() await data.update() proxy = EnturProxy(data) entities = [] for place in data.all_stop_places_quays(): try: given_name = f"{name} {data.get_stop_info(place).name}" except KeyError: given_name = f"{name} {place}" entities.append( EnturPublicTransportSensor(proxy, given_name, place, show_on_map)) async_add_entities(entities, True)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Entur public transport sensor.""" expand = config.get(CONF_EXPAND_PLATFORMS) line_whitelist = config.get(CONF_WHITELIST_LINES) name = config.get(CONF_NAME) show_on_map = config.get(CONF_SHOW_ON_MAP) stop_ids = config.get(CONF_STOP_IDS) omit_non_boarding = config.get(CONF_OMIT_NON_BOARDING) number_of_departures = config.get(CONF_NUMBER_OF_DEPARTURES) stops = [s for s in stop_ids if "StopPlace" in s] quays = [s for s in stop_ids if "Quay" in s] data = EnturPublicTransportData( API_CLIENT_NAME, stops=stops, quays=quays, line_whitelist=line_whitelist, omit_non_boarding=omit_non_boarding, number_of_departures=number_of_departures, web_session=async_get_clientsession(hass), ) if expand: await data.expand_all_quays() await data.update() proxy = EnturProxy(data) entities = [] for place in data.all_stop_places_quays(): try: given_name = "{} {}".format(name, data.get_stop_info(place).name) except KeyError: given_name = f"{name} {place}" entities.append( EnturPublicTransportSensor(proxy, given_name, place, show_on_map)) async_add_entities(entities, True)
async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): """Set up the Entur public transport sensor.""" from enturclient import EnturPublicTransportData expand = config.get(CONF_EXPAND_PLATFORMS) line_whitelist = config.get(CONF_WHITELIST_LINES) name = config.get(CONF_NAME) show_on_map = config.get(CONF_SHOW_ON_MAP) stop_ids = config.get(CONF_STOP_IDS) omit_non_boarding = config.get(CONF_OMIT_NON_BOARDING) number_of_departures = config.get(CONF_NUMBER_OF_DEPARTURES) stops = [s for s in stop_ids if "StopPlace" in s] quays = [s for s in stop_ids if "Quay" in s] data = EnturPublicTransportData(API_CLIENT_NAME, stops=stops, quays=quays, line_whitelist=line_whitelist, omit_non_boarding=omit_non_boarding, number_of_departures=number_of_departures, web_session=async_get_clientsession(hass)) if expand: await data.expand_all_quays() await data.update() proxy = EnturProxy(data) entities = [] for place in data.all_stop_places_quays(): try: given_name = "{} {}".format( name, data.get_stop_info(place).name) except KeyError: given_name = "{} {}".format(name, place) entities.append( EnturPublicTransportSensor(proxy, given_name, place, show_on_map)) async_add_entities(entities, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Entur public transport sensor.""" from enturclient import EnturPublicTransportData from enturclient.consts import CONF_NAME as API_NAME expand = config.get(CONF_EXPAND_PLATFORMS) name = config.get(CONF_NAME) show_on_map = config.get(CONF_SHOW_ON_MAP) stop_ids = config.get(CONF_STOP_IDS) stops = [s for s in stop_ids if "StopPlace" in s] quays = [s for s in stop_ids if "Quay" in s] data = EnturPublicTransportData(API_CLIENT_NAME, stops, quays, expand) data.update() proxy = EnturProxy(data) entities = [] for item in data.all_stop_places_quays(): try: given_name = "{} {}".format(name, data.get_stop_info(item)[API_NAME]) except KeyError: given_name = "{} {}".format(name, item) entities.append( EnturPublicTransportSensor(proxy, given_name, item, show_on_map)) add_entities(entities, True)