| 98 | } |
| 99 | |
| 100 | bool 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 | |
| 151 | bool IconTextLampPlugin::setTopic(const String& topic, const JsonObjectConst& value) |
| 152 | { |
nothing calls this directly
no test coverage detected