Update Accessories

This commit is contained in:
2025-03-03 14:27:52 +01:00
parent 90c728a2be
commit e9459044a0
8 changed files with 102 additions and 124 deletions
+16 -14
View File
@@ -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)
})