| 328 | } |
| 329 | |
| 330 | void 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 | |
| 368 | bool Light::can_toggle() { |
| 369 | return true; |
nothing calls this directly
no test coverage detected