1.5.2 • Published 12 months ago

@estanalytical/vasconnect v1.5.2

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

VASConnect

Installation

Using npm:

npm install @estanalytical/vasconnect

In your code:

import VASConnect from '@estanalytical/vasconnect';

const vas = new VASConnect({
  appId: "<app id>",
  licenseType: "<license type>",
  licenseToken: "<license token>",
  authorizeAutomatically: true
});

// Listen to connection status changes between the browser and VASConnect.exe
vas.onConnectionStatusChange((status, oldStatus) => {
  switch (status) {
    case "error": // An error has occurred when trying to connect to VASConnect
      break;
    case "disconnected": // VASConnect is not running.
      break;
    case "unauthorized": // VASConnect is running, but this app is not authorized to use it.
      break;
    case "authorizing": // VASConnect is showing the user the authorization dialog.
      break;
    case "authorized": // VASConnect is ready to use, but the websocket connection is not active.
      break;
    case "websocket": // VASConnect is ready, and the websocket connection is active. Success!
      break;
  }
})

// The welcome message is received once right after the websocket connection is established.
// It contains information about all connected devices and it's a good place to set initial values.
vas.onWelcome((e) => {
  const devices = e.connectedDevices;

  // Zero all the setpoints and set an initial fan speed.
  devices.forEach((device) => {
    vas.updateDevice(device.id, {
      setpoints: [0],
      fanSpeed: 8,
    });
  })
})

// This event is fired whenever a device connects to VASConnect.
vas.onDeviceConnected((e) => {
  console.log(`Device connected: id=${e.device.id}`);
  vas.updateDevice(e.device.id, {
    setpoints: [0],
    fanSpeed: 8,
  });
})

// This event is fired whenever a device disconnects from VASConnect.
vas.onDeviceDisconnected((e) => {
  console.log(`Device disconnected: id=${e.device.id}`);
})

// This event is fired whenever new information is available for a device, such a change in setpoints,
// measured flows, or fan speed. This could be caused by VASConnect's constant polling of the device,
// or a change made by this app or another app.
vas.onDeviceUpdated((e) => {
  // IMPORTANT: This event is fired whenever this app updates a device. This means that if you
  // update a device in response to this event, you will cause an infinite loop. To avoid this,
  // you can check the "causedByThisApp" property of the event.
  if (e.causedByThisApp) {
    return;
  }

  // You can also check if this event was caused by another app or by VASConnect itself.
  // e.causedByVASConnect
  // e.causedByAnotherApp

  // Get details about the device that was updated
  const device = e.device;
  const setpoints = device.setpoints;
  const flows = device.flows;
  const fanSpeed = device.fanSpeed;
})

Note: You must have a license to use this package. If you have already been invited, you can view your license information in GLS.

Support

Tested on Chrome 113.

This library is maintained by EST Analytical. Please email jkrusling@estanalytical.com with any bug reports or feedback.

1.5.2

12 months ago

1.5.1

12 months ago

1.5.0

1 year ago

1.4.9

1 year ago

1.4.8

1 year ago

1.4.7

1 year ago

1.4.6

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago