mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Fix hive authentication process (#72719)
* Fix hive authentication process * Update hive test scripts to add new data
This commit is contained in:
parent
d31e43b980
commit
a53aaf696c
@ -76,8 +76,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Hive from a config entry."""
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(hass)
|
||||
hive = Hive(websession)
|
||||
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_config["options"] = {}
|
||||
hive_config["options"].update(
|
||||
|
@ -103,6 +103,7 @@ class HiveFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
# Setup the config entry
|
||||
self.data["tokens"] = self.tokens
|
||||
self.data["device_data"] = await self.hive_auth.getDeviceData()
|
||||
if self.context["source"] == config_entries.SOURCE_REAUTH:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.entry, title=self.data["username"], data=self.data
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "Hive",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/hive",
|
||||
"requirements": ["pyhiveapi==0.4.2"],
|
||||
"requirements": ["pyhiveapi==0.5.4"],
|
||||
"codeowners": ["@Rendili", "@KJonline"],
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["apyhiveapi"]
|
||||
|
@ -1538,7 +1538,7 @@ pyheos==0.7.2
|
||||
pyhik==0.3.0
|
||||
|
||||
# homeassistant.components.hive
|
||||
pyhiveapi==0.4.2
|
||||
pyhiveapi==0.5.4
|
||||
|
||||
# homeassistant.components.homematic
|
||||
pyhomematic==0.1.77
|
||||
|
@ -1029,7 +1029,7 @@ pyhaversion==22.4.1
|
||||
pyheos==0.7.2
|
||||
|
||||
# homeassistant.components.hive
|
||||
pyhiveapi==0.4.2
|
||||
pyhiveapi==0.5.4
|
||||
|
||||
# homeassistant.components.homematic
|
||||
pyhomematic==0.1.77
|
||||
|
@ -13,7 +13,7 @@ USERNAME = "username@home-assistant.com"
|
||||
UPDATED_USERNAME = "updated_username@home-assistant.com"
|
||||
PASSWORD = "test-password"
|
||||
UPDATED_PASSWORD = "updated-password"
|
||||
INCORRECT_PASSWORD = "incoreect-password"
|
||||
INCORRECT_PASSWORD = "incorrect-password"
|
||||
SCAN_INTERVAL = 120
|
||||
UPDATED_SCAN_INTERVAL = 60
|
||||
MFA_CODE = "1234"
|
||||
@ -33,6 +33,13 @@ async def test_import_flow(hass):
|
||||
"AccessToken": "mock-access-token",
|
||||
},
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.hive.config_flow.Auth.getDeviceData",
|
||||
return_value=[
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
), patch(
|
||||
"homeassistant.components.hive.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
@ -57,6 +64,11 @@ async def test_import_flow(hass):
|
||||
},
|
||||
"ChallengeName": "SUCCESS",
|
||||
},
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
}
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
@ -81,6 +93,13 @@ async def test_user_flow(hass):
|
||||
"AccessToken": "mock-access-token",
|
||||
},
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.hive.config_flow.Auth.getDeviceData",
|
||||
return_value=[
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
), patch(
|
||||
"homeassistant.components.hive.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
@ -105,6 +124,11 @@ async def test_user_flow(hass):
|
||||
},
|
||||
"ChallengeName": "SUCCESS",
|
||||
},
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
}
|
||||
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
@ -148,6 +172,13 @@ async def test_user_flow_2fa(hass):
|
||||
"AccessToken": "mock-access-token",
|
||||
},
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.hive.config_flow.Auth.getDeviceData",
|
||||
return_value=[
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
), patch(
|
||||
"homeassistant.components.hive.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
@ -171,6 +202,11 @@ async def test_user_flow_2fa(hass):
|
||||
},
|
||||
"ChallengeName": "SUCCESS",
|
||||
},
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
}
|
||||
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
@ -243,7 +279,15 @@ async def test_option_flow(hass):
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title=USERNAME,
|
||||
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
data={
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
@ -317,6 +361,13 @@ async def test_user_flow_2fa_send_new_code(hass):
|
||||
"AccessToken": "mock-access-token",
|
||||
},
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.hive.config_flow.Auth.getDeviceData",
|
||||
return_value=[
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
), patch(
|
||||
"homeassistant.components.hive.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
@ -340,6 +391,11 @@ async def test_user_flow_2fa_send_new_code(hass):
|
||||
},
|
||||
"ChallengeName": "SUCCESS",
|
||||
},
|
||||
"device_data": [
|
||||
"mock-device-group-key",
|
||||
"mock-device-key",
|
||||
"mock-device-password",
|
||||
],
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user