Skip to content

Commit

Permalink
fix temp calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Jan 7, 2025
1 parent 425b364 commit dfcc065
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ async function initScenes() {
}
}

function handleValueChangeCorrections(value, native) {
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value / 2;
}
return value
}

function handleSetValueCorrections(value, native) {
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value * 2;
}
return value
}

async function initDeviceGroups() {
if (!appCloudApi || !appCloudApi.groups) {
return;
Expand Down Expand Up @@ -293,15 +313,10 @@ async function initDeviceGroups() {

if (obj.scale) {
value *= Math.pow(10, obj.scale);
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value * 2;
}
} else if (obj.states) {
value = obj.states[value.toString()];
}
value = handleSetValueCorrections(value, native);

const dps = {};
dps[id] = value;
Expand All @@ -319,12 +334,7 @@ async function initDeviceGroups() {
valueHandler[`${deviceGroupId}.${id}`] = (value) => {
if (value === undefined) return undefined;
value = Math.floor(value * Math.pow(10, -obj.scale) * 100) / 100;
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value / 2;
}
value = handleValueChangeCorrections(value, native);
return value;
};
values[id] = valueHandler[`${deviceGroupId}.${id}`](values[id]);
Expand Down Expand Up @@ -371,6 +381,7 @@ async function initDeviceGroups() {
if (obj.type === 'boolean') {
return (!value || value === 'false') ? false : true;
} else if (obj.type === 'number') {
value = handleValueChangeCorrections(value, native);
return parseFloat(value);
} else {
return value;
Expand Down Expand Up @@ -566,15 +577,10 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {

if (obj.scale) {
value *= Math.pow(10, obj.scale);
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value * 2;
}
} else if (obj.states) {
value = obj.states[value.toString()];
}
value = handleSetValueCorrections(value, native);

const parentDpList = knownDevices[physicalDeviceId] && knownDevices[physicalDeviceId].dpIdList || [];
let sendViaCloud;
Expand All @@ -588,12 +594,7 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {
valueHandler[`${deviceId}.${id}`] = (value) => {
if (value === undefined) return undefined;
value = Math.floor(value * Math.pow(10, -obj.scale) * 100) / 100;
if ((
(native.code === 'TempSet' && native.id === 2) ||
(native.code === 'TempCurrent' && native.id === 3) ||
(native.code === 'floorTemp' && native.id === 102)) && native.property && native.property.step === 5) {
value = value / 2;
}
value = handleValueChangeCorrections(value, native);
return value;
};
values[id] = valueHandler[`${deviceId}.${id}`](values[id]);
Expand Down Expand Up @@ -635,6 +636,9 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {
}
delete obj.encoding;
}
if (!valueHandler[`${deviceId}.${id}`] && obj.type === 'number') {
valueHandler[`${deviceId}.${id}`] = (value) => handleValueChangeCorrections(value, native);
}
objectHelper.setOrUpdateObject(`${deviceId}.${id}`, {
type: 'state',
common: obj,
Expand Down

0 comments on commit dfcc065

Please sign in to comment.