Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for TuYa 1 gang, 2 gang and 3 gang switches #5939

Merged
merged 11 commits into from
Jul 7, 2023
69 changes: 69 additions & 0 deletions src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,25 @@ const definitions: Definition[] = [
await reporting.bind(device.getEndpoint(1), coordinatorEndpoint, ['genOnOff']);
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_gbagoilo']),
model: 'TS0601-1-gang-switchboard',
krishnachytanya marked this conversation as resolved.
Show resolved Hide resolved
vendor: 'TuYa',
description: '1 gang switch',
exposes: [e.switch().withEndpoint('l1').setAccess('state', ea.STATE_SET)],
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
endpoint: (device) => {
return {'l1': 1};
},
meta: {
multiEndpoint: true,
krishnachytanya marked this conversation as resolved.
Show resolved Hide resolved
tuyaDatapoints: [
[21, 'state_l1', tuya.valueConverterBasic.legacyOnOff()],
],
},
},
{
fingerprint: [
{modelID: 'TS0601', manufacturerName: '_TZE200_nkjintbl'},
Expand All @@ -1491,6 +1510,30 @@ const definitions: Definition[] = [
return {'l1': 1, 'l2': 1};
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_nh9m9emk']),
model: 'TS0601-2-gang-switchboard',
vendor: 'TuYa',
description: '2 gang switch',
exposes: [
e.switch().withEndpoint('l1').setAccess('state', ea.STATE_SET),
e.switch().withEndpoint('l2').setAccess('state', ea.STATE_SET),
],
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
endpoint: (device) => {
// Endpoint selection is made in tuya_switch_state
return {'l1': 1, 'l2': 1};
},
meta: {
multiEndpoint: true,
tuyaDatapoints: [
[21, 'state_l1', tuya.valueConverterBasic.legacyOnOff()],
[22, 'state_l2', tuya.valueConverterBasic.legacyOnOff()],
],
},
},
{
fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_kyfqmmyl'},
{modelID: 'TS0601', manufacturerName: '_TZE200_2hf7x9n3'},
Expand All @@ -1517,6 +1560,32 @@ const definitions: Definition[] = [
return {'l1': 1, 'l2': 1, 'l3': 1};
},
},
{
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_go3tvswy']),
model: 'TS0601-3-gang-switchboard',
vendor: 'TuYa',
description: '3 gang switch',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
configure: tuya.configureMagicPacket,
exposes: [
e.switch().withEndpoint('l1').setAccess('state', ea.STATE_SET),
e.switch().withEndpoint('l2').setAccess('state', ea.STATE_SET),
e.switch().withEndpoint('l3').setAccess('state', ea.STATE_SET),
],
endpoint: (device) => {
// Endpoint selection is made in tuya_switch_state
return {'l1': 1, 'l2': 1, 'l3': 1};
},
meta: {
multiEndpoint: true,
tuyaDatapoints: [
[21, 'state_l1', tuya.valueConverterBasic.legacyOnOff()],
[22, 'state_l2', tuya.valueConverterBasic.legacyOnOff()],
[23, 'state_l3', tuya.valueConverterBasic.legacyOnOff()],
],
},
},
{
fingerprint: tuya.fingerprint('TS0215A', ['_TZ3000_4fsgukof', '_TZ3000_wr2ucaj9', '_TZ3000_zsh6uat3', '_TZ3000_tj4pwzzm',
'_TZ3000_2izubafb', '_TZ3000_pkfazisv']),
Expand Down
9 changes: 9 additions & 0 deletions src/lib/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ export const valueConverterBasic = {
trueFalse: (valueTrue: number | Enum) => {
return {from: (v: number) => v === valueTrue};
},
legacyOnOff: ( ) => {
krishnachytanya marked this conversation as resolved.
Show resolved Hide resolved
const legacyLookupMap = {'ON': true, 'OFF': false};
return {
to: (v: string) => utils.getFromLookup(v, legacyLookupMap),
from: (v:number) => {
return v ? 'ON': 'OFF';
},
};
},
};

export const valueConverter = {
Expand Down