added new command called commands

This commit is contained in:
proddy
2021-05-09 10:58:44 +02:00
parent 4a06d328d6
commit 81f4724d71
9 changed files with 157 additions and 51 deletions

View File

@@ -40,10 +40,17 @@ void DallasSensor::start() {
#ifndef EMSESP_STANDALONE
bus_.begin(dallas_gpio_);
#endif
// API call
Command::add_with_json(EMSdevice::DeviceType::DALLASSENSOR, F_(info), [&](const char * value, const int8_t id, JsonObject & json) {
return command_info(value, id, json);
});
// API calls
Command::add_with_json(
EMSdevice::DeviceType::DALLASSENSOR,
F_(info),
[&](const char * value, const int8_t id, JsonObject & json) { return command_info(value, id, json); },
F_(info_cmd));
Command::add_with_json(
EMSdevice::DeviceType::DALLASSENSOR,
F_(commands),
[&](const char * value, const int8_t id, JsonObject & json) { return command_commands(value, id, json); },
F_(commands_cmd));
}
}
@@ -306,6 +313,11 @@ bool DallasSensor::updated_values() {
return false;
}
// list commands
bool DallasSensor::command_commands(const char * value, const int8_t id, JsonObject & json) {
return Command::list(EMSdevice::DeviceType::DALLASSENSOR, json);
}
// creates JSON doc from values
// returns false if empty
// e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03-5F","temp":23.30},"sensor2":{"id":"28-233D-9497-0C03-8B","temp":24.0}}
@@ -413,7 +425,6 @@ void DallasSensor::publish_values(const bool force) {
sensor_no++; // increment sensor count
}
// doc.shrinkToFit();
Mqtt::publish(F("dallassensor_data"), doc.as<JsonObject>());
}