ilcato / homebridge-Fibaro-HC2

Homebridge plugin for Fibaro Home Center 2 (and Home Center Lite ...)
Apache License 2.0
65 stars 27 forks source link

Can't change temperature unit from C to F on Fibaro HC2 because HomeKit invalid Value #166

Closed emarrero closed 5 years ago

emarrero commented 5 years ago

when I change Fibaro HC2 unit to F on control location panel. The homebridge-Fibaro-HC2 not validate if the unit is F or C.

The homebridge-Fibaro-HC2 on fibaro-api.ts getDevices() the result

{
    "type": "com.fibaro.temperatureSensor", 
    "properties": {
        "unit": "F",
       "value": "82.22"
    }
}

I change the getDevices() to fix my problem

    getDevices() {
        let p = new Promise((resolve, reject) => {
            let url = "http://"+this.host+"/api/devices";
            request.get({
                url: url,
                headers : this.headers,
                json: true
            }, function(err, response, json) {
                if (!err && response.statusCode == 200) {
                    json.forEach(function (dev) {
                        if (dev.type == "com.fibaro.temperatureSensor") {
                            if (dev.unit == "F") {
                                dev.unit = "C"
                                dev.value =  (dev.value-32) * 5 / 9;
                            }
                        }
                    });
                    resolve(json);
                }
                else {
                    reject(err);
                }
            });
        });
        return p;
    }

I need to change the pollerupdate.ts. the only problem with this change is that result do not include unit to validate if is F or C. I assuming that the value is in F because I change the HC2 to F. For other people this not going to work. if the Unit on HC2 it is in C the updates the value will be change unnecessary and broke the Temperature

ilcato, Can you implement a better solution in the next version? Thank you

    manageValue(change) {
        for (let i = 0; i < this.platform.updateSubscriptions.length; i++) {
            let subscription = this.platform.updateSubscriptions[i];
            if (subscription.id == change.id && subscription.property == "value") {
                if (subscription.characteristic.displayName == "Current Temperature") {
                    change.value = (change.value-32) * 5 / 9;
                }
                this.platform.log("Updating value for device: ", `${subscription.id}  parameter: ${subscription.characteristic.displayName}, value: ${change.value}`);
                if (this.platform.config.enableIFTTTnotification == "all" || this.platform.config.enableIFTTTnotification == "hc")
                    this.platform.notifyIFTTT(VALUE_GET, subscription.id, subscription.characteristic.displayName.replace(" ", "_"), change.value);
                let getFunction = this.platform.getFunctions.getFunctionsMapping.get(subscription.characteristic.UUID);
                if (getFunction.function)
                    getFunction.function.call(this.platform.getFunctions, null, subscription.characteristic, subscription.service, null, change);
            }
        }
    }   

IMG_1283 IMG_1282

Screen Shot 2019-08-13 at 1 14 27 PM
emarrero commented 5 years ago
    getDeviceProperties(ID) {
        let p = new Promise((resolve, reject) => {
            let url = "http://"+this.host+"/api/devices/"+ID;
            request.get({
                url: url,
                headers : this.headers,
                json: true
            }, function(err, response, json) {
                if (!err && response.statusCode == 200) {
                    if (json.type == "com.fibaro.temperatureSensor") {
                        if (json.properties.unit == "F") {
                            json.properties.unit = "C"
                            json.properties.value =  (json.properties.value-32) * 5 / 9;
                        }
                    }
                    resolve(json.properties);
                }
                else {
                    reject(err);
                }

            });
        });
        return p;
    }
![IMG_1285](https://user-images.githubusercontent.com/1309555/62968522-38cca780-bdd9-11e9-8e61-0f0fdbdd6c88.jpeg)
ilcato commented 5 years ago

Are you able to create a PR?

emarrero commented 5 years ago

I already submit to the Pull Request. I change the way of updating the temperature with a new variable in the config and only do the conversion when FibaroTemperatureUnit = "F" if the variable is "C" does not do the conversion.

emarrero commented 5 years ago

ilcato, thank you very much for accepting the Pull request.