How to use the home-assistant-js-websocket.ERR_HASS_HOST_REQUIRED function in home-assistant-js-websocket

To help you get started, we’ve selected a few home-assistant-js-websocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zachowj / node-red-contrib-home-assistant-websocket / lib / ha-websocket.js View on Github external
createSocket() {
        const self = this.self;

        if (!self.config.baseUrl) {
            throw homeassistant.ERR_HASS_HOST_REQUIRED;
        }

        // Convert from http:// -> ws://, https:// -> wss://
        const isHassio = self.config.baseUrl === 'http://hassio/homeassistant';
        const url = `ws${self.config.baseUrl.substr(4)}${
            isHassio ? '' : '/api'
        }/websocket`;

        const authObj = {
            type: 'auth'
        };

        authObj[self.config.legacy ? 'api_password' : 'access_token'] =
            self.config.apiPass;

        debug('[Auth Phase] Initializing', url);