homebridge-denon-tv 3.17.21 → 3.17.22-beta.0

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.
Files changed (4) hide show
  1. package/README.md +4 -43
  2. package/index.js +21 -17
  3. package/package.json +1 -1
  4. package/src/denon.js +30 -29
package/README.md CHANGED
@@ -23,21 +23,10 @@ This plugin is based upon the official documentation for communicating with and
23
23
  | Package | Installation | Role | Required |
24
24
  | --- | --- | --- | --- |
25
25
  | [Homebridge](https://github.com/homebridge/homebridge) | [Homebridge Wiki](https://github.com/homebridge/homebridge/wiki) | HomeKit Bridge | Required |
26
- | [Config UI X](https://github.com/oznu/homebridge-config-ui-x/wiki) | [Config UI X Wiki](https://github.com/oznu/homebridge-config-ui-x/wiki) | Web User Interface | Recommended |
27
- | [Denon TV](https://www.npmjs.com/package/homebridge-denon-tv) | `npm install -g homebridge-denon-tv` | Plug-In | Required |
26
+ | [Config UI X](https://github.com/oznu/homebridge-config-ui-x/wiki) | [Config UI X Wiki](https://github.com/oznu/homebridge-config-ui-x/wiki) | Homebridge Web User Interface | Recommended |
27
+ | [Denon TV](https://www.npmjs.com/package/homebridge-denon-tv) | [Plug-In Wiki](https://github.com/grzegorz914/homebridge-denon-tv/wiki) | Homebridge Plug-In | Required |
28
28
 
29
- ## Note
30
- * For homebridge-denon-tv versions 3.6.0 and above the minimum required version of Homebridge is 1.3.x.
31
- * If update to 3.15.0 need remove the accessory frome HomeKit app and add it again.
32
-
33
- ## Troubleshooting
34
- * If for some reason the device is not displayed in HomeKit app try this procedure:
35
- * Go to `./homebridge/persist` macOS or `/var/lib/homebridge/persist` for RPI.
36
- * Remove `AccessoryInfo.xxx` file which contain Your device data: `{"displayName":"AV Receiver"}`.
37
- * Next remove `IdentifierCashe.xxx` file with same name as `AccessoryInfo.xxx`.
38
- * Restart Homebridge and try add it to the HomeKit app again.
39
-
40
- ## Features and How To Use Them
29
+ ## About The Plugin
41
30
  * Multi Zone control.
42
31
  * Power ON/OFF short press tile in HomeKit app.
43
32
  * RC/Media control is possible after you go to the RC app on iPhone/iPad.
@@ -48,7 +37,7 @@ This plugin is based upon the official documentation for communicating with and
48
37
  * Digital Input Modes can be controlled by creating separate tile in the buttons section.
49
38
  * Siri can be used for all functions, some times need create legacy buttons/switches/sensors.
50
39
  * Automations can be used for all functions, some times need create legacy buttons/switches/sensors.
51
- * MQTT Client publisch all available data from device.
40
+ * MQTT publisch topic *Info*, *State* and *Sound Mode* as payload JSON data.
52
41
 
53
42
  <p align="left">
54
43
  <a href="https://github.com/grzegorz914/homebridge-denon-tv"><img src="https://raw.githubusercontent.com/grzegorz914/homebridge-denon-tv/main/graphics/homekit.png" width="382"></a>
@@ -288,31 +277,3 @@ This plugin is based upon the official documentation for communicating with and
288
277
  ]
289
278
  }
290
279
  ```
291
-
292
- ### Adding to HomeKit
293
- * Each accessory needs to be manually paired.
294
- * Open the Home <img src='https://user-images.githubusercontent.com/3979615/78010622-4ea1d380-738e-11ea-8a17-e6a465eeec35.png' width='16.42px'> app on your device.
295
- * Tap the Home tab, then tap <img src='https://user-images.githubusercontent.com/3979615/78010869-9aed1380-738e-11ea-9644-9f46b3633026.png' width='16.42px'>.
296
- * Tap *Add Accessory*, and select *I Don't Have a Code, Cannot Scan* or *More options*.
297
- * Select Your accessory and press add anyway.
298
- * Enter the PIN or scan the QR code, this can be found in Homebridge UI or Homebridge logs.
299
- * Complete the accessory setup.
300
-
301
- ## Limitations
302
- * That maximum Services for 1 accessory is 100. If Services > 100, accessory stop responding.
303
- * To solve this problem the plugin counts the number of Services and not allow add more as 100.
304
- * If You have configured more as 100 Services some inputs or buttons will not be available in the HomeKit app.
305
- * The Services in this accessory are:
306
- * Information.
307
- * Speaker.
308
- * Lightbulb.
309
- * Fan.
310
- * Television.
311
- * Inputs, which may range from 6 to 100 as each input is 1 service.
312
- * Buttons, which may range from 6 to 100 as each button is 1 service.
313
-
314
- ## [What's New](https://github.com/grzegorz914/homebridge-denon-tv/blob/main/CHANGELOG.md)
315
-
316
- ## Development
317
- Please feel free to create a Pull request and help in development. It will be highly appreciated.
318
-
package/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
  const fsPromises = fs.promises;
5
- const denon = require('./src/denon');
6
- const mqttClient = require('./src/mqtt.js');
5
+ const Mqtt = require('./src/mqtt.js');
6
+ const Denon = require('./src/denon');
7
7
 
8
8
  const PLUGIN_NAME = 'homebridge-denon-tv';
9
9
  const PLATFORM_NAME = 'DenonTv';
@@ -80,7 +80,7 @@ class denonTvDevice {
80
80
  this.buttonsZone2 = config.buttonsZone2 || [];
81
81
  this.buttonsZone3 = config.buttonsZone3 || [];
82
82
  this.soundModes = config.surrounds || [];
83
- this.enableMqtt = config.enableMqtt || false;
83
+ this.mqttEnabled = config.enableMqtt || false;
84
84
  this.mqttHost = config.mqttHost;
85
85
  this.mqttPort = config.mqttPort || 1883;
86
86
  this.mqttPrefix = config.mqttPrefix;
@@ -165,8 +165,8 @@ class denonTvDevice {
165
165
  };
166
166
 
167
167
  //mqtt client
168
- this.mqttClient = new mqttClient({
169
- enabled: this.enableMqtt,
168
+ this.mqtt = new Mqtt({
169
+ enabled: this.mqttEnabled,
170
170
  host: this.mqttHost,
171
171
  port: this.mqttPort,
172
172
  prefix: this.mqttPrefix,
@@ -177,7 +177,7 @@ class denonTvDevice {
177
177
  debug: this.mqttDebug
178
178
  });
179
179
 
180
- this.mqttClient.on('connected', (message) => {
180
+ this.mqtt.on('connected', (message) => {
181
181
  this.log(`Device: ${this.host} ${this.name}, ${message}`);
182
182
  })
183
183
  .on('error', (error) => {
@@ -194,28 +194,19 @@ class denonTvDevice {
194
194
  });
195
195
 
196
196
  //denon client
197
- this.denon = new denon({
197
+ this.denon = new Denon({
198
198
  host: this.host,
199
199
  port: this.port,
200
200
  infoLog: this.disableLogInfo,
201
201
  debugLog: this.enableDebugMode,
202
202
  zoneControl: this.zoneControl,
203
203
  devInfoFile: this.devInfoFile,
204
- mqttEnabled: this.enableMqtt
204
+ mqttEnabled: this.mqttEnabled
205
205
  });
206
206
 
207
207
  this.denon.on('connected', (message) => {
208
208
  this.log(`Device: ${this.host} ${this.name}, ${message}`);
209
209
  })
210
- .on('error', (error) => {
211
- this.log.error(`Device: ${this.host} ${this.name}, ${error}`);
212
- })
213
- .on('debug', (message) => {
214
- this.log(`Device: ${this.host} ${this.name}, debug: ${message}`);
215
- })
216
- .on('message', (message) => {
217
- this.log(`Device: ${this.host} ${this.name}, ${message}`);
218
- })
219
210
  .on('deviceInfo', (manufacturer, modelName, serialNumber, firmwareRevision, zones, apiVersion) => {
220
211
  if (!this.disableLogDeviceInfo) {
221
212
  this.log('-------- %s --------', this.name);
@@ -295,6 +286,15 @@ class denonTvDevice {
295
286
  this.prepareAccessory();
296
287
  };
297
288
  })
289
+ .on('error', (error) => {
290
+ this.log.error(`Device: ${this.host} ${this.name}, ${error}`);
291
+ })
292
+ .on('debug', (message) => {
293
+ this.log(`Device: ${this.host} ${this.name}, debug: ${message}`);
294
+ })
295
+ .on('message', (message) => {
296
+ this.log(`Device: ${this.host} ${this.name}, ${message}`);
297
+ })
298
298
  .on('mqtt', (topic, message) => {
299
299
  this.mqttClient.send(topic, message);
300
300
  })
@@ -344,6 +344,7 @@ class denonTvDevice {
344
344
  try {
345
345
  const setPower = (state != this.power) ? await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + newState) : false;
346
346
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set Power state successful, state: %s', this.host, accessoryName, newState);
347
+ this.power = state;
347
348
  } catch (error) {
348
349
  this.log.error('Device: %s %s, can not set Power state. Might be due to a wrong settings in config, error: %s', this.host, accessoryName, error);
349
350
  };
@@ -366,6 +367,7 @@ class denonTvDevice {
366
367
  try {
367
368
  const setInput = (inputReference != undefined) ? await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + inputRef) : false;
368
369
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set %s successful, name: %s, reference: %s', this.host, accessoryName, this.zoneControl <= 2 ? 'Input' : 'Sound Mode', inputName, inputRef);
370
+ this.inputIdentifier = inputIdentifier;
369
371
  } catch (error) {
370
372
  this.log.error('Device: %s %s, can not set %s. Might be due to a wrong settings in config, error: %s', this.host, accessoryName, this.zoneControl <= 2 ? 'Input' : 'Sound Mode', error);
371
373
  };
@@ -596,6 +598,7 @@ class denonTvDevice {
596
598
  try {
597
599
  const setVolume = await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + zone + volume);
598
600
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set new Volume level successful, volume: %s dB', this.host, accessoryName, volume - 80);
601
+ this.volume = volume;
599
602
  } catch (error) {
600
603
  this.log.error('Device: %s %s, can not set new Volume level. Might be due to a wrong settings in config, error: %s', this.host, accessoryName, error);
601
604
  };
@@ -614,6 +617,7 @@ class denonTvDevice {
614
617
  try {
615
618
  const toggleMute = (this.power && state != this.mute) ? await this.denon.send(CONSTANS.ApiUrls.iPhoneDirect + zone + newState) : false;
616
619
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s %s, set new Mute state successful, state: %s', this.host, accessoryName, state ? 'ON' : 'OFF');
620
+ this.mute = mute;
617
621
  } catch (error) {
618
622
  this.log.error('Device: %s %s, can not set new Mute state. Might be due to a wrong settings in config, error: %s', this.host, accessoryName, error);
619
623
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Denon TV",
3
3
  "name": "homebridge-denon-tv",
4
- "version": "3.17.21",
4
+ "version": "3.17.22-beta.0",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Denon/Marantz AV Receivers.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/denon.js CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
  const fs = require('fs');
3
3
  const fsPromises = fs.promises;
4
- const EventEmitter = require('events');
5
4
  const axios = require('axios');
6
- const parseStringPromise = require('xml2js').parseStringPromise;
7
-
5
+ const parseString = require('xml2js').parseStringPromise;
6
+ const EventEmitter = require('events');
8
7
  const CONSTANS = require('./constans.json');
9
- const soundModeStatus = `<?xml version="1.0" encoding="utf-8"?>
8
+
9
+ const SOUND_MODES_STATUS = `<?xml version="1.0" encoding="utf-8"?>
10
10
  <tx>
11
11
  <cmd id="1">${CONSTANS.BodyXml.GetSurroundModeStatus}</cmd>
12
12
  </tx>`;
13
- const configXml = {
14
- data: soundModeStatus,
13
+ const CONFIG_XML = {
14
+ data: SOUND_MODES_STATUS,
15
15
  headers: {
16
16
  'Content-Type': 'text/xml'
17
17
  }
@@ -60,21 +60,21 @@ class DENON extends EventEmitter {
60
60
  .on('checkDeviceInfo', async () => {
61
61
  try {
62
62
  const deviceInfo = await this.axiosInstance(CONSTANS.ApiUrls.DeviceInfo);
63
- const parseDeviceInfo = await parseStringPromise(deviceInfo.data);
64
- const devInfo = JSON.stringify(parseDeviceInfo.Device_Info, null, 2);
65
- const debug = this.debugLog ? this.emit('debug', `Parse info data: ${devInfo}`) : false;
66
- const writeDevInfo = (this.zoneControl == 0) ? await fsPromises.writeFile(this.devInfoFile, devInfo) : false;
67
- this.devInfo = devInfo;
63
+ const parseDeviceInfo = await parseString(deviceInfo.data);
64
+ const devInfo = parseDeviceInfo.Device_Info;
65
+ const debug = this.debugLog ? this.emit('debug', `Info: ${JSON.stringify(devInfo, null, 2)}`) : false;
66
+ const writeDevInfo = (this.zoneControl == 0) ? await fsPromises.writeFile(this.devInfoFile, JSON.stringify(devInfo, null, 2)) : false;
68
67
 
69
68
  let manufacturer = 'Denon/Marantz';
70
- if (typeof parseDeviceInfo.Device_Info.BrandCode[0] !== 'undefined') {
71
- manufacturer = ['Denon', 'Marantz'][parseDeviceInfo.Device_Info.BrandCode[0]];
69
+ if (typeof devInfo.BrandCode[0] !== 'undefined') {
70
+ manufacturer = ['Denon', 'Marantz'][devInfo.BrandCode[0]];
72
71
  };
73
- const modelName = parseDeviceInfo.Device_Info.ModelName[0];
74
- const serialNumber = parseDeviceInfo.Device_Info.MacAddress[0];
75
- const firmwareRevision = parseDeviceInfo.Device_Info.UpgradeVersion[0];
76
- const zones = parseDeviceInfo.Device_Info.DeviceZones[0];
77
- const apiVersion = parseDeviceInfo.Device_Info.CommApiVers[0];
72
+ const modelName = devInfo.ModelName[0];
73
+ const serialNumber = devInfo.MacAddress[0];
74
+ const firmwareRevision = devInfo.UpgradeVersion[0];
75
+ const zones = devInfo.DeviceZones[0];
76
+ const apiVersion = devInfo.CommApiVers[0];
77
+ this.devInfo = devInfo;
78
78
 
79
79
  if (serialNumber != null && serialNumber != undefined) {
80
80
  this.emit('deviceInfo', manufacturer, modelName, serialNumber, firmwareRevision, zones, apiVersion);
@@ -92,19 +92,20 @@ class DENON extends EventEmitter {
92
92
  try {
93
93
  const zoneUrl = [CONSTANS.ApiUrls.MainZoneStatusLite, CONSTANS.ApiUrls.Zone2StatusLite, CONSTANS.ApiUrls.Zone3StatusLite, CONSTANS.ApiUrls.SoundModeStatus][this.zoneControl];
94
94
  const deviceState = await this.axiosInstance(zoneUrl);
95
- const parseDeviceState = await parseStringPromise(deviceState.data);
96
- const debug = this.debugLog ? this.emit('debug', `State data: ${JSON.stringify(parseDeviceState, null, 2)}`) : false;
95
+ const parseDeviceState = await parseString(deviceState.data);
96
+ const devState = parseDeviceState.item;
97
+ const debug = this.debugLog ? this.emit('debug', `State: ${JSON.stringify(devState, null, 2)}`) : false;
97
98
 
98
99
  const checkSoundMode = (this.zoneControl == 0 || this.zoneControl == 3)
99
- const deviceSoundMode = checkSoundMode ? await this.axiosInstancePost(CONSTANS.ApiUrls.AppCommand, configXml) : false;
100
- const parseDeviceSoundMode = checkSoundMode ? await parseStringPromise(deviceSoundMode.data) : false;
101
- const debug1 = this.debugLog ? this.emit('debug', `Sound mode data: ${JSON.stringify(parseDeviceSoundMode, null, 2)}`) : false;
100
+ const deviceSoundMode = checkSoundMode ? await this.axiosInstancePost(CONSTANS.ApiUrls.AppCommand, CONFIG_XML) : false;
101
+ const parseDeviceSoundMode = checkSoundMode ? await parseString(deviceSoundMode.data) : false;
102
+ const debug1 = this.debugLog ? this.emit('debug', `Sound mode: ${JSON.stringify(parseDeviceSoundMode, null, 2)}`) : false;
102
103
  const soundMode = checkSoundMode ? CONSTANS.SoundMode[(parseDeviceSoundMode.rx.cmd[0].surround[0]).replace(/[^a-zA-Z0-9]/g, '').toUpperCase()] : this.soundMode;
103
104
 
104
- const power = (parseDeviceState.item.Power[0].value[0] == 'ON');
105
- const reference = (this.zoneControl == 3) ? soundMode : (parseDeviceState.item.InputFuncSelect[0].value[0] == 'Internet Radio') ? 'IRADIO' : (parseDeviceState.item.InputFuncSelect[0].value[0] == 'AirPlay') ? 'NET' : parseDeviceState.item.InputFuncSelect[0].value[0];
106
- const volume = (parseFloat(parseDeviceState.item.MasterVolume[0].value[0]) >= -79.5) ? parseInt(parseDeviceState.item.MasterVolume[0].value[0]) + 80 : this.volume;
107
- const mute = power ? (parseDeviceState.item.Mute[0].value[0] == 'on') : true;
105
+ const power = (devState.Power[0].value[0] == 'ON');
106
+ const reference = (this.zoneControl == 3) ? soundMode : (devState.InputFuncSelect[0].value[0] == 'Internet Radio') ? 'IRADIO' : (devState.InputFuncSelect[0].value[0] == 'AirPlay') ? 'NET' : devState.InputFuncSelect[0].value[0];
107
+ const volume = (parseFloat(devState.MasterVolume[0].value[0]) >= -79.5) ? parseInt(devState.MasterVolume[0].value[0]) + 80 : this.volume;
108
+ const mute = power ? (devState.Mute[0].value[0] == 'on') : true;
108
109
  if (this.checkStateOnFirstRun == true || power != this.power || reference != this.reference || volume != this.volume || mute != this.mute || soundMode != this.soundMod) {
109
110
  this.power = power;
110
111
  this.reference = reference;
@@ -114,8 +115,8 @@ class DENON extends EventEmitter {
114
115
  this.checkStateOnFirstRun = false;
115
116
  this.emit('stateChanged', power, reference, volume, mute, soundMode);
116
117
  };
117
- const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Info', this.devInfo) : false;
118
- const mqtt1 = this.mqttEnabled ? this.emit('mqtt', 'State', JSON.stringify(parseDeviceState.item, null, 2)) : false;
118
+ const mqtt = this.mqttEnabled ? this.emit('mqtt', 'Info', JSON.stringify(this.devInfo, null, 2)) : false;
119
+ const mqtt1 = this.mqttEnabled ? this.emit('mqtt', 'State', JSON.stringify(devState, null, 2)) : false;
119
120
  const surroundMode = {
120
121
  'surround': soundMode
121
122
  }