Change DoorWindowSensor to ContactSensor
This commit is contained in:
@@ -9,7 +9,7 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
private service: Service
|
||||
|
||||
private state = {
|
||||
Position: 0
|
||||
Position: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -34,7 +34,7 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
doorWindowSensorDevices.push(object)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resolve(doorWindowSensorDevices)
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -54,11 +54,14 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
.setCharacteristic(this.platform.Characteristic.SerialNumber, '04000' + accessory.context.device.typeId)
|
||||
|
||||
if (accessory.context.device.detailedType == "door") {
|
||||
this.service = this.accessory.getService(this.platform.Service.Door) || this.accessory.addService(this.platform.Service.Door)
|
||||
this.service = this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)
|
||||
} else { // window
|
||||
this.service = this.accessory.getService(this.platform.Service.Window) || this.accessory.addService(this.platform.Service.Window)
|
||||
this.service = this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)
|
||||
}
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
|
||||
.onGet(this.getContactSensorState.bind(this));
|
||||
/*
|
||||
this.service.getCharacteristic(this.platform.Characteristic.CurrentPosition)
|
||||
.onGet(this.getCurrentPosition.bind(this));
|
||||
|
||||
@@ -67,7 +70,7 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
||||
.onGet(this.getTargetPosition.bind(this))
|
||||
|
||||
*/
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -79,12 +82,14 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
setValue(key, value) {
|
||||
if (key == "state" && value != "") {
|
||||
if (value == "Off") {
|
||||
this.state.Position = 0
|
||||
this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
||||
} else {
|
||||
this.state.Position = 100
|
||||
this.state.Position = 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)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,12 +106,14 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
for (const device of devices.doorwindow) {
|
||||
if (device.id == this.accessory.context.device.typeId) {
|
||||
if (device.state == 'closed') {
|
||||
this.state.Position = 0
|
||||
this.state.Position = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
||||
} else { // open
|
||||
this.state.Position = 100
|
||||
this.state.Position = 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)
|
||||
*/
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -115,7 +122,7 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
this.platform.log.debug('doorWindowSensorAccessory::update Error ->' + error)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
getCurrentPosition(): CharacteristicValue {
|
||||
return this.state.Position
|
||||
}
|
||||
@@ -131,4 +138,8 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
getPosition(): CharacteristicValue {
|
||||
return this.state.Position
|
||||
}
|
||||
*/
|
||||
getContactSensorState(): CharacteristicValue {
|
||||
return this.state.Position
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user