| 1268 | } |
| 1269 | |
| 1270 | void NSPanel::command_callback(NSPanelMQTTManagerCommand &command) { |
| 1271 | if (command.has_button_pressed()) { |
| 1272 | if (command.nspanel_id() == this->_id) { |
| 1273 | // TODO: Handle button press |
| 1274 | SPDLOG_DEBUG("NSPanel {}::{} got button {} press,", this->_id, this->_name, command.button_pressed().button_id()); |
| 1275 | |
| 1276 | if (command.button_pressed().button_id() == 1) { |
| 1277 | ButtonMode button_mode = static_cast<ButtonMode>(this->_settings.button1_mode); |
| 1278 | switch (button_mode) { |
| 1279 | case ButtonMode::DETACHED: { |
| 1280 | if (this->_settings.button1_detached_mode_light_id.has_value()) { |
| 1281 | auto light = EntityManager::get_entity_by_id<Light>(MQTT_MANAGER_ENTITY_TYPE::LIGHT, this->_settings.button1_detached_mode_light_id.value()); |
| 1282 | if (light) |
| 1283 | (*light)->toggle(); |
| 1284 | else |
| 1285 | SPDLOG_ERROR("Tried to toggle detached light via panel but no light was was found with configured ID."); |
| 1286 | } else { |
| 1287 | SPDLOG_ERROR("Tried to toggle detached light via panel but no light was configured for button."); |
| 1288 | } |
| 1289 | break; |
| 1290 | } |
| 1291 | |
| 1292 | case ButtonMode::MQTT_PAYLOAD: { |
| 1293 | std::string topic = this->_get_nspanel_setting_with_default("button1_mqtt_topic", ""); |
| 1294 | std::string payload = this->_get_nspanel_setting_with_default("button1_mqtt_payload", ""); |
| 1295 | MQTT_Manager::publish(topic, payload); |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | default: |
| 1300 | SPDLOG_WARN("Unknown button mode triggered from panel."); |
| 1301 | break; |
| 1302 | } |
| 1303 | } else if (command.button_pressed().button_id() == 2) { |
| 1304 | ButtonMode button_mode = static_cast<ButtonMode>(this->_settings.button2_mode); |
| 1305 | switch (button_mode) { |
| 1306 | case ButtonMode::DETACHED: { |
| 1307 | if (this->_settings.button2_detached_mode_light_id.has_value()) { |
| 1308 | auto light = EntityManager::get_entity_by_id<Light>(MQTT_MANAGER_ENTITY_TYPE::LIGHT, this->_settings.button2_detached_mode_light_id.value()); |
| 1309 | if (light) |
| 1310 | (*light)->toggle(); |
| 1311 | else |
| 1312 | SPDLOG_ERROR("Tried to toggle detached light via panel but no light was was found with configured ID."); |
| 1313 | } else { |
| 1314 | SPDLOG_ERROR("Tried to toggle detached light via panel but no light was configured for button."); |
| 1315 | } |
| 1316 | break; |
| 1317 | } |
| 1318 | |
| 1319 | case ButtonMode::MQTT_PAYLOAD: { |
| 1320 | std::string topic = this->_get_nspanel_setting_with_default("button2_mqtt_topic", ""); |
| 1321 | std::string payload = this->_get_nspanel_setting_with_default("button2_mqtt_payload", ""); |
| 1322 | MQTT_Manager::publish(topic, payload); |
| 1323 | break; |
| 1324 | } |
| 1325 | |
| 1326 | default: |
| 1327 | SPDLOG_WARN("Unknown button mode triggered from panel."); |
nothing calls this directly
no test coverage detected