Hive auth fix for users (#73247)

This commit is contained in:
Khole 2022-06-10 04:54:24 +01:00 committed by GitHub
parent d3f01f7ea9
commit 1dd7781acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 35 deletions

View File

@ -27,6 +27,7 @@ class HiveFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.data = {}
self.tokens = {}
self.entry = None
self.device_registration = False
async def async_step_user(self, user_input=None):
"""Prompt user input. Create or edit entry."""
@ -88,6 +89,7 @@ class HiveFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if not errors:
try:
self.device_registration = True
return await self.async_setup_hive_entry()
except UnknownHiveError:
errors["base"] = "unknown"
@ -102,9 +104,10 @@ class HiveFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
raise UnknownHiveError
# Setup the config entry
await self.hive_auth.device_registration("Home Assistant")
if self.device_registration:
await self.hive_auth.device_registration("Home Assistant")
self.data["device_data"] = await self.hive_auth.getDeviceData()
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

View File

@ -6,7 +6,7 @@
"models": ["HHKBridge*"]
},
"documentation": "https://www.home-assistant.io/integrations/hive",
"requirements": ["pyhiveapi==0.5.5"],
"requirements": ["pyhiveapi==0.5.9"],
"codeowners": ["@Rendili", "@KJonline"],
"iot_class": "cloud_polling",
"loggers": ["apyhiveapi"]

View File

@ -1541,7 +1541,7 @@ pyheos==0.7.2
pyhik==0.3.0
# homeassistant.components.hive
pyhiveapi==0.5.5
pyhiveapi==0.5.9
# homeassistant.components.homematic
pyhomematic==0.1.77

View File

@ -1032,7 +1032,7 @@ pyhaversion==22.4.1
pyheos==0.7.2
# homeassistant.components.hive
pyhiveapi==0.5.5
pyhiveapi==0.5.9
# homeassistant.components.homematic
pyhomematic==0.1.77

View File

@ -33,16 +33,6 @@ 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=[
"mock-device-group-key",
"mock-device-key",
"mock-device-password",
],
), patch(
"homeassistant.components.hive.async_setup", return_value=True
) as mock_setup, patch(
@ -67,11 +57,6 @@ 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
@ -96,16 +81,6 @@ 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=[
"mock-device-group-key",
"mock-device-key",
"mock-device-password",
],
), patch(
"homeassistant.components.hive.async_setup", return_value=True
) as mock_setup, patch(
@ -130,11 +105,6 @@ 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