Add LowBattery and Active states to wireless sensors
This commit is contained in:
@@ -10,6 +10,8 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
|
||||
private state = {
|
||||
ContactSensorState: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED,
|
||||
LowBattery: false,
|
||||
Active: false
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -62,6 +64,12 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
|
||||
.onGet(this.getContactSensorState.bind(this));
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -79,6 +87,22 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState)
|
||||
}
|
||||
else if (key == "battery" && value != "") {
|
||||
if (value < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
}
|
||||
else if (key == "online" && value != "") {
|
||||
if (value == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -100,7 +124,21 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
||||
}
|
||||
|
||||
if (device.battery < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
|
||||
if (device.online == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
|
||||
break
|
||||
}
|
||||
@@ -115,4 +153,12 @@ export class doorWindowSensorAccessory extends accessory {
|
||||
getContactSensorState(): CharacteristicValue {
|
||||
return this.state.ContactSensorState
|
||||
}
|
||||
|
||||
getLowBattery(): CharacteristicValue {
|
||||
return this.state.LowBattery
|
||||
}
|
||||
|
||||
getActive(): CharacteristicValue {
|
||||
return this.state.Active
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,9 @@ export class environmentSensorAccessory extends accessory {
|
||||
|
||||
private state = {
|
||||
Temperature: 0,
|
||||
Humidity: 0
|
||||
Humidity: 0,
|
||||
LowBattery: false,
|
||||
Active: false
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -63,6 +65,16 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
|
||||
.onGet(this.getHumidity.bind(this))
|
||||
|
||||
this.serviceTemperature.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
|
||||
this.serviceTemperature.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -81,6 +93,24 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.state.Humidity = value / 100
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
|
||||
}
|
||||
else if (key == "battery" && value != "") {
|
||||
if (value < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
}
|
||||
else if (key == "online" && value != "") {
|
||||
if (value == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -99,8 +129,24 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.state.Temperature = device.temperature
|
||||
this.state.Humidity = device.humidity
|
||||
|
||||
if (device.battery < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
|
||||
if (device.online == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
|
||||
break
|
||||
}
|
||||
@@ -119,4 +165,12 @@ export class environmentSensorAccessory extends accessory {
|
||||
getHumidity(): CharacteristicValue {
|
||||
return this.state.Humidity
|
||||
}
|
||||
|
||||
getLowBattery(): CharacteristicValue {
|
||||
return this.state.LowBattery
|
||||
}
|
||||
|
||||
getActive(): CharacteristicValue {
|
||||
return this.state.Active
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ export class motionSensorAccessory extends accessory {
|
||||
private service: Service
|
||||
|
||||
private state = {
|
||||
Motion: false
|
||||
Motion: false,
|
||||
LowBattery: false,
|
||||
Active: false
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -58,6 +60,12 @@ export class motionSensorAccessory extends accessory {
|
||||
this.service.getCharacteristic(this.platform.Characteristic.MotionDetected)
|
||||
.onGet(this.getState.bind(this));
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -75,6 +83,22 @@ export class motionSensorAccessory extends accessory {
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
|
||||
}
|
||||
else if (key == "battery" && value != "") {
|
||||
if (value < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
}
|
||||
else if (key == "online" && value != "") {
|
||||
if (value == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -96,7 +120,21 @@ export class motionSensorAccessory extends accessory {
|
||||
this.state.Motion = true
|
||||
}
|
||||
|
||||
if (device.battery < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
|
||||
if (device.online == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
|
||||
break
|
||||
}
|
||||
@@ -111,4 +149,12 @@ export class motionSensorAccessory extends accessory {
|
||||
getState(): CharacteristicValue {
|
||||
return this.state.Motion
|
||||
}
|
||||
|
||||
getLowBattery(): CharacteristicValue {
|
||||
return this.state.LowBattery
|
||||
}
|
||||
|
||||
getActive(): CharacteristicValue {
|
||||
return this.state.Active
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user