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