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)
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)
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)