Change growatt server URL (#76824)
Co-authored-by: Chris Straffon <c.m.straffon@gmail.com>
This commit is contained in:
parent
90aba6c523
commit
324f5555ed
2 changed files with 18 additions and 2 deletions
|
@ -8,11 +8,15 @@ DEFAULT_PLANT_ID = "0"
|
|||
DEFAULT_NAME = "Growatt"
|
||||
|
||||
SERVER_URLS = [
|
||||
"https://server.growatt.com/",
|
||||
"https://server-api.growatt.com/",
|
||||
"https://server-us.growatt.com/",
|
||||
"http://server.smten.com/",
|
||||
]
|
||||
|
||||
DEPRECATED_URLS = [
|
||||
"https://server.growatt.com/",
|
||||
]
|
||||
|
||||
DEFAULT_URL = SERVER_URLS[0]
|
||||
|
||||
DOMAIN = "growatt_server"
|
||||
|
|
|
@ -19,6 +19,7 @@ from .const import (
|
|||
CONF_PLANT_ID,
|
||||
DEFAULT_PLANT_ID,
|
||||
DEFAULT_URL,
|
||||
DEPRECATED_URLS,
|
||||
DOMAIN,
|
||||
LOGIN_INVALID_AUTH_CODE,
|
||||
)
|
||||
|
@ -62,12 +63,23 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Growatt sensor."""
|
||||
config = config_entry.data
|
||||
config = {**config_entry.data}
|
||||
username = config[CONF_USERNAME]
|
||||
password = config[CONF_PASSWORD]
|
||||
url = config.get(CONF_URL, DEFAULT_URL)
|
||||
name = config[CONF_NAME]
|
||||
|
||||
# If the URL has been deprecated then change to the default instead
|
||||
if url in DEPRECATED_URLS:
|
||||
_LOGGER.info(
|
||||
"URL: %s has been deprecated, migrating to the latest default: %s",
|
||||
url,
|
||||
DEFAULT_URL,
|
||||
)
|
||||
url = DEFAULT_URL
|
||||
config[CONF_URL] = url
|
||||
hass.config_entries.async_update_entry(config_entry, data=config)
|
||||
|
||||
api = growattServer.GrowattApi()
|
||||
api.server_url = url
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue