Skip to content

Commit

Permalink
Added the ability to show default buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Apr 3, 2018
1 parent e652511 commit 618c9f8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
46 changes: 46 additions & 0 deletions defaultSwitches.json
@@ -0,0 +1,46 @@
[
{
"name": "Menu",
"command": "menu"
},
{
"name": "TV/Home",
"command": "tv"
},
{
"name": "Mic/Siri",
"command": "mic"
},
{
"name": "Play",
"command": "play"
},
{
"name": "Pause",
"command": "pause"
},
{
"name": "Up",
"command": "up"
},
{
"name": "Down",
"command": "down"
},
{
"name": "Left",
"command": "left"
},
{
"name": "Right",
"command": "right"
},
{
"name": "Select",
"command": "select"
},
{
"name": "Sleep",
"command": "sleep"
}
]
24 changes: 24 additions & 0 deletions platform.js
Expand Up @@ -11,6 +11,8 @@ const AppleTVPlatform = class extends HomebridgePlatform {

constructor (log, config = {}) {
super(log, config, homebridgeRef);

if (!config.devices) config.devices = [];
}

async addAccessories (accessories) {
Expand All @@ -36,10 +38,32 @@ const AppleTVPlatform = class extends HomebridgePlatform {

log(`\x1b[35m[INFO]\x1b[0m Added pair switch for Apple TV (${appleTV.name}) at ${appleTV.address}`)
}

});

await connectToDevices(config, log);

config.devices.forEach((device) => {
// Add default switches
if (config.showDefaultSwitches === true) {
const defaultSwitches = require('./defaultSwitches.json');

defaultSwitches.forEach((accessory) => {
accessory.deviceID = device.id;

if (config.defaultSwitchesIncludeATVName !== false) {
accessory.name = `${accessory.name} (${device.name})`;
}

const switchAccessory = new Accessory.Switch(log, accessory);
console.log('switchAccessory', switchAccessory)
accessories.push(switchAccessory);
})

log(`\x1b[35m[INFO]\x1b[0m Added default switches for Apple TV (${device.name}). `)
}
});

// Itterate through the config accessories
config.accessories.forEach((accessory) => {
const switchAccessory = new Accessory.Switch(log, accessory);
Expand Down

0 comments on commit 618c9f8

Please sign in to comment.