Skip to content

Commit

Permalink
Add support for Home Connect Chinese server
Browse files Browse the repository at this point in the history
  • Loading branch information
ekutner committed Sep 4, 2022
1 parent a49ce23 commit 2a53081
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ home_connect_alt:
name_template: $brand $appliance - $name
language: < Supported langage code >
sensor_value_translation: <server | local>
api_host: <Home Connect API host name (only use for China)>
```
## Parameters:
* *client_id* (required) - The Client ID of your Home Connect app.
Expand All @@ -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.

Expand Down
18 changes: 8 additions & 10 deletions custom_components/home_connect_alt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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}',
)
)

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions custom_components/home_connect_alt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/home_connect_alt/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 2a53081

Please sign in to comment.