Change growatt server URL (#76824)

Co-authored-by: Chris Straffon <c.m.straffon@gmail.com>
This commit is contained in:
Dave Atherton 2022-08-19 10:51:27 +01:00 committed by GitHub
parent 90aba6c523
commit 324f5555ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -8,11 +8,15 @@ DEFAULT_PLANT_ID = "0"
DEFAULT_NAME = "Growatt" DEFAULT_NAME = "Growatt"
SERVER_URLS = [ SERVER_URLS = [
"https://server.growatt.com/", "https://server-api.growatt.com/",
"https://server-us.growatt.com/", "https://server-us.growatt.com/",
"http://server.smten.com/", "http://server.smten.com/",
] ]
DEPRECATED_URLS = [
"https://server.growatt.com/",
]
DEFAULT_URL = SERVER_URLS[0] DEFAULT_URL = SERVER_URLS[0]
DOMAIN = "growatt_server" DOMAIN = "growatt_server"

View File

@ -19,6 +19,7 @@ from .const import (
CONF_PLANT_ID, CONF_PLANT_ID,
DEFAULT_PLANT_ID, DEFAULT_PLANT_ID,
DEFAULT_URL, DEFAULT_URL,
DEPRECATED_URLS,
DOMAIN, DOMAIN,
LOGIN_INVALID_AUTH_CODE, LOGIN_INVALID_AUTH_CODE,
) )
@ -62,12 +63,23 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up the Growatt sensor.""" """Set up the Growatt sensor."""
config = config_entry.data config = {**config_entry.data}
username = config[CONF_USERNAME] username = config[CONF_USERNAME]
password = config[CONF_PASSWORD] password = config[CONF_PASSWORD]
url = config.get(CONF_URL, DEFAULT_URL) url = config.get(CONF_URL, DEFAULT_URL)
name = config[CONF_NAME] 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 = growattServer.GrowattApi()
api.server_url = url api.server_url = url