diff --git a/CHANGELOG.md b/CHANGELOG.md index d91efbb..4058bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - after update to 4.7.x buttons, sensors, volume display type need to be configure again using config UI - after update to 3.15.x need remove the accessory frome Home app and add it again +## [5.2.0] - (01.12.2024) + +## Changes + +- move from commonJS to esm module +- moved constants.json to constants.js +- cleanup + ## [5.1.11] - (07.09.2024) ## Changes diff --git a/index.js b/index.js index 4741d61..f3d93fb 100644 --- a/index.js +++ b/index.js @@ -1,26 +1,26 @@ 'use strict'; -const path = require('path'); -const fs = require('fs'); -const MainZone = require('./src/mainzone.js'); -const Zone2 = require('./src/zone2.js'); -const Zone3 = require('./src/zone3.js'); -const Surround = require('./src/surround.js'); -const ImpulseGenerator = require('./src/impulsegenerator.js'); -const CONSTANTS = require('./src/constants.json'); +import { join } from 'path'; +import { mkdirSync, existsSync, writeFileSync } from 'fs'; +import MainZone from './src/mainzone.js'; +import Zone2 from './src/zone2.js'; +import Zone3 from './src/zone3.js'; +import Surround from './src/surround.js'; +import ImpulseGenerator from './src/impulsegenerator.js'; +import { PluginName, PlatformName, ZoneNameShort } from './src/constants.js'; class DenonPlatform { constructor(log, config, api) { // only load if configured if (!config || !Array.isArray(config.devices)) { - log.warn(`No configuration found for ${CONSTANTS.PluginName}`); + log.warn(`No configuration found for ${PluginName}`); return; } this.accessories = []; //check if prefs directory exist - const prefDir = path.join(api.user.storagePath(), 'denonTv'); + const prefDir = join(api.user.storagePath(), 'denonTv'); try { - fs.mkdirSync(prefDir, { recursive: true }); + mkdirSync(prefDir, { recursive: true }); } catch (error) { log.error(`Prepare directory error: ${error.message ?? error}`); return; @@ -56,7 +56,7 @@ class DenonPlatform { const refreshInterval = device.refreshInterval * 1000 || 5000; //check files exists, if not then create it - const postFix = `${CONSTANTS.ZoneNameShort[zoneControl]}${host.split('.').join('')}` + const postFix = `${ZoneNameShort[zoneControl]}${host.split('.').join('')}` const devInfoFile = `${prefDir}/devInfo_${postFix}`; const inputsFile = `${prefDir}/inputs_${postFix}`; const inputsNamesFile = `${prefDir}/inputsNames_${postFix}`; @@ -71,8 +71,8 @@ class DenonPlatform { ]; files.forEach((file) => { - if (!fs.existsSync(file)) { - fs.writeFileSync(file, ''); + if (!existsSync(file)) { + writeFileSync(file, ''); } }); } catch (error) { @@ -86,7 +86,7 @@ class DenonPlatform { try { const mainZone = new MainZone(api, device, zoneControl, deviceName, host, port, generation, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, refreshInterval); mainZone.on('publishAccessory', (accessory) => { - api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); + api.publishExternalAccessories(PluginName, [accessory]); log.success(`Device: ${host} ${deviceName}, Published as external accessory.`); }) .on('devInfo', (devInfo) => { @@ -131,7 +131,7 @@ class DenonPlatform { try { const zone2 = new Zone2(api, device, zoneControl, deviceName, host, port, generation, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, refreshInterval); zone2.on('publishAccessory', (accessory) => { - api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); + api.publishExternalAccessories(PluginName, [accessory]); log.success(`Device: ${host} ${deviceName}, Published as external accessory.`); }) .on('devInfo', (devInfo) => { @@ -176,7 +176,7 @@ class DenonPlatform { try { const zone3 = new Zone3(api, device, zoneControl, deviceName, host, port, generation, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, refreshInterval); zone3.on('publishAccessory', (accessory) => { - api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); + api.publishExternalAccessories(PluginName, [accessory]); log.success(`Device: ${host} ${deviceName}, Published as external accessory.`); }) .on('devInfo', (devInfo) => { @@ -221,7 +221,7 @@ class DenonPlatform { try { const surround = new Surround(api, device, zoneControl, deviceName, host, port, generation, devInfoFile, inputsFile, inputsNamesFile, inputsTargetVisibilityFile, refreshInterval); surround.on('publishAccessory', (accessory) => { - api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]); + api.publishExternalAccessories(PluginName, [accessory]); log.success(`Device: ${host} ${deviceName}, Published as external accessory.`); }) .on('devInfo', (devInfo) => { @@ -276,6 +276,6 @@ class DenonPlatform { } }; -module.exports = (api) => { - api.registerPlatform(CONSTANTS.PluginName, CONSTANTS.PlatformName, DenonPlatform, true); +export default (api) => { + api.registerPlatform(PluginName, PlatformName, DenonPlatform, true); }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 961a32c..262d145 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-denon-tv", - "version": "5.1.27", + "version": "5.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "homebridge-denon-tv", - "version": "5.1.27", + "version": "5.2.0", "license": "MIT", "dependencies": { "async-mqtt": "^2.6.3", diff --git a/package.json b/package.json index 4de406f..6512dda 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Denon TV", "name": "homebridge-denon-tv", - "version": "5.1.27", + "version": "5.2.0", "description": "Homebridge plugin to control Denon/Marantz AV Receivers.", "license": "MIT", "author": "grzegorz914", @@ -16,6 +16,7 @@ "bugs": { "url": "https://github.com/grzegorz914/homebridge-denon-tv/issues" }, + "type": "module", "main": "index.js", "files": [ "src", diff --git a/src/constants.js b/src/constants.js new file mode 100644 index 0000000..a26894e --- /dev/null +++ b/src/constants.js @@ -0,0 +1,563 @@ +export const PlatformName = "DenonTv"; +export const PluginName = "homebridge-denon-tv"; + +export const ApiUrls = { + "UPNP": ":60006/upnp/desc/aios_device/aios_device.xml", + "Description": ":8080/description.xml", + "DeviceInfoGen0": "/goform/formMainZone_MainZoneXml.xml", + "DeviceInfoGen1": "/goform/Deviceinfo.xml", + "DeviceInfoGen2": "/goform/Deviceinfo.xml", + "MainZoneStatus": "/goform/formMainZone_MainZoneXmlStatus.xml", + "MainZoneStatusLite": "/goform/formMainZone_MainZoneXmlStatusLite.xml", + "Zone2Status": "/goform/formZone2_Zone2XmlStatus.xml", + "Zone2StatusLite": "/goform/formZone2_Zone2XmlStatusLite.xml", + "Zone3Status": "/goform/formZone3_Zone3XmlStatus.xml", + "Zone3StatusLite": "/goform/formZone3_Zone3XmlStatusLite.xml", + "Zone4Status": "/goform/formZone4_Zone4XmlStatus.xml", + "Zone4StatusLite": "/goform/formZone4_Zone4XmlStatusLite.xml", + "SoundModeStatus": "/goform/formMainZone_MainZoneXmlStatusLite.xml", + "iPhoneDirect": "/goform/formiPhoneAppDirect.xml?", + "AppCommand": "/goform/AppCommand.xml", + "AppCommand300": "/goform/AppCommand0300.xml", + "TunerStatus": "/goform/formTuner_TunerXml.xml", + "HdTunerStatus": "/goform/formTuner_HdXml.xml", + "NetAudioStatus": "/goform/formNetAudio_StatusXml.xml", + "NetAudioAlbum": "/img/album%20art_S.png", + "NetAudioArt": "/NetAudio/art.asp-jpg?{time}", + "NetAudioPost": "/NetAudio/index.put.asp" +}; + +export const BodyXml = { + "GetZoneName": { + "data": " GetZoneName " + }, + "GetAllZonePowerStatus": { + "data": " GetAllZonePowerStatus " + }, + "GetAllZoneSource": { + "data": " GetAllZoneSource " + }, + "GetAllZoneVolume": { + "data": " GetAllZoneVolume " + }, + "GetAllZoneMuteStatus": { + "data": " GetAllZoneMuteStatus " + }, + "GetAllZoneStereo": { + "data": " GetAllZoneStereo " + }, + "GetPowerStatus": { + "data": " GetPowerStatus " + }, + "GetSourceStatus": { + "data": " GetSourceStatus " + }, + "GetVolumeLevel": { + "data": " GetVolumeLevel " + }, + "GetMuteStatus": { + "data": " GetMuteStatus " + }, + "GetPictureMode": { + "data": " GetPictureMode " + }, + "GetSurroundModeStatus": { + "data": " GetSurroundModeStatus " + }, + "GetDimmer": { + "data": " GetDimmer " + }, + "GetChannelIndicators": { + "data": " GetChannelIndicators " + }, + "GetVideoSelect": { + "data": " GetVideoSelect " + }, + "GetQuickSelectName": { + "data": " GetQuickSelectName " + }, + "GetAutoStandby": { + "data": " GetAutoStandby " + }, + "GetToneControl": { + "data": " GetToneControl " + }, + "GetSubwooferLevel": { + "data": " GetSubwooferLevel " + }, + "GetNetAudioStatus": { + "data": " GetNetAudioStatus " + }, + "GetRenameSource": { + "data": " GetRenameSource " + }, + "GetDeletedSource": { + "data": " GetDeletedSource " + }, + "GetAudyssey": { + "data": " GetAudyssey " + }, + "GetAudysseyEQCurveType": { + "data": " GetAudysseyEQCurveType " + }, + "SetAudyssey": { + "data": " SetAudyssey " + } +}; + +export const BodyXml300 = { + "GetZoneName": { + "data": " GetZoneName " + }, + "GetAllZonePowerStatus": { + "data": " GetAllZonePowerStatus " + }, + "GetAllZoneSource": { + "data": " GetAllZoneSource " + }, + "GetAllZoneVolume": { + "data": " GetAllZoneVolume " + }, + "GetAllZoneMuteStatus": { + "data": " GetAllZoneMuteStatus " + }, + "GetAllZoneStereo": { + "data": " GetAllZoneStereo " + }, + "GetPowerStatus": { + "data": " GetPowerStatus " + }, + "GetSourceStatus": { + "data": " GetSourceStatus " + }, + "GetVolumeLevel": { + "data": " GetVolumeLevel " + }, + "GetMuteStatus": { + "data": " GetMuteStatus " + }, + "GetPictureMode": { + "data": " GetPictureMode " + }, + "GetSurroundModeStatus": { + "data": " GetSurroundModeStatus " + }, + "GetDimmer": { + "data": " GetDimmer " + }, + "GetChannelIndicators": { + "data": " GetChannelIndicators " + }, + "GetVideoSelect": { + "data": " GetVideoSelect " + }, + "GetQuickSelectName": { + "data": " GetQuickSelectName " + }, + "GetAutoStandby": { + "data": " GetAutoStandby " + }, + "GetToneControl": { + "data": " GetToneControl " + }, + "GetSubwooferLevel": { + "data": " GetSubwooferLevel " + }, + "GetNetAudioStatus": { + "data": " GetNetAudioStatus " + }, + "GetRenameSource": { + "data": " GetRenameSource " + }, + "GetDeletedSource": { + "data": " GetDeletedSource " + }, + "GetAudyssey": { + "data": " GetAudyssey " + }, + "GetAudysseyEQCurveType": { + "data": " GetAudysseyEQCurveType " + }, + "SetAudyssey": { + "data": " SetAudyssey " + } +}; + +export const ZoneName = [ + "Main Zone", + "Zone 2", + "Zone 3", + "Sound Mode" +]; + +export const ZoneNameShort = [ + "MZ", + "Z2", + "Z3", + "SM" +]; + +export const ZoneInputSurroundName = [ + "Input", + "Input", + "Input", + "Surround" +]; + +export const InputSourceType = [ + "OTHER", + "HOME_SCREEN", + "TUNER", + "HDMI", + "COMPOSITE_VIDEO", + "S_VIDEO", + "COMPONENT_VIDEO", + "DVI", + "AIRPLAY", + "USB", + "APPLICATION" +]; + +export const InputMode = { + "INPUT": "SI", + "FAVOR": "ZM", + "QUICK": "MS", + "SMART": "MS", + "FV": "FV " +}; + +export const DirectSoundMode = { + "0MSMOVIE0": { + "mode": "MSMOVIE", + "surround": "MSSTEREO" + }, + "0MSMOVIE1": { + "mode": "MSMOVIE", + "surround": "MSDOLBY DIGITAL" + }, + "0MSMOVIE2": { + "mode": "MSMOVIE", + "surround": "MSDTS SURROUND" + }, + "0MSMOVIE3": { + "mode": "MSMOVIE", + "surround": "MSAURO2DSURR" + }, + "0MSMOVIE4": { + "mode": "MSMOVIE", + "surround": "MSAURO3D" + }, + "0MSMOVIE5": { + "mode": "MSMOVIE", + "surround": "MSMCH STEREO" + }, + "0MSMOVIE6": { + "mode": "MSMOVIE", + "surround": "MSMONO MOVIE" + }, + "0MSMOVIE7": { + "mode": "MSMOVIE", + "surround": "MSVIRTUAL" + }, + "0MSMUSIC0": { + "mode": "MSMUSIC", + "surround": "MSSTEREO" + }, + "0MSMUSIC1": { + "mode": "MSMUSIC", + "surround": "MSDOLBY DIGITAL" + }, + "0MSMUSIC2": { + "mode": "MSMUSIC", + "surround": "MSDTS SURROUND" + }, + "0MSMUSIC3": { + "mode": "MSMUSIC", + "surround": "MSAURO2DSURR" + }, + "0MSMUSIC4": { + "mode": "MSMUSIC", + "surround": "MSAURO3D" + }, + "0MSMUSIC5": { + "mode": "MSMUSIC", + "surround": "MSMCH STEREO" + }, + "0MSMUSIC6": { + "mode": "MSMUSIC", + "surround": "MSROCK ARENA" + }, + "0MSMUSIC7": { + "mode": "MSMUSIC", + "surround": "MSJAZZ CLUB" + }, + "0MSMUSIC8": { + "mode": "MSMUSIC", + "surround": "MSMATRIX" + }, + "0MSMUSIC9": { + "mode": "MSMUSIC", + "surround": "MSVIRTUAL" + }, + "0MSGAME0": { + "mode": "MSGAME", + "surround": "MSSTEREO" + }, + "0MSGAME1": { + "mode": "MSGAME", + "surround": "MSDOLBY DIGITAL" + }, + "0MSGAME2": { + "mode": "MSGAME", + "surround": "MSDTS SURROUND" + }, + "0MSGAME3": { + "mode": "MSGAME", + "surround": "MSAURO2DSURR" + }, + "0MSGAME4": { + "mode": "MSGAME", + "surround": "MSAURO3D" + }, + "0MSGAME5": { + "mode": "MSGAME", + "surround": "MSMCH STEREO" + }, + "0MSGAME6": { + "mode": "MSGAME", + "surround": "MSVIDEO GAME" + }, + "0MSGAME7": { + "mode": "MSGAME", + "surround": "MSVIRTUAL" + } +}; + +export const SoundModeConversion = { + "AUTO": "AUTO", + "MOVIE": "MOVIE", + "MUSIC": "MUSIC", + "GAME": "GAME", + "DIRECT": "DIRECT", + "DSDDIRECT": "DIRECT", + "PUREDIRECT": "PURE DIRECT", + "DSDPUREDIRECT": "PURE DIRECT", + "STEREO": "STEREO", + "ALLZONESTEREO": "STEREO", + "71IN": "MCH STEREO", + "MCHSTEREO": "MCH STEREO", + "MULTICHSTEREO": "MCH STEREO", + "DOLBYSURROUND": "DOLBY DIGITAL", + "DOLBYPROLOGIC": "DOLBY DIGITAL", + "DOLBYPLIIMV": "DOLBY DIGITAL", + "DOLBYPLIIMS": "DOLBY DIGITAL", + "DOLBYPLIIGM": "DOLBY DIGITAL", + "DOLBYPL2C": "DOLBY DIGITAL", + "DOLBYPL2M": "DOLBY DIGITAL", + "DOLBYPL2G": "DOLBY DIGITAL", + "DOLBYPL2XC": "DOLBY DIGITAL", + "DOLBYPL2XM": "DOLBY DIGITAL", + "DOLBYPL2XG": "DOLBY DIGITAL", + "DOLBYPL2ZH": "DOLBY DIGITAL", + "DOLBYATMOS": "DOLBY DIGITAL", + "DOLBYDIGITAL": "DOLBY DIGITAL", + "DOLBYAUDIODSUR": "DOLBY DIGITAL", + "DOLBYAUDIODD": "DOLBY DIGITAL", + "DOLBYDEX": "DOLBY DIGITAL", + "DOLBYDPL2XC": "DOLBY DIGITAL", + "DOLBYDPL2XM": "DOLBY DIGITAL", + "DOLBYDPL2ZH": "DOLBY DIGITAL", + "DOLBYDDS": "DOLBY DIGITAL", + "DOLBYAUDIODDDSUR": "DOLBY DIGITAL", + "DOLBYDNEOXC": "DOLBY DIGITAL", + "DOLBYDNEOXM": "DOLBY DIGITAL", + "DOLBYDNEOXG": "DOLBY DIGITAL", + "DOLBYDNEURALX": "DOLBY DIGITAL", + "DOLBYAUDIODDNEURALX": "DOLBY DIGITAL", + "DOLBYAUDIODDNERUALX": "DOLBY DIGITAL", + "DOLBYAUDIOTRUEHD": "DOLBY DIGITAL", + "DOLBYHDEX": "DOLBY DIGITAL", + "DOLBYHDPL2XC": "DOLBY DIGITAL", + "DOLBYHDPL2XM": "DOLBY DIGITAL", + "DOLBYHDPL2ZH": "DOLBY DIGITAL", + "DOLBYAUDIOTRUEHDDSUR": "DOLBY DIGITAL", + "DOLBYHDNEOXC": "DOLBY DIGITAL", + "DOLBYHDNEOXM": "DOLBY DIGITAL", + "DOLBYHDNEOXG": "DOLBY DIGITAL", + "DOLBYAUDIOTRUEHDNEURALX": "DOLBY DIGITAL", + "MULTIINDOLBYSURROUND": "DOLBY DIGITAL", + "DTSSURROUND": "DTS SURROUND", + "DTSDSUR": "DTS SURROUND", + "DTS9624": "DTS SURROUND", + "DTS96ESMTRX": "DTS SURROUND", + "DTSPL2XC": "DTS SURROUND", + "DTSPL2XM": "DTS SURROUND", + "DTSPL2ZH": "DTS SURROUND", + "DTSNEURALX": "DTS SURROUND", + "DTSVIRTUALX": "DTS SURROUND", + "DTSEXPRESS": "DTS SURROUND", + "DTSNEO6": "DTS SURROUND", + "DTSNEO6C": "DTS SURROUND", + "DTSNEO6M": "DTS SURROUND", + "DTSNEOXC": "DTS SURROUND", + "DTSNEOXM": "DTS SURROUND", + "DTSNEOXG": "DTS SURROUND", + "DTSESDSCRT61": "DTS SURROUND", + "DTSESMTRX61": "DTS SURROUND", + "DTSESMTRXNEURALX": "DTS SURROUND", + "DTSESDSCRTNEURALX": "DTS SURROUND", + "DTSES8CHDSCRT": "DTS SURROUND", + "DTSHD": "DTS SURROUND", + "DTSHDMSTR": "DTS SURROUND", + "DTSHDPL2XC": "DTS SURROUND", + "DTSHDPL2XM": "DTS SURROUND", + "DTSHDPL2ZH": "DTS SURROUND", + "DTSHDDSUR": "DTS SURROUND", + "DTSHDNEO6": "DTS SURROUND", + "DTSHDNEOXC": "DTS SURROUND", + "DTSHDNEOXM": "DTS SURROUND", + "DTSHDNEOXG": "DTS SURROUND", + "DTSHDNEURALX": "DTS SURROUND", + "DTSHDVIRTUALX": "DTS SURROUND", + "DTSX": "DTS SURROUND", + "DTSXMSTR": "DTS SURROUND", + "DTSXVIRTUALX": "DTS SURROUND", + "IMAXDTS": "DTS SURROUND", + "IMAXDTSX": "DTS SURROUND", + "IMAXDTSNEURALX": "DTS SURROUND", + "IMAXDTSVIRTUALX": "DTS SURROUND", + "IMAXDTSXVIRTUALX": "DTS SURROUND", + "IMAXDTSXNEURALX": "DTS SURROUND", + "MCHINDOLBYEX": "DTS SURROUND", + "MCHINPL2XC": "DTS SURROUND", + "MCHINPL2XM": "DTS SURROUND", + "MCHINPL2ZH": "DTS SURROUND", + "MCHINDSUR": "DTS SURROUND", + "MCHINNEOXC": "DTS SURROUND", + "MCHINNEOXM": "DTS SURROUND", + "MCHINNEOXG": "DTS SURROUND", + "MCHINNEURALX": "DTS SURROUND", + "MCHINVIRTUALX": "DTS SURROUND", + "MULTICHIN": "DTS SURROUND", + "MULTICHIN71": "DTS SURROUND", + "MULTIINNEURALX": "DTS SURROUND", + "MULTIINVIRTUALX": "DTS SURROUND", + "MPEG2AAC": "DTS SURROUND", + "AACDOLBYEX": "DTS SURROUND", + "AACPL2XC": "DTS SURROUND", + "AACPL2XM": "DTS SURROUND", + "AACPL2ZH": "DTS SURROUND", + "AACDSUR": "DTS SURROUND", + "AACDS": "DTS SURROUND", + "AACNEOXC": "DTS SURROUND", + "AACNEOXM": "DTS SURROUND", + "AACNEOXG": "DTS SURROUND", + "AACNEURALX": "DTS SURROUND", + "AACVIRTUALX": "DTS SURROUND", + "NEO6CDSX": "DTS SURROUND", + "NEO6MDSX": "DTS SURROUND", + "AUDYSSEYDSX": "DTS SURROUND", + "NEURALX": "DTS SURROUND", + "VIRTUALX": "DTS SURROUND", + "AURO3D": "AURO3D", + "AURO2DSURR": "AURO2DSURR", + "WISDESCREEN": "WIDE SCREEN", + "SUPERSTADIUM": "SUPER STADIUM", + "ROCKARENA": "ROCK ARENA", + "JAZZCLUB": "JAZZ CLUB", + "CLASSICCONCERT": "CLASSIC CONCERT", + "MONOMOVIE": "MONO MOVIE", + "MATRIX": "MATRIX", + "VIDEOGAME": "VIDEO GAME", + "VIRTUAL": "VIRTUAL", + "NEURAL": "NEURAL", + "STANDARD": "STANDARD", + "LEFT": "LEFT", + "RIGHT": "RIGHT" +}; + +export const InputConversion = { + "TV AUDIO": "TV", + "iPod/USB": "USB/IPOD", + "Bluetooth": "BT", + "Blu-ray": "BD", + "CBL/SAT": "SAT/CBL", + "AUX": "AUX1", + "NETWORK": "NET", + "HEOS": "NET", + "AirPlay": "NET", + "Online Music": "NET", + "Media Player": "MPLAY", + "Tuner": "TUNER", + "FM": "TUNER", + "SpotifyConnect": "SPOTIFYCONNECT", + "Internet Radio": "IRADIO", + "Media Server": "SERVER", + "Spotify": "SPOTIFY", + "Flickr": "FLICKR", + "Favorites": "FAVORITES", + "Quick Select1": "QUICK1", + "Quick Select2": "QUICK2", + "Quick Select3": "QUICK3", + "Quick Select4": "QUICK4", + "Quick Select5": "QUICK5", + "Quick Select1 Mode Memory": "QUICK1 MEMORY", + "Quick Select2 Mode Memory": "QUICK2 MEMORY", + "Quick Select3 Mode Memory": "QUICK3 MEMORY", + "Quick Select4 Mode Memory": "QUICK4 MEMORY", + "Quick Select5 Mode Memory": "QUICK5 MEMORY", + "Smart Select1": "SMART1", + "Smart Select2": "SMART2", + "Smart Select3": "SMART3", + "Smart Select4": "SMART4", + "Smart Select5": "SMART5", + "Smart Select1 Mode Memory": "SMART1 MEMORY", + "Smart Select2 Mode Memory": "SMART2 MEMORY", + "Smart Select3 Mode Memory": "SMART3 MEMORY", + "Smart Select4 Mode Memory": "SMART4 MEMORY", + "Smart Select5 Mode Memory": "SMART5 MEMORY" +}; + +export const PictureModesDenon = { + "Off": "OFF", + "Standard": "STANDARD", + "Movie": "MOVIE", + "Vivid": "VIVID", + "Stream": "STREAM", + "Custom": "CUSTOM", + "ISF Day": "ISF DAY", + "ISF Night": "ISF NIGHT" +}; + +export const PictureModesDenonString = { + "PVOFF": "OFF", + "PVSTD": "STANDARD", + "PVMOV": "MOVIE", + "PVVVD": "VIVID", + "PVSTM": "STREAM", + "PVDAY": "ISF DAY", + "PVNGT": "ISF NIGHT", + "PVCTM": "CUSTOM" +}; + +export const PictureModesDenonNumber = { + "0": "OFF", + "1": "STANDARD", + "2": "MOVIE", + "3": "VIVID", + "4": "STREAM", + "5": "ISF DAY", + "6": "ISF NIGHT", + "7": "CUSTOM" +}; + +export const PictureModesConversionToHomeKit = { + "0": 0, + "1": 1, + "2": 5, + "3": 4, + "4": 6, + "5": 2, + "6": 3, + "7": 7 +}; \ No newline at end of file diff --git a/src/constants.json b/src/constants.json deleted file mode 100644 index 2f2d995..0000000 --- a/src/constants.json +++ /dev/null @@ -1,550 +0,0 @@ -{ - "PlatformName": "DenonTv", - "PluginName": "homebridge-denon-tv", - "ApiUrls": { - "UPNP": ":60006/upnp/desc/aios_device/aios_device.xml", - "Description": ":8080/description.xml", - "DeviceInfoGen0": "/goform/formMainZone_MainZoneXml.xml", - "DeviceInfoGen1": "/goform/Deviceinfo.xml", - "DeviceInfoGen2": "/goform/Deviceinfo.xml", - "MainZoneStatus": "/goform/formMainZone_MainZoneXmlStatus.xml", - "MainZoneStatusLite": "/goform/formMainZone_MainZoneXmlStatusLite.xml", - "Zone2Status": "/goform/formZone2_Zone2XmlStatus.xml", - "Zone2StatusLite": "/goform/formZone2_Zone2XmlStatusLite.xml", - "Zone3Status": "/goform/formZone3_Zone3XmlStatus.xml", - "Zone3StatusLite": "/goform/formZone3_Zone3XmlStatusLite.xml", - "Zone4Status": "/goform/formZone4_Zone4XmlStatus.xml", - "Zone4StatusLite": "/goform/formZone4_Zone4XmlStatusLite.xml", - "SoundModeStatus": "/goform/formMainZone_MainZoneXmlStatusLite.xml", - "iPhoneDirect": "/goform/formiPhoneAppDirect.xml?", - "AppCommand": "/goform/AppCommand.xml", - "AppCommand300": "/goform/AppCommand0300.xml", - "TunerStatus": "/goform/formTuner_TunerXml.xml", - "HdTunerStatus": "/goform/formTuner_HdXml.xml", - "NetAudioStatus": "/goform/formNetAudio_StatusXml.xml", - "NetAudioAlbum": "/img/album%20art_S.png", - "NetAudioArt": "/NetAudio/art.asp-jpg?{time}", - "NetAudioPost": "/NetAudio/index.put.asp" - }, - "BodyXml": { - "GetZoneName": { - "data": " GetZoneName " - }, - "GetAllZonePowerStatus": { - "data": " GetAllZonePowerStatus " - }, - "GetAllZoneSource": { - "data": " GetAllZoneSource " - }, - "GetAllZoneVolume": { - "data": " GetAllZoneVolume " - }, - "GetAllZoneMuteStatus": { - "data": " GetAllZoneMuteStatus " - }, - "GetAllZoneStereo": { - "data": " GetAllZoneStereo " - }, - "GetPowerStatus": { - "data": " GetPowerStatus " - }, - "GetSourceStatus": { - "data": " GetSourceStatus " - }, - "GetVolumeLevel": { - "data": " GetVolumeLevel " - }, - "GetMuteStatus": { - "data": " GetMuteStatus " - }, - "GetPictureMode": { - "data": " GetPictureMode " - }, - "GetSurroundModeStatus": { - "data": " GetSurroundModeStatus " - }, - "GetDimmer": { - "data": " GetDimmer " - }, - "GetChannelIndicators": { - "data": " GetChannelIndicators " - }, - "GetVideoSelect": { - "data": " GetVideoSelect " - }, - "GetQuickSelectName": { - "data": " GetQuickSelectName " - }, - "GetAutoStandby": { - "data": " GetAutoStandby " - }, - "GetToneControl": { - "data": " GetToneControl " - }, - "GetSubwooferLevel": { - "data": " GetSubwooferLevel " - }, - "GetNetAudioStatus": { - "data": " GetNetAudioStatus " - }, - "GetRenameSource": { - "data": " GetRenameSource " - }, - "GetDeletedSource": { - "data": " GetDeletedSource " - }, - "GetAudyssey": { - "data": " GetAudyssey " - }, - "GetAudysseyEQCurveType": { - "data": " GetAudysseyEQCurveType " - }, - "SetAudyssey": { - "data": " SetAudyssey " - } - }, - "BodyXml300": { - "GetZoneName": { - "data": " GetZoneName " - }, - "GetAllZonePowerStatus": { - "data": " GetAllZonePowerStatus " - }, - "GetAllZoneSource": { - "data": " GetAllZoneSource " - }, - "GetAllZoneVolume": { - "data": " GetAllZoneVolume " - }, - "GetAllZoneMuteStatus": { - "data": " GetAllZoneMuteStatus " - }, - "GetAllZoneStereo": { - "data": " GetAllZoneStereo " - }, - "GetPowerStatus": { - "data": " GetPowerStatus " - }, - "GetSourceStatus": { - "data": " GetSourceStatus " - }, - "GetVolumeLevel": { - "data": " GetVolumeLevel " - }, - "GetMuteStatus": { - "data": " GetMuteStatus " - }, - "GetPictureMode": { - "data": " GetPictureMode " - }, - "GetSurroundModeStatus": { - "data": " GetSurroundModeStatus " - }, - "GetDimmer": { - "data": " GetDimmer " - }, - "GetChannelIndicators": { - "data": " GetChannelIndicators " - }, - "GetVideoSelect": { - "data": " GetVideoSelect " - }, - "GetQuickSelectName": { - "data": " GetQuickSelectName " - }, - "GetAutoStandby": { - "data": " GetAutoStandby " - }, - "GetToneControl": { - "data": " GetToneControl " - }, - "GetSubwooferLevel": { - "data": " GetSubwooferLevel " - }, - "GetNetAudioStatus": { - "data": " GetNetAudioStatus " - }, - "GetRenameSource": { - "data": " GetRenameSource " - }, - "GetDeletedSource": { - "data": " GetDeletedSource " - }, - "GetAudyssey": { - "data": " GetAudyssey " - }, - "GetAudysseyEQCurveType": { - "data": " GetAudysseyEQCurveType " - }, - "SetAudyssey": { - "data": " SetAudyssey " - } - }, - "ZoneName": [ - "Main Zone", - "Zone 2", - "Zone 3", - "Sound Mode" - ], - "ZoneNameShort": [ - "MZ", - "Z2", - "Z3", - "SM" - ], - "ZoneInputSurroundName": [ - "Input", - "Input", - "Input", - "Surround" - ], - "InputSourceType": [ - "OTHER", - "HOME_SCREEN", - "TUNER", - "HDMI", - "COMPOSITE_VIDEO", - "S_VIDEO", - "COMPONENT_VIDEO", - "DVI", - "AIRPLAY", - "USB", - "APPLICATION" - ], - "InputMode": { - "INPUT": "SI", - "FAVOR": "ZM", - "QUICK": "MS", - "SMART": "MS", - "FV": "FV " - }, - "DirectSoundMode": { - "0MSMOVIE0": { - "mode": "MSMOVIE", - "surround": "MSSTEREO" - }, - "0MSMOVIE1": { - "mode": "MSMOVIE", - "surround": "MSDOLBY DIGITAL" - }, - "0MSMOVIE2": { - "mode": "MSMOVIE", - "surround": "MSDTS SURROUND" - }, - "0MSMOVIE3": { - "mode": "MSMOVIE", - "surround": "MSAURO2DSURR" - }, - "0MSMOVIE4": { - "mode": "MSMOVIE", - "surround": "MSAURO3D" - }, - "0MSMOVIE5": { - "mode": "MSMOVIE", - "surround": "MSMCH STEREO" - }, - "0MSMOVIE6": { - "mode": "MSMOVIE", - "surround": "MSMONO MOVIE" - }, - "0MSMOVIE7": { - "mode": "MSMOVIE", - "surround": "MSVIRTUAL" - }, - "0MSMUSIC0": { - "mode": "MSMUSIC", - "surround": "MSSTEREO" - }, - "0MSMUSIC1": { - "mode": "MSMUSIC", - "surround": "MSDOLBY DIGITAL" - }, - "0MSMUSIC2": { - "mode": "MSMUSIC", - "surround": "MSDTS SURROUND" - }, - "0MSMUSIC3": { - "mode": "MSMUSIC", - "surround": "MSAURO2DSURR" - }, - "0MSMUSIC4": { - "mode": "MSMUSIC", - "surround": "MSAURO3D" - }, - "0MSMUSIC5": { - "mode": "MSMUSIC", - "surround": "MSMCH STEREO" - }, - "0MSMUSIC6": { - "mode": "MSMUSIC", - "surround": "MSROCK ARENA" - }, - "0MSMUSIC7": { - "mode": "MSMUSIC", - "surround": "MSJAZZ CLUB" - }, - "0MSMUSIC8": { - "mode": "MSMUSIC", - "surround": "MSMATRIX" - }, - "0MSMUSIC9": { - "mode": "MSMUSIC", - "surround": "MSVIRTUAL" - }, - "0MSGAME0": { - "mode": "MSGAME", - "surround": "MSSTEREO" - }, - "0MSGAME1": { - "mode": "MSGAME", - "surround": "MSDOLBY DIGITAL" - }, - "0MSGAME2": { - "mode": "MSGAME", - "surround": "MSDTS SURROUND" - }, - "0MSGAME3": { - "mode": "MSGAME", - "surround": "MSAURO2DSURR" - }, - "0MSGAME4": { - "mode": "MSGAME", - "surround": "MSAURO3D" - }, - "0MSGAME5": { - "mode": "MSGAME", - "surround": "MSMCH STEREO" - }, - "0MSGAME6": { - "mode": "MSGAME", - "surround": "MSVIDEO GAME" - }, - "0MSGAME7": { - "mode": "MSGAME", - "surround": "MSVIRTUAL" - } - }, - "SoundModeConversion": { - "AUTO": "AUTO", - "MOVIE": "MOVIE", - "MUSIC": "MUSIC", - "GAME": "GAME", - "DIRECT": "DIRECT", - "DSDDIRECT": "DIRECT", - "PUREDIRECT": "PURE DIRECT", - "DSDPUREDIRECT": "PURE DIRECT", - "STEREO": "STEREO", - "ALLZONESTEREO": "STEREO", - "71IN": "MCH STEREO", - "MCHSTEREO": "MCH STEREO", - "MULTICHSTEREO": "MCH STEREO", - "DOLBYSURROUND": "DOLBY DIGITAL", - "DOLBYPROLOGIC": "DOLBY DIGITAL", - "DOLBYPLIIMV": "DOLBY DIGITAL", - "DOLBYPLIIMS": "DOLBY DIGITAL", - "DOLBYPLIIGM": "DOLBY DIGITAL", - "DOLBYPL2C": "DOLBY DIGITAL", - "DOLBYPL2M": "DOLBY DIGITAL", - "DOLBYPL2G": "DOLBY DIGITAL", - "DOLBYPL2XC": "DOLBY DIGITAL", - "DOLBYPL2XM": "DOLBY DIGITAL", - "DOLBYPL2XG": "DOLBY DIGITAL", - "DOLBYPL2ZH": "DOLBY DIGITAL", - "DOLBYATMOS": "DOLBY DIGITAL", - "DOLBYDIGITAL": "DOLBY DIGITAL", - "DOLBYAUDIODSUR": "DOLBY DIGITAL", - "DOLBYAUDIODD": "DOLBY DIGITAL", - "DOLBYDEX": "DOLBY DIGITAL", - "DOLBYDPL2XC": "DOLBY DIGITAL", - "DOLBYDPL2XM": "DOLBY DIGITAL", - "DOLBYDPL2ZH": "DOLBY DIGITAL", - "DOLBYDDS": "DOLBY DIGITAL", - "DOLBYAUDIODDDSUR": "DOLBY DIGITAL", - "DOLBYDNEOXC": "DOLBY DIGITAL", - "DOLBYDNEOXM": "DOLBY DIGITAL", - "DOLBYDNEOXG": "DOLBY DIGITAL", - "DOLBYDNEURALX": "DOLBY DIGITAL", - "DOLBYAUDIODDNEURALX": "DOLBY DIGITAL", - "DOLBYAUDIODDNERUALX": "DOLBY DIGITAL", - "DOLBYAUDIOTRUEHD": "DOLBY DIGITAL", - "DOLBYHDEX": "DOLBY DIGITAL", - "DOLBYHDPL2XC": "DOLBY DIGITAL", - "DOLBYHDPL2XM": "DOLBY DIGITAL", - "DOLBYHDPL2ZH": "DOLBY DIGITAL", - "DOLBYAUDIOTRUEHDDSUR": "DOLBY DIGITAL", - "DOLBYHDNEOXC": "DOLBY DIGITAL", - "DOLBYHDNEOXM": "DOLBY DIGITAL", - "DOLBYHDNEOXG": "DOLBY DIGITAL", - "DOLBYAUDIOTRUEHDNEURALX": "DOLBY DIGITAL", - "MULTIINDOLBYSURROUND": "DOLBY DIGITAL", - "DTSSURROUND": "DTS SURROUND", - "DTSDSUR": "DTS SURROUND", - "DTS9624": "DTS SURROUND", - "DTS96ESMTRX": "DTS SURROUND", - "DTSPL2XC": "DTS SURROUND", - "DTSPL2XM": "DTS SURROUND", - "DTSPL2ZH": "DTS SURROUND", - "DTSNEURALX": "DTS SURROUND", - "DTSVIRTUALX": "DTS SURROUND", - "DTSEXPRESS": "DTS SURROUND", - "DTSNEO6": "DTS SURROUND", - "DTSNEO6C": "DTS SURROUND", - "DTSNEO6M": "DTS SURROUND", - "DTSNEOXC": "DTS SURROUND", - "DTSNEOXM": "DTS SURROUND", - "DTSNEOXG": "DTS SURROUND", - "DTSESDSCRT61": "DTS SURROUND", - "DTSESMTRX61": "DTS SURROUND", - "DTSESMTRXNEURALX": "DTS SURROUND", - "DTSESDSCRTNEURALX": "DTS SURROUND", - "DTSES8CHDSCRT": "DTS SURROUND", - "DTSHD": "DTS SURROUND", - "DTSHDMSTR": "DTS SURROUND", - "DTSHDPL2XC": "DTS SURROUND", - "DTSHDPL2XM": "DTS SURROUND", - "DTSHDPL2ZH": "DTS SURROUND", - "DTSHDDSUR": "DTS SURROUND", - "DTSHDNEO6": "DTS SURROUND", - "DTSHDNEOXC": "DTS SURROUND", - "DTSHDNEOXM": "DTS SURROUND", - "DTSHDNEOXG": "DTS SURROUND", - "DTSHDNEURALX": "DTS SURROUND", - "DTSHDVIRTUALX": "DTS SURROUND", - "DTSX": "DTS SURROUND", - "DTSXMSTR": "DTS SURROUND", - "DTSXVIRTUALX": "DTS SURROUND", - "IMAXDTS": "DTS SURROUND", - "IMAXDTSX": "DTS SURROUND", - "IMAXDTSNEURALX": "DTS SURROUND", - "IMAXDTSVIRTUALX": "DTS SURROUND", - "IMAXDTSXVIRTUALX": "DTS SURROUND", - "IMAXDTSXNEURALX": "DTS SURROUND", - "MCHINDOLBYEX": "DTS SURROUND", - "MCHINPL2XC": "DTS SURROUND", - "MCHINPL2XM": "DTS SURROUND", - "MCHINPL2ZH": "DTS SURROUND", - "MCHINDSUR": "DTS SURROUND", - "MCHINNEOXC": "DTS SURROUND", - "MCHINNEOXM": "DTS SURROUND", - "MCHINNEOXG": "DTS SURROUND", - "MCHINNEURALX": "DTS SURROUND", - "MCHINVIRTUALX": "DTS SURROUND", - "MULTICHIN": "DTS SURROUND", - "MULTICHIN71": "DTS SURROUND", - "MULTIINNEURALX": "DTS SURROUND", - "MULTIINVIRTUALX": "DTS SURROUND", - "MPEG2AAC": "DTS SURROUND", - "AACDOLBYEX": "DTS SURROUND", - "AACPL2XC": "DTS SURROUND", - "AACPL2XM": "DTS SURROUND", - "AACPL2ZH": "DTS SURROUND", - "AACDSUR": "DTS SURROUND", - "AACDS": "DTS SURROUND", - "AACNEOXC": "DTS SURROUND", - "AACNEOXM": "DTS SURROUND", - "AACNEOXG": "DTS SURROUND", - "AACNEURALX": "DTS SURROUND", - "AACVIRTUALX": "DTS SURROUND", - "NEO6CDSX": "DTS SURROUND", - "NEO6MDSX": "DTS SURROUND", - "AUDYSSEYDSX": "DTS SURROUND", - "NEURALX": "DTS SURROUND", - "VIRTUALX": "DTS SURROUND", - "AURO3D": "AURO3D", - "AURO2DSURR": "AURO2DSURR", - "WISDESCREEN": "WIDE SCREEN", - "SUPERSTADIUM": "SUPER STADIUM", - "ROCKARENA": "ROCK ARENA", - "JAZZCLUB": "JAZZ CLUB", - "CLASSICCONCERT": "CLASSIC CONCERT", - "MONOMOVIE": "MONO MOVIE", - "MATRIX": "MATRIX", - "VIDEOGAME": "VIDEO GAME", - "VIRTUAL": "VIRTUAL", - "NEURAL": "NEURAL", - "STANDARD": "STANDARD", - "LEFT": "LEFT", - "RIGHT": "RIGHT" - }, - "InputConversion": { - "TV AUDIO": "TV", - "iPod/USB": "USB/IPOD", - "Bluetooth": "BT", - "Blu-ray": "BD", - "CBL/SAT": "SAT/CBL", - "AUX": "AUX1", - "NETWORK": "NET", - "HEOS": "NET", - "AirPlay": "NET", - "Online Music": "NET", - "Media Player": "MPLAY", - "Tuner": "TUNER", - "FM": "TUNER", - "SpotifyConnect": "SPOTIFYCONNECT", - "Internet Radio": "IRADIO", - "Media Server": "SERVER", - "Spotify": "SPOTIFY", - "Flickr": "FLICKR", - "Favorites": "FAVORITES", - "Quick Select1": "QUICK1", - "Quick Select2": "QUICK2", - "Quick Select3": "QUICK3", - "Quick Select4": "QUICK4", - "Quick Select5": "QUICK5", - "Quick Select1 Mode Memory": "QUICK1 MEMORY", - "Quick Select2 Mode Memory": "QUICK2 MEMORY", - "Quick Select3 Mode Memory": "QUICK3 MEMORY", - "Quick Select4 Mode Memory": "QUICK4 MEMORY", - "Quick Select5 Mode Memory": "QUICK5 MEMORY", - "Smart Select1": "SMART1", - "Smart Select2": "SMART2", - "Smart Select3": "SMART3", - "Smart Select4": "SMART4", - "Smart Select5": "SMART5", - "Smart Select1 Mode Memory": "SMART1 MEMORY", - "Smart Select2 Mode Memory": "SMART2 MEMORY", - "Smart Select3 Mode Memory": "SMART3 MEMORY", - "Smart Select4 Mode Memory": "SMART4 MEMORY", - "Smart Select5 Mode Memory": "SMART5 MEMORY" - }, - "PictureModesDenon": { - "Off": "OFF", - "Standard": "STANDARD", - "Movie": "MOVIE", - "Vivid": "VIVID", - "Stream": "STREAM", - "Custom": "CUSTOM", - "ISF Day": "ISF DAY", - "ISF Night": "ISF NIGHT" - }, - "PictureModesDenonString": { - "PVOFF": "OFF", - "PVSTD": "STANDARD", - "PVMOV": "MOVIE", - "PVVVD": "VIVID", - "PVSTM": "STREAM", - "PVDAY": "ISF DAY", - "PVNGT": "ISF NIGHT", - "PVCTM": "CUSTOM" - }, - "PictureModesDenonNumber": { - "0": "OFF", - "1": "STANDARD", - "2": "MOVIE", - "3": "VIVID", - "4": "STREAM", - "5": "ISF DAY", - "6": "ISF NIGHT", - "7": "CUSTOM" - }, - "PictureModesConversionToHomeKit": { - "0": 0, - "1": 1, - "2": 5, - "3": 4, - "4": 6, - "5": 2, - "6": 3, - "7": 7 - } -} \ No newline at end of file diff --git a/src/denon.js b/src/denon.js index e8c224e..902d02d 100644 --- a/src/denon.js +++ b/src/denon.js @@ -1,16 +1,16 @@ 'use strict'; -const fs = require('fs'); -const fsPromises = fs.promises; -const https = require('https'); -const axios = require('axios'); -const EventEmitter = require('events'); -const { XMLParser, XMLBuilder, XMLValidator } = require('fast-xml-parser'); -const ImpulseGenerator = require('./impulsegenerator.js'); -const CONSTANTS = require('./constants.json'); -const INPUTS_CONVERSION_KEYS = Object.keys(CONSTANTS.InputConversion); -const SOUND_MODES_CONVERSION_KEYS = Object.keys(CONSTANTS.SoundModeConversion); - -class DENON extends EventEmitter { +import { promises } from 'fs'; +const fsPromises = promises; +import axios from 'axios'; +import { Agent } from 'https'; +import EventEmitter from 'events'; +import ImpulseGenerator from './impulsegenerator.js'; +import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser'; +import { ApiUrls, InputConversion, SoundModeConversion, BodyXml, PictureModesDenonNumber, InputMode } from './constants.js'; +const INPUTS_CONVERSION_KEYS = Object.keys(InputConversion); +const SOUND_MODES_CONVERSION_KEYS = Object.keys(SoundModeConversion); + +class Denon extends EventEmitter { constructor(config) { super(); const host = config.host; @@ -25,7 +25,7 @@ class DENON extends EventEmitter { this.getFavoritesFromDevice = this.getInputsFromDevice ? config.getFavoritesFromDevice : false; this.getQuickSmartSelectFromDevice = this.getInputsFromDevice ? config.getQuickSmartSelectFromDevice : false; this.debugLog = config.debugLog; - this.deviceInfoUrl = [CONSTANTS.ApiUrls.DeviceInfoGen0, CONSTANTS.ApiUrls.DeviceInfoGen1, CONSTANTS.ApiUrls.DeviceInfoGen2][this.generation]; + this.deviceInfoUrl = [ApiUrls.DeviceInfoGen0, ApiUrls.DeviceInfoGen1, ApiUrls.DeviceInfoGen2][this.generation]; const baseUrl = `http://${host}:${port}`; this.axiosInstance = this.generation === 2 ? axios.create({ @@ -34,7 +34,7 @@ class DENON extends EventEmitter { timeout: 15000, maxContentLength: 100000000, maxBodyLength: 1000000000, - httpsAgent: new https.Agent({ + httpsAgent: new Agent({ rejectUnauthorized: false }) }) : axios.create({ @@ -49,7 +49,7 @@ class DENON extends EventEmitter { method: 'POST', baseURL: baseUrl, timeout: 15000, - httpsAgent: new https.Agent({ + httpsAgent: new Agent({ rejectUnauthorized: false }) }) : axios.create({ @@ -248,7 +248,7 @@ class DENON extends EventEmitter { async checkState() { try { //get zones status - const zoneStateUrl = [CONSTANTS.ApiUrls.MainZoneStatusLite, CONSTANTS.ApiUrls.Zone2StatusLite, CONSTANTS.ApiUrls.Zone3StatusLite, CONSTANTS.ApiUrls.SoundModeStatus][this.zone]; + const zoneStateUrl = [ApiUrls.MainZoneStatusLite, ApiUrls.Zone2StatusLite, ApiUrls.Zone3StatusLite, ApiUrls.SoundModeStatus][this.zone]; const deviceState = await this.axiosInstance(zoneStateUrl); const parseDeviceState = this.parseString.parse(deviceState.data); const devState = parseDeviceState.item; @@ -257,14 +257,14 @@ class DENON extends EventEmitter { //get receiver status const statusKeys = Object.keys(devState); const power = devState.Power.value === 'ON'; - const input = INPUTS_CONVERSION_KEYS.includes(devState.InputFuncSelect.value) ? CONSTANTS.InputConversion[devState.InputFuncSelect.value] : devState.InputFuncSelect.value; + const input = INPUTS_CONVERSION_KEYS.includes(devState.InputFuncSelect.value) ? InputConversion[devState.InputFuncSelect.value] : devState.InputFuncSelect.value; const volumeDisplay = statusKeys.includes('VolumeDisplay') ? devState.VolumeDisplay.value : this.volumeDisplay; const volume = parseFloat(devState.MasterVolume.value) >= -79.5 ? parseInt(devState.MasterVolume.value) + 80 : 0; const mute = devState.Mute.value === 'on'; //get picture mode const checkPictureMode = this.supportPictureMode && power && this.zone === 0; - const devicePictureMode = checkPictureMode ? await this.axiosInstancePost(CONSTANTS.ApiUrls.AppCommand, CONSTANTS.BodyXml.GetPictureMode) : false; + const devicePictureMode = checkPictureMode ? await this.axiosInstancePost(ApiUrls.AppCommand, BodyXml.GetPictureMode) : false; const parseDevicePictureMode = checkPictureMode ? this.parseString.parse(devicePictureMode.data) : false; const debug1 = this.debugLog && checkPictureMode ? this.emit('debug', `Picture mode: ${JSON.stringify(parseDevicePictureMode, null, 2)}`) : false; const pictureMode = checkPictureMode ? parseDevicePictureMode.rx.cmd.value : this.pictureMode; @@ -272,14 +272,14 @@ class DENON extends EventEmitter { //get sound mode const checkZone = this.zone === 0 || this.zone === 3; const checkSoundeMode = this.supportSoundMode && power && checkZone; - const deviceSoundMode = checkSoundeMode ? await this.axiosInstancePost(CONSTANTS.ApiUrls.AppCommand, CONSTANTS.BodyXml.GetSurroundModeStatus) : false; + const deviceSoundMode = checkSoundeMode ? await this.axiosInstancePost(ApiUrls.AppCommand, BodyXml.GetSurroundModeStatus) : false; const parseDeviceSoundMode = checkSoundeMode ? this.parseString.parse(deviceSoundMode.data) : false; const debug2 = this.debugLog && checkSoundeMode ? this.emit('debug', `Sound mode: ${JSON.stringify(parseDeviceSoundMode, null, 2)}`) : false; - const soundMode = checkSoundeMode ? SOUND_MODES_CONVERSION_KEYS.includes((parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase()) ? CONSTANTS.SoundModeConversion[(parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase()] : (parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase() : this.soundMode; + const soundMode = checkSoundeMode ? SOUND_MODES_CONVERSION_KEYS.includes((parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase()) ? SoundModeConversion[(parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase()] : (parseDeviceSoundMode.rx.cmd.surround).replace(/[^a-zA-Z0-9]/g, '').toUpperCase() : this.soundMode; //get audyssey mode const checkAudysseyMode = false //power && zone === 0; - const deviceAudysseyMode = checkAudysseyMode ? await this.axiosInstancePost(CONSTANTS.ApiUrls.AppCommand, CONSTANTS.BodyXml.GetAudyssey) : false; + const deviceAudysseyMode = checkAudysseyMode ? await this.axiosInstancePost(ApiUrls.AppCommand, BodyXml.GetAudyssey) : false; const parseDeviceAudysseyMode = checkAudysseyMode ? this.parseString.parse(deviceAudysseyMode.data) : false; const debug3 = this.debugLog && checkAudysseyMode ? this.emit('debug', `Audyssey mode: ${JSON.stringify(parseDeviceAudysseyMode, null, 2)}`) : false; const audysseyMode = checkAudysseyMode ? parseDeviceAudysseyMode.rx.cmd.value : this.audysseyMode; @@ -290,13 +290,13 @@ class DENON extends EventEmitter { //restFul this.emit('restFul', 'info', this.devInfo); this.emit('restFul', 'state', devState); - const restFul1 = checkPictureMode ? this.emit('restFul', 'picture', { 'Picture Mode': CONSTANTS.PictureModesDenonNumber[pictureMode] }) : false; + const restFul1 = checkPictureMode ? this.emit('restFul', 'picture', { 'Picture Mode': PictureModesDenonNumber[pictureMode] }) : false; const restFul2 = checkSoundeMode ? this.emit('restFul', 'surround', { 'Sound Mode': soundMode }) : false; //mqtt this.emit('mqtt', 'Info', this.devInfo); this.emit('mqtt', 'State', devState); - const mqtt2 = checkPictureMode ? this.emit('mqtt', 'Picture', { 'Picture Mode': CONSTANTS.PictureModesDenonNumber[pictureMode] }) : false; + const mqtt2 = checkPictureMode ? this.emit('mqtt', 'Picture', { 'Picture Mode': PictureModesDenonNumber[pictureMode] }) : false; const mqtt3 = checkSoundeMode ? this.emit('mqtt', 'Surround', { 'Sound Mode': soundMode }) : false; //update only if value change @@ -408,7 +408,7 @@ class DENON extends EventEmitter { const allInputs = []; for (const input of tempInputs) { const inputName = input.name; - let inputReference = INPUTS_CONVERSION_KEYS.includes(input.reference) ? CONSTANTS.InputConversion[input.reference] : input.reference; + let inputReference = INPUTS_CONVERSION_KEYS.includes(input.reference) ? InputConversion[input.reference] : input.reference; let inputMode = 'SI'; //zones @@ -416,14 +416,14 @@ class DENON extends EventEmitter { case 0: //Denon const inputReferenceSubstring = inputReference.substring(0, 5) ?? 'Unknown'; - const inputModeExist = inputReferenceSubstring in CONSTANTS.InputMode; + const inputModeExist = inputReferenceSubstring in InputMode; //Marantz M-CR611 const inputReferenceSubstring1 = inputReference.substring(0, 2) ?? 'Unknown'; - const inputModeExist1 = inputReferenceSubstring1 in CONSTANTS.InputMode; + const inputModeExist1 = inputReferenceSubstring1 in InputMode; inputReference = inputModeExist1 ? inputReference.substring(3) : inputReference; - inputMode = inputModeExist ? CONSTANTS.InputMode[inputReferenceSubstring] : inputModeExist1 ? CONSTANTS.InputMode[inputReferenceSubstring1] : inputMode; + inputMode = inputModeExist ? InputMode[inputReferenceSubstring] : inputModeExist1 ? InputMode[inputReferenceSubstring1] : inputMode; break; case 1: inputMode = 'Z2'; @@ -469,7 +469,7 @@ class DENON extends EventEmitter { async send(command) { try { - const path = `${CONSTANTS.ApiUrls.iPhoneDirect}${command}`; + const path = `${ApiUrls.iPhoneDirect}${command}`; await this.axiosInstance(path); return true; } catch (error) { @@ -477,4 +477,4 @@ class DENON extends EventEmitter { }; }; }; -module.exports = DENON; +export default Denon; diff --git a/src/impulsegenerator.js b/src/impulsegenerator.js index 75af0b9..c5edded 100644 --- a/src/impulsegenerator.js +++ b/src/impulsegenerator.js @@ -1,5 +1,5 @@ "use strict"; -const EventEmitter = require('events'); +import EventEmitter from 'events'; class ImpulseGenerator extends EventEmitter { constructor() { @@ -15,7 +15,7 @@ class ImpulseGenerator extends EventEmitter { this.timers = []; for (const timer of timers) { this.emit(timer.name); - + const newTimer = setInterval(() => { this.emit(timer.name); }, timer.sampling); @@ -39,7 +39,7 @@ class ImpulseGenerator extends EventEmitter { this.timersState = false; this.state(); - return true; + return true } state() { @@ -47,4 +47,4 @@ class ImpulseGenerator extends EventEmitter { return this.timersState; } } -module.exports = ImpulseGenerator; +export default ImpulseGenerator; diff --git a/src/mainzone.js b/src/mainzone.js index 787f2db..80e990f 100644 --- a/src/mainzone.js +++ b/src/mainzone.js @@ -1,11 +1,11 @@ 'use strict'; -const fs = require('fs'); -const fsPromises = fs.promises; -const EventEmitter = require('events'); -const RestFul = require('./restful.js'); -const Mqtt = require('./mqtt.js'); -const Denon = require('./denon.js'); -const CONSTANTS = require('./constants.json'); +import { promises } from 'fs'; +const fsPromises = promises; +import EventEmitter from 'events'; +import Mqtt from './mqtt.js'; +import RestFul from './restful.js'; +import Denon from './denon.js'; +import { PictureModesConversionToHomeKit, PictureModesDenonNumber, PictureModesDenonString, DirectSoundMode } from './constants.js'; let Accessory, Characteristic, Service, Categories, Encode, AccessoryUUID; class MainZone extends EventEmitter { @@ -254,7 +254,7 @@ class MainZone extends EventEmitter { const input = this.inputsConfigured.find(input => input.reference === reference) ?? false; const inputIdentifier = input ? input.identifier : this.inputIdentifier; mute = power ? mute : true; - const pictureModeHomeKit = CONSTANTS.PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; + const pictureModeHomeKit = PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; if (this.televisionService) { this.televisionService @@ -358,7 +358,7 @@ class MainZone extends EventEmitter { this.emit('message', `Volume: ${volume - 80}dB`); this.emit('message', `Mute: ${mute ? 'ON' : 'OFF'}`); this.emit('message', `Volume Control Type: ${volumeControlType}`); - this.emit('message', `Picture Mode: ${CONSTANTS.PictureModesDenonNumber[pictureMode]}`); + this.emit('message', `Picture Mode: ${PictureModesDenonNumber[pictureMode]}`); }; }) .on('success', (message) => { @@ -661,7 +661,7 @@ class MainZone extends EventEmitter { } await this.denon.send(command); - const info = this.disableLogInfo ? false : this.emit('message', `set Picture Mode: ${CONSTANTS.PictureModesDenonString[command]}`); + const info = this.disableLogInfo ? false : this.emit('message', `set Picture Mode: ${PictureModesDenonString[command]}`); } catch (error) { this.emit('warn', `set Picture Mode error: ${error}`); }; @@ -1037,7 +1037,7 @@ class MainZone extends EventEmitter { }) .onSet(async (state) => { try { - const directSound = CONSTANTS.DirectSoundMode[buttonReference] ?? false; + const directSound = DirectSoundMode[buttonReference] ?? false; const directSoundModeMode = directSound ? directSound.mode : false; const directSoundModeSurround = directSound ? directSound.surround : false; const command = directSound ? directSoundModeMode : buttonReference.substring(1); @@ -1064,4 +1064,4 @@ class MainZone extends EventEmitter { } }; -module.exports = MainZone; +export default MainZone; diff --git a/src/mqtt.js b/src/mqtt.js index 2459847..3388791 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -1,6 +1,7 @@ "use strict"; -const AsyncMqtt = require("async-mqtt"); -const EventEmitter = require('events'); +import asyncMqtt from 'async-mqtt'; +const { connectAsync } = asyncMqtt; +import EventEmitter from 'events'; class Mqtt extends EventEmitter { constructor(config) { @@ -16,7 +17,7 @@ class Mqtt extends EventEmitter { this.on('connect', async () => { try { //connect - this.mqttClient = await AsyncMqtt.connectAsync(url, options); + this.mqttClient = await connectAsync(url, options); this.emit('connected', 'MQTT Connected.'); //subscribe @@ -52,4 +53,4 @@ class Mqtt extends EventEmitter { this.emit('connect'); }; }; -module.exports = Mqtt; \ No newline at end of file +export default Mqtt \ No newline at end of file diff --git a/src/restful.js b/src/restful.js index 9ac725a..8be05e9 100644 --- a/src/restful.js +++ b/src/restful.js @@ -1,6 +1,6 @@ "use strict"; -const express = require('express'); -const EventEmitter = require('events'); +import express, { json } from 'express'; +import EventEmitter from 'events'; class RestFul extends EventEmitter { constructor(config) { @@ -22,7 +22,7 @@ class RestFul extends EventEmitter { try { const restFul = express(); restFul.set('json spaces', 2); - restFul.use(express.json()); + restFul.use(json()); restFul.get('/info', (req, res) => { res.json(this.restFulData.info) }); restFul.get('/state', (req, res) => { res.json(this.restFulData.state) }); restFul.get('/picture', (req, res) => { res.json(this.restFulData.picture) }); @@ -72,4 +72,4 @@ class RestFul extends EventEmitter { const emitDebug = this.restFulDebug ? this.emit('debug', `RESTFul update path: ${path}, data: ${data}`) : false; }; }; -module.exports = RestFul; \ No newline at end of file +export default RestFul; \ No newline at end of file diff --git a/src/surround.js b/src/surround.js index 87e506e..0300ec9 100644 --- a/src/surround.js +++ b/src/surround.js @@ -1,11 +1,11 @@ 'use strict'; -const fs = require('fs'); -const fsPromises = fs.promises; -const EventEmitter = require('events'); -const RestFul = require('./restful.js'); -const Mqtt = require('./mqtt.js'); -const Denon = require('./denon.js'); -const CONSTANTS = require('./constants.json'); +import { promises } from 'fs'; +const fsPromises = promises; +import EventEmitter from 'events'; +import Mqtt from './mqtt.js'; +import RestFul from './restful.js'; +import Denon from './denon.js'; +import { PictureModesConversionToHomeKit, PictureModesDenonNumber } from './constants.js'; let Accessory, Characteristic, Service, Categories, Encode, AccessoryUUID; class Surround extends EventEmitter { @@ -235,7 +235,7 @@ class Surround extends EventEmitter { const input = this.inputsConfigured.find(input => input.reference === reference) ?? false; const inputIdentifier = input ? input.identifier : this.inputIdentifier; mute = power ? mute : true; - const pictureModeHomeKit = CONSTANTS.PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; + const pictureModeHomeKit = PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; if (this.televisionService) { this.televisionService @@ -324,7 +324,7 @@ class Surround extends EventEmitter { this.emit('message', `Volume: ${volume - 80}dB`); this.emit('message', `Mute: ${mute ? 'ON' : 'OFF'}`); this.emit('message', `Volume Control Type: ${volumeControlType}`); - this.emit('message', `Picture Mode: ${CONSTANTS.PictureModesDenonNumber[pictureMode]}`); + this.emit('message', `Picture Mode: ${PictureModesDenonNumber[pictureMode]}`); }; }) .on('success', (message) => { @@ -914,4 +914,4 @@ class Surround extends EventEmitter { } }; -module.exports = Surround; +export default Surround; diff --git a/src/zone2.js b/src/zone2.js index 4931d98..367151d 100644 --- a/src/zone2.js +++ b/src/zone2.js @@ -1,11 +1,11 @@ 'use strict'; -const fs = require('fs'); -const fsPromises = fs.promises; -const EventEmitter = require('events'); -const RestFul = require('./restful.js'); -const Mqtt = require('./mqtt.js'); -const Denon = require('./denon.js'); -const CONSTANTS = require('./constants.json'); +import { promises } from 'fs'; +const fsPromises = promises; +import EventEmitter from 'events'; +import Mqtt from './mqtt.js'; +import RestFul from './restful.js'; +import Denon from './denon.js'; +import { PictureModesConversionToHomeKit, PictureModesDenonNumber } from './constants.js'; let Accessory, Characteristic, Service, Categories, Encode, AccessoryUUID; class Zone2 extends EventEmitter { @@ -254,7 +254,7 @@ class Zone2 extends EventEmitter { const input = this.inputsConfigured.find(input => input.reference === reference) ?? false; const inputIdentifier = input ? input.identifier : this.inputIdentifier; mute = power ? mute : true; - const pictureModeHomeKit = CONSTANTS.PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; + const pictureModeHomeKit = PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; if (this.televisionService) { this.televisionService @@ -354,7 +354,7 @@ class Zone2 extends EventEmitter { this.emit('message', `Volume: ${volume - 80}dB`); this.emit('message', `Mute: ${mute ? 'ON' : 'OFF'}`); this.emit('message', `Volume Control Type: ${volumeControlType}`); - this.emit('message', `Picture Mode: ${CONSTANTS.PictureModesDenonNumber[pictureMode]}`); + this.emit('message', `Picture Mode: ${PictureModesDenonNumber[pictureMode]}`); }; }) .on('success', (message) => { @@ -972,4 +972,4 @@ class Zone2 extends EventEmitter { } }; -module.exports = Zone2; +export default Zone2; diff --git a/src/zone3.js b/src/zone3.js index be80bba..1cb96db 100644 --- a/src/zone3.js +++ b/src/zone3.js @@ -1,11 +1,11 @@ 'use strict'; -const fs = require('fs'); -const fsPromises = fs.promises; -const EventEmitter = require('events'); -const RestFul = require('./restful.js'); -const Mqtt = require('./mqtt.js'); -const Denon = require('./denon.js'); -const CONSTANTS = require('./constants.json'); +import { promises } from 'fs'; +const fsPromises = promises; +import EventEmitter from 'events'; +import Mqtt from './mqtt.js'; +import RestFul from './restful.js'; +import Denon from './denon.js'; +import { PictureModesConversionToHomeKit, PictureModesDenonNumber } from './constants.js'; let Accessory, Characteristic, Service, Categories, Encode, AccessoryUUID; class Zone3 extends EventEmitter { @@ -254,7 +254,7 @@ class Zone3 extends EventEmitter { const input = this.inputsConfigured.find(input => input.reference === reference) ?? false; const inputIdentifier = input ? input.identifier : this.inputIdentifier; mute = power ? mute : true; - const pictureModeHomeKit = CONSTANTS.PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; + const pictureModeHomeKit = PictureModesConversionToHomeKit[pictureMode] ?? this.pictureMode; if (this.televisionService) { this.televisionService @@ -354,7 +354,7 @@ class Zone3 extends EventEmitter { this.emit('message', `Volume: ${volume - 80}dB`); this.emit('message', `Mute: ${mute ? 'ON' : 'OFF'}`); this.emit('message', `Volume Control Type: ${volumeControlType}`); - this.emit('message', `Picture Mode: ${CONSTANTS.PictureModesDenonNumber[pictureMode]}`); + this.emit('message', `Picture Mode: ${PictureModesDenonNumber[pictureMode]}`); }; }) .on('success', (message) => { @@ -971,4 +971,4 @@ class Zone3 extends EventEmitter { } }; -module.exports = Zone3; +export default Zone3;