|
@@ -9,7 +9,7 @@ export class doorWindowSensorAccessory extends accessory {
|
|
|
private service: Service
|
|
private service: Service
|
|
|
|
|
|
|
|
private state = {
|
|
private state = {
|
|
|
- Position: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
|
|
|
|
|
+ ContactSensorState: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
|
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
|
@@ -61,16 +61,7 @@ export class doorWindowSensorAccessory extends accessory {
|
|
|
|
|
|
|
|
this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
|
|
this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
|
|
|
.onGet(this.getContactSensorState.bind(this));
|
|
.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.setName(accessory.context.device.deviceName)
|
|
|
this.update()
|
|
this.update()
|
|
|
}
|
|
}
|
|
@@ -82,14 +73,11 @@ 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 = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
|
|
|
|
|
+ this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
|
} else {
|
|
} 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) => {
|
|
.then((response) => {
|
|
|
const devices = JSON.parse(response.body)
|
|
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)
|
|
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 {
|
|
getContactSensorState(): CharacteristicValue {
|
|
|
- return this.state.Position
|
|
|
|
|
|
|
+ return this.state.ContactSensorState
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|