Skip to content

Commit 8d5b2c1

Browse files
fix(refactor): Migrate GTZ10 to generic device_mode mapping value converter
1 parent f435547 commit 8d5b2c1

File tree

2 files changed

+46
-48
lines changed

2 files changed

+46
-48
lines changed

src/devices/tuya.ts

+46-10
Original file line numberDiff line numberDiff line change
@@ -5601,9 +5601,9 @@ const definitions: DefinitionWithExtend[] = [
56015601
'system_mode',
56025602
tuya.valueConverter.thermostatSystemModeAndPresetMap({
56035603
toMap: {
5604-
auto: new tuya.Enum(0), // auto
5605-
heat: new tuya.Enum(1), // manual
5606-
off: new tuya.Enum(2), // off
5604+
auto: new tuya.Enum(0), // auto
5605+
heat: new tuya.Enum(1), // manual
5606+
off: new tuya.Enum(2), // off
56075607
},
56085608
}),
56095609
],
@@ -5612,10 +5612,10 @@ const definitions: DefinitionWithExtend[] = [
56125612
'preset',
56135613
tuya.valueConverter.thermostatSystemModeAndPresetMap({
56145614
toMap: {
5615-
none: new tuya.Enum(1), // manual
5616-
eco: new tuya.Enum(3), // eco
5617-
comfort: new tuya.Enum(4), // comfort
5618-
boost: new tuya.Enum(5), // boost
5615+
none: new tuya.Enum(1), // manual
5616+
eco: new tuya.Enum(3), // eco
5617+
comfort: new tuya.Enum(4), // comfort
5618+
boost: new tuya.Enum(5), // boost
56195619
},
56205620
}),
56215621
],
@@ -13389,9 +13389,45 @@ const definitions: DefinitionWithExtend[] = [
1338913389
],
1339013390
meta: {
1339113391
tuyaDatapoints: [
13392-
[2, null, tuya.valueConverter.thermostatGtz10SystemModeAndPreset(null)],
13393-
[2, 'preset', tuya.valueConverter.thermostatGtz10SystemModeAndPreset('preset')],
13394-
[2, 'system_mode', tuya.valueConverter.thermostatGtz10SystemModeAndPreset('system_mode')],
13392+
[
13393+
2,
13394+
null,
13395+
tuya.valueConverter.thermostatSystemModeAndPresetMap({
13396+
fromMap: {
13397+
0: {device_mode: 'manual', system_mode: 'heat', preset: 'manual'},
13398+
1: {device_mode: 'auto', system_mode: 'auto', preset: 'auto'},
13399+
2: {device_mode: 'holiday', system_mode: 'heat', preset: 'holiday'},
13400+
3: {device_mode: 'comfort', system_mode: 'heat', preset: 'comfort'},
13401+
4: {device_mode: 'eco', system_mode: 'heat', preset: 'eco'},
13402+
5: {device_mode: 'off', system_mode: 'off', preset: 'off'},
13403+
},
13404+
}),
13405+
],
13406+
[
13407+
2,
13408+
'preset',
13409+
tuya.valueConverter.thermostatSystemModeAndPresetMap({
13410+
toMap: {
13411+
manual: new tuya.Enum(0),
13412+
auto: new tuya.Enum(1),
13413+
holiday: new tuya.Enum(2),
13414+
comfort: new tuya.Enum(3),
13415+
eco: new tuya.Enum(4),
13416+
off: new tuya.Enum(5),
13417+
},
13418+
}),
13419+
],
13420+
[
13421+
2,
13422+
'system_mode',
13423+
tuya.valueConverter.thermostatSystemModeAndPresetMap({
13424+
toMap: {
13425+
heat: new tuya.Enum(0),
13426+
auto: new tuya.Enum(1),
13427+
off: new tuya.Enum(5),
13428+
},
13429+
}),
13430+
],
1339513431
[4, 'current_heating_setpoint', tuya.valueConverter.divideBy10],
1339613432
[5, 'local_temperature', tuya.valueConverter.divideBy10],
1339713433
[6, 'battery', tuya.valueConverter.raw],

src/lib/tuya.ts

-38
Original file line numberDiff line numberDiff line change
@@ -1173,44 +1173,6 @@ export const valueConverter = {
11731173
},
11741174
};
11751175
},
1176-
thermostatGtz10SystemModeAndPreset: (toKey: string) => {
1177-
return {
1178-
from: (v: string) => {
1179-
utils.assertNumber(v, 'system_mode');
1180-
const presetLookup = {
1181-
0: 'manual',
1182-
1: 'auto',
1183-
2: 'holiday',
1184-
3: 'comfort',
1185-
4: 'eco',
1186-
5: 'off',
1187-
};
1188-
const systemModeLookup = {
1189-
0: 'heat',
1190-
1: 'auto',
1191-
5: 'off',
1192-
};
1193-
return {preset: presetLookup[v], system_mode: systemModeLookup[v]};
1194-
},
1195-
to: (v: string) => {
1196-
const presetLookup = {
1197-
manual: new Enum(0),
1198-
auto: new Enum(1),
1199-
holiday: new Enum(2),
1200-
comfort: new Enum(3),
1201-
eco: new Enum(4),
1202-
off: new Enum(5),
1203-
};
1204-
const systemModeLookup = {
1205-
heat: new Enum(0),
1206-
auto: new Enum(1),
1207-
off: new Enum(5),
1208-
};
1209-
const lookup = toKey === 'preset' ? presetLookup : systemModeLookup;
1210-
return utils.getFromLookup(v, lookup);
1211-
},
1212-
};
1213-
},
12141176
ZWT198_schedule: {
12151177
from: (value: number[], meta: Fz.Meta, options: KeyValue) => {
12161178
const programmingMode = [];

0 commit comments

Comments
 (0)