Fixes for remote instances Home Assistant

pull/60/head
Paulus Schoutsen 2015-03-14 12:58:18 -07:00
parent cdeceb140d
commit 633d0453be
2 changed files with 14 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import logging
import json
import enum
import urllib.parse
import os
import requests
@ -49,13 +50,16 @@ 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, port=None):
def __init__(self, host, api_password=None, port=None):
self.host = host
self.port = port or SERVER_PORT
self.api_password = api_password
self.base_url = "http://{}:{}".format(host, self.port)
self.status = None
self._headers = {HTTP_HEADER_HA_AUTH: api_password}
self._headers = {}
if api_password is not None:
self._headers[HTTP_HEADER_HA_AUTH] = api_password
def validate_api(self, force_validate=False):
""" Tests if we can communicate with the API. """
@ -95,7 +99,7 @@ class API(object):
class HomeAssistant(ha.HomeAssistant):
""" Home Assistant that forwards work. """
# pylint: disable=super-init-not-called
# pylint: disable=super-init-not-called,too-many-instance-attributes
def __init__(self, remote_api, local_api=None):
if not remote_api.validate_api():
@ -106,13 +110,15 @@ class HomeAssistant(ha.HomeAssistant):
self.remote_api = remote_api
self.local_api = local_api
self._pool = pool = ha.create_worker_pool()
self.pool = pool = ha.create_worker_pool()
self.bus = EventBus(remote_api, pool)
self.services = ha.ServiceRegistry(self.bus, pool)
self.states = StateMachine(self.bus, self.remote_api)
self.components = []
self.config_dir = os.path.join(os.getcwd(), 'config')
def start(self):
# Ensure a local API exists to connect with remote
if self.local_api is None:
@ -142,9 +148,9 @@ class HomeAssistant(ha.HomeAssistant):
disconnect_remote_events(self.remote_api, self.local_api)
# Wait till all responses to homeassistant_stop are done
self._pool.block_till_done()
self.pool.block_till_done()
self._pool.stop()
self.pool.stop()
class EventBus(ha.EventBus):

View File

@ -208,7 +208,7 @@ class TestRemoteClasses(unittest.TestCase):
slave.states.set("remote.test", "remote.statemachine test")
# Wait till slave tells master
slave._pool.block_till_done()
slave.pool.block_till_done()
# Wait till master gives updated state
hass.pool.block_till_done()
@ -228,7 +228,7 @@ class TestRemoteClasses(unittest.TestCase):
slave.bus.fire("test.event_no_data")
# Wait till slave tells master
slave._pool.block_till_done()
slave.pool.block_till_done()
# Wait till master gives updated event
hass.pool.block_till_done()