コード例 #1
0
def setUpModule():   # pylint: disable=invalid-name
    """ Initalizes a Home Assistant server and Slave instance. """
    global hass, slave, master_api

    hass = ha.HomeAssistant()

    hass.bus.listen('test_event', lambda _: _)
    hass.states.set('test.test', 'a_state')

    http.setup(hass,
               {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD}})

    hass.start()

    master_api = remote.API("127.0.0.1", API_PASSWORD)

    # Start slave
    local_api = remote.API("127.0.0.1", API_PASSWORD, 8124)
    slave = remote.HomeAssistant(master_api, local_api)

    http.setup(slave,
               {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
                              http.CONF_SERVER_PORT: 8124}})

    slave.start()
コード例 #2
0
ファイル: remote.py プロジェクト: brad999/home-assistant
    def start(self):
        # If there is no local API setup but we do want to connect with remote
        # We create a random password and set up a local api
        if self.local_api is None:
            import homeassistant.components.http as http
            import random

            # pylint: disable=too-many-format-args
            random_password = '******'.format(random.randrange(16**30))

            http.setup(
                self, {http.DOMAIN: {
                    http.CONF_API_PASSWORD: random_password
                }})

        ha.Timer(self)

        self.bus.fire(ha.EVENT_HOMEASSISTANT_START,
                      origin=ha.EventOrigin.remote)

        # Setup that events from remote_api get forwarded to local_api
        # Do this after we fire START, otherwise HTTP is not started
        if not connect_remote_events(self.remote_api, self.local_api):
            raise ha.HomeAssistantError(
                ('Could not setup event forwarding from api {} to '
                 'local api {}').format(self.remote_api, self.local_api))
コード例 #3
0
 def test_setup(self):
     """ Test setup method of history. """
     http.setup(self.hass,
                {http.DOMAIN: {
                    http.CONF_SERVER_PORT: SERVER_PORT
                }})
     self.assertTrue(history.setup(self.hass, {}))
コード例 #4
0
def setUpModule():  # pylint: disable=invalid-name
    """ Initalizes a Home Assistant server and Slave instance. """
    global hass, slave, master_api, broken_api

    hass = ha.HomeAssistant()

    hass.bus.listen('test_event', lambda _: _)
    hass.states.set('test.test', 'a_state')

    http.setup(
        hass, {
            http.DOMAIN: {
                http.CONF_API_PASSWORD: API_PASSWORD,
                http.CONF_SERVER_PORT: 8122
            }
        })

    hass.start()

    master_api = remote.API("127.0.0.1", API_PASSWORD, 8122)

    # Start slave
    slave = remote.HomeAssistant(master_api)

    slave.start()

    # Setup API pointing at nothing
    broken_api = remote.API("127.0.0.1", "", 8125)
コード例 #5
0
 def test_setup(self):
     """ Test setup method. """
     try:
         hass = get_test_home_assistant()
         http.setup(hass, {
             http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
         self.assertTrue(logbook.setup(hass, {}))
     finally:
         hass.stop()
コード例 #6
0
 def test_setup(self):
     """ Test setup method. """
     try:
         hass = get_test_home_assistant()
         http.setup(hass,
                    {http.DOMAIN: {
                        http.CONF_SERVER_PORT: SERVER_PORT
                    }})
         self.assertTrue(logbook.setup(hass, {}))
     finally:
         hass.stop()
コード例 #7
0
def setUpModule():   # pylint: disable=invalid-name
    """ Initalizes a Home Assistant server. """
    global hass

    hass = ha.HomeAssistant()

    hass.bus.listen('test_event', lambda _: _)
    hass.states.set('test.test', 'a_state')

    http.setup(hass,
               {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
                              http.CONF_SERVER_PORT: SERVER_PORT}})

    hass.start()
コード例 #8
0
ファイル: remote.py プロジェクト: alexsahka/home-assistant
    def start(self):
        # If there is no local API setup but we do want to connect with remote
        # We create a random password and set up a local api
        if self.local_api is None:
            import homeassistant.components.http as http
            import random

            http.setup(self, '%030x'.format(random.randrange(16**30)))

        ha.Timer(self)

        # Setup that events from remote_api get forwarded to local_api
        connect_remote_events(self.remote_api, self.local_api)

        self.bus.fire(ha.EVENT_HOMEASSISTANT_START,
                      origin=ha.EventOrigin.remote)
コード例 #9
0
ファイル: test.py プロジェクト: JMSwag/home-assistant
def ensure_homeassistant_started():
    """ Ensures home assistant is started. """

    if not HAHelper.hass:
        hass = ha.HomeAssistant()

        hass.bus.listen('test_event', lambda _: _)
        hass.states.set('test.test', 'a_state')

        http.setup(hass,
                   {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD}})

        hass.start()

        HAHelper.hass = hass

    return HAHelper.hass
コード例 #10
0
def setUpModule():  # pylint: disable=invalid-name
    """ Initalizes a Home Assistant server. """
    global hass

    hass = ha.HomeAssistant()

    hass.bus.listen('test_event', lambda _: _)
    hass.states.set('test.test', 'a_state')

    http.setup(
        hass, {
            http.DOMAIN: {
                http.CONF_API_PASSWORD: API_PASSWORD,
                http.CONF_SERVER_PORT: SERVER_PORT
            }
        })

    hass.start()
コード例 #11
0
ファイル: test.py プロジェクト: alexsahka/home-assistant
def ensure_slave_started():
    """ Ensure a home assistant slave is started. """

    if not HAHelper.slave:
        local_api = remote.API("127.0.0.1", API_PASSWORD, 8124)
        remote_api = remote.API("127.0.0.1", API_PASSWORD)
        slave = remote.HomeAssistant(local_api, remote_api)

        http.setup(slave, API_PASSWORD, 8124)

        slave.start()

        # Give objects time to startup
        time.sleep(1)

        HAHelper.slave = slave

    return HAHelper.slave
コード例 #12
0
    def start(self):
        # Ensure a local API exists to connect with remote
        if self.local_api is None:
            import homeassistant.components.http as http

            http.setup(self)

        ha.Timer(self)

        self.bus.fire(ha.EVENT_HOMEASSISTANT_START,
                      origin=ha.EventOrigin.remote)

        # Setup that events from remote_api get forwarded to local_api
        # Do this after we fire START, otherwise HTTP is not started
        if not connect_remote_events(self.remote_api, self.local_api):
            raise ha.HomeAssistantError(
                ('Could not setup event forwarding from api {} to '
                 'local api {}').format(self.remote_api, self.local_api))
コード例 #13
0
ファイル: remote.py プロジェクト: snowshow/home-assistant
    def start(self):
        # If there is no local API setup but we do want to connect with remote
        # We create a random password and set up a local api
        if self.local_api is None:
            import homeassistant.components.http as http
            import random

            # pylint: disable=too-many-format-args
            random_password = '******'.format(random.randrange(16**30))

            http.setup(self, random_password)

        ha.Timer(self)

        # Setup that events from remote_api get forwarded to local_api
        connect_remote_events(self.remote_api, self.local_api)

        self.bus.fire(ha.EVENT_HOMEASSISTANT_START,
                      origin=ha.EventOrigin.remote)
コード例 #14
0
ファイル: test.py プロジェクト: alexsahka/home-assistant
def ensure_homeassistant_started():
    """ Ensures home assistant is started. """

    if not HAHelper.hass:
        hass = ha.HomeAssistant()

        hass.bus.listen('test_event', len)
        hass.states.set('test', 'a_state')

        http.setup(hass, API_PASSWORD)

        hass.start()

        # Give objects time to startup
        time.sleep(1)

        HAHelper.hass = hass

    return HAHelper.hass
コード例 #15
0
ファイル: test.py プロジェクト: JMSwag/home-assistant
def ensure_slave_started():
    """ Ensure a home assistant slave is started. """

    ensure_homeassistant_started()

    if not HAHelper.slave:
        local_api = remote.API("127.0.0.1", API_PASSWORD, 8124)
        remote_api = remote.API("127.0.0.1", API_PASSWORD)
        slave = remote.HomeAssistant(remote_api, local_api)

        http.setup(slave,
                   {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
                                  http.CONF_SERVER_PORT: 8124}})

        slave.start()

        HAHelper.slave = slave

    return HAHelper.slave
コード例 #16
0
def ensure_homeassistant_started():
    """ Ensures home assistant is started. """

    if not HAHelper.hass:
        hass = ha.HomeAssistant()

        hass.bus.listen('test_event', lambda _: _)
        hass.states.set('test.test', 'a_state')

        http.setup(hass,
                   {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD}})

        hass.start()

        # Give objects time to startup
        time.sleep(1)

        HAHelper.hass = hass

    return HAHelper.hass
コード例 #17
0
def ensure_slave_started():
    """ Ensure a home assistant slave is started. """

    ensure_homeassistant_started()

    if not HAHelper.slave:
        local_api = remote.API("127.0.0.1", API_PASSWORD, 8124)
        remote_api = remote.API("127.0.0.1", API_PASSWORD)
        slave = remote.HomeAssistant(remote_api, local_api)

        http.setup(slave,
                   {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
                                  http.CONF_SERVER_PORT: 8124}})

        slave.start()

        # Give objects time to startup
        time.sleep(1)

        HAHelper.slave = slave

    return HAHelper.slave
コード例 #18
0
    def start(self):
        # If there is no local API setup but we do want to connect with remote
        # We create a random password and set up a local api
        if self.local_api is None:
            import homeassistant.components.http as http
            import random

            # pylint: disable=too-many-format-args
            random_password = '******'.format(random.randrange(16**30))

            http.setup(
                self, {http.DOMAIN: {http.CONF_API_PASSWORD: random_password}})

        ha.Timer(self)

        self.bus.fire(ha.EVENT_HOMEASSISTANT_START,
                      origin=ha.EventOrigin.remote)

        # Setup that events from remote_api get forwarded to local_api
        # Do this after we fire START, otherwise HTTP is not started
        if not connect_remote_events(self.remote_api, self.local_api):
            raise ha.HomeAssistantError((
                'Could not setup event forwarding from api {} to '
                'local api {}').format(self.remote_api, self.local_api))
コード例 #19
0
 def test_setup(self):
     """ Test http.setup. """
     self.assertFalse(http.setup(hass, {}))
     self.assertFalse(http.setup(hass, {http.DOMAIN: {}}))
コード例 #20
0
 def test_setup(self):
     """ Test http.setup. """
     self.assertFalse(http.setup(hass, {}))
     self.assertFalse(http.setup(hass, {http.DOMAIN: {}}))
コード例 #21
0
 def test_setup(self):
     """ Test setup method of history. """
     http.setup(self.hass, {
         http.DOMAIN: {http.CONF_SERVER_PORT: SERVER_PORT}})
     self.assertTrue(history.setup(self.hass, {}))