diff --git a/.gitignore b/.gitignore index 18a1657..59d4351 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /node_modules/ -.git /dist/ -*.pdf +.git .build +.vscode +*.pdf +*.zip \ No newline at end of file diff --git a/Makefile b/Makefile index ec12327..1a0db5d 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ - +all: clean zip-send build: .build -.build: $(*.ts) +.build: $(src/*.ts) tsc @touch .build @echo "Build called" @@ -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" + \ No newline at end of file diff --git a/package.json b/package.json index ff0c43e..a97d70b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-nuvo", - "version": "2.2.5", + "version": "2.2.6", "main": "dist/platform.js", "scripts": { "clean": "rimraf ./dist", diff --git a/src/platform.ts b/src/platform.ts index 9d890e6..c6cc051 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -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}`); @@ -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; @@ -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; @@ -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); + } } } @@ -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); + } } } @@ -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); } - } + } } }