I am trying to modify the homebridge-wink3 code to add a variable so I can track the state in. I have 5 shades in my house, so each instance of the variable needs to be unique.
In the shade.js file, it has;
exports.default = ({ Characteristic, Service }) => {
return {
type: "shade",
group: "shades",
services: [{
service: Service.WindowCovering,
characteristics: [{
characteristic: Characteristic.TargetPosition,
get: (state, desired_state) => desired_state.position * 100,
I'd like to change the get (and set elsewhere in the code) so it uses a local variable lastState to track state.
get: (state, desired_state) => {
if (desired_state.position != null) {
lastState = desired_state.position * 100;
}
else if (lastState != undefined) {
desired_state.position = lastState / 100;
}
return lastState;
I've spent hours trying to work out how to have the code maintain individual variables per shade (object instance), but they always seem to be sharing the same instance of the lastState variable.
What do I need to do here?
See https://github.com/sibartlett/homebridge-wink3/blob/master/src/devices/shade.js for the code.
exports.defaultappears to return a bunch of parameters (type, group, services[]). I need to have thegetparameter/function have access to a local variable (in my example;lastState) that can be set by thesetparameter/function.homebridge-wink3user, but I would do my best to help. The problem is that I don't know what have you tried so far and I don't want to waste time trying to do the same thing you have tried for hours. My thinking about this is usually what the rest of StackOverflow members thinks, so, what have you tried so far?lastStateoutside ofexports.defaultit appears all of the devices (or 'objects' for want of a better word) use the same variable. I need each object to point to a unique instance oflastStateand be able to reference that within theexports.defaultreturnstatement. Perhaps take a look at the code - specifically that file I linked to. Consider what you would do if you needed to add a local variable to thegetandsetstatements, that was unique to each device/object created.