homebridge-dune-hd
Version:
Homebridge Plugin to control your Dune HD.
832 lines (817 loc) • 160 kB
JavaScript
"use strict";
const PLATFORM_NAME = 'duneHDPlugin';
const PLUGIN_NAME = 'homebridge-dune-hd';
const request = require('http');
const udp = require('dgram');
module.exports = (api) => {
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, duneHDPlatform, true);
};
//// Platform/////////////////////////////////////////////////////////////////////////////////////////////////
class duneHDPlatform {
constructor(log, config, api) {
this.log = log;
this.config = config;
this.api = api;
this.Service = this.api.hap.Service;
this.Characteristic = this.api.hap.Characteristic;
this.config.name = this.config.name || 'Dune HD';
this.config.newPlatformUUID = this.config.newPlatformUUID || false;
// this is used to track restored cached accessories
this.accessories = [];
this.log.debug('Finished initializing platform:', this.config.name);
this.api.on('didFinishLaunching', () => {
log.debug('didFinishLaunching callback');
this.iniDevice();
});
}
configureAccessory(accessory) {
this.log.info('Loading accessory from cache:', accessory.displayName);
this.accessories.push(accessory);
}
removeAccessory(accessory) {
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
}
iniDevice() {
if (this.config.newPlatformUUID === false) {
this.duneHDDevice =
{
duneHDUniqueId: 'nicocatagameztanarro',
duneHDDisplayName: `${this.config.name}`
};
}
if (this.config.newPlatformUUID === true) {
this.duneHDDevice =
{
duneHDUniqueId: `${this.config.name}catanico`,
duneHDDisplayName: `${this.config.name}`
};
this.log.debug('Generationg a new UUID');
}
const uuid = this.api.hap.uuid.generate(this.duneHDDevice.duneHDUniqueId);
this.log.debug('Adding new accessory:', this.duneHDDevice.duneHDDisplayName);
const accessory = new this.api.platformAccessory(this.duneHDDevice.duneHDDisplayName, uuid);
accessory.category = this.api.hap.Accessory.Categories.TV_SET_TOP_BOX;
accessory.context.device = this.duneHDDevice;
new duneHDAccessory(this, accessory);
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
}
}
class duneHDAccessory {
constructor(platform, accessory) {
this.platform = platform;
this.accessory = accessory;
this.config = platform.config;
this.DUNEHD_IP = this.config.ip;
this.DUNEHD_PORT = this.config.port || 80;
this.statelessTimeOut = 1000;
this.turnOffCommand = false;
this.turnOnCommand = false;
//////Initial Switch and sensors state///////////////////////////////////////////////////////////////////////////////////////////////
this.powerState = false;
this.playBackState = [false, false, false];
this.powerStateTV = 0;
this.currentVolume = 0;
this.currentMuteState = true;
this.currentVolumeSwitch = false;
this.inputID = 1;
this.mediaState = 4;
this.videoState = false;
this.audioState = false;
this.chapterTime = '';
this.inputName = 'Media Name';
this.mediaDuration = 'Runtime';
this.mediaInformation = 'Video Information';
this.mediaChapter = 'Current Chapter';
this.mediaAudioFormat = 'Audio Format';
this.language = 'Audio Language';
this.subtitleLanguage = '';
this.showState = false;
this.httpNotResponding = 0;
this.turnOffAllUsed = false;
this.counter = 0;
/////MovieConstants
this.currentMovieProgress = 0;
this.currentMovieProgressState = false;
this.movieElapsed = 0;
this.currentMoviePosition = 0;
this.movieRemaining = 0;
this.bluryaDVD = false;
////Connection parameters
this.reconnectionTry = 10;
//Device Information//////////////////////////////////////////////////////////////////////////////////////
this.config.name = platform.config.name || 'Dune HD';
this.config.ip = platform.config.ip;
this.config.manufacturer = platform.config.manufacturer || 'Dune HD';
this.config.pollingInterval = platform.config.pollingInterval || 1000;
this.config.modelName = platform.config.modelName || 'Real Vision 4K';
this.config.serialN = platform.config.serialN || 'B210U71647033894';
this.config.mediaButtons = platform.config.mediaButtons || false;
this.config.volume = platform.config.volume || false;
this.config.cursorUpB = platform.config.cursorUpB || false;
this.config.cursorDownB = platform.config.cursorDownB || false;
this.config.cursorLeftB = platform.config.cursorLeftB || false;
this.config.cursorRightB = platform.config.cursorRightB || false;
this.config.cursorEnterB = platform.config.cursorEnterB || false;
this.config.searchB = platform.config.searchB || false;
this.config.backButtonB = platform.config.backButtonB || false;
this.config.infoB = platform.config.infoB || false;
this.config.pageUpB = platform.config.pageUpB || false;
this.config.pageDownB = platform.config.pageDownB || false;
this.config.popUpMenuB = platform.config.popUpMenuB || false;
this.config.redB = platform.config.redB || false;
this.config.yellowB = platform.config.yellowB || false;
this.config.blueB = platform.config.blueB || false;
this.config.audioB = platform.config.audioB || false;
this.config.greenB = platform.config.greenB || false;
this.config.subtitleB = platform.config.subtitleB || false;
this.config.repeatB = platform.config.repeatB || false;
this.config.pipB = platform.config.pipB || false;
this.config.selectB = platform.config.selectB || false;
this.config.movieControl = platform.config.movieControl || false;
this.config.powerB = platform.config.powerB || false;
this.config.muteB = platform.config.muteB || false;
this.config.recordB = platform.config.recordB || false;
this.config.movieB = platform.config.movieB || false;
this.config.musicB = platform.config.musicB || false;
this.config.tvB = platform.config.tvB || false;
this.config.ejectB = platform.config.ejectB || false;
this.config.modeB = platform.config.modeB || false;
this.config.slowB = platform.config.slowB || false;
this.config.mouseB = platform.config.mouseB || false;
this.config.clearB = platform.config.clearB || false;
this.config.zoomB = platform.config.zoomB || false;
this.config.setupB = platform.config.setupB || false;
this.config.topMenuB = platform.config.topMenuB || false;
this.config.angleB = platform.config.angleB || false;
this.config.recentB = platform.config.recentB || false;
this.config.changeDimmersToFan = platform.config.changeDimmersToFan || false;
this.config.remainMovieTimer = platform.config.remainMovieTimer || false;
this.config.infoToMenu = platform.config.infoToMenu || false;
////Checking if the necessary information was given by the user////////////////////////////////////////////////////
try {
if (!this.config.ip) {
throw new Error(`Dune HD IP address is required for ${this.config.name}`);
}
} catch (error) {
this.platform.log(error);
this.platform.log('Failed to create platform device, missing mandatory information!');
this.platform.log('Please check your device config!');
return;
}
////////////Get Model/////////////////////
this.accessory.getService(this.platform.Service.AccessoryInformation)
.setCharacteristic(this.platform.Characteristic.Manufacturer, this.config.manufacturer)
.setCharacteristic(this.platform.Characteristic.Model, this.config.modelName)
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.config.serialN);
// set accessory information//////////////////////////////////////////////////////////////////////////////////////////
/////////Television Controls///////////////////////////////////////////////////////////////////////////////////////////
// add the tv service
this.tvService = this.accessory.getService(this.config.name) ||
this.accessory.addService(this.platform.Service.Television, this.config.name, 'CataNicoGaTa-7');
this.tvService.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.config.name);
this.tvService.setCharacteristic(this.platform
.Characteristic.SleepDiscoveryMode, this.platform.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
this.tvService.getCharacteristic(this.platform.Characteristic.Active)
.on('set', (newValue, callback) => {
this.platform.log.debug('Set Dune HD Active to: ' + newValue);
if (newValue === 1) {
this.newPowerState(true);
this.turnOnCommand = true;
this.turnOffCommand = false;
this.sending([this.pressedButton('POWER ON')]);
// this.WakeupOnLAN();
// this.sending([this.pressedButton('POWER ON')]);
}
else {
this.sending([this.pressedButton('STOP')]);
this.newPowerState(false);
this.turnOffAll();
this.turnOffCommand = true;
this.turnOnCommand = false;
// this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=standby&result_syntax=json"]);
setTimeout(() => {
this.sending([this.pressedButton('POWER OFF')]);
}, 1000);
}
callback(null);
})
.on('get', (callback) => {
let currentValue = this.powerStateTV;
callback(null, currentValue);
});
this.tvService.getCharacteristic(this.platform.Characteristic.ClosedCaptions)
.on('get', (callback) => {
this.platform.log.debug('Subtitle GET On');
let currentValue = 0;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Subtitle SET On:', value);
if (value === 1) {
this.sending([this.pressedButton('SUBTITLE')]);
}
this.tvService.updateCharacteristic(this.platform.Characteristic.ClosedCaptions, 0);
callback(null);
});
this.tvService.getCharacteristic(this.platform.Characteristic.RemoteKey)
.on('set', (newValue, callback) => {
switch (newValue) {
case this.platform.Characteristic.RemoteKey.REWIND: {
this.platform.log.debug('set Remote Key Pressed: REWIND');
this.sending([this.pressedButton('REWIND')]);
break;
}
case this.platform.Characteristic.RemoteKey.FAST_FORWARD: {
this.platform.log.debug('set Remote Key Pressed: FAST_FORWARD');
this.sending([this.pressedButton('FORWARD')]);
break;
}
case this.platform.Characteristic.RemoteKey.NEXT_TRACK: {
this.platform.log.debug('set Remote Key Pressed: NEXT_TRACK');
this.sending([this.pressedButton('NEXT')]);
break;
}
case this.platform.Characteristic.RemoteKey.PREVIOUS_TRACK: {
this.platform.log.debug('set Remote Key Pressed: PREVIOUS_TRACK');
this.sending([this.pressedButton('PREVIOUS')]);
break;
}
case this.platform.Characteristic.RemoteKey.ARROW_UP: {
this.platform.log.debug('set Remote Key Pressed: ARROW_UP');
this.sending([this.pressedButton('CURSOR UP')]);
break;
}
case this.platform.Characteristic.RemoteKey.ARROW_DOWN: {
this.platform.log.debug('set Remote Key Pressed: ARROW_DOWN');
this.sending([this.pressedButton('CURSOR DOWN')]);
break;
}
case this.platform.Characteristic.RemoteKey.ARROW_LEFT: {
this.platform.log.debug('set Remote Key Pressed: ARROW_LEFT');
this.sending([this.pressedButton('CURSOR LEFT')]);
break;
}
case this.platform.Characteristic.RemoteKey.ARROW_RIGHT: {
this.platform.log.debug('set Remote Key Pressed: ARROW_RIGHT');
this.sending([this.pressedButton('CURSOR RIGHT')]);
break;
}
case this.platform.Characteristic.RemoteKey.SELECT: {
this.platform.log.debug('set Remote Key Pressed: SELECT');
this.sending([this.pressedButton('CURSOR ENTER')]);
break;
}
case this.platform.Characteristic.RemoteKey.BACK: {
this.platform.log.debug('set Remote Key Pressed: BACK');
this.sending([this.pressedButton('BACK')]);
break;
}
case this.platform.Characteristic.RemoteKey.EXIT: {
this.platform.log.debug('set Remote Key Pressed: EXIT');
this.sending([this.pressedButton('HOME MENU')]);
break;
}
case this.platform.Characteristic.RemoteKey.PLAY_PAUSE: {
this.platform.log.debug('set Remote Key Pressed: PLAY_PAUSE');
this.sending([this.pressedButton('PLAY/PAUSE')]);
/* if (this.playBackState[0] === false) {
this.sending([this.pressedButton('PLAY')]);
}
else {
this.sending([this.pressedButton('PAUSE')]);
}
*/
break;
}
case this.platform.Characteristic.RemoteKey.INFORMATION: {
if (this.config.infoToMenu) {
this.platform.log.debug('set Remote Key Pressed: MENU');
this.sending([this.pressedButton('POP-UP MENU')]);
}
else {
this.platform.log.debug('set Remote Key Pressed: INFORMATION');
this.sending([this.pressedButton('INFO')]);
}
break;
}
}
callback(null);
});
//////////////////////////////////TV Service//////////////////////////////////////////////////////////////////////////
this.tvService
.setCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.inputID);
this.tvService
.getCharacteristic(this.platform.Characteristic.ActiveIdentifier)
.on('set', (inputIdentifier, callback) => {
this.platform.log.debug('Active Identifier set to:', inputIdentifier);
this.inputID = inputIdentifier;
callback();
})
.on('get', (callback) => {
let currentValue = this.inputID;
this.platform.log.debug('Active Identifier set to:', currentValue);
callback(null, currentValue);
});
this.tvService
.getCharacteristic(this.platform.Characteristic.PowerModeSelection)
.on('set', (newValue, callback) => {
this.platform.log.debug('Requested Dune HD Settings ' + newValue);
if (this.playBackState[0] === false && this.playBackState[1] === false && this.playBackState[2] === false) {
this.sending([this.pressedButton('TOP MENU')]);
}
else {
this.sending([this.pressedButton('POP-UP MENU')]);
}
callback();
});
// Input Sources///////////////////////////////////////////////////////////////////////////////////////////////////////////
this.videoAudioTitle = this.accessory.getService('Media Title') ||
this.accessory.addService(this.platform.Service.InputSource, 'Media Title', 'CataNicoGaTa-1003')
.setCharacteristic(this.platform.Characteristic.Identifier, 1)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.inputName)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.platform.Characteristic.CurrentVisibilityState.SHOWN);
this.videoAudioTitle.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.inputName;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.videoAudioTitle);
this.runtime = this.accessory.getService('Runtime') ||
this.accessory.addService(this.platform.Service.InputSource, 'Runtime', 'CataNicoGaTa-1004')
.setCharacteristic(this.platform.Characteristic.Identifier, 2)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.mediaDuration)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.HDMI)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.platform.Characteristic.CurrentVisibilityState.SHOWN);
this.runtime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.mediaDuration;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.runtime);
this.videoAudioElapseTime = this.accessory.getService('Video Information') ||
this.accessory.addService(this.platform.Service.InputSource, 'Video Information', 'CataNicoGaTa-1005')
.setCharacteristic(this.platform.Characteristic.Identifier, 4)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.mediaInformation)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.HDMI)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, false ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, false ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.videoAudioElapseTime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.mediaInformation;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.videoAudioElapseTime);
this.currentChaper = this.accessory.getService('Current Chapter') ||
this.accessory.addService(this.platform.Service.InputSource, 'Current Chapter', 'CataNicoGaTa-4005')
.setCharacteristic(this.platform.Characteristic.Identifier, 3)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.mediaChapter)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.HDMI)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showState ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showState ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.currentChaper.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.mediaChapter;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.currentChaper);
this.audioFormat = this.accessory.getService('Audio Format') ||
this.accessory.addService(this.platform.Service.InputSource, 'Audio Format', 'CataNicoGaTa-4006')
.setCharacteristic(this.platform.Characteristic.Identifier, 5)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.mediaAudioFormat)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.HDMI)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showState ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showState ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.audioFormat.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.mediaAudioFormat;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.audioFormat);
this.audioLanguage = this.accessory.getService('Audio Language') ||
this.accessory.addService(this.platform.Service.InputSource, 'Audio Language', 'CataNicoGaTa-4007')
.setCharacteristic(this.platform.Characteristic.Identifier, 6)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.language)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.HDMI)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showState ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showState ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.audioLanguage.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
let currentValue = this.language;
this.platform.log.debug('Getting' + currentValue);
callback(null, currentValue);
});
this.tvService.addLinkedService(this.audioLanguage);
/////Media State/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this.tvService.getCharacteristic(this.platform.Characteristic.CurrentMediaState)
.on('get', (callback) => {
let currentValue = this.mediaState;
this.platform.log.debug('Current Playback State', currentValue);
callback(null, currentValue);
});
this.tvService.getCharacteristic(this.platform.Characteristic.TargetMediaState)
.on('get', (callback) => {
let currentValue = this.mediaState;
if (this.mediaState === 4) {
currentValue = 2;
}
this.platform.log.debug('Current Playback State', currentValue);
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === 0) {
this.sending([this.pressedButton('PLAY')]);
}
else if (value === 1) {
this.sending([this.pressedButton('PAUSE')]);
}
else if (value === 2) {
this.sending([this.pressedButton('STOP')]);
}
this.platform.log.debug('Playback State set to:', value);
callback(null);
});
////Things to remove
this.tvService.getCharacteristic(this.platform.Characteristic.Brightness)
.on('get', (callback) => {
let currentValue = this.currentVolume;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&volume=" + newValue + "&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: ' + newValue);
callback(null);
});
this.tvService.getCharacteristic(this.platform.Characteristic.PictureMode)
.on('set', (newValue, callback) => {
if (newValue === 1) {
this.sending([this.pressedButton('VOLUME DOWN')]);
}
if (newValue === 0) {
this.sending([this.pressedButton('VOLUME UP')]);
}
this.platform.log('Volume Value moved by: ' + newValue);
callback(null);
});
//////
////////Volume services for the Dune HD/////////////////////////////////////////////////////////////////////////////////
this.speakerService = this.accessory.getService('Dune HD Volume Control') ||
this.accessory.addService(this.platform.Service.TelevisionSpeaker, 'Dune HD Volume Control', 'CataNicoGaTa-20');
this.speakerService
.setCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE)
.setCharacteristic(this.platform.Characteristic.VolumeControlType, this.platform.Characteristic.VolumeControlType.ABSOLUTE);
this.speakerService.getCharacteristic(this.platform.Characteristic.VolumeSelector)
.on('set', (newValue, callback) => {
if (newValue === 1) {
this.sending([this.pressedButton('VOLUME DOWN')]);
}
if (newValue === 0) {
this.sending([this.pressedButton('VOLUME UP')]);
}
this.platform.log('Volume Value moved by: ' + newValue);
callback(null);
});
this.speakerService.getCharacteristic(this.platform.Characteristic.Mute)
.on('get', (callback) => {
let currentValue = this.currentMuteState;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
if (newValue === true) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state_&mute=1&result_syntax=json"]);
this.platform.log('Volume Value set to: Mute');
}
if (newValue === false) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: Unmute');
}
callback(null);
});
this.speakerService.addCharacteristic(this.platform.Characteristic.Volume)
.on('get', (callback) => {
let currentValue = this.currentVolume;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&volume=" + newValue + "&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: ' + newValue);
callback(null);
});
this.tvService.addLinkedService(this.speakerService);
/////Volume and Video/Movie Controls/////////////////////////////////////////////////////////////////////
if (this.config.volume === true) {
if (this.config.changeDimmersToFan === false) {
this.volumeDimmer = this.accessory.getService('Dune HD Volume') ||
this.accessory.addService(this.platform.Service.Lightbulb, 'Dune HD Volume', 'CataNicoGaT-98');
this.volumeDimmer.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.volumeDimmer.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Dune HD Volume');
this.volumeDimmer.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
let currentValue = this.currentVolumeSwitch;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
if (newValue === true) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state_&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: Unmute');
}
if (newValue === false) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&mute=1&result_syntax=json"]);
this.platform.log('Volume Value set to: Mute');
}
callback(null);
});
this.volumeDimmer.addCharacteristic(new this.platform.Characteristic.Brightness())
.on('get', (callback) => {
let currentValue = this.currentVolume;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&volume=" + newValue + "&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: ' + newValue);
callback(null);
});
}
else {
this.volumeFan = this.accessory.getService('Dune HD Volume') ||
this.accessory.addService(this.platform.Service.Fanv2, 'Dune HD Volume', 'CataNicoGaT-98F');
this.volumeFan.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.volumeFan.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Dune HD Volume');
this.volumeFan.getCharacteristic(this.platform.Characteristic.Active)
.on('get', (callback) => {
let currentValue = 0;
if (this.currentVolumeSwitch === true) {
currentValue = 1;
}
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
if (newValue === 1) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state_&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: Unmute');
}
if (newValue === 0) {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&mute=1&result_syntax=json"]);
this.platform.log('Volume Value set to: Mute');
}
callback(null);
});
this.volumeFan.addCharacteristic(new this.platform.Characteristic.RotationSpeed)
.on('get', (callback) => {
let currentValue = this.currentVolume;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&volume=" + newValue + "&mute=0&result_syntax=json"]);
this.platform.log('Volume Value set to: ' + newValue);
callback(null);
});
}
}
if (this.config.movieControl === true) {
if (this.config.changeDimmersToFan === false) {
this.movieControlL = this.accessory.getService('Media Progress') ||
this.accessory.addService(this.platform.Service.Lightbulb, 'Media Progress', 'CataNicoGaTa-301');
this.movieControlL.setCharacteristic(this.platform.Characteristic.Name, 'Media Progress');
this.movieControlL.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.movieControlL.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Media Progress');
this.movieControlL.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
let currentValue = this.currentMovieProgressState;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.platform.log('Movie progress state set to: ' + newValue);
callback(null);
});
this.movieControlL.addCharacteristic(new this.platform.Characteristic.Brightness())
.on('get', (callback) => {
let currentValue = this.currentMovieProgress;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
let newSendValue = Math.round(newValue * (this.movieRemaining) / 100);
if (newSendValue > this.movieRemaining) {
newSendValue = this.movieRemaining;
}
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&position=" + newSendValue + "&result_syntax=json"]);
this.newMovieTime(newSendValue);
this.platform.log('Movie progress set to: ' + newValue + '%');
callback(null);
});
}
else {
this.movieControlF = this.accessory.getService('Media Progress') ||
this.accessory.addService(this.platform.Service.Fanv2, 'Media Progress', 'CataNicoGaTa-301F');
this.movieControlF.setCharacteristic(this.platform.Characteristic.Name, 'Media Progress');
this.movieControlF.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.movieControlF.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Media Progress');
this.movieControlF.getCharacteristic(this.platform.Characteristic.Active)
.on('get', (callback) => {
let currentValue = 0;
if (this.currentMovieProgressState === true) {
currentValue = 1;
}
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
this.platform.log('Movie progress state set to: ' + newValue);
callback(null);
});
this.movieControlF.addCharacteristic(new this.platform.Characteristic.RotationSpeed)
.on('get', (callback) => {
let currentValue = this.currentMovieProgress;
callback(null, currentValue);
})
.on('set', (newValue, callback) => {
let newSendValue = Math.round(newValue * (this.movieRemaining) / 100);
if (newSendValue > this.movieRemaining) {
newSendValue = this.movieRemaining;
}
this.sending(["http://" + this.DUNEHD_IP + ":" + this.DUNEHD_PORT + "/cgi-bin/do?cmd=set_playback_state&position=" + newSendValue + "&result_syntax=json"]);
this.newMovieTime(newSendValue);
this.platform.log('Movie progress set to: ' + newValue + '%');
callback(null);
});
}
}
/////////////Addtional Services////////////////////////////////////////////////////////////////////////////////////
if (this.config.powerB === true) {
this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch);
this.service.setCharacteristic(this.platform.Characteristic.Name, `${accessory.context.device.duneHDDisplayName} Power Switch`);
this.service.updateCharacteristic(this.platform.Characteristic.Name, `${accessory.context.device.duneHDDisplayName} Power Switch`);
this.service.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.service.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.context.device.duneHDDisplayName} Power Switch`);
this.service.getCharacteristic(this.platform.Characteristic.On)
.on('set', this.setOn.bind(this))
.on('get', this.getOn.bind(this));
};
this.play = this.accessory.getService('Play') ||
this.accessory.addService(this.platform.Service.Switch, 'Play', 'CataNicoGaTa-10');
this.play.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.play.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Play');
this.play.getCharacteristic(this.platform.Characteristic.On)
.on('get', this.playSwitchStateGet.bind(this))
.on('set', this.playSwitchStateSet.bind(this));
this.pause = this.accessory.getService('Pause') ||
this.accessory.addService(this.platform.Service.Switch, 'Pause', 'CataNicoGaTa-11');
this.pause.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.pause.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Pause');
this.pause.getCharacteristic(this.platform.Characteristic.On)
.on('get', this.pauseSwitchStateGet.bind(this))
.on('set', this.pauseSwitchStateSet.bind(this));
this.stop = this.accessory.getService('Stop') ||
this.accessory.addService(this.platform.Service.Switch, 'Stop', 'CataNicoGaTa-12');
this.stop.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.stop.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Stop');
this.stop.getCharacteristic(this.platform.Characteristic.On)
.on('get', this.stopSwitchStateGet.bind(this))
.on('set', this.stopSwitchStateSet.bind(this));
///////////////////////////////////Input buttons//////////////////////////////////////////////////////////////////////////
////other Controls /////////////////////////////////////////////////////////
if (this.config.cursorUpB === true) {
this.cursorUp = this.accessory.getService('Cursor Up') ||
this.accessory.addService(this.platform.Service.Switch, 'Cursor Up', 'CataNicoGaTa-31');
this.cursorUp.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cursorUp.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Cursor Up');
this.cursorUp.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Cursor Up GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Cursor Up SET On:', value);
if (value === true) {
this.sending([this.pressedButton('CURSOR UP')]);
}
setTimeout(() => {
this.cursorUp.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.cursorDownB === true) {
this.cursorDown = this.accessory.getService('Cursor Down') ||
this.accessory.addService(this.platform.Service.Switch, 'Cursor Down', 'CataNicoGaTa-32');
this.cursorDown.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cursorDown.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Cursor Down');
this.cursorDown.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Cursor Down GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Cursor Down SET On:', value);
if (value === true) {
this.sending([this.pressedButton('CURSOR DOWN')]);
}
setTimeout(() => {
this.cursorDown.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.cursorLeftB === true) {
this.cursorLeft = this.accessory.getService('Cursor Left') ||
this.accessory.addService(this.platform.Service.Switch, 'Cursor Left', 'CataNicoGaTa-33');
this.cursorLeft.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cursorLeft.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Cursor Left');
this.cursorLeft.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Cursor Left GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Cursor Left SET On:', value);
if (value === true) {
this.sending([this.pressedButton('CURSOR LEFT')]);
}
setTimeout(() => {
this.cursorLeft.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.cursorRightB === true) {
this.cursorRight = this.accessory.getService('Cursor Right') ||
this.accessory.addService(this.platform.Service.Switch, 'Cursor Right', 'CataNicoGaTa-34');
this.cursorRight.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cursorRight.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Cursor Right');
this.cursorRight.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Cursor Right GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Cursor Right SET On:', value);
if (value === true) {
this.sending([this.pressedButton('CURSOR RIGHT')]);
}
setTimeout(() => {
this.cursorRight.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.cursorEnterB === true) {
this.cursorEnter = this.accessory.getService('Cursor Enter') ||
this.accessory.addService(this.platform.Service.Switch, 'Cursor Enter', 'CataNicoGaTa-35');
this.cursorEnter.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cursorEnter.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Cursor Enter');
this.cursorEnter.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Cursor Enter GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Cursor Enter SET On:', value);
if (value === true) {
this.sending([this.pressedButton('CURSOR ENTER')]);
}
setTimeout(() => {
this.cursorEnter.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.searchB === true) {
this.searchB = this.accessory.getService('Search') ||
this.accessory.addService(this.platform.Service.Switch, 'Search', 'CataNicoGaTa-36');
this.searchB.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.searchB.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Search');
this.searchB.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
this.platform.log.debug('Search GET On');
let currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.platform.log.debug('Search SET On:', value);
if (value === true) {
this.sending([this.pressedButton('SEARCH')]);
}
setTimeout(() => {
this.searchB.updateCharacteristic(this.platform.Characteristic.On, false);
}, this.statelessTimeOut);
callback(null);
});
}
if (this.config.backButtonB === true) {
this.backButton = this.accessory.getService('Back') ||
this.accessory.addService(this.platf