opened
offbyone
username_0
<!-- READ THIS FIRST:
  - If you need additional help with this template, please refer to https://www.home-assistant.io/help/reporting_issues/
  - Make sure you are running the latest version of Home Assistant before reporting an issue: https://github.com/home-assistant/core/releases
  - Do not report issues for integrations if you are using custom components or integrations.
  - Provide as many details as possible. Paste logs, configuration samples and code into the backticks.
  DO NOT DELETE ANY TEXT from this template! Otherwise, your issue may be closed without comment.
-->
## The problem
If the `waqi` search API is not available when HA starts up, it leaves the sensor in a state where it can't ever find the stations.

## Environment
<!--
  Provide details about the versions you are using, which helps us to reproduce
  and find the issue quicker. Version information is found in the
  Home Assistant frontend: Configuration -> Info.
-->

- Home Assistant Core release with the issue: Home Assistant 0.114.4
- Last working Home Assistant Core release (if known): None
- Operating environment (OS/Container/Supervised/Core): raspbian
- Integration causing this issue: waqi
- Link to integration documentation on our website: https://www.home-assistant.io/integrations/waqi/

## Problem-relevant `configuration.yaml`
```yaml
sensor:
  - platform: waqi
    token: "{{ waqi_api_token }}"
    locations:
      - seattle
      - corvallis
```

## Traceback/Error logs
<!--
  If you come across any trace or error logs, please provide them.
-->

```txt
2020-09-11 15:11:31 ERROR (MainThread) [homeassistant.components.waqi.sensor] Failed to connect to WAQI servers
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.7/asyncio/base_events.py", line 986, in create_connection
    ssl_handshake_timeout=ssl_handshake_timeout)
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1014, in _create_connection_transport
    await waiter
  File "/usr/lib/python3.7/asyncio/selector_events.py", line 801, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/waqi/sensor.py", line 73, in async_setup_platform
    stations = await client.search(location_name)
  File "/srv/homeassistant/lib/python3.7/site-packages/waqiasync/__init__.py", line 32, in search
    return (yield from self._get(SEARCH_URL, keyword=keyword))
  File "/srv/homeassistant/lib/python3.7/site-packages/waqiasync/__init__.py", line 48, in _get
    path, params=dict(self._params, **kwargs))
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/client.py", line 483, in _request
    timeout=real_timeout
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 859, in _create_connection
    req, traces, timeout)
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.waqi.info:443 ssl:default [Connection reset by peer]
```

## Additional information

From looking at the code in `waqi/sensor.py` it looks a lot like the mapping of location to station is done early in the process of HA start, and not again. That means that uses of this sensor fail pretty clunkily, with errors like "Entity is non-numeric: sensor.waqi_queen_anne_hill_seattle_washington_usa" and do not appear to recover.
WAQI integration is unrecoverably disabled if the search API is not available during HA startup.
issue