hue-emu
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

Logo

NPM version Downloads Dependency Status Known Vulnerabilities

NPM

hue-emu

Allows to simulate a hue bridge

Getting Started

The emulator does not force you to follow any structure regarding the data provided. It just helps you with the communication. Check out the examples to see how it works.

Create builder

You need to create an instance of HueUpnp and HueServer. To do that you first need to create a HueBuilder.

  • host: used by HueUpnp and HueServer
  • port: used by HueServer
  • discoveryHost: used by HueUpnp and HueServer. Name of the host the emulator will be discovered from other services
  • discoveryPort: used by HueUpnp and HueServer. Port the emulator will be discovered from other services
  • https: Configuration for https. Check util class for certificate generation
  • udn: used by HueUpnp and HueSever. Unique uuid is fine
  • mac: mac address. E.g. aa:aa:aa:aa:aa:aa
const hueBuilder = HueBuilder.builder()
  .withHost(host)
  .withPort(port)
  .withHttps(undefined)
  .withDiscoveryHost(host)
  .withDiscoveryPort(port)
  .withUdn(udn)
  .withMac(mac);

Create Server

const upnp = new HueUpnp(hueBuilder);
const server = new HueServer(hueBuilder, {
  onPairing(req: Request, devicetype: string, generateclientkey?: boolean): Observable<string> {
    if (pairingEnabled) {
      // Do something awesome
      return of(username);
    } else {
      return throwError(HueError.LINK_BUTTON_NOT_PRESSED);
    }
  },
  onLights(req: Request, username: string): Observable<any> {
    // Return all lights
    return of({
      "1": {
        // ...
      },
    });
  },
  onLight(req: Request, username: string, lightId: string): Observable<any> {
    // Return a specific light
    return of({
      // ...
    });
  },
  onLightsState(req: Request, username: string, lightId: string, key: string, value: any): Observable<any> {
    // Change state.key of your fake light to the value specified
    // Return the changed light (just for logging)
    return of({
      // ...
    });
  },
});

Examples

You can find an example in test directory. Npm arguments must be set manually.

Package Sidebar

Install

npm i hue-emu

Weekly Downloads

0

Version

0.2.3

License

MIT

Unpacked Size

333 kB

Total Files

91

Last publish

Collaborators

  • holomekc