From f5e0363117f66458299fdf1ac5f1bbc86d8a97fd Mon Sep 17 00:00:00 2001 From: Khole Date: Thu, 2 Jun 2022 22:54:26 +0100 Subject: [PATCH] Fix Hive authentication (#72929) --- homeassistant/components/hive/__init__.py | 9 ++------- homeassistant/components/hive/config_flow.py | 1 + homeassistant/components/hive/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/hive/test_config_flow.py | 15 +++++++++++++++ 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 292bbe62ae1..f3ed9674fcd 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -75,14 +75,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Hive from a config entry.""" - websession = aiohttp_client.async_get_clientsession(hass) + web_session = aiohttp_client.async_get_clientsession(hass) hive_config = dict(entry.data) - hive = Hive( - websession, - deviceGroupKey=hive_config["device_data"][0], - deviceKey=hive_config["device_data"][1], - devicePassword=hive_config["device_data"][2], - ) + hive = Hive(web_session) hive_config["options"] = {} hive_config["options"].update( diff --git a/homeassistant/components/hive/config_flow.py b/homeassistant/components/hive/config_flow.py index 9c391f13294..c713a3011f4 100644 --- a/homeassistant/components/hive/config_flow.py +++ b/homeassistant/components/hive/config_flow.py @@ -102,6 +102,7 @@ class HiveFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): raise UnknownHiveError # Setup the config entry + await self.hive_auth.device_registration("Home Assistant") self.data["tokens"] = self.tokens self.data["device_data"] = await self.hive_auth.getDeviceData() if self.context["source"] == config_entries.SOURCE_REAUTH: diff --git a/homeassistant/components/hive/manifest.json b/homeassistant/components/hive/manifest.json index 472adc137ba..d8cd56abe0b 100644 --- a/homeassistant/components/hive/manifest.json +++ b/homeassistant/components/hive/manifest.json @@ -3,7 +3,7 @@ "name": "Hive", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/hive", - "requirements": ["pyhiveapi==0.5.4"], + "requirements": ["pyhiveapi==0.5.5"], "codeowners": ["@Rendili", "@KJonline"], "iot_class": "cloud_polling", "loggers": ["apyhiveapi"] diff --git a/requirements_all.txt b/requirements_all.txt index d51e776863d..ad38e5c5fb1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1538,7 +1538,7 @@ pyheos==0.7.2 pyhik==0.3.0 # homeassistant.components.hive -pyhiveapi==0.5.4 +pyhiveapi==0.5.5 # homeassistant.components.homematic pyhomematic==0.1.77 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f7b246c64d2..94b978ece80 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1029,7 +1029,7 @@ pyhaversion==22.4.1 pyheos==0.7.2 # homeassistant.components.hive -pyhiveapi==0.5.4 +pyhiveapi==0.5.5 # homeassistant.components.homematic pyhomematic==0.1.77 diff --git a/tests/components/hive/test_config_flow.py b/tests/components/hive/test_config_flow.py index bb567b0bdfc..51ceec43ad2 100644 --- a/tests/components/hive/test_config_flow.py +++ b/tests/components/hive/test_config_flow.py @@ -33,6 +33,9 @@ async def test_import_flow(hass): "AccessToken": "mock-access-token", }, }, + ), patch( + "homeassistant.components.hive.config_flow.Auth.device_registration", + return_value=True, ), patch( "homeassistant.components.hive.config_flow.Auth.getDeviceData", return_value=[ @@ -93,6 +96,9 @@ async def test_user_flow(hass): "AccessToken": "mock-access-token", }, }, + ), patch( + "homeassistant.components.hive.config_flow.Auth.device_registration", + return_value=True, ), patch( "homeassistant.components.hive.config_flow.Auth.getDeviceData", return_value=[ @@ -172,6 +178,9 @@ async def test_user_flow_2fa(hass): "AccessToken": "mock-access-token", }, }, + ), patch( + "homeassistant.components.hive.config_flow.Auth.device_registration", + return_value=True, ), patch( "homeassistant.components.hive.config_flow.Auth.getDeviceData", return_value=[ @@ -256,6 +265,9 @@ async def test_reauth_flow(hass): "AccessToken": "mock-access-token", }, }, + ), patch( + "homeassistant.components.hive.config_flow.Auth.device_registration", + return_value=True, ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -361,6 +373,9 @@ async def test_user_flow_2fa_send_new_code(hass): "AccessToken": "mock-access-token", }, }, + ), patch( + "homeassistant.components.hive.config_flow.Auth.device_registration", + return_value=True, ), patch( "homeassistant.components.hive.config_flow.Auth.getDeviceData", return_value=[