homebridge-philips-hue-sync-box
Version:
Homebridge plugin for the Philips Hue Sync Box.
68 lines • 2.75 kB
JavaScript
import { BaseTvDevice } from './baseTv.js';
export class IntensityTvDevice extends BaseTvDevice {
platform;
accessory;
state;
mainAccessory;
constructor(platform, accessory, state, mainAccessory) {
super(platform, accessory, state, mainAccessory);
this.platform = platform;
this.accessory = accessory;
this.state = state;
this.mainAccessory = mainAccessory;
this.service
.getCharacteristic(this.platform.api.hap.Characteristic.ActiveIdentifier)
.onSet((value) => {
const mode = this.getMode();
const intensity = this.numberToIntensity.get(value) ?? '';
this.platform.log.debug('Switch intensity to ' + intensity);
const body = {};
body[mode] = {
intensity,
};
this.updateExecution(body);
});
}
createInputServices() {
for (const [num, name] of this.numberToIntensity.entries()) {
const position = 'INTENSITY ' + num;
const intensityInputService = this.getInputService(name, position);
// Adds the input as a linked service, which is important so that the input is properly displayed in the Home app
this.service.addLinkedService(intensityInputService);
this.inputServices.push(intensityInputService);
}
this.service.setCharacteristic(this.platform.api.hap.Characteristic.SleepDiscoveryMode, this.platform.api.hap.Characteristic.SleepDiscoveryMode
.ALWAYS_DISCOVERABLE);
this.updateSources(this.inputServices);
}
updateTv() {
// Gets the current mode or the last sync mode to set the intensity
const mode = this.getMode();
if (!this.state.execution[mode]) {
this.platform.log.debug('Current mode ' + mode + ' does not have an intensity to update');
return;
}
// Updates the intensity input characteristic
this.platform.log.debug('Updated intensity to ' + this.state.execution[mode]?.intensity);
const brightness = this.intensityToNumber.get(this.state.execution[mode].intensity);
if (brightness) {
this.service.updateCharacteristic(this.platform.api.hap.Characteristic.ActiveIdentifier, brightness);
}
}
getSuffix() {
return '-I';
}
getServiceSubType() {
return 'IntensityTVAccessory';
}
getServiceName() {
return 'Intensity';
}
getConfiguredNamePropertyName() {
return 'intensityTvAccessoryConfiguredName';
}
isLightbulbEnabled() {
return this.platform.config.intensityTvAccessoryLightbulb;
}
}
//# sourceMappingURL=intensityTv.js.map