From 324f5555ed6caa668111173ad81c50fb6f4f2e3a Mon Sep 17 00:00:00 2001 From: Dave Atherton Date: Fri, 19 Aug 2022 10:51:27 +0100 Subject: [PATCH] Change growatt server URL (#76824) Co-authored-by: Chris Straffon --- homeassistant/components/growatt_server/const.py | 6 +++++- homeassistant/components/growatt_server/sensor.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/growatt_server/const.py b/homeassistant/components/growatt_server/const.py index 4fcc4887843..4e548ef2c2a 100644 --- a/homeassistant/components/growatt_server/const.py +++ b/homeassistant/components/growatt_server/const.py @@ -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" diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index db045242987..c90bfa6f3fb 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -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