Update Accessories
This commit is contained in:
+4
-14
@@ -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)
|
||||
})
|
||||
|
||||
@@ -89,6 +89,7 @@ export class cameraAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('camera')) {
|
||||
for (const device of devices.camera) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.motionstate == 'absent') {
|
||||
@@ -101,6 +102,7 @@ export class cameraAccessory extends accessory {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('cameraAccessory::update Error ->' + error)
|
||||
|
||||
@@ -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<device[]> {
|
||||
@@ -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,43 +91,28 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('doorwindow')) {
|
||||
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
|
||||
this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
||||
} else { // open
|
||||
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)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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,15 +93,19 @@ export class environmentSensorAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('environmentSensorAccessory::getTemperature Error ->' + error)
|
||||
|
||||
@@ -94,6 +94,7 @@ export class klikAanKlikUitAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('klikaanklikuit')) {
|
||||
for (const device of devices.klikaanklikuit) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.state == 'on') {
|
||||
@@ -111,6 +112,7 @@ export class klikAanKlikUitAccessory extends accessory {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('klikAanKlikUitAccessory::update Error ->' + error)
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -87,6 +87,7 @@ export class motionSensorAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('motion')) {
|
||||
for (const device of devices.motion) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.state == 'absent') {
|
||||
@@ -94,11 +95,13 @@ export class motionSensorAccessory extends accessory {
|
||||
} else { // present
|
||||
this.state.Motion = true
|
||||
}
|
||||
return this.state.Motion
|
||||
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('motionSensorAccessory::update Error ->' + error)
|
||||
|
||||
@@ -94,6 +94,7 @@ export class powerSocketAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('powersocket')) {
|
||||
for (const device of devices.powersocket) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.state == 'on') {
|
||||
@@ -105,6 +106,7 @@ export class powerSocketAccessory extends accessory {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('powerSocketAccessory::update Error ->' + error)
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -100,6 +100,7 @@ export class powerSwitchAccessory extends accessory {
|
||||
.then((response) => {
|
||||
const devices = JSON.parse(response.body)
|
||||
|
||||
if (devices.hasOwnProperty('powerswitch')) {
|
||||
for (const device of devices.powerswitch) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.state == 'on') {
|
||||
@@ -116,6 +117,7 @@ export class powerSwitchAccessory extends accessory {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.platform.log.debug('powerSwitchAccessory::update Error ->' + error)
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user