UNPKG

homebridge-plugin-waveshare-relay

Version:

Homebridge plugin exposing Waveshare Raspberry Pi Relay Board as a series of switches

34 lines 1.22 kB
export class WaveshareRelayApi { url; constructor(url) { this.url = url; } async setRelay(id, state, log) { log.debug(`setRelay ${this.url}#${id} ${state}`); const result = await fetch(`${this.url}/${id}/${state ? 'on' : 'off'}`, { method: 'POST' }); const json = (await result.json()); json.url = this.url; log.debug(`setRelay result ${result.status}`, json); return json; } async getRelay(id, log) { log.debug(`getRelay ${this.url}#${id}`); const result = await fetch(`${this.url}/${id}`, { method: 'GET' }); const json = (await result.json()); json.url = this.url; log.debug(`getRelay result ${result.status}`, json); return json; } async getRelays(log) { log.debug(`getRelays`); const result = await fetch(`${this.url}`, { method: 'GET' }); const json = (await result.json()); json.forEach((relay) => (relay.url = this.url)); log.debug(`getRelays result ${result.status}`, json); return json; } static buildRelayGuid(relay) { return `${relay.url}#${relay.id}`; } } //# sourceMappingURL=waveshare-relay-api.js.map