Skip to content

Commit

Permalink
add configuration option for local api_host
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisisnate committed Jun 9, 2018
1 parent bc0d075 commit c2b7e10
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions homeassistant/components/konnected.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DOMAIN = 'konnected'

CONF_ACTIVATION = 'activation'
CONF_API_HOST = 'api_host'
STATE_LOW = 'low'
STATE_HIGH = 'high'

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
)


Expand Down

0 comments on commit c2b7e10

Please sign in to comment.