Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the NWS weather platform."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
station = config.get(CONF_STATION)
api_key = config[CONF_API_KEY]
mode = config[CONF_MODE]
websession = async_get_clientsession(hass)
# ID request as being from HA, pynws prepends the api_key in addition
api_key_ha = f"{api_key} homeassistant"
nws = SimpleNWS(latitude, longitude, api_key_ha, mode, websession)
_LOGGER.debug("Setting up station: %s", station)
try:
await nws.set_station(station)
except ERRORS as status:
_LOGGER.error(
"Error getting station list for %s: %s", (latitude, longitude), status
)
raise PlatformNotReady
_LOGGER.debug("Station list: %s", nws.stations)
_LOGGER.debug(
"Initialized for coordinates %s, %s -> station %s",
latitude,
longitude,
nws.station,