From e9459044a02887a1438ff2f36503db44c903f223 Mon Sep 17 00:00:00 2001 From: JDierkse Date: Mon, 3 Mar 2025 14:27:52 +0100 Subject: [PATCH] Update Accessories --- activityAccessory.ts | 18 +++------- cameraAccessory.ts | 20 ++++++----- doorWindowSensorAccessory.ts | 63 ++++++++++------------------------- environmentSensorAccessory.ts | 20 ++++++----- klikAanKlikUitAccessory.ts | 32 +++++++++--------- motionSensorAccessory.ts | 23 +++++++------ powerSocketAccessory.ts | 20 ++++++----- powerSwitchAccessory.ts | 30 +++++++++-------- 8 files changed, 102 insertions(+), 124 deletions(-) diff --git a/activityAccessory.ts b/activityAccessory.ts index 8814b51..f5e9b38 100644 --- a/activityAccessory.ts +++ b/activityAccessory.ts @@ -23,9 +23,9 @@ export class activityAccessory extends accessory { typeId: device.id, uniqueId: "Activity." + device.id, deviceName: device.name, - switchable: device.switchable, - dimmable: "true", - detailedType: device.type + switchable: "false", + dimmable: "false", + detailedType: "" } activityDevices.push(object) } @@ -49,22 +49,12 @@ export class activityAccessory extends accessory { .setCharacteristic(this.platform.Characteristic.Model, 'Domotica-Activity') .setCharacteristic(this.platform.Characteristic.SerialNumber, '08000' + accessory.context.device.typeId) -//* this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch) this.service.getCharacteristic(this.platform.Characteristic.On) .onGet(this.getOn.bind(this)) .onSet(this.setOn.bind(this)); -/*/ - this.service = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch) || this.accessory.addService(this.platform.Service.StatefulProgrammableSwitch) - this.service.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent) - .onGet(this.getOn.bind(this)); - - this.service.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState) - .onGet(this.getOn.bind(this)) - .onSet(this.setOn.bind(this)); -//*/ this.setName(accessory.context.device.deviceName) } @@ -85,7 +75,7 @@ export class activityAccessory extends accessory { async setOn(value: CharacteristicValue) { // http://$domoticaIP/external/WebUpdate.php?data=Activity/$id/ - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=Activity/' + this.accessory.context.device.typeId + '/') + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=Activity/' + this.accessory.context.device.typeId + '/') .catch((error) => { this.platform.log.debug('activityAccessory::setOn Error ->' + error) }) diff --git a/cameraAccessory.ts b/cameraAccessory.ts index ece8933..1baf3aa 100644 --- a/cameraAccessory.ts +++ b/cameraAccessory.ts @@ -89,16 +89,18 @@ export class cameraAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.camera) { - if (device.id == this.accessory.context.device.typeId) { - if (device.motionstate == 'absent') { - this.state.Motion = false - } else { // present - this.state.Motion = true + if (devices.hasOwnProperty('camera')) { + for (const device of devices.camera) { + if (device.id == this.accessory.context.device.typeId) { + if (device.motionstate == 'absent') { + this.state.Motion = false + } else { // present + this.state.Motion = true + } + return this.state.Motion + this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion) + break } - return this.state.Motion - this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion) - break } } }) diff --git a/doorWindowSensorAccessory.ts b/doorWindowSensorAccessory.ts index 85ef65a..3dcc8d2 100644 --- a/doorWindowSensorAccessory.ts +++ b/doorWindowSensorAccessory.ts @@ -9,7 +9,7 @@ export class doorWindowSensorAccessory extends accessory { private service: Service private state = { - Position: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED + ContactSensorState: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED, } static async discoverDevices(platform: domoticaPlatform): Promise { @@ -61,16 +61,7 @@ export class doorWindowSensorAccessory extends accessory { this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState) .onGet(this.getContactSensorState.bind(this)); -/* - this.service.getCharacteristic(this.platform.Characteristic.CurrentPosition) - .onGet(this.getCurrentPosition.bind(this)); - this.service.getCharacteristic(this.platform.Characteristic.PositionState) - .onGet(this.getPositionState.bind(this)); - - this.service.getCharacteristic(this.platform.Characteristic.TargetPosition) - .onGet(this.getTargetPosition.bind(this)) -*/ this.setName(accessory.context.device.deviceName) this.update() } @@ -82,14 +73,11 @@ export class doorWindowSensorAccessory extends accessory { setValue(key, value) { if (key == "state" && value != "") { if (value == "Off") { - this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED + this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED } else { - this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED + this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED } -/* - this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.state.Position) - this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.state.Position) -*/ + this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState) } } @@ -103,18 +91,19 @@ export class doorWindowSensorAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.doorwindow) { - if (device.id == this.accessory.context.device.typeId) { - if (device.state == 'closed') { - this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED - } else { // open - this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED + if (devices.hasOwnProperty('doorwindow')) { + for (const device of devices.doorwindow) { + if (device.id == this.accessory.context.device.typeId) { + if (device.state == 'closed') { + this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED + } else { // open + this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED + } + + this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState) + + break } -/* - this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.state.Position) - this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.state.Position) -*/ - break } } }) @@ -122,24 +111,8 @@ export class doorWindowSensorAccessory extends accessory { this.platform.log.debug('doorWindowSensorAccessory::update Error ->' + error) }) } -/* - getCurrentPosition(): CharacteristicValue { - return this.state.Position - } - getPositionState(): CharacteristicValue { - return this.platform.Characteristic.PositionState.STOPPED; - } - - getTargetPosition(): CharacteristicValue { - return this.state.Position - } - - getPosition(): CharacteristicValue { - return this.state.Position - } -*/ getContactSensorState(): CharacteristicValue { - return this.state.Position + return this.state.ContactSensorState } -} +} \ No newline at end of file diff --git a/environmentSensorAccessory.ts b/environmentSensorAccessory.ts index 5a74b58..e83e3d1 100644 --- a/environmentSensorAccessory.ts +++ b/environmentSensorAccessory.ts @@ -77,7 +77,7 @@ export class environmentSensorAccessory extends accessory { this.state.Temperature = value / 100 this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature) } - if (key == "humidity" && value != "") { + else if (key == "humidity" && value != "") { this.state.Humidity = value / 100 this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity) } @@ -93,13 +93,17 @@ export class environmentSensorAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.environment) { - if (device.id == this.accessory.context.device.typeId) { - this.state.Temperature = device.temperature - this.state.Humidity = device.humidity - this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature) - this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity) - break + if (devices.hasOwnProperty('environment')) { + for (const device of devices.environment) { + if (device.id == this.accessory.context.device.typeId) { + this.state.Temperature = device.temperature + this.state.Humidity = device.humidity + + this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature) + this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity) + + break + } } } }) diff --git a/klikAanKlikUitAccessory.ts b/klikAanKlikUitAccessory.ts index c2b6d89..6a28a64 100644 --- a/klikAanKlikUitAccessory.ts +++ b/klikAanKlikUitAccessory.ts @@ -94,21 +94,23 @@ export class klikAanKlikUitAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.klikaanklikuit) { - if (device.id == this.accessory.context.device.typeId) { - if (device.state == 'on') { - this.state.On = true - } else { - this.state.On = false - } - this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) + if (devices.hasOwnProperty('klikaanklikuit')) { + for (const device of devices.klikaanklikuit) { + if (device.id == this.accessory.context.device.typeId) { + if (device.state == 'on') { + this.state.On = true + } else { + this.state.On = false + } + this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) - if (device.dimmable != 'false') { // WTF? - this.state.Brightness = device.dimLevel; - this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness) - } + if (device.dimmable != 'false') { // WTF? + this.state.Brightness = device.dimLevel; + this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness) + } - break + break + } } } }) @@ -121,7 +123,7 @@ export class klikAanKlikUitAccessory extends accessory { this.state.On = value as boolean // http://$domoticaIP/external/WebUpdate.php?data=KlikAanKlikUit/$id/$state/ - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') .catch((error) => { this.platform.log.debug('klikAanKlikUitAccessory::setOn Error ->' + error) }) @@ -135,7 +137,7 @@ export class klikAanKlikUitAccessory extends accessory { this.state.Brightness = value as number // http://$domoticaIP/external/WebUpdate.php?data=KlikAanKlikUit/$id/$state/$dimLevel - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '//' + this.state.Brightness) + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=KlikAanKlikUit/' + this.accessory.context.device.typeId + '//' + this.state.Brightness) .catch((error) => { this.platform.log.debug('klikAanKlikUitAccessory::setBrightness Error ->' + error) }) diff --git a/motionSensorAccessory.ts b/motionSensorAccessory.ts index 2c9e947..271872b 100644 --- a/motionSensorAccessory.ts +++ b/motionSensorAccessory.ts @@ -87,16 +87,19 @@ export class motionSensorAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.motion) { - if (device.id == this.accessory.context.device.typeId) { - if (device.state == 'absent') { - this.state.Motion = false - } else { // present - this.state.Motion = true + if (devices.hasOwnProperty('motion')) { + for (const device of devices.motion) { + if (device.id == this.accessory.context.device.typeId) { + if (device.state == 'absent') { + this.state.Motion = false + } else { // present + this.state.Motion = true + } + + this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion) + + break } - return this.state.Motion - this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion) - break } } }) @@ -108,4 +111,4 @@ export class motionSensorAccessory extends accessory { getState(): CharacteristicValue { return this.state.Motion } -} +} \ No newline at end of file diff --git a/powerSocketAccessory.ts b/powerSocketAccessory.ts index 9bfbefd..efb40b0 100644 --- a/powerSocketAccessory.ts +++ b/powerSocketAccessory.ts @@ -94,15 +94,17 @@ export class powerSocketAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.powersocket) { - if (device.id == this.accessory.context.device.typeId) { - if (device.state == 'on') { - this.state.On = true - } else { - this.state.On = false + if (devices.hasOwnProperty('powersocket')) { + for (const device of devices.powersocket) { + if (device.id == this.accessory.context.device.typeId) { + if (device.state == 'on') { + this.state.On = true + } else { + this.state.On = false + } + this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) + break } - this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) - break } } }) @@ -115,7 +117,7 @@ export class powerSocketAccessory extends accessory { this.state.On = value as boolean // http://$domoticaIP/external/WebUpdate.php?data=PowerSocket/$id/$state/ - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSocket/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSocket/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') .catch((error) => { this.platform.log.debug('powerSocketAccessory::setOn Error ->' + error) }) diff --git a/powerSwitchAccessory.ts b/powerSwitchAccessory.ts index 88ab331..a33bccd 100644 --- a/powerSwitchAccessory.ts +++ b/powerSwitchAccessory.ts @@ -100,20 +100,22 @@ export class powerSwitchAccessory extends accessory { .then((response) => { const devices = JSON.parse(response.body) - for (const device of devices.powerswitch) { - if (device.id == this.accessory.context.device.typeId) { - if (device.state == 'on') { - this.state.On = true - } else { - this.state.On = false - } - this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) + if (devices.hasOwnProperty('powerswitch')) { + for (const device of devices.powerswitch) { + if (device.id == this.accessory.context.device.typeId) { + if (device.state == 'on') { + this.state.On = true + } else { + this.state.On = false + } + this.service.updateCharacteristic(this.platform.Characteristic.On, this.state.On) - if (device.dimmable != 'false') { // WTF? - this.state.Brightness = device.dimlevel; - this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness) + if (device.dimmable != 'false') { // WTF? + this.state.Brightness = device.dimlevel; + this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.state.Brightness) + } + break } - break } } }) @@ -126,7 +128,7 @@ export class powerSwitchAccessory extends accessory { this.state.On = value as boolean // http://$domoticaIP/external/WebUpdate.php?data=PowerSwitch/$id/$state/ - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '/' + (this.state.On? '1': '0') + '/') .catch((error) => { this.platform.log.debug('powerSwitchAccessory::setOn Error ->' + error) }) @@ -140,7 +142,7 @@ export class powerSwitchAccessory extends accessory { this.state.Brightness = value as number // http://$domoticaIP/external/WebUpdate.php?data=PowerSwitch/$id/$state/$dimLevel - httpRequest("http://" + this.platform.config.hostname + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '//' + this.state.Brightness) + httpRequest("http://" + 'administration-container:8080' + '/external/WebUpdate.php?data=PowerSwitch/' + this.accessory.context.device.typeId + '///' + this.state.Brightness) .catch((error) => { this.platform.log.debug('powerSwitchAccessory::setBrightness Error ->' + error) })