diff --git a/homeassistant/components/konnected.py b/homeassistant/components/konnected.py index 70b66f84ae95f5..c0626a1b16f62d 100644 --- a/homeassistant/components/konnected.py +++ b/homeassistant/components/konnected.py @@ -31,6 +31,7 @@ DOMAIN = 'konnected' CONF_ACTIVATION = 'activation' +CONF_API_HOST = 'api_host' STATE_LOW = 'low' STATE_HIGH = 'high' @@ -60,6 +61,7 @@ { DOMAIN: vol.Schema({ vol.Required(CONF_ACCESS_TOKEN): cv.string, + vol.Optional(CONF_API_HOST): vol.Url(), vol.Required(CONF_DEVICES): [{ vol.Required(CONF_ID): cv.string, vol.Optional(CONF_BINARY_SENSORS): vol.All( @@ -87,7 +89,10 @@ async def async_setup(hass, config): access_token = cfg.get(CONF_ACCESS_TOKEN) if DOMAIN not in hass.data: - hass.data[DOMAIN] = {CONF_ACCESS_TOKEN: access_token} + hass.data[DOMAIN] = { + CONF_ACCESS_TOKEN: access_token, + CONF_API_HOST: cfg.get(CONF_API_HOST) + } def device_discovered(service, info): """Call when a Konnected device has been discovered.""" @@ -254,14 +259,26 @@ def sync_device_config(self): _LOGGER.debug('%s: current actuator config: %s', self.device_id, current_actuator_config) + desired_api_host = \ + self.hass.data[DOMAIN].get(CONF_API_HOST) or \ + self.hass.config.api.base_url + desired_api_endpoint = desired_api_host + ENDPOINT_ROOT + current_api_endpoint = self.status.get('endpoint') + + _LOGGER.debug('%s: desired api endpoint: %s', self.device_id, + desired_api_endpoint) + _LOGGER.debug('%s: current api endpoint: %s', self.device_id, + current_api_endpoint) + if (desired_sensor_configuration != current_sensor_configuration) or \ - (current_actuator_config != desired_actuator_config): + (current_actuator_config != desired_actuator_config) or \ + (current_api_endpoint != desired_api_endpoint): _LOGGER.debug('pushing settings to device %s', self.device_id) self.client.put_settings( desired_sensor_configuration, desired_actuator_config, self.hass.data[DOMAIN].get(CONF_ACCESS_TOKEN), - self.hass.config.api.base_url + ENDPOINT_ROOT + desired_api_endpoint )