@homebridge-plugins/homebridge-smarthq
Version:
The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.
58 lines • 2.44 kB
JavaScript
import axios from 'axios';
import { interval, skipWhile } from 'rxjs';
import { ERD_TYPES } from '../settings.js';
import { deviceBase } from './device.js';
export class SmartHQDishWasher extends deviceBase {
platform;
device;
// Service
DishWasher;
// Updates
SensorUpdateInProgress;
deviceStatus;
constructor(platform, accessory, device) {
super(platform, accessory, device);
this.platform = platform;
this.device = device;
this.debugLog(`Dishwasher Features: ${JSON.stringify(accessory.context.device.features)}`);
accessory.context.device.features.forEach((feature) => {
switch (feature) {
case 'DISHWASHER_V1_FOUNDATION': {
const dishwasher = this.accessory.getService(accessory.displayName) ?? this.accessory.addService(this.platform.Service.Lightbulb, accessory.displayName, 'Dishwasher');
dishwasher
.getCharacteristic(this.platform.Characteristic.On)
.onGet(() => this.readErd(ERD_TYPES.DISHWASHER_CYCLE).then(r => Number.parseInt(r) !== 0))
.onSet(value => this.writeErd(ERD_TYPES.DISHWASHER_CYCLE, 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=dishwasher.js.map