Skip to content

Commit

Permalink
Fix growatt identification issue (home-assistant#84628)
Browse files Browse the repository at this point in the history
Fixes home-assistant#84600
fixes undefined
  • Loading branch information
muppet3000 authored and frenck committed Dec 30, 2022
1 parent f05de2b commit 2cb7a80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/growatt_server/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -46,6 +46,10 @@ async def async_step_user(self, user_input=None):
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]
Expand Down
10 changes: 2 additions & 8 deletions homeassistant/components/growatt_server/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cb7a80

Please sign in to comment.