Skip to content

Commit

Permalink
Fix wrong temperature on sensor. (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5e authored Nov 2, 2022
1 parent 2c78afb commit 7f9b264
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/accessory/TemperatureHumiditySensorAccessory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PlatformAccessory } from 'homebridge';
import { TuyaDeviceFunctionIntegerProperty } from '../device/TuyaDevice';
import { TuyaPlatform } from '../platform';
import BaseAccessory from './BaseAccessory';

Expand All @@ -13,8 +14,11 @@ export default class TemperatureHumiditySensorAccessory extends BaseAccessory {

service.getCharacteristic(this.Characteristic.CurrentTemperature)
.onGet(() => {
const property = this.device.getDeviceFunctionProperty('va_temperature') as TuyaDeviceFunctionIntegerProperty | undefined;
const multiple = property ? Math.pow(10, property.scale) : 1;
const status = this.device.getDeviceStatus('va_temperature');
let temperature = Math.max(-270, status!.value as number);
let temperature = status!.value as number / multiple;
temperature = Math.max(-270, temperature);
temperature = Math.min(100, temperature);
return temperature;
});
Expand Down

0 comments on commit 7f9b264

Please sign in to comment.