Skip to content

Commit

Permalink
1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoduj committed Apr 26, 2020
1 parent f6e2494 commit 4e8e9fd
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## 1.1.2

- [FIX] reset targetState at startup just in case
- [NEW] cleaning lost devices from cache

## 1.1.1

- [NEW] minor improvment in opening / closing process.
Expand Down
63 changes: 63 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function Gogogate2Platform(log, config, api) {
this.cleanCache = config['cleanCache'];

this.foundAccessories = [];

this._confirmedAccessories = [];
this._confirmedServices = [];

this.gogogateAPI = new GogogateAPI(log, this);

if (api) {
Expand Down Expand Up @@ -99,6 +103,52 @@ Gogogate2Platform.prototype = {
this.gogogateAPI.logout(() => {});
},

//Cleaning methods
cleanPlatform: function () {
this.cleanAccessories();
this.cleanServices();
},

cleanAccessories: function () {
//cleaning accessories
let accstoRemove = [];
for (let acc of this.foundAccessories) {
if (!this._confirmedAccessories.find((x) => x.UUID == acc.UUID)) {
accstoRemove.push(acc);
this.log('WARNING - Accessory will be Removed ' + acc.UUID + '/' + acc.displayName);
}
}

if (accstoRemove.length > 0)
this.api.unregisterPlatformAccessories('homebridge-gogogate2', 'GogoGate2', accstoRemove);
},

cleanServices: function () {
//cleaning services
for (let acc of this.foundAccessories) {
let servicestoRemove = [];
for (let serv of acc.services) {
if (
serv.subtype !== undefined &&
!this._confirmedServices.find((x) => x.UUID == serv.UUID && x.subtype == serv.subtype)
) {
servicestoRemove.push(serv);
}
}
for (let servToDel of servicestoRemove) {
this.log(
'WARNING - Service Removed' +
servToDel.UUID +
'/' +
servToDel.subtype +
'/' +
servToDel.displayName
);
acc.removeService(servToDel);
}
}
},

discoverDoors: function () {
this.gogogateAPI.on('doorsRetrieveError', () => {
if (this.timerID == undefined) {
Expand Down Expand Up @@ -203,6 +253,9 @@ Gogogate2Platform.prototype = {
this.bindTargetDoorStateCharacteristic(HKService);
this.bindObstructionDetectedCharacteristic(HKService);

this._confirmedAccessories.push(myGogogateDoorAccessory);
this._confirmedServices.push(HKService);

if (sensors[i] && !sensors[i].isEmpty()) {
this.log('INFO - Discovered sensor : ' + sensors[i]);

Expand Down Expand Up @@ -240,9 +293,14 @@ Gogogate2Platform.prototype = {
HKService2.gateId = i + 1;

this.bindCurrentTemperatureLevelCharacteristic(HKService2);

this._confirmedServices.push(HKService1);
this._confirmedServices.push(HKService2);
}
}
}

this.cleanPlatform();
this.refreshAllDoors();
//timer for background refresh
this.refreshBackground();
Expand Down Expand Up @@ -469,6 +527,11 @@ Gogogate2Platform.prototype = {
},

bindTargetDoorStateCharacteristic: function (service) {
//at startup, set to currentstate to reset
service
.getCharacteristic(Characteristic.TargetDoorState)
.updateValue(service.getCharacteristic(Characteristic.CurrentDoorState).value);

service
.getCharacteristic(Characteristic.TargetDoorState)
.on(
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-gogogate2",
"version": "1.1.1",
"version": "1.1.2",
"author": "Nicolas Dujardin",
"description": "Publish your gogogate 2 to homebridge",
"main": "index.js",
Expand Down

0 comments on commit 4e8e9fd

Please sign in to comment.