Skip to content

Commit

Permalink
tuya: send channel value directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Feb 6, 2021
1 parent b35a565 commit 012c381
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/espurna/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LightProvider {
public:
virtual void update() = 0;
virtual void state(bool) = 0;
virtual void channel(unsigned char ch, double value) = 0;
virtual void channel(unsigned char ch, float value) = 0;
};

struct LightTransition {
Expand Down
13 changes: 2 additions & 11 deletions code/espurna/tuya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace tuya {
}
}

void channel(unsigned char channel, double value) override {
void channel(unsigned char channel, float value) override {
// XXX: can't handle channel values when OFF, and will turn the lights ON
if (!_last_state) {
return;
Expand All @@ -150,18 +150,9 @@ namespace tuya {
return;
}

auto rounded = static_cast<unsigned int>(value);

// input dimmer channel value when lights are OFF is 16
// for the same reason as above, don't send OFF values
constexpr unsigned int Low { 16u };
constexpr unsigned int High { 255u };
rounded = std::clamp(rounded, Low, High);
if (rounded == 16u) {
return;
}

send(entry->dp_id, rounded);
send(entry->dp_id, static_cast<unsigned int>(value));
}

private:
Expand Down

0 comments on commit 012c381

Please sign in to comment.