Browse Source

tuya: build defaults based on #2414 discussion

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
92d5e7becb
4 changed files with 98 additions and 4 deletions
  1. +60
    -0
      code/espurna/config/defaults.h
  2. +7
    -0
      code/espurna/config/hardware.h
  3. +1
    -1
      code/espurna/homeassistant.cpp
  4. +30
    -3
      code/espurna/tuya.cpp

+ 60
- 0
code/espurna/config/defaults.h View File

@ -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
// -----------------------------------------------------------------------------


+ 7
- 0
code/espurna/config/hardware.h View File

@ -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


+ 1
- 1
code/espurna/homeassistant.cpp View File

@ -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);
}


+ 30
- 3
code/espurna/tuya.cpp View File

@ -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<TuyaLightProvider>(channelIds, &channelStateId));
}


Loading…
Cancel
Save