mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-18 22:27:05 +01:00
light: ws channel data is text
This commit is contained in:
@@ -1462,19 +1462,30 @@ String _lightGroupPayload() {
|
||||
|
||||
long _lightAdjustValue(long value, espurna::StringView operation) {
|
||||
if (operation.length()) {
|
||||
char* endp { nullptr };
|
||||
auto updated = std::strtol(operation.begin(), &endp, 10);
|
||||
if ((endp == operation.begin()) || (*endp != '\0')) {
|
||||
return value;
|
||||
}
|
||||
|
||||
switch (operation[0]) {
|
||||
case '+':
|
||||
case '-':
|
||||
return updated + value;
|
||||
{
|
||||
const long multiplier = (operation[0] == '-') ? -1 : 1;
|
||||
operation = espurna::StringView(
|
||||
operation.begin() + 1, operation.end());
|
||||
|
||||
const auto result = parseUnsigned(operation, 10);
|
||||
if (result.ok && result.value < std::numeric_limits<long>::max()) {
|
||||
return value + (static_cast<long>(result.value) * multiplier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return updated;
|
||||
default:
|
||||
{
|
||||
const auto result = parseUnsigned(operation, 10);
|
||||
if (result.ok && result.value < std::numeric_limits<long>::max()) {
|
||||
return result.value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -2576,12 +2587,12 @@ void _lightWebSocketOnAction(uint32_t client_id, const char* action, JsonObject&
|
||||
|
||||
if (channel.success()) {
|
||||
for (auto& kv : channel) {
|
||||
const auto id = parseUnsigned(kv.key, 10);
|
||||
if (!id.ok) {
|
||||
size_t id;
|
||||
if (!_lightTryParseChannel(kv.key, id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
lightChannel(id.value, kv.value.as<long>());
|
||||
_lightAdjustChannel(id, kv.value.as<String>());
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,9 +355,10 @@ const uint8_t* hexEncodeImpl(const uint8_t* in_begin, const uint8_t* in_end, T&&
|
||||
|
||||
auto* in_ptr = in_begin;
|
||||
for (; in_ptr != in_end; ++in_ptr) {
|
||||
char buf[2] {
|
||||
const char buf[2] {
|
||||
base16[((*in_ptr) & Left) >> Shift],
|
||||
base16[(*in_ptr) & Right]};
|
||||
base16[(*in_ptr) & Right]
|
||||
};
|
||||
if (!callback(buf)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user