mirror of
https://github.com/nicolabs/musiccast-repairkit.git
synced 2026-05-21 03:10:03 +02:00
+ on/off sync scenario
This commit is contained in:
parent
332e25eb13
commit
e564f8a139
14
README.md
14
README.md
|
|
@ -51,6 +51,20 @@ On the command line, use `-s scripts/sync-volume.js` to enable this script and u
|
|||
Top-level options (e.g. `--source`) and configuration file are also valid (see instructions below).
|
||||
|
||||
|
||||
### Sync standby mode of several devices
|
||||
|
||||
It sometimes happens that wirelessly-linked devices don't go to standby mode or don't awake together with the main one.
|
||||
It may be a bug or a reliability issue with network protocols ; however the result is that this forces you to physically put them on/off.
|
||||
|
||||
This script will automatically forces a given list of devices to power on or off following the main device power status.
|
||||
|
||||
On the command line, use `-s scripts/standby-together.js` to enable this script and use the following options :
|
||||
- `--conf.standby-together.source` sets the hostname or IP address of the *master* receiver
|
||||
- `--conf.standby-together.target` lists the *slave* devices that will follow the master's power status. You can separate them with a space or pass the option several times.
|
||||
|
||||
Top-level options (e.g. `--source`) and configuration file are also valid (see instructions below).
|
||||
|
||||
|
||||
## Command line usage
|
||||
|
||||
This program requires [Node.js](https://nodejs.org) to run.
|
||||
|
|
|
|||
66
scripts/standby-together.js
Normal file
66
scripts/standby-together.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
const log = require('../logging');
|
||||
const YamahaYXC = require('yamaha-yxc-nodejs');
|
||||
|
||||
module.exports = class Scenario {
|
||||
|
||||
/**
|
||||
Expects a configuration in the form :
|
||||
|
||||
{
|
||||
"source": <hostname/ip of the MusicCast device to listen to standby status changes>,
|
||||
"target": [ <list of hostname/ip of the MC devices to put on/off following the source device status> ]
|
||||
|
||||
E.g. { "source": "192.168.1.42", "target": [ "192.168.1.43", "192.168.1.44" ] }
|
||||
*/
|
||||
constructor( configuration ) {
|
||||
|
||||
// Instanciates the source device and enrich with technical infos
|
||||
var source = new YamahaYXC(configuration.source);
|
||||
source.getDeviceInfo().
|
||||
then( result => {
|
||||
source.deviceInfo = JSON.parse(result);
|
||||
log.debug("Source : %s",source);
|
||||
}
|
||||
);
|
||||
this.source = source;
|
||||
|
||||
// Instanciates the target devices
|
||||
this.targets = [];
|
||||
if ( Array.isArray(configuration.target) ) {
|
||||
for ( var t=0 ; t<configuration.target.length ; t++ ) {
|
||||
this.targets.push( new YamahaYXC(configuration.target[t]) );
|
||||
}
|
||||
} else {
|
||||
// We allow 'configuration.target' to be a string if only one value is given
|
||||
this.targets.push( new YamahaYXC(configuration.target) );
|
||||
}
|
||||
log.debug("Targets : %s",this.targets);
|
||||
}
|
||||
|
||||
/**
|
||||
Puts off target devices when the source one goes off/standby.
|
||||
Puts on target devices when the source one goes on.
|
||||
E.g. event = { main: { power: "standby" }, device_id: 'AC44F2852577' }
|
||||
*/
|
||||
onEvent( event ) {
|
||||
|
||||
// Filters out events
|
||||
if ( !event.main || typeof event.main.power == 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
// It seems that a device may report for another, linked one => we filter out those events
|
||||
if ( typeof event.device_id != undefined && event.device_id != this.source.deviceInfo.device_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("<<< Received power change event : %j", event);
|
||||
|
||||
for ( var t=0 ; t<this.targets.length ; t++ ) {
|
||||
// Here we use YamahaYXC's API to implement our behaviour
|
||||
log.info(">>> Sending power '%s' to %s", event.main.power, this.targets[t].ip );
|
||||
// Possible values for 'power' are : 'on' or 'standby' (see https://github.com/foxthefox/yamaha-yxc-nodejs)
|
||||
this.targets[t].power(event.main.power);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue