Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stateValue(state) {
switch (this.textType) {
case 'temperature':
if ('Uninitialized' === state) {
return 0.0;
}
return +state;
case 'contact':
if ('CLOSED' === state) {
return Characteristic.ContactSensorState.CONTACT_DETECTED;
}
// fall back to 'no contact' if uninitialized or OPEN
return Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
default:
// For generic text values, we use labels rather than state
return '';
}
};
convertState(state) {
if ('CLOSED' === state) {
return Characteristic.ContactSensorState.CONTACT_DETECTED;
}
// fall back to 'no contact' if uninitialized or OPEN
return Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
}
}
convertState(state) {
if ('CLOSED' === state) {
return Characteristic.ContactSensorState.CONTACT_DETECTED;
}
// fall back to 'no contact' if uninitialized or OPEN
return Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
}
}
buildAccessory(state, name) {
let accessory = new Accessory(this.name,
uuid.generate(this.constructor.name + this.name));
let service = CustomServices.TextInfoService;
let characteristic = CustomCharacteristics.TextInfoCharacteristic;
let initialValue = this.labelValue(name);
switch (this.textType) {
case 'contact':
service = Service.ContactSensor;
characteristic = Characteristic.ContactSensorState;
initialValue = this.stateValue(state);
break;
case 'temperature':
service = Service.TemperatureSensor;
characteristic = Characteristic.CurrentTemperature;
initialValue = this.stateValue(state);
}
this.characteristic = accessory.addService(service, this.name).getCharacteristic(characteristic);
this.characteristic.on('get', this.readOpenHabText.bind(this));
this.characteristic.setValue(initialValue);
return accessory;
};
changeAction = function(newState){
service.getCharacteristic(Characteristic.ContactSensorState)
.setValue(newState ? Characteristic.ContactSensorState.CONTACT_DETECTED : Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
};
} else {
ISYDoorWindowSensorAccessory.prototype.handleExternalChange = function() {
this.sensorService
.setCharacteristic(Characteristic.ContactSensorState, this.translateCurrentDoorWindowState());
}
changeAction = function(newState){
service.getCharacteristic(Characteristic.ContactSensorState)
.setValue(newState ? Characteristic.ContactSensorState.CONTACT_DETECTED : Characteristic.ContactSensorState.CONTACT_NOT_DETECTED);
};
} else {
ISYDoorWindowSensorAccessory.prototype.translateCurrentDoorWindowState = function() {
return (this.device.getCurrentDoorWindowState()) ? Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : Characteristic.ContactSensorState.CONTACT_DETECTED;
}
buildAccessory(state) {
let accessory = new Accessory(this.name,
uuid.generate(this.constructor.name + this.name));
let charactersiticContactState = accessory
.addService(Service.ContactSensor, this.name)
.getCharacteristic(Characteristic.ContactSensorState);
charactersiticContactState.setValue(this.convertState(state));
charactersiticContactState.on('get', this.readOpenHabContact.bind(this));
return accessory;
}