From 73f227b6514e32c6be5eb1c937a5d74077994a37 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 11 Apr 2021 22:31:25 -1000 Subject: [PATCH] Use shared httpx client in enphase_envoy (#48709) * Use shared httpx client in enphase_envoy * test fix * f * bump version --- homeassistant/components/enphase_envoy/__init__.py | 11 ++++++++--- homeassistant/components/enphase_envoy/config_flow.py | 9 +++++++-- homeassistant/components/enphase_envoy/manifest.json | 4 ++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/enphase_envoy/__init__.py b/homeassistant/components/enphase_envoy/__init__.py index 1b8d09b1f1d..faa9247b4e7 100644 --- a/homeassistant/components/enphase_envoy/__init__.py +++ b/homeassistant/components/enphase_envoy/__init__.py @@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import COORDINATOR, DOMAIN, NAME, PLATFORMS, SENSORS @@ -27,8 +28,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: config = entry.data name = config[CONF_NAME] + envoy_reader = EnvoyReader( - config[CONF_HOST], config[CONF_USERNAME], config[CONF_PASSWORD] + config[CONF_HOST], + config[CONF_USERNAME], + config[CONF_PASSWORD], + async_client=get_async_client(hass), ) try: @@ -36,7 +41,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except httpx.HTTPStatusError as err: _LOGGER.error("Authentication failure during setup: %s", err) return - except (AttributeError, httpx.HTTPError) as err: + except (RuntimeError, httpx.HTTPError) as err: raise ConfigEntryNotReady from err async def async_update_data(): @@ -63,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinator = DataUpdateCoordinator( hass, _LOGGER, - name="envoy {name}", + name=f"envoy {name}", update_method=async_update_data, update_interval=SCAN_INTERVAL, ) diff --git a/homeassistant/components/enphase_envoy/config_flow.py b/homeassistant/components/enphase_envoy/config_flow.py index 41d72c09a31..934b02be311 100644 --- a/homeassistant/components/enphase_envoy/config_flow.py +++ b/homeassistant/components/enphase_envoy/config_flow.py @@ -18,6 +18,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.httpx_client import get_async_client from .const import DOMAIN @@ -31,14 +32,18 @@ CONF_SERIAL = "serial" async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]: """Validate the user input allows us to connect.""" envoy_reader = EnvoyReader( - data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD], inverters=True + data[CONF_HOST], + data[CONF_USERNAME], + data[CONF_PASSWORD], + inverters=True, + async_client=get_async_client(hass), ) try: await envoy_reader.getData() except httpx.HTTPStatusError as err: raise InvalidAuth from err - except (AttributeError, httpx.HTTPError) as err: + except (RuntimeError, httpx.HTTPError) as err: raise CannotConnect from err diff --git a/homeassistant/components/enphase_envoy/manifest.json b/homeassistant/components/enphase_envoy/manifest.json index 23601060737..9b8f01f2547 100644 --- a/homeassistant/components/enphase_envoy/manifest.json +++ b/homeassistant/components/enphase_envoy/manifest.json @@ -3,11 +3,11 @@ "name": "Enphase Envoy", "documentation": "https://www.home-assistant.io/integrations/enphase_envoy", "requirements": [ - "envoy_reader==0.18.3" + "envoy_reader==0.18.4" ], "codeowners": [ "@gtdiehl" ], "config_flow": true, "zeroconf": [{ "type": "_enphase-envoy._tcp.local."}] -} \ No newline at end of file +} diff --git a/requirements_all.txt b/requirements_all.txt index d10f866636e..a58cf60f2a5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -557,7 +557,7 @@ env_canada==0.2.5 # envirophat==0.0.6 # homeassistant.components.enphase_envoy -envoy_reader==0.18.3 +envoy_reader==0.18.4 # homeassistant.components.season ephem==3.7.7.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a0732f55aa2..667b49a8335 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -303,7 +303,7 @@ emulated_roku==0.2.1 enocean==0.50 # homeassistant.components.enphase_envoy -envoy_reader==0.18.3 +envoy_reader==0.18.4 # homeassistant.components.season ephem==3.7.7.0