How to use the home-assistant-js-websocket.callService 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 timmo001 / home-panel / src / Components / HomeAssistant / HomeAssistant.tsx View on Github external
entities[data.entity_id].attributes.entity_id.map((entity: string) =>
        callService(
          connection,
          entity.split('.')[0],
          state ? 'turn_on' : 'turn_off',
          { entity_id: entity }
        ).then(
          () => {},
          err => {
            console.error('Error calling service:', err);
          }
        )
      );
github timmo001 / home-panel / src / Components / HomeAssistant / HomeAssistant.tsx View on Github external
export function handleChange(
  domain: string,
  state: string | boolean,
  data?: any,
  entities?: HassEntities
) {
  process.env.NODE_ENV === 'development' &&
    console.log('handleChange:', domain, state, data);
  if (typeof state === 'string') {
    callService(connection, domain, state, data).then(
      () => {},
      err => {
        console.error('Error calling service:', err);
      }
    );
  } else {
    if (domain === 'group' && entities) {
      entities[data.entity_id].attributes.entity_id.map((entity: string) =>
        callService(
          connection,
          entity.split('.')[0],
          state ? 'turn_on' : 'turn_off',
          { entity_id: entity }
        ).then(
          () => {},
          err => {
github timmo001 / home-panel / src / Components / HomeAssistant / HomeAssistant.tsx View on Github external
if (domain === 'group' && entities) {
      entities[data.entity_id].attributes.entity_id.map((entity: string) =>
        callService(
          connection,
          entity.split('.')[0],
          state ? 'turn_on' : 'turn_off',
          { entity_id: entity }
        ).then(
          () => {},
          err => {
            console.error('Error calling service:', err);
          }
        )
      );
    } else
      callService(
        connection,
        domain,
        state ? 'turn_on' : 'turn_off',
        data
      ).then(
        () => {},
        err => {
          console.error('Error calling service:', err);
        }
      );
  }
}
github timmo001 / home-panel / src / Components / Root.js View on Github external
console.log('handleChange:', domain, state, data);
    if (typeof state === 'string') {
      callService(connection, domain, state, data).then(
        () => {
          this.setState({ snackMessage: { open: true, text: 'Changed.' } });
        },
        err => {
          console.error('Error calling service:', err);
          this.setState({
            snackMessage: { open: true, text: 'Error calling service' },
            entities: undefined
          });
        }
      );
    } else {
      callService(
        connection,
        domain,
        state ? 'turn_on' : 'turn_off',
        data
      ).then(
        () => {
          this.setState({ snackMessage: { open: true, text: 'Changed.' } });
        },
        err => {
          console.error('Error calling service:', err);
          this.setState({
            snackMessage: { open: true, text: 'Error calling service' },
            entities: undefined
          });
        }
      );
github timmo001 / home-panel / src / Components / Root.js View on Github external
handleChange = (domain, state, data = undefined) => {
    process.env.NODE_ENV === 'development' &&
      console.log('handleChange:', domain, state, data);
    if (typeof state === 'string') {
      callService(connection, domain, state, data).then(
        () => {
          this.setState({ snackMessage: { open: true, text: 'Changed.' } });
        },
        err => {
          console.error('Error calling service:', err);
          this.setState({
            snackMessage: { open: true, text: 'Error calling service' },
            entities: undefined
          });
        }
      );
    } else {
      callService(
        connection,
        domain,
        state ? 'turn_on' : 'turn_off',
github zachowj / node-red-contrib-home-assistant-websocket / lib / ha-websocket.js View on Github external
async callService(domain, service, data) {
        const result = homeassistant.callService(
            this.client,
            domain,
            service,
            data
        );

        return result;
    }
github stanford-oval / thingpedia-common-devices / io.home-assistant / base.js View on Github external
_callService(domain, service, data = {}) {
        data.entity_id = this._entityId;
        return HomeAssistant.callService(this.master.connection, domain, service, data);
    }