コード例 #1
0
    def __init__(self, remote_api, local_api=None):
        if not remote_api.validate_api():
            raise ha.HomeAssistantError(
                "Remote API at {}:{} not valid: {}".format(
                    remote_api.host, remote_api.port, remote_api.status))

        self.remote_api = remote_api
        self.local_api = local_api

        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 = []
コード例 #2
0
ファイル: remote.py プロジェクト: wdn/home-assistant
    def start(self):
        # Ensure a local API exists to connect with remote
        if self.config.api is None:
            bootstrap.setup_component(self, 'http')
            bootstrap.setup_component(self, 'api')

        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.config.api):
            raise ha.HomeAssistantError(
                ('Could not setup event forwarding from api {} to '
                 'local api {}').format(self.remote_api, self.config.api))
コード例 #3
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))