homebridge-denon-tv 4.9.13 → 4.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ Tested Denon AVR-2112CI, AVR-3311CI, AVR-X6300H, AVR-X2700H, AVC-X4800H, Marantz
37
37
  * Digital Input Modes can be controlled by creating separate tile in the buttons section.
38
38
  * Siri can be used for all functions, some times need create legacy buttons/switches/sensors.
39
39
  * Automations can be used for all functions, some times need create legacy buttons/switches/sensors.
40
- * This plugin is based upon the official documentation: [Denon Control Protocol 2020](https://github.com/grzegorz914/homebridge-denon-tv/blob/main/src/Denon%20Control%20Protocol.xlsx)
40
+ * This plugin is based upon the official documentation: [Denon Control Protocol 2020](https://github.com/grzegorz914/homebridge-denon-tv/blob/main/doc/Denon%20Control%20Protocol.xlsx)
41
41
  * RESTful server:
42
42
  * Request: `http//homebridge_ip_address:port/path`.
43
43
  * Path: `info`, `state`, `picture`, `surround`.
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
+ const RestFul = require('./src/restful.js');
5
+ const Mqtt = require('./src/mqtt.js');
4
6
  const DenonDevice = require('./src/denondevice.js');
5
7
  const CONSTANS = require('./src/constans.json');
6
8
 
@@ -21,33 +23,101 @@ class DenonPlatform {
21
23
 
22
24
  api.on('didFinishLaunching', async () => {
23
25
  for (const device of config.devices) {
24
- if (!device.name || !device.host || !device.port || !(device.zoneControl >= 0 && device.zoneControl <= 3)) {
25
- log.warn(`Name: ${device.name ? 'OK' : device.name}, host: ${device.host ? 'OK' : device.host}, port: ${device.port ? 'OK' : device.port}, zone: ${(device.zoneControl >= 0 && device.zoneControl <= 3) ? 'OK' : device.zoneControl}, in config wrong or missing.`);
26
+ const deviceName = device.name;
27
+ const host = device.host;
28
+ const port = device.port;
29
+ const zoneControl = device.zoneControl;
30
+
31
+ if (!deviceName || !host || !port || !(zoneControl >= 0 && zoneControl <= 3)) {
32
+ log.warn(`Name: ${deviceName ? 'OK' : deviceName}, host: ${host ? 'OK' : host}, port: ${port ? 'OK' : port}, zone: ${(zoneControl >= 0 && zoneControl <= 3) ? 'OK' : zoneControl}, in config wrong or missing.`);
26
33
  return;
27
34
  }
28
35
  await new Promise(resolve => setTimeout(resolve, 500))
29
36
 
30
37
  //debug config
31
- const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, did finish launching.`) : false;
32
- const debug1 = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, Config: ${JSON.stringify(device, null, 2)}`) : false;
38
+ const enableDebugMode = device.enableDebugMode || false;
39
+ const debug = enableDebugMode ? log(`Device: ${host} ${deviceName}, did finish launching.`) : false;
40
+ const debug1 = enableDebugMode ? log(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(device, null, 2)}`) : false;
41
+
42
+ //RESTFul server
43
+ const restFulEnabled = device.enableRestFul || false;
44
+ if (restFulEnabled) {
45
+ this.restFulConnected = false;
46
+ const restFulPort = device.restFulPort || 3000;
47
+ const restFulDebug = device.restFulDebug || false;
48
+ this.restFul = new RestFul({
49
+ port: restFulPort,
50
+ debug: restFulDebug
51
+ });
52
+
53
+ this.restFul.on('connected', (message) => {
54
+ log(`Device: ${host} ${deviceName}, ${message}`);
55
+ this.restFulConnected = true;
56
+ })
57
+ .on('error', (error) => {
58
+ log.error(`Device: ${host} ${deviceName}, ${error}`);
59
+ })
60
+ .on('debug', (debug) => {
61
+ log(`Device: ${host} ${deviceName}, debug: ${debug}`);
62
+ });
63
+ }
64
+
65
+ //MQTT client
66
+ const mqttEnabled = device.enableMqtt || false;
67
+ if (mqttEnabled) {
68
+ this.mqttConnected = false;
69
+ const mqttHost = device.mqttHost;
70
+ const mqttPort = device.mqttPort || 1883;
71
+ const mqttClientId = device.mqttClientId || `Denon_${Math.random().toString(16).slice(3)}`;
72
+ const mqttPrefix = device.mqttPrefix;
73
+ const mqttUser = device.mqttUser;
74
+ const mqttPasswd = device.mqttPasswd;
75
+ const mqttDebug = device.mqttDebug || false;
76
+ this.mqtt = new Mqtt({
77
+ host: mqttHost,
78
+ port: mqttPort,
79
+ clientId: mqttClientId,
80
+ user: mqttUser,
81
+ passwd: mqttPasswd,
82
+ prefix: `${mqttPrefix}/${deviceName}`,
83
+ debug: mqttDebug
84
+ });
85
+
86
+ this.mqtt.on('connected', (message) => {
87
+ log(`Device: ${host} ${deviceName}, ${message}`);
88
+ this.mqttConnected = true;
89
+ })
90
+ .on('error', (error) => {
91
+ log.error(`Device: ${host} ${deviceName}, ${error}`);
92
+ })
93
+ .on('debug', (debug) => {
94
+ log(`Device: ${host} ${deviceName}, debug: ${debug}`);
95
+ });
96
+ }
33
97
 
34
98
  //denon device
35
99
  const denonDevice = new DenonDevice(api, prefDir, device);
36
100
  denonDevice.on('publishAccessory', (accessory) => {
37
101
  api.publishExternalAccessories(CONSTANS.PluginName, [accessory]);
38
- const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, published as external accessory.`) : false;
102
+ const debug = enableDebugMode ? log(`Device: ${host} ${deviceName}, published as external accessory.`) : false;
39
103
  })
40
104
  .on('devInfo', (devInfo) => {
41
105
  log(devInfo);
42
106
  })
43
107
  .on('message', (message) => {
44
- log(`Device: ${device.host} ${device.name}, ${message}`);
108
+ log(`Device: ${host} ${deviceName}, ${message}`);
45
109
  })
46
110
  .on('debug', (debug) => {
47
- log(`Device: ${device.host} ${device.name}, debug: ${debug}`);
111
+ log(`Device: ${host} ${deviceName}, debug: ${debug}`);
48
112
  })
49
113
  .on('error', (error) => {
50
- log.error(`Device: ${device.host} ${device.name}, ${error}`);
114
+ log.error(`Device: ${host} ${deviceName}, ${error}`);
115
+ })
116
+ .on('restFul', (path, data) => {
117
+ const restFul = this.restFulConnected ? this.restFul.update(path, data) : false;
118
+ })
119
+ .on('mqtt', (topic, message) => {
120
+ const mqtt = this.mqttConnected ? this.mqtt.send(topic, message) : false;
51
121
  });
52
122
  }
53
123
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "4.9.13",
4
+ "version": "4.9.16",
5
5
  "description": "Homebridge plugin to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "async-mqtt": "^2.6.3",
32
32
  "axios": "^1.6.7",
33
- "fast-xml-parser": "^4.3.4",
33
+ "fast-xml-parser": "^4.3.5",
34
34
  "express": "^4.18.2"
35
35
  },
36
36
  "keywords": [
package/src/denon.js CHANGED
@@ -26,8 +26,6 @@ class DENON extends EventEmitter {
26
26
  const debugLog = config.debugLog;
27
27
  const disableLogConnectError = config.disableLogConnectError;
28
28
  const refreshInterval = config.refreshInterval;
29
- const restFulEnabled = config.restFulEnabled;
30
- const mqttEnabled = config.mqttEnabled;
31
29
  const deviceInfoUrl = [CONSTANS.ApiUrls.DeviceInfoGen0, CONSTANS.ApiUrls.DeviceInfoGen1, CONSTANS.ApiUrls.DeviceInfoGen2][generation];
32
30
 
33
31
  this.debugLog = debugLog;
@@ -38,13 +36,17 @@ class DENON extends EventEmitter {
38
36
  method: 'GET',
39
37
  baseURL: baseUrl,
40
38
  timeout: 10000,
39
+ maxContentLength: 100000000,
40
+ maxBodyLength: 1000000000,
41
41
  httpsAgent: new https.Agent({
42
42
  rejectUnauthorized: false
43
43
  })
44
44
  }) : axios.create({
45
45
  method: 'GET',
46
46
  baseURL: baseUrl,
47
- timeout: 10000
47
+ timeout: 10000,
48
+ maxContentLength: 100000000,
49
+ maxBodyLength: 1000000000,
48
50
  });
49
51
 
50
52
  this.axiosInstancePost = generation === 2 ? axios.create({
@@ -210,10 +212,10 @@ class DENON extends EventEmitter {
210
212
  this.emitDeviceInfo = false;
211
213
 
212
214
  //restFul
213
- const restFul = restFulEnabled ? this.emit('restFul', 'info', devInfo) : false;
215
+ this.emit('restFul', 'info', devInfo);
214
216
 
215
217
  //mqtt
216
- const mqtt = mqttEnabled ? this.emit('mqtt', 'Info', devInfo) : false;
218
+ this.emit('mqtt', 'Info', devInfo);
217
219
 
218
220
  this.supportPictureMode = supportPictureMode;
219
221
  this.supportSoundMode = supportSoundMode;
@@ -290,14 +292,14 @@ class DENON extends EventEmitter {
290
292
  this.emit('stateChanged', power, reference, volume, volumeDisplay, mute, pictureMode);
291
293
 
292
294
  //restFul
293
- const restFul = restFulEnabled ? this.emit('restFul', 'state', devState) : false;
294
- const restFul1 = restFulEnabled && checkPictureMode ? this.emit('restFul', 'picture', { 'Picture Mode': CONSTANS.PictureModesDenonNumber[pictureMode] }) : false;
295
- const restFul2 = restFulEnabled && checkSoundeMode ? this.emit('restFul', 'surround', { 'Sound Mode': CONSTANS.SoundModeConversion[soundMode] }) : false;
295
+ this.emit('restFul', 'state', devState);
296
+ const restFul1 = checkPictureMode ? this.emit('restFul', 'picture', { 'Picture Mode': CONSTANS.PictureModesDenonNumber[pictureMode] }) : false;
297
+ const restFul2 = checkSoundeMode ? this.emit('restFul', 'surround', { 'Sound Mode': CONSTANS.SoundModeConversion[soundMode] }) : false;
296
298
 
297
299
  //mqtt
298
- const mqtt1 = mqttEnabled ? this.emit('mqtt', 'State', devState) : false;
299
- const mqtt2 = mqttEnabled && checkPictureMode ? this.emit('mqtt', 'Picture', { 'Picture Mode': CONSTANS.PictureModesDenonNumber[pictureMode] }) : false;
300
- const mqtt3 = mqttEnabled && checkSoundeMode ? this.emit('mqtt', 'Surround', { 'Sound Mode': CONSTANS.SoundModeConversion[soundMode] }) : false;
300
+ this.emit('mqtt', 'State', devState);
301
+ const mqtt2 = checkPictureMode ? this.emit('mqtt', 'Picture', { 'Picture Mode': CONSTANS.PictureModesDenonNumber[pictureMode] }) : false;
302
+ const mqtt3 = checkSoundeMode ? this.emit('mqtt', 'Surround', { 'Sound Mode': CONSTANS.SoundModeConversion[soundMode] }) : false;
301
303
 
302
304
  this.checkState();
303
305
  } catch (error) {
@@ -346,7 +348,7 @@ class DENON extends EventEmitter {
346
348
  const inputsArr = [];
347
349
  let i = 0;
348
350
  for (const input of inputs) {
349
- const inputNameOldAvr = generation === 0 ? devInfo.RenameSource.value[i].trim() !== '' ? devInfo.RenameSource.value[i] : inputs[i] : '';
351
+ const inputNameOldAvr = getInputsFromDevice && generation === 0 ? devInfo.RenameSource.value[i].trim() !== '' ? devInfo.RenameSource.value[i] : inputs[i] : `Input ${i}`;
350
352
  const inputName = getInputsFromDevice ? [inputNameOldAvr, input.DefaultName, input.DefaultName][generation] : input.name;
351
353
  const inputReference = getInputsFromDevice ? [input, input.FuncName, input.FuncName][generation] : input.reference;
352
354
  const obj = {
@@ -2,14 +2,12 @@
2
2
  const fs = require('fs');
3
3
  const fsPromises = fs.promises;
4
4
  const EventEmitter = require('events');
5
- const RestFul = require('./restful.js');
6
- const Mqtt = require('./mqtt.js');
7
5
  const Denon = require('./denon.js');
8
6
  const CONSTANS = require('./constans.json');
9
7
  let Accessory, Characteristic, Service, Categories, Encode, UUID;
10
8
 
11
9
  class DenonDevice extends EventEmitter {
12
- constructor(api, prefDir, config) {
10
+ constructor(api, prefDir, device) {
13
11
  super();
14
12
 
15
13
  Accessory = api.platformAccessory;
@@ -20,54 +18,38 @@ class DenonDevice extends EventEmitter {
20
18
  UUID = api.hap.uuid;
21
19
 
22
20
  //device configuration
23
- this.name = config.name;
24
- this.host = config.host;
25
- this.port = config.port;
26
- this.generation = config.generation || 0;
27
- this.zone = config.zoneControl || 0;
28
- this.getInputsFromDevice = [config.getInputsFromDevice, config.getInputsFromDevice, config.getInputsFromDevice, false][config.zoneControl] || false;
29
- this.getFavoritesFromDevice = this.getInputsFromDevice ? config.getFavoritesFromDevice : false;
30
- this.getQuickSmartSelectFromDevice = this.getInputsFromDevice ? config.getQuickSmartSelectFromDevice : false;
31
- this.inputsDisplayOrder = config.inputsDisplayOrder || 0;
32
- this.inputs = [config.inputs, config.inputs, config.inputs, config.surrounds][config.zoneControl] || [];
33
- this.buttons = [config.buttons, config.buttonsZ2, config.buttonsZ3, []][config.zoneControl] || [];
34
- this.sensorPower = config.sensorPower || false;
35
- this.sensorVolume = config.sensorVolume || false
36
- this.sensorMute = config.sensorMute || false;
37
- this.sensorInput = config.sensorInput || false;
38
- this.sensorInputs = config.sensorInputs || [];
39
- this.enableDebugMode = config.enableDebugMode || false;
40
- this.disableLogInfo = config.disableLogInfo || false;
41
- this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
42
- this.disableLogConnectError = config.disableLogConnectError || false;
43
- this.masterPower = config.masterPower || false;
44
- this.masterVolume = config.masterVolume || false;
45
- this.masterMute = config.masterMute || false;
46
- this.infoButtonCommand = config.infoButtonCommand || 'MNINF';
47
- this.volumeControl = config.volumeControl || false;
48
- this.refreshInterval = config.refreshInterval || 5;
49
- this.restFulEnabled = config.enableRestFul || false;
50
- this.restFulPort = config.restFulPort || 3000;
51
- this.restFulDebug = config.restFulDebug || false;
52
- this.mqttEnabled = config.enableMqtt || false;
53
- this.mqttHost = config.mqttHost;
54
- this.mqttPort = config.mqttPort || 1883;
55
- this.mqttClientId = config.mqttClientId || `denon_${Math.random().toString(16).slice(3)}`;
56
- this.mqttPrefix = config.mqttPrefix;
57
- this.mqttAuth = config.mqttAuth || false;
58
- this.mqttUser = config.mqttUser;
59
- this.mqttPasswd = config.mqttPasswd;
60
- this.mqttDebug = config.mqttDebug || false;
21
+ this.name = device.name;
22
+ this.host = device.host;
23
+ this.port = device.port;
24
+ this.generation = device.generation || 0;
25
+ this.zone = device.zoneControl || 0;
26
+ this.getInputsFromDevice = [device.getInputsFromDevice, device.getInputsFromDevice, device.getInputsFromDevice, false][device.zoneControl] || false;
27
+ this.getFavoritesFromDevice = this.getInputsFromDevice ? device.getFavoritesFromDevice : false;
28
+ this.getQuickSmartSelectFromDevice = this.getInputsFromDevice ? device.getQuickSmartSelectFromDevice : false;
29
+ this.inputsDisplayOrder = device.inputsDisplayOrder || 0;
30
+ this.inputs = [device.inputs, device.inputs, device.inputs, device.surrounds][device.zoneControl] || [];
31
+ this.buttons = [device.buttons, device.buttonsZ2, device.buttonsZ3, []][device.zoneControl] || [];
32
+ this.sensorPower = device.sensorPower || false;
33
+ this.sensorVolume = device.sensorVolume || false
34
+ this.sensorMute = device.sensorMute || false;
35
+ this.sensorInput = device.sensorInput || false;
36
+ this.sensorInputs = device.sensorInputs || [];
37
+ this.enableDebugMode = device.enableDebugMode || false;
38
+ this.disableLogInfo = device.disableLogInfo || false;
39
+ this.disableLogDeviceInfo = device.disableLogDeviceInfo || false;
40
+ this.disableLogConnectError = device.disableLogConnectError || false;
41
+ this.masterPower = device.masterPower || false;
42
+ this.masterVolume = device.masterVolume || false;
43
+ this.masterMute = device.masterMute || false;
44
+ this.infoButtonCommand = device.infoButtonCommand || 'MNINF';
45
+ this.volumeControl = device.volumeControl || false;
46
+ this.refreshInterval = device.refreshInterval || 5;
61
47
 
62
48
  //zones
63
49
  this.zoneName = CONSTANS.ZoneName[this.zone];
64
50
  this.sZoneName = CONSTANS.ZoneNameShort[this.zone];
65
51
  this.zoneInputSurroundName = CONSTANS.ZoneInputSurroundName[this.zone];
66
52
 
67
- //external integrations
68
- this.restFulConnected = false;
69
- this.mqttConnected = false;
70
-
71
53
  //services
72
54
  this.allServices = [];
73
55
  this.sensorsInputsServices = [];
@@ -120,49 +102,6 @@ class DenonDevice extends EventEmitter {
120
102
  this.emit('error', `prepare files error: ${error}`);
121
103
  }
122
104
 
123
- //RESTFul server
124
- if (this.restFulEnabled) {
125
- this.restFul = new RestFul({
126
- port: this.restFulPort,
127
- debug: this.restFulDebug
128
- });
129
-
130
- this.restFul.on('connected', (message) => {
131
- this.emit('message', `${message}`);
132
- this.restFulConnected = true;
133
- })
134
- .on('error', (error) => {
135
- this.emit('error', error);
136
- })
137
- .on('debug', (debug) => {
138
- this.emit('debug', debug);
139
- });
140
- }
141
-
142
- //MQTT client
143
- if (this.mqttEnabled) {
144
- this.mqtt = new Mqtt({
145
- host: this.mqttHost,
146
- port: this.mqttPort,
147
- clientId: this.mqttClientId,
148
- user: this.mqttUser,
149
- passwd: this.mqttPasswd,
150
- prefix: `${this.mqttPrefix}/${this.name}`,
151
- debug: this.mqttDebug
152
- });
153
-
154
- this.mqtt.on('connected', (message) => {
155
- this.emit('message', message);
156
- this.mqttConnected = true;
157
- })
158
- .on('debug', (debug) => {
159
- this.emit('debug', debug);
160
- })
161
- .on('error', (error) => {
162
- this.emit('error', error);
163
- });
164
- };
165
-
166
105
  //denon client
167
106
  this.denon = new Denon({
168
107
  host: this.host,
@@ -179,8 +118,6 @@ class DenonDevice extends EventEmitter {
179
118
  debugLog: this.enableDebugMode,
180
119
  disableLogConnectError: this.disableLogConnectError,
181
120
  refreshInterval: this.refreshInterval,
182
- restFulEnabled: this.restFulEnabled,
183
- mqttEnabled: this.mqttEnabled
184
121
  });
185
122
 
186
123
  this.denon.on('deviceInfo', (manufacturer, modelName, serialNumber, firmwareRevision, deviceZones, apiVersion, supportPictureMode) => {
@@ -256,7 +193,7 @@ class DenonDevice extends EventEmitter {
256
193
  }
257
194
 
258
195
  if (this.sensorVolumeService && volume !== this.volume) {
259
- for (let i = 0; i < 1; i++) {
196
+ for (let i = 0; i < 2; i++) {
260
197
  const state = power ? [true, false][i] : false;
261
198
  this.sensorVolumeService
262
199
  .updateCharacteristic(Characteristic.ContactSensorState, state)
@@ -271,7 +208,7 @@ class DenonDevice extends EventEmitter {
271
208
  }
272
209
 
273
210
  if (this.sensorInputService && reference !== this.reference) {
274
- for (let i = 0; i < 1; i++) {
211
+ for (let i = 0; i < 2; i++) {
275
212
  const state = power ? [true, false][i] : false;
276
213
  this.sensorInputService
277
214
  .updateCharacteristic(Characteristic.ContactSensorState, state)
@@ -341,10 +278,10 @@ class DenonDevice extends EventEmitter {
341
278
  this.emit('error', error);
342
279
  })
343
280
  .on('restFul', (path, data) => {
344
- const restFul = this.restFulConnected ? this.restFul.update(path, data) : false;
281
+ this.emit('restFul', path, data)
345
282
  })
346
283
  .on('mqtt', (topic, message) => {
347
- const mqtt = this.mqttConnected ? this.mqtt.send(topic, message) : false;
284
+ this.emit('mqtt', topic, message)
348
285
  })
349
286
  .on('disconnected', (message) => {
350
287
  this.emit('message', message);
Binary file