Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support entities api endpoint for multiple devices of same type #2373

Merged
merged 20 commits into from
Jan 26, 2025
Merged
2 changes: 1 addition & 1 deletion src/ESP32React/NetworkSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void NetworkSettingsService::setWiFiPowerOnRSSI() {
p = WIFI_POWER_5dBm;

#if defined(EMSESP_DEBUG)
// emsesp::EMSESP::logger().debug("Recommended WiFi Tx Power (set_power %d, new power %d, rssi %d, threshold %d)", min_tx_pwr / 10, p, rssi, threshold);
// emsesp::EMSESP::logger().debug("Recommended WiFi Tx Power (set_power %d, new power %d, rssi %d, threshold %d)", min_tx_pwr / 10, p, rssi, threshold);
#endif

if (!WiFi.setTxPower(p)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ uint8_t Command::call(const uint8_t device_type, const char * command, const cha
return Command::list(device_type, output);
}
if (EMSESP::get_device_value_info(output, cmd, id, device_type)) { // entity = cmd
LOG_DEBUG("Fetched device entity/attributes for %s/%s", dname, cmd);
LOG_DEBUG("Fetched device entity/attributes for %s/%s (id=%d)", dname, cmd, id);
return CommandRet::OK;
}
} else if (device_type == EMSdevice::DeviceType::SYSTEM && strchr(cmd, '/')) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/device_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
{ 93, DeviceType::THERMOSTAT, "RC20RF", DeviceFlags::EMS_DEVICE_FLAG_RC20}, // 0x19
{ 94, DeviceType::THERMOSTAT, "RFM20 Remote", DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x18
{151, DeviceType::THERMOSTAT, "RC25", DeviceFlags::EMS_DEVICE_FLAG_RC25}, // 0x17
{157, DeviceType::THERMOSTAT, "RC200, CW100, CR120, CR50", DeviceFlags::EMS_DEVICE_FLAG_RC100}, // 0x18,, CR120 v22 is FLAG_BC400
{157, DeviceType::THERMOSTAT, "RC200, CW100, CR120, CR50", DeviceFlags::EMS_DEVICE_FLAG_RC100}, // 0x18, CR120 v22 is FLAG_BC400
{158, DeviceType::THERMOSTAT, "RC3*0, Moduline 3000/1010H, CW400, Sense II, HPC410", DeviceFlags::EMS_DEVICE_FLAG_RC300}, // 0x10
{165, DeviceType::THERMOSTAT, "RC100, CR10, Moduline 1000/1010", DeviceFlags::EMS_DEVICE_FLAG_RC100}, // 0x18, 0x38
{172, DeviceType::THERMOSTAT, "Rego 2000/3000", DeviceFlags::EMS_DEVICE_FLAG_R3000}, // 0x10
Expand Down
7 changes: 6 additions & 1 deletion src/core/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,16 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype) {
// check first for EMS devices
bool found_device = false;

for (const auto & emsdevice : emsdevices) {
if (emsdevice->device_type() == devicetype) {
found_device = true;
// we may have multiple devices of the same type, so we need to check the id (e.g. id could be a hc number)
if (emsdevice->get_value_info(root, cmd, id)) {
return true;
// if we have no values, keep going traversing the devices, it may be a thermostat with multiple hc's
if (root.size()) {
return true;
}
}
}
}
Expand Down
27 changes: 23 additions & 4 deletions src/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) {
if (cmd == "2thermostats") {
EMSESP::logger().notice("Testing with multiple thermostats...");

add_device(0x08, 123); // GB072
add_device(0x08, 123); // GB072 boiler

add_device(0x10, 158); // RC310
add_device(0x18, 157); // Bosch CR100
add_device(0x19, 157); // RC200

// Boiler -> Me, UBAMonitorFast(0x18), telegram: 08 00 18 00 00 02 5A 73 3D 0A 10 65 40 02 1A 80 00 01 E1 01 76 0E 3D 48 00 C9 44 02 00 (#data=25)
uart_telegram({0x08, 0x00, 0x18, 0x00, 0x00, 0x02, 0x5A, 0x73, 0x3D, 0x0A, 0x10, 0x65, 0x40, 0x02, 0x1A,
Expand All @@ -122,7 +123,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) {

// 2nd thermostat on HC2
// Thermostat RC300Monitor(0x02A6)
uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA6, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24,
uart_telegram({0x99, 0x00, 0xFF, 0x00, 0x01, 0xA6, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24,
0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03});

return true;
Expand Down Expand Up @@ -616,9 +617,27 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const

if (command == "2thermostats") {
shell.printfln("Testing multiple thermostats...");
// adds hc1=(0x10, 158) RC310 and hc2=(0x19, 157) RC200
test("2thermostats");
// shell.invoke_command("show values");
shell.invoke_command("show values");
// shell.invoke_command("show devices");

AsyncWebServerRequest request;
request.method(HTTP_GET);

request.url("/api/thermostat");
EMSESP::webAPIService.webAPIService(&request);
Serial.println();

request.url("/api/thermostat/hc1/entities");
EMSESP::webAPIService.webAPIService(&request);
Serial.println();


request.url("/api/thermostat/hc2/entities");
EMSESP::webAPIService.webAPIService(&request);
Serial.println();

ok = true;
}

Expand Down
Loading