diff --git a/code/espurna/config/defaults.h b/code/espurna/config/defaults.h index fd3b9d56..541f92cb 100644 --- a/code/espurna/config/defaults.h +++ b/code/espurna/config/defaults.h @@ -1043,6 +1043,66 @@ #define LIGHT_CH5_INVERSE 0 #endif +// ----------------------------------------------------------------------------- +// Tuya +// ----------------------------------------------------------------------------- + +#ifndef TUYA_CH_STATE_DPID +#define TUYA_CH_STATE_DPID 0 +#endif + +#ifndef TUYA_CH1_DPID +#define TUYA_CH1_DPID 0 +#endif + +#ifndef TUYA_CH2_DPID +#define TUYA_CH2_DPID 0 +#endif + +#ifndef TUYA_CH3_DPID +#define TUYA_CH3_DPID 0 +#endif + +#ifndef TUYA_CH4_DPID +#define TUYA_CH4_DPID 0 +#endif + +#ifndef TUYA_CH5_DPID +#define TUYA_CH5_DPID 0 +#endif + +#ifndef TUYA_SW1_DPID +#define TUYA_SW1_DPID 0 +#endif + +#ifndef TUYA_SW2_DPID +#define TUYA_SW2_DPID 0 +#endif + +#ifndef TUYA_SW3_DPID +#define TUYA_SW3_DPID 0 +#endif + +#ifndef TUYA_SW4_DPID +#define TUYA_SW4_DPID 0 +#endif + +#ifndef TUYA_SW5_DPID +#define TUYA_SW5_DPID 0 +#endif + +#ifndef TUYA_SW6_DPID +#define TUYA_SW6_DPID 0 +#endif + +#ifndef TUYA_SW7_DPID +#define TUYA_SW7_DPID 0 +#endif + +#ifndef TUYA_SW8_DPID +#define TUYA_SW8_DPID 0 +#endif + // ----------------------------------------------------------------------------- // General // ----------------------------------------------------------------------------- diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 8e87bb38..1b7890a6 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -4495,6 +4495,13 @@ #define TUYA_SUPPORT 1 #define LIGHT_PROVIDER LIGHT_PROVIDER_CUSTOM + #define LED1_GPIO 14 + + #define TUYA_CH_STATE_DPID 1 + #define TUYA_CH1_DPID 2 + + #define DEBUG_SERIAL_SUPPORT 0 + // ----------------------------------------------------------------------------- // Etekcity ESW01-USA // https://www.amazon.com/Etekcity-Voltson-Outlet-Monitoring-Required/dp/B01M3MYIFS diff --git a/code/espurna/homeassistant.cpp b/code/espurna/homeassistant.cpp index 49e6edc9..dabc363b 100644 --- a/code/espurna/homeassistant.cpp +++ b/code/espurna/homeassistant.cpp @@ -73,7 +73,7 @@ public: manufacturer(manufacturer_), device(device_) { - name = normalize_ascii(std::move(name)); + name = normalize_ascii(std::move(name)); identifier = normalize_ascii(std::move(identifier), true); } diff --git a/code/espurna/tuya.cpp b/code/espurna/tuya.cpp index a319e199..2656630c 100644 --- a/code/espurna/tuya.cpp +++ b/code/espurna/tuya.cpp @@ -527,6 +527,33 @@ error: } + namespace build { + + constexpr unsigned char channelDpId(unsigned char index) { + return (index == 0) ? TUYA_CH1_DPID : + (index == 1) ? TUYA_CH2_DPID : + (index == 2) ? TUYA_CH3_DPID : + (index == 3) ? TUYA_CH4_DPID : + (index == 4) ? TUYA_CH5_DPID : 0u; + } + + constexpr unsigned char switchDpId(unsigned char index) { + return (index == 0) ? TUYA_SW1_DPID : + (index == 1) ? TUYA_SW2_DPID : + (index == 2) ? TUYA_SW3_DPID : + (index == 3) ? TUYA_SW4_DPID : + (index == 4) ? TUYA_SW5_DPID : + (index == 5) ? TUYA_SW6_DPID : + (index == 6) ? TUYA_SW7_DPID : + (index == 7) ? TUYA_SW8_DPID : 0u; + } + + constexpr unsigned char channelStateDpId() { + return TUYA_CH_STATE_DPID; + } + + } // namespace build + // Predefined DP<->SWITCH, DP<->CHANNEL associations // Respective provider setup should be called before state restore, // so we can use dummy values @@ -534,7 +561,7 @@ error: void setupSwitches() { bool done { false }; for (unsigned char id = 0; id < RelaysMax; ++id) { - auto dp = getSetting({"tuyaSwitch", id}, 0); + auto dp = getSetting({"tuyaSwitch", id}, build::switchDpId(id)); if (!dp) { break; } @@ -560,7 +587,7 @@ error: void setupChannels() { bool done { false }; for (unsigned char id = 0; id < Light::ChannelsMax; ++id) { - auto dp = getSetting({"tuyaChannel", id}, 0); + auto dp = getSetting({"tuyaChannel", id}, build::channelDpId(id)); if (!dp) { break; } @@ -577,7 +604,7 @@ error: } if (done) { - channelStateId = getSetting("tuyaChanState", 0u); + channelStateId = getSetting("tuyaChanState", build::channelStateDpId()); lightSetProvider(std::make_unique(channelIds, &channelStateId)); }