@homebridge-plugins/homebridge-smarthq
Version:
The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.
42 lines • 1.56 kB
JavaScript
import axios from 'axios';
export class OpalDeviceBase {
platform;
accessory;
device;
hkcControllerNotificationsSecret;
constructor(platform, accessory, device) {
this.platform = platform;
this.accessory = accessory;
this.device = device;
this.hkcControllerNotificationsSecret = this.platform.config.options?.homekitControllerNotificationsSecret;
}
// Shared utility methods
async readErd(erd) {
const d = await axios
.get(`/appliance/${this.accessory.context.device.applianceId}/erd/${erd}`);
return String(d.data.value);
}
async writeErd(erd, value) {
await axios
.post(`/appliance/${this.accessory.context.device.applianceId}/erd/${erd}`, {
kind: 'appliance#erdListEntry',
userId: this.accessory.context.userId,
applianceId: this.accessory.context.device.applianceId,
erd,
value: typeof value === 'boolean' ? (value ? '01' : '00') : value,
});
return undefined;
}
async sendHomeKitControllerNotification(hkcNotificationPath) {
if (this.hkcControllerNotificationsSecret) {
try {
await axios.get(`https://api.controllerforhomekit.com/notify/${this.hkcControllerNotificationsSecret}/${hkcNotificationPath}`);
}
catch (err) {
const typedErr = err;
this.platform.debugLog(typedErr.message);
}
}
}
}
//# sourceMappingURL=OpalDeviceBase.js.map