Skip to content

Commit

Permalink
release v5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Aug 23, 2024
1 parent 3b3a9b1 commit a9d0706
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 219 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Note - after update to 3.15.x need remove the accessory frome Home app and add it again

## [5.1.0] - (22.08.2024)

## Changes

- add control over RESTFul POST JSON Object
- bump dependencies
- cleanup

## [5.0.2] - (18.08.2024)

## Changes
Expand Down
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,35 @@ Tested Denon AVR-2112CI, AVR-3311CI, AVR-X6300H, AVR-X2700H, AVC-X4800H, Marantz

### RESTFul Integration

* Request: `http//homebridge_ip_address:port/path`.
* Path: `info`, `state`, `picture`, `surround`.
* Respone as JSON object.
* POST data as a JSON Object `{Power: true}`

| Method | URL | Path | Response | Type |
| --- | --- | --- | --- | --- |
| GET | `http//ip:port` | `info`, `state`, `picture`, `surround`. | `{"Power": {"value": OFF}}` | JSON object. |

| Method | URL | Key | Value | Type | Description |
| --- | --- | --- | --- | --- | --- |
| POST | `http//ip:port` | `Power` | `true`, `false` | boolean | Power On/Off. |
| | `http//ip:port` | `Input` | `SAT/CBL` | string | Set input. |
| | `http//ip:port` | `Surround` | `MUSIC` | string | Set surround mode. |
| | `http//ip:port` | `RcControl` | `NS9E` | string | Send RC command. |
| | `http//ip:port` | `Volume` | `100` | integer | Set volume. |
| | `http//ip:port` | `Mute` | `true`, `false` | string | Set mute On/Off. |

### MQTT Integration

| Direction | Topic | Message | Payload Data |
| --- | --- | --- | --- |
| Publish | `Info`, `State`, `Picture`, `Surround` | `{"Power": {"value": OFF}}` | JSON object. |
| Subscribe | `Set` | `{"Power": true}` | JSON object. |
* Subscribe data as a JSON Object `{Power: true}`

| Subscribe | Key | Value | Type | Description |
| --- | --- | --- | --- | --- |
| Denon/Marantz | | | | |
| | `Power` | `true`, `false` | boolean | Power state. |
| | `Input` | `SAT/CBL` | string | Set input. |
| | `Surround` | `MUSIC` | string | Set surround mode. |
| | `RcControl` | `NS9E` | string | Send RC command. |
| | `Volume` | `100` | integer | Set volume. |
| | `Mute` | `true`, `false` | boolean | Set mute. |
| Method | Topic | Message | Type |
| --- | --- | --- | --- |
| Publish | `Info`, `State`, `Picture`, `Surround` | `{"Power": {"value": OFF}}` | JSON object. |

| Method | Topic | Key | Value | Type | Description |
| --- | --- | --- | --- | --- | --- |
| Denon/Marantz | | | | | |
| Subscribe | `Set` | `Power` | `true`, `false` | boolean | Power state. |
| | `Set` | `Input` | `SAT/CBL` | string | Set input. |
| | `Set` | `Surround` | `MUSIC` | string | Set surround mode. |
| | `Set` | `RcControl` | `NS9E` | string | Send RC command. |
| | `Set` | `Volume` | `100` | integer | Set volume. |
| | `Set` | `Mute` | `true`, `false` | boolean | Set mute. |
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class DenonPlatform {
const config = {
...device,
mqtt: {
...device.mqtt,
passwd: 'removed'
...device.mqtt,
passwd: 'removed'
}
};
};
const debug1 = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(config, null, 2)}`) : false;

//zones
Expand Down Expand Up @@ -87,6 +87,9 @@ class DenonPlatform {
.on('devInfo', (devInfo) => {
log.info(devInfo);
})
.on('success', (message) => {
log.success(`Device: ${host} ${deviceName}, ${message}`);
})
.on('message', (message) => {
log.info(`Device: ${host} ${deviceName}, ${message}`);
})
Expand All @@ -109,6 +112,9 @@ class DenonPlatform {
.on('devInfo', (devInfo) => {
log(devInfo);
})
.on('success', (message) => {
log.success(`Device: ${host} ${deviceName}, ${message}`);
})
.on('message', (message) => {
log(`Device: ${host} ${deviceName}, ${message}`);
})
Expand All @@ -131,6 +137,9 @@ class DenonPlatform {
.on('devInfo', (devInfo) => {
log.info(devInfo);
})
.on('success', (message) => {
log.success(`Device: ${host} ${deviceName}, ${message}`);
})
.on('message', (message) => {
log.info(`Device: ${host} ${deviceName}, ${message}`);
})
Expand All @@ -153,6 +162,9 @@ class DenonPlatform {
.on('devInfo', (devInfo) => {
log.info(devInfo);
})
.on('success', (message) => {
log.success(`Device: ${host} ${deviceName}, ${message}`);
})
.on('message', (message) => {
log.info(`Device: ${host} ${deviceName}, ${message}`);
})
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Denon TV",
"name": "homebridge-denon-tv",
"version": "5.0.4",
"version": "5.1.0",
"description": "Homebridge plugin to control Denon/Marantz AV Receivers.",
"license": "MIT",
"author": "grzegorz914",
Expand All @@ -28,11 +28,11 @@
],
"engines": {
"node": ">=18.0.0",
"homebridge": ">=1.6.0"
"homebridge": ">=1.8.0"
},
"dependencies": {
"async-mqtt": "^2.6.3",
"axios": "^1.7.4",
"axios": "^1.7.5",
"fast-xml-parser": "^4.4.1",
"express": "^4.19.2"
},
Expand Down
117 changes: 67 additions & 50 deletions src/mainzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class MainZone extends EventEmitter {
this.volumeControl = device.volumeControl || false;
this.volumeMax = device.volumeMax || 100;
this.masterPower = device.masterPower || false;
this.restFul = device.restFul || {};
this.mqtt = device.mqtt || {};

//external integration
const restFul = device.restFul || {};
this.restFulConnected = false;
const mqtt = device.mqtt || {};
this.mqttConnected = false;

//services
Expand Down Expand Up @@ -248,17 +248,24 @@ class MainZone extends EventEmitter {
})
.on('prepareAccessory', async (allInputs) => {
//RESTFul server
const restFulEnabled = this.restFul.enable || false;
const restFulEnabled = restFul.enable || false;
if (restFulEnabled) {
this.restFul = new RestFul({
port: this.restFul.port || 3000,
debug: this.restFul.debug || false
port: restFul.port || 3000,
debug: restFul.debug || false
});

this.restFul.on('connected', (message) => {
this.emit('message', message);
this.emit('success', message);
this.restFulConnected = true;
})
.on('set', async (key, value) => {
try {
await this.setOverExternalIntegration('RESTFul', key, value);
} catch (error) {
this.emit('warn', `RESTFul set error: ${error}`);
};
})
.on('debug', (debug) => {
this.emit('debug', debug);
})
Expand All @@ -268,58 +275,30 @@ class MainZone extends EventEmitter {
}

//mqtt client
const mqttEnabled = this.mqtt.enable || false;
const mqttEnabled = mqtt.enable || false;
if (mqttEnabled) {
this.mqtt = new Mqtt({
host: this.mqtt.host,
port: this.mqtt.port || 1883,
clientId: this.mqtt.clientId || `denon_${Math.random().toString(16).slice(3)}`,
prefix: `${this.mqtt.prefix}/${name}`,
user: this.mqtt.user,
passwd: this.mqtt.passwd,
debug: this.mqtt.debug || false
host: mqtt.host,
port: mqtt.port || 1883,
clientId: mqtt.clientId || `denon_${Math.random().toString(16).slice(3)}`,
prefix: `${mqtt.prefix}/${name}`,
user: mqtt.user,
passwd: mqtt.passwd,
debug: mqtt.debug || false
});

this.mqtt.on('connected', (message) => {
this.emit('message', message);
this.emit('success', message);
this.mqttConnected = true;
})
.on('subscribed', (message) => {
this.emit('message', message);
this.emit('success', message);
})
.on('subscribedMessage', async (key, value) => {
try {
switch (key) {
case 'Power':
const powerState = this.masterPower ? (value ? 'PWON' : 'PWSTANDBY') : (value ? 'ZMON' : 'ZMOFF');
await this.denon.send(powerState)
break;
case 'Input':
const input = `SI${value}`;
await this.denon.send(input);
break;
case 'Volume':
const value1 = (value < 0 || value > 100) ? this.volume : (value < 10 ? `0${value}` : value);
const volume = `MV${value1}`;
await this.denon.send(volume);
break;
case 'Mute':
const mute = value ? 'MUON' : 'MUOFF';
await this.denon.send(mute);
break;
case 'Surround':
const surround = `MS${value}`;
await this.denon.send(surround);
break;
case 'RcControl':
await this.denon.send(value);
break;
default:
this.emit('message', `MQTT Received unknown key: ${key}, value: ${value}`);
break;
};
await this.setOverExternalIntegration('MQTT', key, value);
} catch (error) {
this.emit('warn', `MQTT send error: ${error}.`);
this.emit('warn', `MQTT set error: ${error}.`);
};
})
.on('debug', (debug) => {
Expand Down Expand Up @@ -404,7 +383,7 @@ class MainZone extends EventEmitter {
this.televisionService.setCharacteristic(Characteristic.DisplayOrder, Encode(1, displayOrder).toString('base64'));
return true;
} catch (error) {
throw new Error( error);
throw new Error(error);
};
}

Expand All @@ -414,7 +393,7 @@ class MainZone extends EventEmitter {
const debug = !this.enableDebugMode ? false : this.emit('debug', `Saved data: ${JSON.stringify(data, null, 2)}`);
return true;
} catch (error) {
throw new Error( error);
throw new Error(error);
};
}

Expand All @@ -423,7 +402,45 @@ class MainZone extends EventEmitter {
const data = await fsPromises.readFile(path);
return data;
} catch (error) {
throw new Error( `Read saved data error: ${error}`);
throw new Error(`Read saved data error: ${error}`);
};
}

async setOverExternalIntegration(integration, key, value) {
try {
let set = false
switch (key) {
case 'Power':
const powerState = this.masterPower ? (value ? 'PWON' : 'PWSTANDBY') : (value ? 'ZMON' : 'ZMOFF');
set = await this.denon.send(powerState)
break;
case 'Input':
const input = `SI${value}`;
set = await this.denon.send(input);
break;
case 'Volume':
const value1 = (value < 0 || value > 100) ? this.volume : (value < 10 ? `0${value}` : value);
const volume = `MV${value1}`;
set = await this.denon.send(volume);
break;
case 'Mute':
const mute = value ? 'MUON' : 'MUOFF';
set = await this.denon.send(mute);
break;
case 'Surround':
const surround = `MS${value}`;
set = await this.denon.send(surround);
break;
case 'RcControl':
set = await this.denon.send(value);
break;
default:
this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);
break;
};
return set;
} catch (error) {
throw new Error(`${integration} set key: ${key}, value: ${value}, error: ${error}`);
};
}

Expand Down Expand Up @@ -1005,7 +1022,7 @@ class MainZone extends EventEmitter {

return accessory;
} catch (error) {
throw new Error( error)
throw new Error(error)
};
}
};
Expand Down
Loading

0 comments on commit a9d0706

Please sign in to comment.