@homebridge-plugins/homebridge-smarthq
Version:
The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.
59 lines • 2.48 kB
JavaScript
import axios from 'axios';
import { interval, skipWhile } from 'rxjs';
import { ERD_TYPES } from '../settings.js';
import { deviceBase } from './device.js';
export class SmartHQRefrigerator extends deviceBase {
platform;
device;
// Updates
SensorUpdateInProgress;
deviceStatus;
constructor(platform, accessory, device) {
super(platform, accessory, device);
this.platform = platform;
this.device = device;
this.debugLog(`Refrigerator Features: ${JSON.stringify(accessory.context.device.features)}`);
accessory.context.device.features.forEach((feature) => {
/* [
"DOOR_STATUS"
] */
switch (feature) {
case 'DOOR_STATUS': {
const refrigerator = this.accessory.getService(accessory.displayName) ?? this.accessory.addService(this.platform.Service.ContactSensor, accessory.displayName, 'Refrigerator');
refrigerator
.getCharacteristic(this.platform.Characteristic.ContactSensorState)
.onGet(() => this.readErd(ERD_TYPES.DOOR_STATUS).then(r => Number.parseInt(r) !== 0))
.onSet(value => this.writeErd(ERD_TYPES.DOOR_STATUS, value));
break;
}
}
});
// this is subject we use to track when we need to POST changes to the SmartHQ API
this.SensorUpdateInProgress = false;
// Retrieve initial values and updateHomekit
// this.refreshStatus()
// Start an update interval
interval(this.deviceRefreshRate * 10000)
.pipe(skipWhile(() => this.SensorUpdateInProgress))
.subscribe(async () => {
// await this.refreshStatus()
});
}
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;
}
}
//# sourceMappingURL=refrigerator.js.map