asednev / homebridge-plugin-govee

Govee H-series Thermometer Hygrometer plugin for Homebrige.
Apache License 2.0
53 stars 9 forks source link

H5102 needs same temp fix as H5705 #56

Closed soward closed 2 years ago

soward commented 2 years ago

Describe The Bug:

Using H5102 units, saw the same 100c temp.

Altering the code to use the same mechanism as the H5075 to detect temps below freezing works:

const decodeH5101Values = (streamUpdate) => {
    // TODO would be great to find a way to validate
    let encodedData = parseInt(streamUpdate.substring(8, 14), 16);
    let tempIsNegative = false;
    if (encodedData & 0x800000) {
        tempIsNegative = true;
        encodedData = encodedData ^ 0x800000;
    }
    const battery = parseInt(streamUpdate.substring(14, 16), 16);
    let tempInC = encodedData / 10000;
    if (tempIsNegative) {
        tempInC = 0 - tempInC;
    }
    const tempInF = (tempInC * 9) / 5 + 32;
    const humidity = (encodedData % 1000) / 10;
    return {
        battery,
        humidity,
        tempInC,
        tempInF,
    };
};

To Reproduce:

Add H5102 device and chill it below 0c/32F

Expected behavior:

Should see the lower temps and not 100c

Logs:

Show the Homebridge logs here, remove any sensitive information.

Plugin Config:

{
    "bridge": {
        "name": "Homebridge C343",
        "username": "XXXXXXXXX",
        "port": 51184,
        "pin": "XXX-XX-XXXX"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "Govee",
            "batteryThreshold": 25,
            "debug": true,
            "humidityOffset": 0,
            "platform": "GoveeHomebridgePlugin"
        },
        {
            "platform": "WLED",
            "name": "WLED",
            "wleds": [
                {
                    "name": "WLED-Stove",
                    "host": "10.20.10.131",
                    "effects": [
                        "Rainbow Runner",
                        "Circus",
                        "Lake",
                        "Sine"
                    ],
                    "showEffectControl": true,
                    "log": true
                }
            ]
        }
    ]
}

Screenshots:

Environment:

asednev commented 2 years ago

@soward do you think you could create pull request for this along with some tests?

doggkruse commented 2 years ago

@soward do you think you could create pull request for this along with some tests?

I created a PR for this along with a test case: https://github.com/asednev/govee-bt-client/pull/14