MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / getTopic

Method getTopic

lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp:100–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100bool IconTextLampPlugin::getTopic(const String& topic, JsonObject& value) const
101{
102 bool isSuccessful = false;
103
104 if (true == topic.equals(TOPIC_TEXT))
105 {
106 getActualConfiguration(value);
107 isSuccessful = true;
108 }
109 else if (true == topic.equals(TOPIC_LAMPS))
110 {
111 JsonArray lampArray = value.createNestedArray("lamps");
112 uint8_t lampId = 0U;
113
114 for (lampId = 0U; lampId < _IconTextLampPlugin::View::MAX_LAMPS; ++lampId)
115 {
116 bool lampOnState = getLamp(lampId);
117 JsonObject lampObj = lampArray.createNestedObject();
118
119 lampObj["id"] = lampId;
120 lampObj["state"] = (false == lampOnState) ? String("off") : String("on");
121 }
122
123 isSuccessful = true;
124 }
125 else if (true == topic.startsWith(String(TOPIC_LAMP) + "/"))
126 {
127 uint32_t indexBeginLampId = topic.lastIndexOf("/") + 1U;
128 String lampIdStr = topic.substring(indexBeginLampId);
129 uint8_t lampId = _IconTextLampPlugin::View::MAX_LAMPS;
130 bool status = Util::strToUInt8(lampIdStr, lampId);
131
132 if ((true == status) &&
133 (_IconTextLampPlugin::View::MAX_LAMPS > lampId))
134 {
135 bool lampState = getLamp(lampId);
136 String lampStateStr = (false == lampState) ? "off" : "on";
137
138 value["state"] = lampStateStr;
139
140 isSuccessful = true;
141 }
142 }
143 else
144 {
145 ;
146 }
147
148 return isSuccessful;
149}
150
151bool IconTextLampPlugin::setTopic(const String& topic, const JsonObjectConst& value)
152{

Callers

nothing calls this directly

Calls 4

StringClass · 0.85
startsWithMethod · 0.80
lastIndexOfMethod · 0.80
substringMethod · 0.80

Tested by

no test coverage detected