MCPcopy Create free account
hub / github.com/NSPManager/NSPanelManager / command_callback

Method command_callback

docker/MQTTManager/include/light/light.cpp:330–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330void Light::command_callback(NSPanelMQTTManagerCommand &command) {
331 if (command.has_light_command()) {
332 // Check if this light ID is in command
333 auto light_id = std::find_if(command.light_command().light_ids().begin(), command.light_command().light_ids().end(), [this](int32_t id) {
334 return id == this->_id;
335 });
336
337 if (light_id != command.light_command().light_ids().end()) {
338 NSPanelMQTTManagerCommand_LightCommand cmd = command.light_command();
339 if (cmd.has_brightness()) {
340 this->set_brightness(cmd.brightness(), false);
341 if (cmd.brightness() > 0) {
342 this->turn_on(false);
343 } else {
344 this->turn_off(false);
345 }
346 }
347 if (cmd.has_color_temperature()) {
348 // Convert color temperature (0-100) to actual color temperature in kelvin.
349 uint32_t color_temperature_kelvin = cmd.color_temperature() * ((MqttManagerConfig::get_settings().color_temp_max - MqttManagerConfig::get_settings().color_temp_min) / 100);
350 if (MqttManagerConfig::get_settings().reverse_color_temperature_slider) {
351 color_temperature_kelvin = MqttManagerConfig::get_settings().color_temp_max - color_temperature_kelvin;
352 } else {
353 color_temperature_kelvin += MqttManagerConfig::get_settings().color_temp_min;
354 }
355 this->set_color_temperature(color_temperature_kelvin, false);
356 }
357 if (cmd.has_hue()) {
358 this->set_hue(cmd.hue(), false);
359 }
360 if (cmd.has_saturation()) {
361 this->set_saturation(cmd.saturation(), false);
362 }
363 this->send_state_update_to_controller();
364 }
365 }
366}
367
368bool Light::can_toggle() {
369 return true;

Callers

nothing calls this directly

Calls 15

set_brightnessMethod · 0.95
turn_onMethod · 0.95
turn_offMethod · 0.95
set_color_temperatureMethod · 0.95
set_hueMethod · 0.95
set_saturationMethod · 0.95
has_light_commandMethod · 0.80
has_brightnessMethod · 0.80
has_color_temperatureMethod · 0.80
color_temperatureMethod · 0.80
has_hueMethod · 0.80
has_saturationMethod · 0.80

Tested by

no test coverage detected