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()
Exemple #2
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))
 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, {}))
Exemple #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)
 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()
 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()
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()
Exemple #8
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

            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)
Exemple #9
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()

        HAHelper.hass = hass

    return HAHelper.hass
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()
Exemple #11
0
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
Exemple #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))
Exemple #13
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, 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)
Exemple #14
0
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
Exemple #15
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()

        HAHelper.slave = slave

    return HAHelper.slave
Exemple #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
Exemple #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
    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))
 def test_setup(self):
     """ Test http.setup. """
     self.assertFalse(http.setup(hass, {}))
     self.assertFalse(http.setup(hass, {http.DOMAIN: {}}))
 def test_setup(self):
     """ Test http.setup. """
     self.assertFalse(http.setup(hass, {}))
     self.assertFalse(http.setup(hass, {http.DOMAIN: {}}))
 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, {}))