Skip to content

Commit

Permalink
1.0.0-beta9
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoduj committed Mar 27, 2019
1 parent 897b190 commit ed6baa2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 68 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Fields:

- `platform` must be "HarmonyHubWebSocket" (required).
- `name` is the name of the published Platform (required).
- `publishAsTVAsExternalAccessory` publish all TV accessory as external Accessories. This way, if another plugin on the same homebridge instance as one, the one on harmony will also be visible, but you will have to add them manually after the hub itself. Defaults to false (in that case, only second tv accessory or following will be published by this plugin as external accessories, first one will be linked to the hub).
- `cleanCache` option to clean all cached Accessory. Please use with caution, might be needed if you change names / config of the hub and there is some ghost devices in Homekit. Be sure that all your icloud sync is done while launching Homebridge with this option set to true. Set it back to false after and launch again !
- `subPlatform` is an array of hubs platform
- `name` is the name of the published hub (required). Use a different name for each entry if you have multiple hubs or if you had the same hub multiple times.
Expand All @@ -120,7 +121,7 @@ Fields:
- `publishDevicesAsIndividualAccessories` option to publish devices as individual accessories. Defaults to true.
- `sequencesToPublishAsAccessoriesSwitch` array of Sequences to exposes through a switch.
- `publishSequencesAsIndividualAccessories` option to publish sequences as individual accessories. Defaults to true.
- `publishHomeControlButtons` set to true if you want to publish home controls as switches
- `homeControlsToPublishAsAccessoriesSwitch` array of home controls you want to publish as switches
- `publishHomeControlsAsIndividualAccessories` option to publish home controls as individual accessories. Defaults to true.
- `TVPlatformMode` option to try TV mode . STILL WORK IN PROGRESS - NEEDS IOS 12.2 / HOMEBRIDGE 0.0.46
- `mainActivity` set the mainactivity of the TV mode
Expand Down
7 changes: 5 additions & 2 deletions harmonyAsTVPlatform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Service, Characteristic;
var Service, Characteristic, Accessory;

const HarmonyBase = require('./harmonyBase').HarmonyBase;
const HarmonyConst = require('./harmonyConst');
Expand All @@ -14,7 +14,7 @@ module.exports = {
function HarmonyPlatformAsTVPlatform(log, config, api, mainPlatform) {
Service = api.hap.Service;
Characteristic = api.hap.Characteristic;

Accessory = api.hap.Accessory;
this.api = api;
this.mainPlatform = mainPlatform;
this.harmonyBase = new HarmonyBase(api);
Expand Down Expand Up @@ -215,11 +215,14 @@ HarmonyPlatformAsTVPlatform.prototype = {
let name = this.devMode ? 'DEV' : '';

myHarmonyAccessory = this.harmonyBase.checkAccessory(this, name);

if (!myHarmonyAccessory) {
myHarmonyAccessory = this.harmonyBase.createAccessory(this, name);
accessoriesToAdd.push(myHarmonyAccessory);
}

myHarmonyAccessory.category = Accessory.Categories.TELEVISION;

this.log('INFO - configuring Main TV Service');
this.configureMainService(myHarmonyAccessory);

Expand Down
135 changes: 71 additions & 64 deletions harmonyBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ HarmonyBase.prototype = {
true
);

harmonyPlatform.publishHomeControlButtons =
config['publishHomeControlButtons'];
harmonyPlatform.homeControlsToPublishAsAccessoriesSwitch =
config['homeControlsToPublishAsAccessoriesSwitch'];
harmonyPlatform.publishHomeControlsAsIndividualAccessories = HarmonyTools.checkParameter(
config['publishHomeControlsAsIndividualAccessories'],
true
Expand Down Expand Up @@ -203,15 +203,19 @@ HarmonyBase.prototype = {
) {
//creating accessories

if (isTv && harmonyPlatform.mainPlatform._oneTVAdded) {
if (
isTv &&
(harmonyPlatform.mainPlatform._oneTVAdded ||
harmonyPlatform.mainPlatform.publishAsTVAsExternalAccessory)
) {
try {
harmonyPlatform.api.publishExternalAccessories(
'homebridge-harmonyHub',
accessoriesToAdd
);
} catch (err) {
harmonyPlatform.log(
"ERROR - readAccessories - Can't publish TV Acccessory as external device, need Homebridge 0.0.48 at least : " +
"ERROR - readAccessories - Can't publish TV Acccessory as external device, need Homebridge 0.0.47 at least : " +
err
);
}
Expand Down Expand Up @@ -336,42 +340,51 @@ HarmonyBase.prototype = {
for (var key in homeControls) {
let switchName = key;

if (harmonyPlatform.devMode) {
switchName = 'DEV' + switchName;
}
if (
harmonyPlatform.homeControlsToPublishAsAccessoriesSwitch.includes(
switchName
)
) {
if (harmonyPlatform.devMode) {
switchName = 'DEV' + switchName;
}

harmonyPlatform.log('INFO - Discovered Home Control : ' + switchName);
harmonyPlatform.log('INFO - Discovered Home Control : ' + switchName);

if (harmonyPlatform.publishHomeControlsAsIndividualAccessories) {
myHarmonyAccessory = this.checkAccessory(harmonyPlatform, switchName);
if (!myHarmonyAccessory) {
myHarmonyAccessory = this.createAccessory(
harmonyPlatform,
switchName
);
accessoriesToAdd.push(myHarmonyAccessory);
if (harmonyPlatform.publishHomeControlsAsIndividualAccessories) {
myHarmonyAccessory = this.checkAccessory(harmonyPlatform, switchName);
if (!myHarmonyAccessory) {
myHarmonyAccessory = this.createAccessory(
harmonyPlatform,
switchName
);
accessoriesToAdd.push(myHarmonyAccessory);
}
}
}

let subType = switchName;
let service = this.getSwitchService(
harmonyPlatform,
myHarmonyAccessory,
switchName,
subType
);
let subType = switchName;
let service = this.getSwitchService(
harmonyPlatform,
myHarmonyAccessory,
switchName,
subType
);

service.HomeId = key;
service.type = HarmonyConst.HOME_TYPE;
this.bindCharacteristicEventsForSwitch(harmonyPlatform, service);
service.HomeId = key;
service.type = HarmonyConst.HOME_TYPE;
this.bindCharacteristicEventsForSwitch(harmonyPlatform, service);
}
}

//creating accessories
this.addAccessories(harmonyPlatform, accessoriesToAdd);
},

getHomeControlsAccessories: function(harmonyPlatform) {
if (harmonyPlatform.publishHomeControlButtons) {
if (
harmonyPlatform.homeControlsToPublishAsAccessoriesSwitch &&
harmonyPlatform.homeControlsToPublishAsAccessoriesSwitch.length > 0
) {
harmonyPlatform.log.debug('INFO - getting home controls ...');
return this.harmony.getAutomationCommands();
} else {
Expand Down Expand Up @@ -406,50 +419,44 @@ HarmonyBase.prototype = {
}
}

for (
let c = 0,
len = harmonyPlatform.sequencesToPublishAsAccessoriesSwitch.length;
c < len;
c++
) {
var sequence = harmonyPlatform.sequencesToPublishAsAccessoriesSwitch[c];

for (let i = 0, len = sequences.length; i < len; i++) {
if (sequences[i].name === sequence) {
let switchName = sequence;

if (harmonyPlatform.devMode) {
switchName = 'DEV' + switchName;
}
for (let i = 0, len = sequences.length; i < len; i++) {
let switchName = sequences[i].name;
if (
harmonyPlatform.sequencesToPublishAsAccessoriesSwitch.includes(
switchName
)
) {
if (harmonyPlatform.devMode) {
switchName = 'DEV' + switchName;
}

harmonyPlatform.log('INFO - Discovered sequence : ' + switchName);
harmonyPlatform.log('INFO - Discovered sequence : ' + switchName);

if (harmonyPlatform.publishSequencesAsIndividualAccessories) {
myHarmonyAccessory = this.checkAccessory(
if (harmonyPlatform.publishSequencesAsIndividualAccessories) {
myHarmonyAccessory = this.checkAccessory(
harmonyPlatform,
switchName
);
if (!myHarmonyAccessory) {
myHarmonyAccessory = this.createAccessory(
harmonyPlatform,
switchName
);
if (!myHarmonyAccessory) {
myHarmonyAccessory = this.createAccessory(
harmonyPlatform,
switchName
);
accessoriesToAdd.push(myHarmonyAccessory);
}
accessoriesToAdd.push(myHarmonyAccessory);
}
}

let subType = switchName + '-' + sequence;
let service = this.getSwitchService(
harmonyPlatform,
myHarmonyAccessory,
switchName,
subType
);
let subType = switchName + '-' + sequence;
let service = this.getSwitchService(
harmonyPlatform,
myHarmonyAccessory,
switchName,
subType
);

service.SequenceId = sequences[i].id;
service.type = HarmonyConst.SEQUENCE_TYPE;
this.bindCharacteristicEventsForSwitch(harmonyPlatform, service);
}
service.SequenceId = sequences[i].id;
service.type = HarmonyConst.SEQUENCE_TYPE;
this.bindCharacteristicEventsForSwitch(harmonyPlatform, service);
}
}

Expand Down
7 changes: 7 additions & 0 deletions harmonyPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const HarmonyPlatformAsSwitches = require('./harmonyAsSwitches')
.HarmonyPlatformAsSwitches;
const HarmonyPlatformAsTVPlatform = require('./harmonyAsTVPlatform')
.HarmonyPlatformAsTVPlatform;
const HarmonyTools = require('./harmonyTools.js');

module.exports = {
HarmonyPlatform: HarmonyPlatform,
Expand All @@ -13,6 +14,12 @@ function HarmonyPlatform(log, config, api) {
this.log = log;
this.plaformsConfigs = config['subPlatform'];
this.cleanCache = config['cleanCache'];

this.publishAsTVAsExternalAccessory = HarmonyTools.checkParameter(
config['publishAsTVAsExternalAccessory'],
false
);

this.platforms = [];
this._foundAccessories = [];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-harmony",
"version": "1.0.0-beta8",
"version": "1.0.0-beta9",
"author": "Nicolas Dujardin",
"description": "Publish your harmony activities as homekit accessories",
"main": "index.js",
Expand Down

0 comments on commit ed6baa2

Please sign in to comment.