set entity_id on HA side for all switches - keep the id consistent, regardless of the name or where it is used

This commit is contained in:
Nicu Hodos 2025-10-09 10:18:49 +02:00
parent b4d4a179f1
commit 0998f815fd

View File

@ -27,6 +27,11 @@ struct PollinSwitch : Switch {
return (new string{Protocol_1::buildId(group, channel)})->c_str();
}()), group(group), channel(channel) { // cppcheck-suppress [selfInitialization]
if (!name) name = (new string{string(man).append(" ").append(id)})->c_str();
entityId = [this]() {
auto eId = string{man};
transform(eId.begin(), eId.end(), eId.begin(), ::tolower);
return (new string{eId.append("_").append(id)})->c_str();
}();
mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer(man).withArea(area).withParent(gatewayDevice);
withStateTopic();
deviceClass = "outlet";
@ -57,6 +62,7 @@ struct EasyHomeSwitch : Switch {
(*n) += remotePosition;
name = n->c_str();
}
entityId = id;
mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer("Intertek").withModel("Easy Home").withArea(area).withParent(gatewayDevice);
withStateTopic();
deviceClass = "outlet";