@o-lukas/homebridge-smartthings-tv
Version:
This is a plugin for Homebridge. It offers some basic functions to control Samsung TVs using the SmartThings API.
41 lines • 1.79 kB
JavaScript
import { SmartThingsAccessory } from './smartThingsAccessory.js';
/**
* Class implements a switch accessory to execute a capability commmand and get capability status.
*/
export class SwitchAccessory extends SmartThingsAccessory {
capability;
command;
value;
stateful;
service;
constructor(device, component, client, log, platform, accessory, capability, command, value, stateful = false) {
super(device, component, client, platform, accessory, log);
this.capability = capability;
this.command = command;
this.value = value;
this.stateful = stateful;
this.service = this.accessory.getService(this.platform.Service.Switch) ??
this.accessory.addService(this.platform.Service.Switch);
this.service.getCharacteristic(this.platform.Characteristic.On)
.onGet(this.handleGet.bind(this))
.onSet(this.handleSet.bind(this));
}
async handleGet() {
if (!this.stateful) {
return false;
}
const status = await this.getCapabilityStatus(this.capability, true);
this.logDebug('Get %s mode: %s %s %s', this.capability, this.value, this.value === status?.inputSource.value ? '==' : '!=', status?.inputSource.value);
return status?.inputSource.value === this.value;
}
async handleSet(value) {
if (this.stateful || value === true) {
this.logDebug('Set %s mode to: %s', this.capability, this.value);
await this.executeCommand(this.capability, this.command, this.value ? [this.value] : []);
setTimeout(() => {
this.service.setCharacteristic(this.platform.Characteristic.On, false);
}, 500);
}
}
}
//# sourceMappingURL=switchAccessory.js.map