Fix Hive authentication (#72929)

pull/72944/head
Khole 2022-06-02 22:54:26 +01:00 committed by Paulus Schoutsen
parent f1bcfedf84
commit f5e0363117
6 changed files with 21 additions and 10 deletions

View File

@ -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(

View File

@ -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:

View File

@ -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"]

View File

@ -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

View File

@ -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

View File

@ -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=[