Skip to content

Commit

Permalink
Recently Disabled Zones/Sources are removed & fixes/proper implementa…
Browse files Browse the repository at this point in the history
…tion for #10
  • Loading branch information
Willmac16 committed Jan 10, 2022
1 parent 16e9a15 commit 99d361c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 55 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules/
.git
/dist/
*.pdf
.git
.build
.vscode
*.pdf
*.zip
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

all: clean zip-send

build: .build

.build: $(*.ts)
.build: $(src/*.ts)
tsc
@touch .build
@echo "Build called"
Expand All @@ -18,6 +18,7 @@ send: build
ssh nuvo "cd ~/homebridge-nuvo; sudo npm ci"

zip-send: build
zip -u ./hbnv.zip -r . -x ./node-modules/* ./.git*
zip -u ./hbnv.zip -r . -x "*.git*" "*node_modules*" "*.vscode*" "*src*" "NUVO Protocol.pdf" "README.md"
scp ~/homebridge-nuvo/hbnv.zip nuvo:~/homebridge-nuvo/hbnv.zip
ssh nuvo "cd ~/homebridge-nuvo; unzip -o hbnv.zip; sudo npm ci"

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-nuvo",
"version": "2.2.5",
"version": "2.2.6",
"main": "dist/platform.js",
"scripts": {
"clean": "rimraf ./dist",
Expand Down
111 changes: 62 additions & 49 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class NuvoPlatform implements DynamicPlatformPlugin {
});
}


// Make sure this works and doesn't break a promise
configureAccessory(accessory: PlatformAccessory) {
this.log.debug(`adding ${accessory.context.zone}, ${accessory.context.source}`);

Expand All @@ -118,48 +116,48 @@ class NuvoPlatform implements DynamicPlatformPlugin {
const onChar = accessory.getService(hap.Service.Lightbulb).getCharacteristic(hap.Characteristic.On);

onChar.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
if (value === true) {
this.serialConnection.zoneOn(accessory.context.zone);
this.serialConnection.zoneSource(accessory.context.zone, accessory.context.source);
} else {
this.serialConnection.zoneOff(accessory.context.zone);
}
if (value === true) {
this.serialConnection.zoneOn(accessory.context.zone);
this.serialConnection.zoneSource(accessory.context.zone, accessory.context.source);
} else {
this.serialConnection.zoneOff(accessory.context.zone);
}

// this.serialConnection.zoneAskStatus(accessory.context.zone);
callback();
});
callback();
});

onChar.on(CharacteristicEventTypes.GET, (callback: CharacteristicSetCallback) => {
// this.serialConnection.zoneAskStatus(accessory.context.zone);
let on = this.zoneSource[accessory.context.zone] === accessory.context.source;
callback(undefined, on);
});
let on = this.zoneSource[accessory.context.zone] === accessory.context.source;
callback(undefined, on);
});

const brightChar = accessory.getService(hap.Service.Lightbulb).getCharacteristic(hap.Characteristic.Brightness);

brightChar.on(CharacteristicEventTypes.GET, (callback: CharacteristicSetCallback) => {
// this.serialConnection.zoneAskStatus(accessory.context.zone);
let on = this.zoneSource[accessory.context.zone] === accessory.context.source;
if (on) {
let vol = this.zoneVolume[accessory.context.zone];
callback(undefined, vol);
} else {
callback(undefined, 0);
}
});
let on = this.zoneSource[accessory.context.zone] === accessory.context.source;
if (on) {
let vol = this.zoneVolume[accessory.context.zone];
callback(undefined, vol);
} else {
callback(undefined, 0);
}
});

brightChar.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
if (value === 100) {
var vol = this.powOnVol;
} else {
var vol = Math.round((Number(value)*(79/100)-79)*-1);
}
this.serialConnection.zoneVolume(accessory.context.zone, vol);
callback();
});
// Logic to handle the power on to 100% behavior from home app
if (value === 100) {
var vol = this.powOnVol;
this.serialConnection.zoneOn(accessory.context.zone);
} else {
var vol = Math.round((Number(value)*(79/100)-79)*-1);
}
this.serialConnection.zoneVolume(accessory.context.zone, vol);
callback();
});

this.zoneSourceCombo[accessory.context.zone][accessory.context.source] = accessory;

// create element for this plugin's tracking of zone state in source and volume
if (!this.zoneSource[accessory.context.zone]) {
this.zoneSource[accessory.context.zone] = 0;
this.zoneVolume[accessory.context.zone] = 0;
Expand Down Expand Up @@ -188,6 +186,15 @@ class NuvoPlatform implements DynamicPlatformPlugin {
}
}

removeAccessory(zoneNum: number, sourceNum: number) {
if (this.zoneSourceCombo[zoneNum][sourceNum]) {
let accessory = this.zoneSourceCombo[zoneNum][sourceNum];

this.log.debug(`removing ${zoneNum}, ${sourceNum}`);
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
}
}

addZone(zone: number, zoneCfg: string[]) {
this.zoneConfigs[zone] = zoneCfg;

Expand All @@ -198,6 +205,10 @@ class NuvoPlatform implements DynamicPlatformPlugin {
this.addAccessory(zone, source);
}
}
} else {
for (var source = 1; source <= serial.MAX_SOURCES; source++) {
this.removeAccessory(zone, source);
}
}
}

Expand All @@ -211,6 +222,10 @@ class NuvoPlatform implements DynamicPlatformPlugin {
this.addAccessory(zone, source);
}
}
} else {
for (var zone = 1; zone <= this.numZones; zone++) {
this.removeAccessory(zone, source);
}
}
}

Expand Down Expand Up @@ -245,23 +260,21 @@ class NuvoPlatform implements DynamicPlatformPlugin {
let lastVol = this.zoneVolume[zoneNum];
this.zoneVolume[zoneNum] = volume;

if (this.zoneSourceCombo[zoneNum][lastSource]) {
if (lastSource !== sourceOn) {
if (lastSource !== 0) {
this.log.debug(`Messing with ${zoneNum} ${lastSource}`);
this.zoneSourceCombo[zoneNum][lastSource].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.On, false);
this.zoneSourceCombo[zoneNum][lastSource].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, 0);
}
if (sourceOn !== 0) {
this.log.debug(`Mess ${zoneNum} ${sourceOn}`);
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.On, true);
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, volume);
}
} else if (lastVol !== volume) {
if (sourceOn !== 0) {
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, volume);
}
if (lastSource !== sourceOn) {
if (lastSource !== 0 && this.zoneSourceCombo[zoneNum][lastSource]) {
this.log.debug(`Messing with ${zoneNum} ${lastSource}`);
this.zoneSourceCombo[zoneNum][lastSource].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.On, false);
this.zoneSourceCombo[zoneNum][lastSource].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, 0);
}
if (sourceOn !== 0 && this.zoneSourceCombo[zoneNum][sourceOn]) {
this.log.debug(`Mess ${zoneNum} ${sourceOn}`);
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.On, true);
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, volume);
}
} else if (lastVol !== volume) {
if (sourceOn !== 0) {
this.zoneSourceCombo[zoneNum][sourceOn].getService(hap.Service.Lightbulb).updateCharacteristic(hap.Characteristic.Brightness, volume);
}
}
}
}
}

0 comments on commit 99d361c

Please sign in to comment.