mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-13 19:57:05 +01:00
* experimental: refactor get/set/del/hasSetting * sensors * lights * cleaup * r * tuya * fixup! sensors * fixup! tuya * header defaults types * fix lights * setup already checks for max * helper for flashstring * fix overload * oops * refactor includes * warnings * test with migrate * add ids in a separate file * cleanup rev: crash rev: domoticz rev: encoder rev: loopdelay rev: hass rev: i2c rev2: hass rev: mqtt rev: rfm69 rev: relay rev: rpn rev: settings setup rev: hb settings rev: telnet preprocessor fix rev: settings wrap rev: tspk bool style rev: wifi types rev: util hb rev: settings fixup! rev: settings * rev: cleanup wifi injections based on new getters * hasSetting now can return true for empty key * show hardcoded network in web * oops * fix ws referencing wrong index * ensure empty strings are written * c/p * use experimental schema style for payload, mark network as not deletable * allow to customize converter * shorter syntax, try using with wifi * use proper #if syntax to handle definitions that are missing * fixup ota sc checks getter, cast schEnabled to bool * add utils header to sensors
76 lines
1.3 KiB
C++
76 lines
1.3 KiB
C++
/*
|
|
|
|
SETTINGS MODULE
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdlib>
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
namespace settings {
|
|
namespace internal {
|
|
|
|
template <typename T>
|
|
using convert_t = T(*)(const String& value);
|
|
|
|
template <typename T>
|
|
T convert(const String& value);
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
template <>
|
|
float convert(const String& value) {
|
|
return value.toFloat();
|
|
}
|
|
|
|
template <>
|
|
double convert(const String& value) {
|
|
return value.toFloat();
|
|
}
|
|
|
|
template <>
|
|
int convert(const String& value) {
|
|
return value.toInt();
|
|
}
|
|
|
|
template <>
|
|
long convert(const String& value) {
|
|
return value.toInt();
|
|
}
|
|
|
|
template <>
|
|
bool convert(const String& value) {
|
|
return convert<int>(value) == 1;
|
|
}
|
|
|
|
template <>
|
|
unsigned long convert(const String& value) {
|
|
return strtoul(value.c_str(), nullptr, 10);
|
|
}
|
|
|
|
template <>
|
|
unsigned int convert(const String& value) {
|
|
return convert<unsigned long>(value);
|
|
}
|
|
|
|
template <>
|
|
unsigned short convert(const String& value) {
|
|
return convert<unsigned long>(value);
|
|
}
|
|
|
|
template <>
|
|
unsigned char convert(const String& value) {
|
|
return convert<unsigned long>(value);
|
|
}
|
|
|
|
template <>
|
|
String convert(const String& value) {
|
|
return value;
|
|
}
|
|
|
|
} // namespace settings::internal
|
|
} // namespace settings
|