Update API object to support SSL

This commit is contained in:
Paulus Schoutsen 2015-12-06 14:13:35 -08:00
parent f4238ca242
commit b33e9fe6d9
2 changed files with 7 additions and 3 deletions

View file

@ -76,7 +76,8 @@ def setup(hass, config):
threading.Thread(target=server.start, daemon=True).start())
hass.http = server
hass.config.api = rem.API(util.get_local_ip(), api_password, server_port)
hass.config.api = rem.API(util.get_local_ip(), api_password, server_port,
certificate is not None)
return True

View file

@ -51,11 +51,14 @@ class API(object):
""" Object to pass around Home Assistant API location and credentials. """
# pylint: disable=too-few-public-methods
def __init__(self, host, api_password=None, port=None):
def __init__(self, host, api_password=None, port=None, use_ssl=False):
self.host = host
self.port = port or SERVER_PORT
self.api_password = api_password
self.base_url = "http://{}:{}".format(host, self.port)
if use_ssl:
self.base_url = "https://{}:{}".format(host, self.port)
else:
self.base_url = "http://{}:{}".format(host, self.port)
self.status = None
self._headers = {}