sammachin / node-red-matter-bridge

Matter Bridge for Node-RED
10 stars 2 forks source link

Cannot set `setPoint` to zero #7

Closed Steve-Mcl closed 2 weeks ago

Steve-Mcl commented 2 weeks ago

I am unable to set the setPoint to zero. Additionally, the temperature would not be set if zero is sent in.

https://github.com/sammachin/node-red-matter-bridge/blob/90827b2a5a54b9585a4dbe39a25b0b51a85743ba/thermostat.js#L44-L59

I haven't checked other files but at a guess, similar oversights might be present so it might be worth adding a couple of helper functions here to test hasProperty and isNumber that can be reused across the js files?

helpers in file e.g. utils.js

function hasProperty(obj, prop) {
    return obj ? Object.prototype.hasOwnProperty.call(obj, prop) : false
}

function isNumber(value) {
    return typeof value === 'number' && !isNaN(value);
}

module.exports = { hasProperty, isNumber };

Modify the calls to

import helpers
const { hasProperty, isNumber } = require('./utils');
Use helpers
                    if (hasProperty(msg.payload, 'setPoint') && isNumber(msg.payload.setPoint)) { // UPDATE
                        if (systemMode == 4){
                            values.occupiedHeatingSetpoint = msg.payload.setPoint
                        } else if (systemMode == 3){
                            values.occupiedCoolingSetpoint = msg.payload.setPoint
                        } 
                    }
                    node.device.set({thermostat: values})
                    node.ctx.set(node.id+"-values",  values)
                    node.values = values
                }
                if (hasProperty(msg.payload, 'temperature') && isNumber(msg.payload.temperature)) { // UPDATE
                    node.device.set({thermostat : {localTemperature : msg.payload.temperature}})
                    node.ctx.set(node.id+"-temperature",  msg.payload.temperature)
                    node.temperature = msg.payload.temperature
                }
sammachin commented 2 weeks ago

thanks steve well caught, yes the thermostat will have this issue as I check if the value was set because you can send multiple different values into the node but obviously if you set it to zero it will be false, Similar issue in the full color light and the color temp light but I think thats all.

I'll add those helper functions and update to use them

sammachin commented 2 weeks ago

fixed in 0.10.1