From eba64f84ef387f5b30ea91353703f6e4f6f24ddf Mon Sep 17 00:00:00 2001 From: Chris Straffon Date: Fri, 30 Dec 2022 14:33:30 +0000 Subject: [PATCH] Fix growatt identification issue (#84628) Fixes https://github.com/home-assistant/core/issues/84600 fixes undefined --- homeassistant/components/growatt_server/config_flow.py | 6 +++++- homeassistant/components/growatt_server/sensor.py | 10 ++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/growatt_server/config_flow.py b/homeassistant/components/growatt_server/config_flow.py index 11f082f1eab..a4dcd25173f 100644 --- a/homeassistant/components/growatt_server/config_flow.py +++ b/homeassistant/components/growatt_server/config_flow.py @@ -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] diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index 57dd7f10fb1..1dea3b3510c 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -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)