fix dallas sensor checking

This commit is contained in:
Proddy
2022-04-15 18:40:35 +02:00
parent 04a374c380
commit 2f21c896a6
6 changed files with 15 additions and 10 deletions

View File

@@ -503,15 +503,15 @@ DallasSensor::Sensor::Sensor(const uint8_t addr[])
: internal_id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16)
| ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) {
// create ID string
char id_str[20];
snprintf(id_str,
sizeof(id_str),
char id_s[20];
snprintf(id_s,
sizeof(id_s),
"%02X-%04X-%04X-%04X",
(unsigned int)(internal_id_ >> 48) & 0xFF,
(unsigned int)(internal_id_ >> 32) & 0xFFFF,
(unsigned int)(internal_id_ >> 16) & 0xFFFF,
(unsigned int)(internal_id_)&0xFFFF);
id_ = std::string(id_str);
id_ = std::string(id_s);
name_ = std::string{}; // name (alias) is empty
offset_ = 0; // 0 degrees offset
}

View File

@@ -150,7 +150,7 @@ class DallasSensor {
bool temperature_convert_complete();
int16_t get_temperature_c(const uint8_t addr[]);
uint64_t get_id(const uint8_t addr[]);
void remove_ha_topic(const std::string & id_str);
void remove_ha_topic(const std::string & id);
bool command_info(const char * value, const int8_t id, JsonObject & output);
bool command_commands(const char * value, const int8_t id, JsonObject & output);

View File

@@ -550,6 +550,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
if (command == "dallas") {
shell.printfln(F("Testing adding Dallas sensor"));
emsesp::EMSESP::dallassensor_.test();
}
if (command == "dallas_full") {
shell.printfln(F("Testing adding and changing Dallas sensor"));
Mqtt::ha_enabled(true);
Mqtt::nested_format(1);
// Mqtt::nested_format(0);