esphome 2024.12.4__py3-none-any.whl → 2025.2.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/__main__.py +16 -3
- esphome/components/adc/__init__.py +17 -11
- esphome/components/adc/adc_sensor.h +17 -0
- esphome/components/adc/adc_sensor_common.cpp +55 -0
- esphome/components/adc/adc_sensor_esp32.cpp +8 -5
- esphome/components/adc/adc_sensor_esp8266.cpp +10 -6
- esphome/components/adc/adc_sensor_libretiny.cpp +11 -6
- esphome/components/adc/adc_sensor_rp2040.cpp +13 -10
- esphome/components/adc/sensor.py +9 -3
- esphome/components/ads1115/ads1115.cpp +56 -7
- esphome/components/ads1115/ads1115.h +13 -1
- esphome/components/ads1115/sensor/__init__.py +16 -0
- esphome/components/ads1115/sensor/ads1115_sensor.cpp +2 -1
- esphome/components/ads1115/sensor/ads1115_sensor.h +2 -0
- esphome/components/animation/__init__.py +23 -261
- esphome/components/animation/animation.cpp +2 -2
- esphome/components/animation/animation.h +2 -1
- esphome/components/api/api_pb2.cpp +14 -0
- esphome/components/api/api_pb2.h +1 -0
- esphome/components/audio/__init__.py +112 -0
- esphome/components/audio/audio.cpp +67 -0
- esphome/components/audio/audio.h +125 -7
- esphome/components/audio/audio_decoder.cpp +361 -0
- esphome/components/audio/audio_decoder.h +135 -0
- esphome/components/audio/audio_reader.cpp +308 -0
- esphome/components/audio/audio_reader.h +85 -0
- esphome/components/audio/audio_resampler.cpp +159 -0
- esphome/components/audio/audio_resampler.h +101 -0
- esphome/components/audio/audio_transfer_buffer.cpp +165 -0
- esphome/components/audio/audio_transfer_buffer.h +139 -0
- esphome/components/audio_adc/__init__.py +41 -0
- esphome/components/audio_adc/audio_adc.h +17 -0
- esphome/components/audio_adc/automation.h +23 -0
- esphome/components/bk72xx/__init__.py +1 -0
- esphome/components/ble_client/ble_client.cpp +1 -2
- esphome/components/ble_client/sensor/__init__.py +1 -1
- esphome/components/ble_client/text_sensor/__init__.py +1 -1
- esphome/components/bluetooth_proxy/bluetooth_connection.cpp +5 -0
- esphome/components/bluetooth_proxy/bluetooth_connection.h +1 -0
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
- esphome/components/ch422g/ch422g.h +2 -0
- esphome/components/climate/__init__.py +1 -1
- esphome/components/climate_ir/climate_ir.cpp +2 -1
- esphome/components/coolix/coolix.cpp +2 -1
- esphome/components/cse7766/cse7766.cpp +8 -16
- esphome/components/custom/__init__.py +0 -3
- esphome/components/custom/binary_sensor/__init__.py +2 -28
- esphome/components/custom/climate/__init__.py +2 -27
- esphome/components/custom/cover/__init__.py +2 -27
- esphome/components/custom/light/__init__.py +2 -27
- esphome/components/custom/output/__init__.py +2 -58
- esphome/components/custom/sensor/__init__.py +2 -24
- esphome/components/custom/switch/__init__.py +2 -24
- esphome/components/custom/text_sensor/__init__.py +2 -29
- esphome/components/custom_component/__init__.py +3 -27
- esphome/components/daly_bms/daly_bms.cpp +6 -0
- esphome/components/daly_bms/daly_bms.h +2 -0
- esphome/components/daly_bms/sensor.py +6 -0
- esphome/components/debug/debug_component.cpp +4 -0
- esphome/components/debug/debug_component.h +14 -0
- esphome/components/debug/debug_esp32.cpp +154 -74
- esphome/components/dfplayer/dfplayer.cpp +15 -2
- esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +2 -1
- esphome/components/dht/dht.cpp +2 -1
- esphome/components/display/__init__.py +18 -5
- esphome/components/display/display.cpp +2 -1
- esphome/components/display/rect.cpp +2 -1
- esphome/components/es7210/__init__.py +0 -0
- esphome/components/es7210/audio_adc.py +51 -0
- esphome/components/es7210/es7210.cpp +228 -0
- esphome/components/es7210/es7210.h +62 -0
- esphome/components/es7210/es7210_const.h +129 -0
- esphome/components/es7243e/__init__.py +0 -0
- esphome/components/es7243e/audio_adc.py +34 -0
- esphome/components/es7243e/es7243e.cpp +125 -0
- esphome/components/es7243e/es7243e.h +37 -0
- esphome/components/es7243e/es7243e_const.h +54 -0
- esphome/components/es8156/__init__.py +0 -0
- esphome/components/es8156/audio_dac.py +27 -0
- esphome/components/es8156/es8156.cpp +87 -0
- esphome/components/es8156/es8156.h +51 -0
- esphome/components/es8156/es8156_const.h +68 -0
- esphome/components/es8311/audio_dac.py +1 -2
- esphome/components/esp32/__init__.py +1 -0
- esphome/components/esp32/core.cpp +5 -1
- esphome/components/esp32/gpio.h +2 -0
- esphome/components/esp32_ble/__init__.py +39 -0
- esphome/components/esp32_ble/queue.h +4 -4
- esphome/components/esp32_ble_client/ble_client_base.cpp +46 -0
- esphome/components/esp32_ble_client/ble_client_base.h +2 -0
- esphome/components/esp32_ble_server/__init__.py +582 -12
- esphome/components/esp32_ble_server/ble_characteristic.cpp +48 -60
- esphome/components/esp32_ble_server/ble_characteristic.h +24 -17
- esphome/components/esp32_ble_server/ble_descriptor.cpp +21 -9
- esphome/components/esp32_ble_server/ble_descriptor.h +17 -6
- esphome/components/esp32_ble_server/ble_server.cpp +62 -67
- esphome/components/esp32_ble_server/ble_server.h +28 -32
- esphome/components/esp32_ble_server/ble_server_automations.cpp +77 -0
- esphome/components/esp32_ble_server/ble_server_automations.h +115 -0
- esphome/components/esp32_ble_server/ble_service.cpp +17 -15
- esphome/components/esp32_ble_server/ble_service.h +10 -14
- esphome/components/esp32_ble_tracker/__init__.py +6 -39
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +33 -10
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +8 -4
- esphome/components/esp32_improv/__init__.py +2 -8
- esphome/components/esp32_improv/esp32_improv_component.cpp +21 -20
- esphome/components/esp32_improv/esp32_improv_component.h +3 -4
- esphome/components/esp32_rmt/__init__.py +28 -3
- esphome/components/esp32_rmt_led_strip/led_strip.cpp +73 -6
- esphome/components/esp32_rmt_led_strip/led_strip.h +21 -3
- esphome/components/esp32_rmt_led_strip/light.py +72 -7
- esphome/components/esp32_touch/esp32_touch.cpp +5 -0
- esphome/components/esp8266/__init__.py +1 -0
- esphome/components/esp8266/gpio.h +1 -0
- esphome/components/ethernet/__init__.py +10 -10
- esphome/components/event/event.cpp +4 -2
- esphome/components/event/event.h +2 -0
- esphome/components/event_emitter/__init__.py +5 -0
- esphome/components/event_emitter/event_emitter.cpp +14 -0
- esphome/components/event_emitter/event_emitter.h +63 -0
- esphome/components/gcja5/gcja5.cpp +2 -1
- esphome/components/graph/graph.cpp +4 -9
- esphome/components/haier/haier_base.cpp +2 -1
- esphome/components/haier/hon_climate.cpp +2 -1
- esphome/components/heatpumpir/heatpumpir.cpp +2 -1
- esphome/components/host/__init__.py +1 -0
- esphome/components/host/gpio.h +1 -0
- esphome/components/http_request/http_request.h +2 -2
- esphome/components/http_request/http_request_arduino.cpp +1 -1
- esphome/components/http_request/http_request_idf.cpp +1 -1
- esphome/components/i2c/i2c_bus_esp_idf.cpp +4 -0
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +7 -5
- esphome/components/i2s_audio/speaker/__init__.py +53 -6
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +92 -46
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +8 -0
- esphome/components/ili9xxx/display.py +29 -11
- esphome/components/ili9xxx/ili9xxx_display.cpp +2 -5
- esphome/components/ili9xxx/ili9xxx_display.h +2 -1
- esphome/components/image/__init__.py +443 -255
- esphome/components/image/image.cpp +115 -61
- esphome/components/image/image.h +15 -24
- esphome/components/json/json_util.cpp +8 -34
- esphome/components/libretiny/__init__.py +1 -0
- esphome/components/libretiny/gpio_arduino.h +1 -0
- esphome/components/light/light_color_values.h +1 -1
- esphome/components/logger/__init__.py +43 -7
- esphome/components/logger/logger.cpp +16 -11
- esphome/components/logger/logger.h +11 -7
- esphome/components/logger/select/__init__.py +29 -0
- esphome/components/logger/select/logger_level_select.cpp +27 -0
- esphome/components/logger/select/logger_level_select.h +15 -0
- esphome/components/lvgl/__init__.py +96 -73
- esphome/components/lvgl/automation.py +39 -7
- esphome/components/lvgl/defines.py +8 -2
- esphome/components/lvgl/lvgl_esphome.cpp +8 -15
- esphome/components/lvgl/lvgl_esphome.h +20 -5
- esphome/components/lvgl/schemas.py +25 -14
- esphome/components/lvgl/trigger.py +27 -3
- esphome/components/lvgl/widgets/dropdown.py +1 -1
- esphome/components/lvgl/widgets/keyboard.py +8 -1
- esphome/components/lvgl/widgets/meter.py +2 -1
- esphome/components/lvgl/widgets/msgbox.py +1 -1
- esphome/components/lvgl/widgets/obj.py +1 -12
- esphome/components/lvgl/widgets/page.py +37 -2
- esphome/components/lvgl/widgets/tabview.py +1 -1
- esphome/components/max6956/max6956.h +2 -0
- esphome/components/mcp23016/mcp23016.h +2 -0
- esphome/components/mcp23xxx_base/mcp23xxx_base.h +2 -0
- esphome/components/mdns/__init__.py +1 -1
- esphome/components/media_player/__init__.py +37 -8
- esphome/components/media_player/automation.h +11 -2
- esphome/components/media_player/media_player.cpp +8 -0
- esphome/components/media_player/media_player.h +8 -4
- esphome/components/micronova/switch/micronova_switch.cpp +4 -2
- esphome/components/midea/ac_automations.h +3 -1
- esphome/components/midea/air_conditioner.cpp +7 -5
- esphome/components/midea/air_conditioner.h +1 -1
- esphome/components/midea/climate.py +4 -2
- esphome/components/midea/ir_transmitter.h +36 -5
- esphome/components/mixer/__init__.py +0 -0
- esphome/components/mixer/speaker/__init__.py +172 -0
- esphome/components/mixer/speaker/automation.h +19 -0
- esphome/components/mixer/speaker/mixer_speaker.cpp +624 -0
- esphome/components/mixer/speaker/mixer_speaker.h +207 -0
- esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp +7 -13
- esphome/components/mpr121/mpr121.h +2 -0
- esphome/components/mqtt/__init__.py +1 -1
- esphome/components/mqtt/mqtt_client.cpp +7 -1
- esphome/components/mqtt/mqtt_client.h +1 -1
- esphome/components/mqtt/mqtt_climate.cpp +2 -2
- esphome/components/network/ip_address.h +2 -0
- esphome/components/nextion/automation.h +17 -0
- esphome/components/nextion/display.py +42 -17
- esphome/components/nextion/nextion.cpp +4 -10
- esphome/components/nextion/nextion.h +89 -82
- esphome/components/nextion/nextion_commands.cpp +10 -10
- esphome/components/ntc/sensor.py +2 -4
- esphome/components/online_image/__init__.py +98 -46
- esphome/components/online_image/bmp_image.cpp +101 -0
- esphome/components/online_image/bmp_image.h +40 -0
- esphome/components/online_image/image_decoder.cpp +28 -2
- esphome/components/online_image/image_decoder.h +24 -15
- esphome/components/online_image/jpeg_image.cpp +90 -0
- esphome/components/online_image/jpeg_image.h +34 -0
- esphome/components/online_image/online_image.cpp +112 -53
- esphome/components/online_image/online_image.h +24 -7
- esphome/components/online_image/png_image.cpp +7 -3
- esphome/components/online_image/png_image.h +2 -1
- esphome/components/opentherm/__init__.py +73 -7
- esphome/components/opentherm/automation.h +25 -0
- esphome/components/opentherm/const.py +1 -0
- esphome/components/opentherm/generate.py +39 -6
- esphome/components/opentherm/hub.cpp +117 -79
- esphome/components/opentherm/hub.h +31 -15
- esphome/components/opentherm/opentherm.cpp +47 -23
- esphome/components/opentherm/opentherm.h +27 -6
- esphome/components/opentherm/opentherm_macros.h +11 -0
- esphome/components/opentherm/schema.py +78 -1
- esphome/components/opentherm/validate.py +7 -2
- esphome/components/pca6416a/pca6416a.h +2 -0
- esphome/components/pca9554/pca9554.h +2 -0
- esphome/components/pcf8574/pcf8574.h +2 -0
- esphome/components/preferences/__init__.py +2 -4
- esphome/components/preferences/syncer.h +10 -3
- esphome/components/prometheus/prometheus_handler.cpp +313 -0
- esphome/components/prometheus/prometheus_handler.h +48 -7
- esphome/components/psram/psram.cpp +8 -1
- esphome/components/pulse_counter/pulse_counter_sensor.cpp +14 -9
- esphome/components/pulse_counter/pulse_counter_sensor.h +4 -4
- esphome/components/pulse_meter/pulse_meter_sensor.cpp +2 -0
- esphome/components/qspi_dbi/__init__.py +3 -0
- esphome/components/qspi_dbi/display.py +74 -47
- esphome/components/qspi_dbi/models.py +245 -2
- esphome/components/qspi_dbi/qspi_dbi.cpp +9 -16
- esphome/components/qspi_dbi/qspi_dbi.h +2 -2
- esphome/components/remote_base/__init__.py +77 -25
- esphome/components/remote_base/remote_base.cpp +1 -1
- esphome/components/remote_base/remote_base.h +20 -2
- esphome/components/remote_base/toto_protocol.cpp +100 -0
- esphome/components/remote_base/toto_protocol.h +45 -0
- esphome/components/remote_receiver/__init__.py +55 -10
- esphome/components/remote_receiver/remote_receiver.h +36 -3
- esphome/components/remote_receiver/remote_receiver_esp32.cpp +145 -6
- esphome/components/remote_transmitter/__init__.py +62 -4
- esphome/components/remote_transmitter/remote_transmitter.h +21 -2
- esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +140 -4
- esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +3 -3
- esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +3 -3
- esphome/components/resampler/__init__.py +0 -0
- esphome/components/resampler/speaker/__init__.py +103 -0
- esphome/components/resampler/speaker/resampler_speaker.cpp +318 -0
- esphome/components/resampler/speaker/resampler_speaker.h +107 -0
- esphome/components/resistance/resistance_sensor.h +2 -3
- esphome/components/resistance/sensor.py +2 -9
- esphome/components/rotary_encoder/rotary_encoder.cpp +8 -4
- esphome/components/rp2040/__init__.py +1 -0
- esphome/components/rp2040/gpio.h +1 -0
- esphome/components/rtl87xx/__init__.py +2 -0
- esphome/components/sdl/binary_sensor.py +270 -0
- esphome/components/sdl/sdl_esphome.cpp +16 -0
- esphome/components/sdl/sdl_esphome.h +9 -0
- esphome/components/seeed_mr60bha2/binary_sensor.py +25 -0
- esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp +26 -2
- esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +9 -20
- esphome/components/seeed_mr60bha2/sensor.py +9 -1
- esphome/components/sn74hc165/sn74hc165.h +3 -0
- esphome/components/sn74hc595/sn74hc595.h +3 -0
- esphome/components/speaker/__init__.py +5 -4
- esphome/components/speaker/media_player/__init__.py +458 -0
- esphome/components/speaker/media_player/audio_pipeline.cpp +568 -0
- esphome/components/speaker/media_player/audio_pipeline.h +159 -0
- esphome/components/speaker/media_player/automation.h +26 -0
- esphome/components/speaker/media_player/speaker_media_player.cpp +577 -0
- esphome/components/speaker/media_player/speaker_media_player.h +160 -0
- esphome/components/speaker/speaker.h +20 -0
- esphome/components/spi/__init__.py +1 -5
- esphome/components/spi/spi.cpp +7 -1
- esphome/components/spi/spi.h +21 -2
- esphome/components/spi_led_strip/light.py +3 -5
- esphome/components/spi_led_strip/spi_led_strip.cpp +67 -0
- esphome/components/spi_led_strip/spi_led_strip.h +8 -60
- esphome/components/sprinkler/sprinkler.cpp +3 -1
- esphome/components/sx1509/sx1509_gpio_pin.h +2 -0
- esphome/components/tca9555/tca9555.h +2 -0
- esphome/components/toshiba/toshiba.cpp +2 -1
- esphome/components/tuya/light/tuya_light.cpp +4 -2
- esphome/components/uart/uart_component_esp32_arduino.cpp +2 -2
- esphome/components/uart/uart_component_esp_idf.cpp +2 -2
- esphome/components/udp/__init__.py +8 -2
- esphome/components/udp/udp_component.cpp +25 -56
- esphome/components/udp/udp_component.h +3 -0
- esphome/components/uponor_smatrix/sensor/__init__.py +14 -4
- esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +5 -0
- esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +1 -0
- esphome/components/uptime/text_sensor/__init__.py +19 -0
- esphome/components/uptime/text_sensor/uptime_text_sensor.cpp +63 -0
- esphome/components/uptime/text_sensor/uptime_text_sensor.h +25 -0
- esphome/components/voice_assistant/voice_assistant.cpp +24 -14
- esphome/components/voice_assistant/voice_assistant.h +8 -0
- esphome/components/waveshare_epaper/display.py +22 -1
- esphome/components/waveshare_epaper/waveshare_213v3.cpp +9 -3
- esphome/components/waveshare_epaper/waveshare_epaper.cpp +1155 -44
- esphome/components/waveshare_epaper/waveshare_epaper.h +208 -7
- esphome/components/web_server/web_server.cpp +28 -6
- esphome/components/weikai/weikai.h +2 -0
- esphome/components/wifi/__init__.py +6 -6
- esphome/components/wifi/wifi_component.cpp +1 -1
- esphome/components/wifi/wifi_component_esp32_arduino.cpp +30 -1
- esphome/components/wireguard/__init__.py +2 -2
- esphome/components/xl9535/xl9535.h +2 -0
- esphome/components/xxtea/__init__.py +3 -0
- esphome/components/xxtea/xxtea.cpp +46 -0
- esphome/components/xxtea/xxtea.h +26 -0
- esphome/components/yashima/yashima.cpp +2 -1
- esphome/config.py +9 -5
- esphome/config_validation.py +55 -17
- esphome/const.py +7 -10
- esphome/core/__init__.py +6 -13
- esphome/core/base_automation.h +1 -0
- esphome/core/config.py +59 -72
- esphome/core/defines.h +9 -1
- esphome/core/gpio.h +7 -0
- esphome/core/helpers.cpp +19 -15
- esphome/core/helpers.h +57 -8
- esphome/core/log.h +9 -7
- esphome/cpp_generator.py +2 -2
- esphome/espota2.py +3 -2
- esphome/loader.py +12 -4
- esphome/log.py +5 -7
- esphome/yaml_util.py +2 -2
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/METADATA +12 -7
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/RECORD +341 -292
- esphome/components/custom/binary_sensor/custom_binary_sensor.cpp +0 -16
- esphome/components/custom/binary_sensor/custom_binary_sensor.h +0 -26
- esphome/components/custom/climate/custom_climate.h +0 -22
- esphome/components/custom/cover/custom_cover.h +0 -21
- esphome/components/custom/light/custom_light_output.h +0 -24
- esphome/components/custom/output/custom_output.h +0 -37
- esphome/components/custom/sensor/custom_sensor.cpp +0 -16
- esphome/components/custom/sensor/custom_sensor.h +0 -24
- esphome/components/custom/switch/custom_switch.cpp +0 -16
- esphome/components/custom/switch/custom_switch.h +0 -24
- esphome/components/custom/text_sensor/custom_text_sensor.cpp +0 -16
- esphome/components/custom/text_sensor/custom_text_sensor.h +0 -26
- esphome/components/custom_component/custom_component.h +0 -28
- esphome/components/esp32_ble_server/ble_2901.cpp +0 -18
- esphome/components/esp32_ble_server/ble_2901.h +0 -19
- esphome/components/resistance_sampler/__init__.py +0 -6
- esphome/components/resistance_sampler/resistance_sampler.h +0 -10
- esphome/components/uptime/{sensor.py → sensor/__init__.py} +3 -3
- /esphome/components/uptime/{uptime_seconds_sensor.cpp → sensor/uptime_seconds_sensor.cpp} +0 -0
- /esphome/components/uptime/{uptime_seconds_sensor.h → sensor/uptime_seconds_sensor.h} +0 -0
- /esphome/components/uptime/{uptime_timestamp_sensor.cpp → sensor/uptime_timestamp_sensor.cpp} +0 -0
- /esphome/components/uptime/{uptime_timestamp_sensor.h → sensor/uptime_timestamp_sensor.h} +0 -0
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/LICENSE +0 -0
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/WHEEL +0 -0
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/entry_points.txt +0 -0
- {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/top_level.txt +0 -0
@@ -12,7 +12,7 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
|
|
12
12
|
for (int img_y = 0; img_y < height_; img_y++) {
|
13
13
|
if (this->get_binary_pixel_(img_x, img_y)) {
|
14
14
|
display->draw_pixel_at(x + img_x, y + img_y, color_on);
|
15
|
-
} else if (!this->
|
15
|
+
} else if (!this->transparency_) {
|
16
16
|
display->draw_pixel_at(x + img_x, y + img_y, color_off);
|
17
17
|
}
|
18
18
|
}
|
@@ -22,10 +22,27 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
|
|
22
22
|
case IMAGE_TYPE_GRAYSCALE:
|
23
23
|
for (int img_x = 0; img_x < width_; img_x++) {
|
24
24
|
for (int img_y = 0; img_y < height_; img_y++) {
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
const uint32_t pos = (img_x + img_y * this->width_);
|
26
|
+
const uint8_t gray = progmem_read_byte(this->data_start_ + pos);
|
27
|
+
Color color = Color(gray, gray, gray, 0xFF);
|
28
|
+
switch (this->transparency_) {
|
29
|
+
case TRANSPARENCY_CHROMA_KEY:
|
30
|
+
if (gray == 1) {
|
31
|
+
continue; // skip drawing
|
32
|
+
}
|
33
|
+
break;
|
34
|
+
case TRANSPARENCY_ALPHA_CHANNEL: {
|
35
|
+
auto on = (float) gray / 255.0f;
|
36
|
+
auto off = 1.0f - on;
|
37
|
+
// blend color_on and color_off
|
38
|
+
color = Color(color_on.r * on + color_off.r * off, color_on.g * on + color_off.g * off,
|
39
|
+
color_on.b * on + color_off.b * off, 0xFF);
|
40
|
+
break;
|
41
|
+
}
|
42
|
+
default:
|
43
|
+
break;
|
28
44
|
}
|
45
|
+
display->draw_pixel_at(x + img_x, y + img_y, color);
|
29
46
|
}
|
30
47
|
}
|
31
48
|
break;
|
@@ -39,20 +56,10 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
|
|
39
56
|
}
|
40
57
|
}
|
41
58
|
break;
|
42
|
-
case
|
43
|
-
for (int img_x = 0; img_x < width_; img_x++) {
|
44
|
-
for (int img_y = 0; img_y < height_; img_y++) {
|
45
|
-
auto color = this->get_rgb24_pixel_(img_x, img_y);
|
46
|
-
if (color.w >= 0x80) {
|
47
|
-
display->draw_pixel_at(x + img_x, y + img_y, color);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
break;
|
52
|
-
case IMAGE_TYPE_RGBA:
|
59
|
+
case IMAGE_TYPE_RGB:
|
53
60
|
for (int img_x = 0; img_x < width_; img_x++) {
|
54
61
|
for (int img_y = 0; img_y < height_; img_y++) {
|
55
|
-
auto color = this->
|
62
|
+
auto color = this->get_rgb_pixel_(img_x, img_y);
|
56
63
|
if (color.w >= 0x80) {
|
57
64
|
display->draw_pixel_at(x + img_x, y + img_y, color);
|
58
65
|
}
|
@@ -61,20 +68,20 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
|
|
61
68
|
break;
|
62
69
|
}
|
63
70
|
}
|
64
|
-
Color Image::get_pixel(int x, int y, Color color_on, Color color_off) const {
|
71
|
+
Color Image::get_pixel(int x, int y, const Color color_on, const Color color_off) const {
|
65
72
|
if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
|
66
73
|
return color_off;
|
67
74
|
switch (this->type_) {
|
68
75
|
case IMAGE_TYPE_BINARY:
|
69
|
-
|
76
|
+
if (this->get_binary_pixel_(x, y))
|
77
|
+
return color_on;
|
78
|
+
return color_off;
|
70
79
|
case IMAGE_TYPE_GRAYSCALE:
|
71
80
|
return this->get_grayscale_pixel_(x, y);
|
72
81
|
case IMAGE_TYPE_RGB565:
|
73
82
|
return this->get_rgb565_pixel_(x, y);
|
74
|
-
case
|
75
|
-
return this->
|
76
|
-
case IMAGE_TYPE_RGBA:
|
77
|
-
return this->get_rgba_pixel_(x, y);
|
83
|
+
case IMAGE_TYPE_RGB:
|
84
|
+
return this->get_rgb_pixel_(x, y);
|
78
85
|
default:
|
79
86
|
return color_off;
|
80
87
|
}
|
@@ -98,23 +105,40 @@ lv_img_dsc_t *Image::get_lv_img_dsc() {
|
|
98
105
|
this->dsc_.header.cf = LV_IMG_CF_ALPHA_8BIT;
|
99
106
|
break;
|
100
107
|
|
101
|
-
case
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
+
case IMAGE_TYPE_RGB:
|
109
|
+
#if LV_COLOR_DEPTH == 32
|
110
|
+
switch (this->transparent_) {
|
111
|
+
case TRANSPARENCY_ALPHA_CHANNEL:
|
112
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
|
113
|
+
break;
|
114
|
+
case TRANSPARENCY_CHROMA_KEY:
|
115
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
|
116
|
+
break;
|
117
|
+
default:
|
118
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR;
|
119
|
+
break;
|
120
|
+
}
|
108
121
|
#else
|
109
|
-
this->dsc_.header.cf =
|
122
|
+
this->dsc_.header.cf =
|
123
|
+
this->transparency_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGBA8888 : LV_IMG_CF_RGB888;
|
110
124
|
#endif
|
111
125
|
break;
|
112
126
|
|
113
|
-
case
|
114
|
-
#if LV_COLOR_DEPTH ==
|
115
|
-
this->
|
127
|
+
case IMAGE_TYPE_RGB565:
|
128
|
+
#if LV_COLOR_DEPTH == 16
|
129
|
+
switch (this->transparency_) {
|
130
|
+
case TRANSPARENCY_ALPHA_CHANNEL:
|
131
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
|
132
|
+
break;
|
133
|
+
case TRANSPARENCY_CHROMA_KEY:
|
134
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
|
135
|
+
break;
|
136
|
+
default:
|
137
|
+
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR;
|
138
|
+
break;
|
139
|
+
}
|
116
140
|
#else
|
117
|
-
this->dsc_.header.cf =
|
141
|
+
this->dsc_.header.cf = this->transparent_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGB565A8 : LV_IMG_CF_RGB565;
|
118
142
|
#endif
|
119
143
|
break;
|
120
144
|
}
|
@@ -128,51 +152,81 @@ bool Image::get_binary_pixel_(int x, int y) const {
|
|
128
152
|
const uint32_t pos = x + y * width_8;
|
129
153
|
return progmem_read_byte(this->data_start_ + (pos / 8u)) & (0x80 >> (pos % 8u));
|
130
154
|
}
|
131
|
-
Color Image::
|
132
|
-
const uint32_t pos = (x + y * this->width_) *
|
133
|
-
return Color(progmem_read_byte(this->data_start_ + pos + 0), progmem_read_byte(this->data_start_ + pos + 1),
|
134
|
-
progmem_read_byte(this->data_start_ + pos + 2), progmem_read_byte(this->data_start_ + pos + 3));
|
135
|
-
}
|
136
|
-
Color Image::get_rgb24_pixel_(int x, int y) const {
|
137
|
-
const uint32_t pos = (x + y * this->width_) * 3;
|
155
|
+
Color Image::get_rgb_pixel_(int x, int y) const {
|
156
|
+
const uint32_t pos = (x + y * this->width_) * this->bpp_ / 8;
|
138
157
|
Color color = Color(progmem_read_byte(this->data_start_ + pos + 0), progmem_read_byte(this->data_start_ + pos + 1),
|
139
|
-
progmem_read_byte(this->data_start_ + pos + 2));
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
158
|
+
progmem_read_byte(this->data_start_ + pos + 2), 0xFF);
|
159
|
+
|
160
|
+
switch (this->transparency_) {
|
161
|
+
case TRANSPARENCY_CHROMA_KEY:
|
162
|
+
if (color.g == 1 && color.r == 0 && color.b == 0) {
|
163
|
+
// (0, 1, 0) has been defined as transparent color for non-alpha images.
|
164
|
+
color.w = 0;
|
165
|
+
}
|
166
|
+
break;
|
167
|
+
case TRANSPARENCY_ALPHA_CHANNEL:
|
168
|
+
color.w = progmem_read_byte(this->data_start_ + (pos + 3));
|
169
|
+
break;
|
170
|
+
default:
|
171
|
+
break;
|
146
172
|
}
|
147
173
|
return color;
|
148
174
|
}
|
149
175
|
Color Image::get_rgb565_pixel_(int x, int y) const {
|
150
|
-
const uint8_t *pos = this->data_start_;
|
151
|
-
if (this->transparent_) {
|
152
|
-
pos += (x + y * this->width_) * 3;
|
153
|
-
} else {
|
154
|
-
pos += (x + y * this->width_) * 2;
|
155
|
-
}
|
176
|
+
const uint8_t *pos = this->data_start_ + (x + y * this->width_) * this->bpp_ / 8;
|
156
177
|
uint16_t rgb565 = encode_uint16(progmem_read_byte(pos), progmem_read_byte(pos + 1));
|
157
178
|
auto r = (rgb565 & 0xF800) >> 11;
|
158
179
|
auto g = (rgb565 & 0x07E0) >> 5;
|
159
180
|
auto b = rgb565 & 0x001F;
|
160
|
-
auto a =
|
161
|
-
|
162
|
-
|
181
|
+
auto a = 0xFF;
|
182
|
+
switch (this->transparency_) {
|
183
|
+
case TRANSPARENCY_ALPHA_CHANNEL:
|
184
|
+
a = progmem_read_byte(pos + 2);
|
185
|
+
break;
|
186
|
+
case TRANSPARENCY_CHROMA_KEY:
|
187
|
+
if (rgb565 == 0x0020)
|
188
|
+
a = 0;
|
189
|
+
break;
|
190
|
+
default:
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
return Color((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), a);
|
163
194
|
}
|
164
195
|
|
165
196
|
Color Image::get_grayscale_pixel_(int x, int y) const {
|
166
197
|
const uint32_t pos = (x + y * this->width_);
|
167
198
|
const uint8_t gray = progmem_read_byte(this->data_start_ + pos);
|
168
|
-
|
169
|
-
|
199
|
+
switch (this->transparency_) {
|
200
|
+
case TRANSPARENCY_CHROMA_KEY:
|
201
|
+
if (gray == 1)
|
202
|
+
return Color(0, 0, 0, 0);
|
203
|
+
return Color(gray, gray, gray, 0xFF);
|
204
|
+
case TRANSPARENCY_ALPHA_CHANNEL:
|
205
|
+
return Color(0, 0, 0, gray);
|
206
|
+
default:
|
207
|
+
return Color(gray, gray, gray, 0xFF);
|
208
|
+
}
|
170
209
|
}
|
171
210
|
int Image::get_width() const { return this->width_; }
|
172
211
|
int Image::get_height() const { return this->height_; }
|
173
212
|
ImageType Image::get_type() const { return this->type_; }
|
174
|
-
Image::Image(const uint8_t *data_start, int width, int height, ImageType type)
|
175
|
-
: width_(width), height_(height), type_(type), data_start_(data_start) {
|
213
|
+
Image::Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency)
|
214
|
+
: width_(width), height_(height), type_(type), data_start_(data_start), transparency_(transparency) {
|
215
|
+
switch (this->type_) {
|
216
|
+
case IMAGE_TYPE_BINARY:
|
217
|
+
this->bpp_ = 1;
|
218
|
+
break;
|
219
|
+
case IMAGE_TYPE_GRAYSCALE:
|
220
|
+
this->bpp_ = 8;
|
221
|
+
break;
|
222
|
+
case IMAGE_TYPE_RGB565:
|
223
|
+
this->bpp_ = transparency == TRANSPARENCY_ALPHA_CHANNEL ? 24 : 16;
|
224
|
+
break;
|
225
|
+
case IMAGE_TYPE_RGB:
|
226
|
+
this->bpp_ = this->transparency_ == TRANSPARENCY_ALPHA_CHANNEL ? 32 : 24;
|
227
|
+
break;
|
228
|
+
}
|
229
|
+
}
|
176
230
|
|
177
231
|
} // namespace image
|
178
232
|
} // namespace esphome
|
esphome/components/image/image.h
CHANGED
@@ -12,51 +12,40 @@ namespace image {
|
|
12
12
|
enum ImageType {
|
13
13
|
IMAGE_TYPE_BINARY = 0,
|
14
14
|
IMAGE_TYPE_GRAYSCALE = 1,
|
15
|
-
|
15
|
+
IMAGE_TYPE_RGB = 2,
|
16
16
|
IMAGE_TYPE_RGB565 = 3,
|
17
|
-
|
17
|
+
};
|
18
|
+
|
19
|
+
enum Transparency {
|
20
|
+
TRANSPARENCY_OPAQUE = 0,
|
21
|
+
TRANSPARENCY_CHROMA_KEY = 1,
|
22
|
+
TRANSPARENCY_ALPHA_CHANNEL = 2,
|
18
23
|
};
|
19
24
|
|
20
25
|
class Image : public display::BaseImage {
|
21
26
|
public:
|
22
|
-
Image(const uint8_t *data_start, int width, int height, ImageType type);
|
27
|
+
Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency);
|
23
28
|
Color get_pixel(int x, int y, Color color_on = display::COLOR_ON, Color color_off = display::COLOR_OFF) const;
|
24
29
|
int get_width() const override;
|
25
30
|
int get_height() const override;
|
26
31
|
const uint8_t *get_data_start() const { return this->data_start_; }
|
27
32
|
ImageType get_type() const;
|
28
33
|
|
29
|
-
int get_bpp() const {
|
30
|
-
switch (this->type_) {
|
31
|
-
case IMAGE_TYPE_BINARY:
|
32
|
-
return 1;
|
33
|
-
case IMAGE_TYPE_GRAYSCALE:
|
34
|
-
return 8;
|
35
|
-
case IMAGE_TYPE_RGB565:
|
36
|
-
return this->transparent_ ? 24 : 16;
|
37
|
-
case IMAGE_TYPE_RGB24:
|
38
|
-
return 24;
|
39
|
-
case IMAGE_TYPE_RGBA:
|
40
|
-
return 32;
|
41
|
-
}
|
42
|
-
return 0;
|
43
|
-
}
|
34
|
+
int get_bpp() const { return this->bpp_; }
|
44
35
|
|
45
36
|
/// Return the stride of the image in bytes, that is, the distance in bytes
|
46
37
|
/// between two consecutive rows of pixels.
|
47
|
-
|
38
|
+
size_t get_width_stride() const { return (this->width_ * this->get_bpp() + 7u) / 8u; }
|
48
39
|
void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
|
49
40
|
|
50
|
-
|
51
|
-
bool has_transparency() const { return transparent_; }
|
41
|
+
bool has_transparency() const { return this->transparency_ != TRANSPARENCY_OPAQUE; }
|
52
42
|
|
53
43
|
#ifdef USE_LVGL
|
54
44
|
lv_img_dsc_t *get_lv_img_dsc();
|
55
45
|
#endif
|
56
46
|
protected:
|
57
47
|
bool get_binary_pixel_(int x, int y) const;
|
58
|
-
Color
|
59
|
-
Color get_rgba_pixel_(int x, int y) const;
|
48
|
+
Color get_rgb_pixel_(int x, int y) const;
|
60
49
|
Color get_rgb565_pixel_(int x, int y) const;
|
61
50
|
Color get_grayscale_pixel_(int x, int y) const;
|
62
51
|
|
@@ -64,7 +53,9 @@ class Image : public display::BaseImage {
|
|
64
53
|
int height_;
|
65
54
|
ImageType type_;
|
66
55
|
const uint8_t *data_start_;
|
67
|
-
|
56
|
+
Transparency transparency_;
|
57
|
+
size_t bpp_{};
|
58
|
+
size_t stride_{};
|
68
59
|
#ifdef USE_LVGL
|
69
60
|
lv_img_dsc_t dsc_{};
|
70
61
|
#endif
|
@@ -1,45 +1,27 @@
|
|
1
1
|
#include "json_util.h"
|
2
2
|
#include "esphome/core/log.h"
|
3
3
|
|
4
|
-
#ifdef USE_ESP8266
|
5
|
-
#include <Esp.h>
|
6
|
-
#endif
|
7
|
-
#ifdef USE_ESP32
|
8
|
-
#include <esp_heap_caps.h>
|
9
|
-
#endif
|
10
|
-
#ifdef USE_RP2040
|
11
|
-
#include <Arduino.h>
|
12
|
-
#endif
|
13
|
-
|
14
4
|
namespace esphome {
|
15
5
|
namespace json {
|
16
6
|
|
17
7
|
static const char *const TAG = "json";
|
18
8
|
|
19
9
|
static std::vector<char> global_json_build_buffer; // NOLINT
|
10
|
+
static const auto ALLOCATOR = RAMAllocator<uint8_t>(RAMAllocator<uint8_t>::ALLOC_INTERNAL);
|
20
11
|
|
21
12
|
std::string build_json(const json_build_t &f) {
|
22
13
|
// Here we are allocating up to 5kb of memory,
|
23
14
|
// with the heap size minus 2kb to be safe if less than 5kb
|
24
15
|
// as we can not have a true dynamic sized document.
|
25
16
|
// The excess memory is freed below with `shrinkToFit()`
|
26
|
-
|
27
|
-
const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance)
|
28
|
-
#elif defined(USE_ESP32)
|
29
|
-
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
|
30
|
-
#elif defined(USE_RP2040)
|
31
|
-
const size_t free_heap = rp2040.getFreeHeap();
|
32
|
-
#elif defined(USE_LIBRETINY)
|
33
|
-
const size_t free_heap = lt_heap_get_free();
|
34
|
-
#endif
|
35
|
-
|
17
|
+
auto free_heap = ALLOCATOR.get_max_free_block_size();
|
36
18
|
size_t request_size = std::min(free_heap, (size_t) 512);
|
37
19
|
while (true) {
|
38
|
-
ESP_LOGV(TAG, "Attempting to allocate %
|
20
|
+
ESP_LOGV(TAG, "Attempting to allocate %zu bytes for JSON serialization", request_size);
|
39
21
|
DynamicJsonDocument json_document(request_size);
|
40
22
|
if (json_document.capacity() == 0) {
|
41
23
|
ESP_LOGE(TAG,
|
42
|
-
"Could not allocate memory for JSON document! Requested %
|
24
|
+
"Could not allocate memory for JSON document! Requested %zu bytes, largest free heap block: %zu bytes",
|
43
25
|
request_size, free_heap);
|
44
26
|
return "{}";
|
45
27
|
}
|
@@ -47,7 +29,7 @@ std::string build_json(const json_build_t &f) {
|
|
47
29
|
f(root);
|
48
30
|
if (json_document.overflowed()) {
|
49
31
|
if (request_size == free_heap) {
|
50
|
-
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %
|
32
|
+
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %zu bytes",
|
51
33
|
free_heap);
|
52
34
|
return "{}";
|
53
35
|
}
|
@@ -55,7 +37,7 @@ std::string build_json(const json_build_t &f) {
|
|
55
37
|
continue;
|
56
38
|
}
|
57
39
|
json_document.shrinkToFit();
|
58
|
-
ESP_LOGV(TAG, "Size after shrink %
|
40
|
+
ESP_LOGV(TAG, "Size after shrink %zu bytes", json_document.capacity());
|
59
41
|
std::string output;
|
60
42
|
serializeJson(json_document, output);
|
61
43
|
return output;
|
@@ -67,20 +49,12 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
|
|
67
49
|
// with the heap size minus 2kb to be safe if less than that
|
68
50
|
// as we can not have a true dynamic sized document.
|
69
51
|
// The excess memory is freed below with `shrinkToFit()`
|
70
|
-
|
71
|
-
const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance)
|
72
|
-
#elif defined(USE_ESP32)
|
73
|
-
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
|
74
|
-
#elif defined(USE_RP2040)
|
75
|
-
const size_t free_heap = rp2040.getFreeHeap();
|
76
|
-
#elif defined(USE_LIBRETINY)
|
77
|
-
const size_t free_heap = lt_heap_get_free();
|
78
|
-
#endif
|
52
|
+
auto free_heap = ALLOCATOR.get_max_free_block_size();
|
79
53
|
size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5));
|
80
54
|
while (true) {
|
81
55
|
DynamicJsonDocument json_document(request_size);
|
82
56
|
if (json_document.capacity() == 0) {
|
83
|
-
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %
|
57
|
+
ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %zu bytes, free heap: %zu", request_size,
|
84
58
|
free_heap);
|
85
59
|
return false;
|
86
60
|
}
|
@@ -20,6 +20,7 @@ class ArduinoInternalGPIOPin : public InternalGPIOPin {
|
|
20
20
|
void detach_interrupt() const override;
|
21
21
|
ISRInternalGPIOPin to_isr() const override;
|
22
22
|
uint8_t get_pin() const override { return pin_; }
|
23
|
+
gpio::Flags get_flags() const override { return flags_; }
|
23
24
|
bool is_inverted() const override { return inverted_; }
|
24
25
|
|
25
26
|
protected:
|
@@ -36,7 +36,7 @@ inline static uint8_t to_uint8_scale(float x) { return static_cast<uint8_t>(roun
|
|
36
36
|
* range as set in the traits, so the output needs to do this.
|
37
37
|
*
|
38
38
|
* For COLD_WARM_WHITE capability:
|
39
|
-
* - cold_white, warm_white: The brightness of the
|
39
|
+
* - cold_white, warm_white: The brightness of the light's cold and warm white channels.
|
40
40
|
*
|
41
41
|
* All values (except color temperature) are represented using floats in the range 0.0 (off) to 1.0 (on), and are
|
42
42
|
* automatically clamped to this range. Properties not used in the current color mode can still have (invalid) values
|
@@ -35,7 +35,7 @@ from esphome.const import (
|
|
35
35
|
PLATFORM_RP2040,
|
36
36
|
PLATFORM_RTL87XX,
|
37
37
|
)
|
38
|
-
from esphome.core import CORE,
|
38
|
+
from esphome.core import CORE, Lambda, coroutine_with_priority
|
39
39
|
|
40
40
|
CODEOWNERS = ["@esphome/core"]
|
41
41
|
logger_ns = cg.esphome_ns.namespace("logger")
|
@@ -77,6 +77,9 @@ USB_SERIAL_JTAG = "USB_SERIAL_JTAG"
|
|
77
77
|
USB_CDC = "USB_CDC"
|
78
78
|
DEFAULT = "DEFAULT"
|
79
79
|
|
80
|
+
CONF_INITIAL_LEVEL = "initial_level"
|
81
|
+
CONF_LOGGER_ID = "logger_id"
|
82
|
+
|
80
83
|
UART_SELECTION_ESP32 = {
|
81
84
|
VARIANT_ESP32: [UART0, UART1, UART2],
|
82
85
|
VARIANT_ESP32S2: [UART0, UART1, USB_CDC],
|
@@ -154,11 +157,11 @@ def uart_selection(value):
|
|
154
157
|
|
155
158
|
|
156
159
|
def validate_local_no_higher_than_global(value):
|
157
|
-
global_level =
|
160
|
+
global_level = LOG_LEVEL_SEVERITY.index(value[CONF_LEVEL])
|
158
161
|
for tag, level in value.get(CONF_LOGS, {}).items():
|
159
|
-
if LOG_LEVEL_SEVERITY.index(level) >
|
160
|
-
raise
|
161
|
-
f"The
|
162
|
+
if LOG_LEVEL_SEVERITY.index(level) > global_level:
|
163
|
+
raise cv.Invalid(
|
164
|
+
f"The configured log level for {tag} ({level}) must be no more severe than the global log level {value[CONF_LEVEL]}."
|
162
165
|
)
|
163
166
|
return value
|
164
167
|
|
@@ -186,6 +189,8 @@ CONFIG_SCHEMA = cv.All(
|
|
186
189
|
esp32_s3_idf=USB_SERIAL_JTAG,
|
187
190
|
esp32_c3_arduino=USB_CDC,
|
188
191
|
esp32_c3_idf=USB_SERIAL_JTAG,
|
192
|
+
esp32_c6_arduino=USB_CDC,
|
193
|
+
esp32_c6_idf=USB_SERIAL_JTAG,
|
189
194
|
rp2040=USB_CDC,
|
190
195
|
bk72xx=DEFAULT,
|
191
196
|
rtl87xx=DEFAULT,
|
@@ -207,6 +212,7 @@ CONFIG_SCHEMA = cv.All(
|
|
207
212
|
cv.string: is_log_level,
|
208
213
|
}
|
209
214
|
),
|
215
|
+
cv.Optional(CONF_INITIAL_LEVEL): is_log_level,
|
210
216
|
cv.Optional(CONF_ON_MESSAGE): automation.validate_automation(
|
211
217
|
{
|
212
218
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoggerMessageTrigger),
|
@@ -225,7 +231,14 @@ CONFIG_SCHEMA = cv.All(
|
|
225
231
|
@coroutine_with_priority(90.0)
|
226
232
|
async def to_code(config):
|
227
233
|
baud_rate = config[CONF_BAUD_RATE]
|
228
|
-
|
234
|
+
level = config[CONF_LEVEL]
|
235
|
+
initial_level = LOG_LEVELS[config.get(CONF_INITIAL_LEVEL, level)]
|
236
|
+
log = cg.new_Pvariable(
|
237
|
+
config[CONF_ID],
|
238
|
+
baud_rate,
|
239
|
+
config[CONF_TX_BUFFER_SIZE],
|
240
|
+
)
|
241
|
+
cg.add(log.set_log_level(initial_level))
|
229
242
|
if CONF_HARDWARE_UART in config:
|
230
243
|
cg.add(
|
231
244
|
log.set_uart_selection(
|
@@ -237,7 +250,6 @@ async def to_code(config):
|
|
237
250
|
for tag, level in config[CONF_LOGS].items():
|
238
251
|
cg.add(log.set_log_level(tag, LOG_LEVELS[level]))
|
239
252
|
|
240
|
-
level = config[CONF_LEVEL]
|
241
253
|
cg.add_define("USE_LOGGER")
|
242
254
|
this_severity = LOG_LEVEL_SEVERITY.index(level)
|
243
255
|
cg.add_build_flag(f"-DESPHOME_LOG_LEVEL={LOG_LEVELS[level]}")
|
@@ -365,3 +377,27 @@ async def logger_log_action_to_code(config, action_id, template_arg, args):
|
|
365
377
|
|
366
378
|
lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
|
367
379
|
return cg.new_Pvariable(action_id, template_arg, lambda_)
|
380
|
+
|
381
|
+
|
382
|
+
@automation.register_action(
|
383
|
+
"logger.set_level",
|
384
|
+
LambdaAction,
|
385
|
+
cv.maybe_simple_value(
|
386
|
+
{
|
387
|
+
cv.GenerateID(CONF_LOGGER_ID): cv.use_id(Logger),
|
388
|
+
cv.Required(CONF_LEVEL): is_log_level,
|
389
|
+
cv.Optional(CONF_TAG): cv.string,
|
390
|
+
},
|
391
|
+
key=CONF_LEVEL,
|
392
|
+
),
|
393
|
+
)
|
394
|
+
async def logger_set_level_to_code(config, action_id, template_arg, args):
|
395
|
+
level = LOG_LEVELS[config[CONF_LEVEL]]
|
396
|
+
logger = await cg.get_variable(config[CONF_LOGGER_ID])
|
397
|
+
if tag := config.get(CONF_TAG):
|
398
|
+
text = str(cg.statement(logger.set_log_level(tag, level)))
|
399
|
+
else:
|
400
|
+
text = str(cg.statement(logger.set_log_level(level)))
|
401
|
+
|
402
|
+
lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
|
403
|
+
return cg.new_Pvariable(action_id, template_arg, lambda_)
|
@@ -105,12 +105,9 @@ int HOT Logger::level_for(const char *tag) {
|
|
105
105
|
// Uses std::vector<> for low memory footprint, though the vector
|
106
106
|
// could be sorted to minimize lookup times. This feature isn't used that
|
107
107
|
// much anyway so it doesn't matter too much.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
}
|
113
|
-
return ESPHOME_LOG_LEVEL;
|
108
|
+
if (this->log_levels_.count(tag) != 0)
|
109
|
+
return this->log_levels_[tag];
|
110
|
+
return this->current_level_;
|
114
111
|
}
|
115
112
|
|
116
113
|
void HOT Logger::log_message_(int level, const char *tag, int offset) {
|
@@ -167,9 +164,7 @@ void Logger::loop() {
|
|
167
164
|
#endif
|
168
165
|
|
169
166
|
void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
|
170
|
-
void Logger::set_log_level(const std::string &tag, int log_level) {
|
171
|
-
this->log_levels_.push_back(LogLevelOverride{tag, log_level});
|
172
|
-
}
|
167
|
+
void Logger::set_log_level(const std::string &tag, int log_level) { this->log_levels_[tag] = log_level; }
|
173
168
|
|
174
169
|
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
|
175
170
|
UARTSelection Logger::get_uart() const { return this->uart_; }
|
@@ -183,18 +178,28 @@ const char *const LOG_LEVELS[] = {"NONE", "ERROR", "WARN", "INFO", "CONFIG", "DE
|
|
183
178
|
|
184
179
|
void Logger::dump_config() {
|
185
180
|
ESP_LOGCONFIG(TAG, "Logger:");
|
186
|
-
ESP_LOGCONFIG(TAG, " Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
|
181
|
+
ESP_LOGCONFIG(TAG, " Max Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
|
182
|
+
ESP_LOGCONFIG(TAG, " Initial Level: %s", LOG_LEVELS[this->current_level_]);
|
187
183
|
#ifndef USE_HOST
|
188
184
|
ESP_LOGCONFIG(TAG, " Log Baud Rate: %" PRIu32, this->baud_rate_);
|
189
185
|
ESP_LOGCONFIG(TAG, " Hardware UART: %s", get_uart_selection_());
|
190
186
|
#endif
|
191
187
|
|
192
188
|
for (auto &it : this->log_levels_) {
|
193
|
-
ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.
|
189
|
+
ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.first.c_str(), LOG_LEVELS[it.second]);
|
194
190
|
}
|
195
191
|
}
|
196
192
|
void Logger::write_footer_() { this->write_to_buffer_(ESPHOME_LOG_RESET_COLOR, strlen(ESPHOME_LOG_RESET_COLOR)); }
|
197
193
|
|
194
|
+
void Logger::set_log_level(int level) {
|
195
|
+
if (level > ESPHOME_LOG_LEVEL) {
|
196
|
+
level = ESPHOME_LOG_LEVEL;
|
197
|
+
ESP_LOGW(TAG, "Cannot set log level higher than pre-compiled %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
|
198
|
+
}
|
199
|
+
this->current_level_ = level;
|
200
|
+
this->level_callback_.call(level);
|
201
|
+
}
|
202
|
+
|
198
203
|
Logger *global_logger = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
199
204
|
|
200
205
|
} // namespace logger
|
@@ -1,11 +1,12 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <cstdarg>
|
4
|
-
#include <
|
4
|
+
#include <map>
|
5
5
|
#include "esphome/core/automation.h"
|
6
6
|
#include "esphome/core/component.h"
|
7
7
|
#include "esphome/core/defines.h"
|
8
8
|
#include "esphome/core/helpers.h"
|
9
|
+
#include "esphome/core/log.h"
|
9
10
|
|
10
11
|
#ifdef USE_ARDUINO
|
11
12
|
#if defined(USE_ESP8266) || defined(USE_ESP32)
|
@@ -74,8 +75,11 @@ class Logger : public Component {
|
|
74
75
|
UARTSelection get_uart() const;
|
75
76
|
#endif
|
76
77
|
|
78
|
+
/// Set the default log level for this logger.
|
79
|
+
void set_log_level(int level);
|
77
80
|
/// Set the log level of the specified tag.
|
78
81
|
void set_log_level(const std::string &tag, int log_level);
|
82
|
+
int get_log_level() { return this->current_level_; }
|
79
83
|
|
80
84
|
// ========== INTERNAL METHODS ==========
|
81
85
|
// (In most use cases you won't need these)
|
@@ -88,6 +92,9 @@ class Logger : public Component {
|
|
88
92
|
/// Register a callback that will be called for every log message sent
|
89
93
|
void add_on_log_callback(std::function<void(int, const char *, const char *)> &&callback);
|
90
94
|
|
95
|
+
// add a listener for log level changes
|
96
|
+
void add_listener(std::function<void(int)> &&callback) { this->level_callback_.add(std::move(callback)); }
|
97
|
+
|
91
98
|
float get_setup_priority() const override;
|
92
99
|
|
93
100
|
void log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT
|
@@ -159,17 +166,14 @@ class Logger : public Component {
|
|
159
166
|
#ifdef USE_ESP_IDF
|
160
167
|
uart_port_t uart_num_;
|
161
168
|
#endif
|
162
|
-
|
163
|
-
std::string tag;
|
164
|
-
int level;
|
165
|
-
};
|
166
|
-
std::vector<LogLevelOverride> log_levels_;
|
169
|
+
std::map<std::string, int> log_levels_{};
|
167
170
|
CallbackManager<void(int, const char *, const char *)> log_callback_{};
|
171
|
+
int current_level_{ESPHOME_LOG_LEVEL_VERY_VERBOSE};
|
168
172
|
/// Prevents recursive log calls, if true a log message is already being processed.
|
169
173
|
bool recursion_guard_ = false;
|
170
174
|
void *main_task_ = nullptr;
|
175
|
+
CallbackManager<void(int)> level_callback_{};
|
171
176
|
};
|
172
|
-
|
173
177
|
extern Logger *global_logger; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
174
178
|
|
175
179
|
class LoggerMessageTrigger : public Trigger<int, const char *, const char *> {
|