light: ws channel data is text

This commit is contained in:
Maxim Prokhorov
2022-11-05 02:59:45 +03:00
parent 29af260d34
commit c4d3c57e80
2 changed files with 25 additions and 13 deletions

View File

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

View File

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