3 from __future__
import annotations
10 from eagle100
import Eagle
as Eagle100Reader
11 from requests.exceptions
import ConnectionError
as ConnectError, HTTPError, Timeout
16 from .const
import TYPE_EAGLE_100, TYPE_EAGLE_200
18 _LOGGER = logging.getLogger(__name__)
20 UPDATE_100_ERRORS = (ConnectError, HTTPError, Timeout)
28 """Error to indicate a request failed."""
32 """Error to indicate bad auth."""
36 """Try API call 'get_network_info' to see if target device is Eagle-100 or Eagle-200."""
38 hub = aioeagle.EagleHub(
39 aiohttp_client.async_get_clientsession(hass), cloud_id, install_code, host=host
43 async
with asyncio.timeout(30):
44 meters = await hub.get_device_list()
45 except aioeagle.BadAuth
as err:
46 raise InvalidAuth
from err
47 except (KeyError, aiohttp.ClientError):
51 if meters
is not None:
53 hardware_address = meters[0].hardware_address
55 hardware_address =
None
57 return TYPE_EAGLE_200, hardware_address
59 reader = Eagle100Reader(cloud_id, install_code, host)
62 response = await hass.async_add_executor_job(reader.get_network_info)
63 except ValueError
as err:
65 raise InvalidAuth
from err
66 except UPDATE_100_ERRORS
as error:
67 _LOGGER.error(
"Failed to connect during setup: %s", error)
68 raise CannotConnect
from error
72 "NetworkInfo" in response
73 and response[
"NetworkInfo"].
get(
"ModelId") ==
"Z109-EAGLE"
75 return TYPE_EAGLE_100,
None
web.Response get(self, web.Request request, str config_key)
def async_get_type(hass, cloud_id, install_code, host)