From 2a530818dc10bd29e71ec363a77c657390885e7c Mon Sep 17 00:00:00 2001 From: ekutner <> Date: Sun, 4 Sep 2022 19:39:55 +0300 Subject: [PATCH] Add support for Home Connect Chinese server --- .devcontainer/config/configuration.yaml | 2 +- README.md | 2 ++ custom_components/home_connect_alt/__init__.py | 18 ++++++++---------- custom_components/home_connect_alt/const.py | 5 ++--- .../home_connect_alt/manifest.json | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.devcontainer/config/configuration.yaml b/.devcontainer/config/configuration.yaml index 449e24f..0fada74 100644 --- a/.devcontainer/config/configuration.yaml +++ b/.devcontainer/config/configuration.yaml @@ -32,9 +32,9 @@ home_connect_alt: client_id: !secret home_connect_client_id client_secret: !secret home_connect_client_secret # cache: false - # simulate: false language: en sensor_value_translation: local name_template: $appliance $name ($brand) log_mode: 5 + #api_host: https://simulator.home-connect.com diff --git a/README.md b/README.md index 3b292b0..b7e9dfa 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ home_connect_alt: name_template: $brand $appliance - $name language: < Supported langage code > sensor_value_translation: + api_host: ``` ## Parameters: * *client_id* (required) - The Client ID of your Home Connect app. @@ -87,6 +88,7 @@ home_connect_alt: When set to **"server"** sensor values are translated to friendly names using the Home Connect service. In this mode the internal values of string sensors will be translated and the translated values must be used in scripts referring to those sensors. **_Note:_** Select box values are always translated localy so they require the trsnalation files to contain all the possible values. +* *api_host* (optional) - If you are based in China, and only then, set this to *https://api.home-connect.cn* After the integration is configured READ THE FAQ then add it from the Home-Assistant UI. diff --git a/custom_components/home_connect_alt/__init__.py b/custom_components/home_connect_alt/__init__.py index 34fa103..338d48c 100644 --- a/custom_components/home_connect_alt/__init__.py +++ b/custom_components/home_connect_alt/__init__.py @@ -30,7 +30,7 @@ { vol.Required(CONF_CLIENT_ID): cv.string, vol.Required(CONF_CLIENT_SECRET): cv.string, - vol.Optional(CONF_SIMULATE, default=False): cv.boolean, + vol.Optional(CONF_API_HOST, default=None): vol.Any(str, None), vol.Optional(CONF_CACHE, default=True): cv.boolean, vol.Optional(CONF_LANG, default=None): vol.Any(str, None), vol.Optional(CONF_SENSORS_TRANSLATION, default=None): vol.Any(str, None), @@ -54,18 +54,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True conf = config[DOMAIN] - - simulate = conf[CONF_SIMULATE] + api_host = conf[CONF_API_HOST] if conf[CONF_API_HOST] else DEFAULT_API_HOST config_flow.OAuth2FlowHandler.async_register_implementation( hass, HomeConnectOauth2Impl( hass, DOMAIN, - config[DOMAIN][CONF_CLIENT_ID], - config[DOMAIN][CONF_CLIENT_SECRET], - f'{SIM_HOST if simulate else API_HOST}{ENDPOINT_AUTHORIZE}', - f'{SIM_HOST if simulate else API_HOST}{ENDPOINT_TOKEN}', + conf[CONF_CLIENT_ID], + conf[CONF_CLIENT_SECRET], + f'{api_host}{ENDPOINT_AUTHORIZE}', + f'{api_host}{ENDPOINT_TOKEN}', ) ) @@ -84,16 +83,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation) conf = hass.data[DOMAIN] - simulate = conf[CONF_SIMULATE] + api_host = conf[CONF_API_HOST] if conf[CONF_API_HOST] else DEFAULT_API_HOST lang = conf[CONF_LANG] # if conf[CONF_LANG] != "" else None - host = SIM_HOST if simulate else API_HOST use_cache = conf[CONF_CACHE] logmode = conf[CONF_LOG_MODE] if conf[CONF_LOG_MODE] else ConditionalLogger.LogMode.REQUESTS Configuration.set_global_config(conf) # If using an aiohttp-based API lib auth = api.AsyncConfigEntryAuth( - aiohttp_client.async_get_clientsession(hass), session, host + aiohttp_client.async_get_clientsession(hass), session, api_host ) # homeconnect:HomeConnect = None diff --git a/custom_components/home_connect_alt/const.py b/custom_components/home_connect_alt/const.py index e1eee30..dd2a6b3 100644 --- a/custom_components/home_connect_alt/const.py +++ b/custom_components/home_connect_alt/const.py @@ -2,12 +2,11 @@ DOMAIN = "home_connect_alt" -SIM_HOST = "https://simulator.home-connect.com" -API_HOST = "https://api.home-connect.com" +DEFAULT_API_HOST = "https://api.home-connect.com" ENDPOINT_AUTHORIZE = "/security/oauth/authorize" ENDPOINT_TOKEN = "/security/oauth/token" SCOPES = "IdentifyAppliance Monitor Control Settings" -CONF_SIMULATE = "simulate" +CONF_API_HOST = "api_host" CONF_LANG = "language" CONF_CACHE = "cache" CONF_SENSORS_TRANSLATION = "sensor_value_translation" diff --git a/custom_components/home_connect_alt/manifest.json b/custom_components/home_connect_alt/manifest.json index 5c8237e..e9d255e 100644 --- a/custom_components/home_connect_alt/manifest.json +++ b/custom_components/home_connect_alt/manifest.json @@ -1,7 +1,7 @@ { "domain": "home_connect_alt", "name": "Home Connect Alt", - "version": "0.5.6", + "version": "0.5.7", "config_flow": true, "documentation": "https://github.com/ekutner/home-connect-hass", "issue_tracker": "https://github.com/ekutner/home-connect-hass/issues",