Fix growatt identification issue (#84628)

Fixes https://github.com/home-assistant/core/issues/84600
fixes undefined
This commit is contained in:
Chris Straffon 2022-12-30 14:33:30 +00:00 committed by GitHub
parent a9be2adf06
commit eba64f84ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -22,7 +22,7 @@ class GrowattServerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
def __init__(self):
"""Initialise growatt server flow."""
self.api = growattServer.GrowattApi()
self.api = None
self.user_id = None
self.data = {}
@ -46,6 +46,10 @@ class GrowattServerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if not user_input:
return self._async_show_user_form()
# Initialise the library with the username & a random id each time it is started
self.api = growattServer.GrowattApi(
add_random_user_id=True, agent_identifier=user_input[CONF_USERNAME]
)
self.api.server_url = user_input[CONF_URL]
login_response = await self.hass.async_add_executor_job(
self.api.login, user_input[CONF_USERNAME], user_input[CONF_PASSWORD]

View File

@ -80,14 +80,8 @@ async def async_setup_entry(
config[CONF_URL] = url
hass.config_entries.async_update_entry(config_entry, data=config)
# Initialise the library with a random user id each time it is started,
# also extend the library's default identifier to include 'home-assistant'
api = growattServer.GrowattApi(
add_random_user_id=True,
agent_identifier=(
f"{growattServer.GrowattApi.agent_identifier} - home-assistant"
),
)
# Initialise the library with the username & a random id each time it is started
api = growattServer.GrowattApi(add_random_user_id=True, agent_identifier=username)
api.server_url = url
devices, plant_id = await hass.async_add_executor_job(get_device_list, api, config)