I have written my first adapter and it install properly. However, I think I am confused by some semantics. I have a sensor which is exposed as a device. That device has a property ‘tripped’ that should be true when motion is expected. When a created the device I set the property to be read-only. However, when I detect motion I am using the SetProperty method on the device to change the property - and error is thrown in the log:
2019-08-29 21:31:45.264 INFO : dsc: Unhandled Rejection
2019-08-29 21:31:45.266 ERROR : dsc: Read-only property
Which makes sense. My question is shouldn’t the property of a sensor be readOnly and how do I modify the value of the property to reflect the actual sensor. I don’t think code will help much but here are two snippets.
-
this is where I set up the property
–> in device class
this.properties.set(‘tripped’, new Property(this, ‘tripped’, {type: ‘boolean’, readOnly: true} )) -
this is where I try to reflect the new status ( I am reading form a serial port that is connected to the actual device)
—> in adapter sub-class
…
this.serialPort.pipe(new Readline()).on(‘data’, data => {
console.log(‘from it100:’, data)const cmd = zoneCommands.get(data.slice(0,3)), zone = zones.get(data.slice(3,6)) if( cmd && zone ) { console.log(`setting prop ${cmd.prop} to ${cmd.value}`) **zone.setProperty(cmd.prop, cmd.value) <--- this is the problem** } else { console.log('unknown command skipping ', data.slice(0,3)) }
})