UNPKG

@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.

62 lines 3.05 kB
import { SmartThingsAccessory } from './smartThingsAccessory.js'; /** * Class implements a slider accessory to execute a capability commmand. */ export class SliderAccessory extends SmartThingsAccessory { capability; command; onGet; onSet; pollingInterval; cyclicCallsLogging; service; // stores the last value before the off functionality has been used // so this value can be restored when turning back on lastValueBeforeOff = 0; constructor(device, component, client, log, platform, accessory, capability, command, onGet, onSet, pollingInterval, cyclicCallsLogging) { super(device, component, client, platform, accessory, log); this.capability = capability; this.command = command; this.onGet = onGet; this.onSet = onSet; this.pollingInterval = pollingInterval; this.cyclicCallsLogging = cyclicCallsLogging; this.service = this.accessory.getService(this.platform.Service.Lightbulb) ?? this.accessory.addService(this.platform.Service.Lightbulb); this.service.getCharacteristic(this.platform.Characteristic.On) .onGet(this.handleGetOn.bind(this)) .onSet(this.handleSetOn.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.Brightness) .onGet(this.handleGetBrightness.bind(this)) .onSet(this.handleSetBrightness.bind(this)); this.startStatusPolling(this.capability + '_on', this.service, this.platform.Characteristic.On, this.handleGetOn.bind(this, this.cyclicCallsLogging), this.pollingInterval); this.startStatusPolling(this.capability + '_brightness', this.service, this.platform.Characteristic.Brightness, this.handleGetBrightness.bind(this, this.cyclicCallsLogging), this.pollingInterval); } async handleGetOn(log = true) { return await this.handleGetBrightness(log) > 0; } async handleSetOn(value) { if (value) { this.logDebug('Turning back on - set %s to: %s', this.capability, this.lastValueBeforeOff); await this.executeCommand(this.capability, this.command, [this.lastValueBeforeOff]); } else { this.lastValueBeforeOff = await this.handleGetBrightness(); this.logDebug('Turning off - saving %s last value %s and setting value to: %s', this.capability, this.lastValueBeforeOff, 0); await this.executeCommand(this.capability, this.command, [0]); } } async handleGetBrightness(log = true) { const apiValue = this.onGet(await this.getCapabilityStatus(this.capability, log)); if (log) { this.logDebug('Get %s value: %s', this.capability, apiValue); } return apiValue; } async handleSetBrightness(value) { const apiValue = this.onSet(value); this.logDebug('Set %s to: %s', this.capability, apiValue); await this.executeCommand(this.capability, this.command, apiValue); } } //# sourceMappingURL=sliderAccessory.js.map