esphome 2024.12.3__py3-none-any.whl → 2025.2.0__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/api/client.py +8 -3
- 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 +4 -2
- esphome/components/dht/sensor.py +1 -1
- esphome/components/display/__init__.py +18 -5
- esphome/components/display/display.cpp +16 -3
- 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_dac/esp32_dac.cpp +16 -7
- esphome/components/esp32_dac/esp32_dac.h +8 -0
- esphome/components/esp32_dac/output.py +16 -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/font/__init__.py +1 -1
- 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 +45 -9
- esphome/components/logger/logger.cpp +16 -14
- 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 +31 -2
- esphome/components/online_image/image_decoder.h +24 -15
- esphome/components/online_image/jpeg_image.cpp +92 -0
- esphome/components/online_image/jpeg_image.h +34 -0
- esphome/components/online_image/online_image.cpp +118 -58
- esphome/components/online_image/online_image.h +39 -9
- 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/scd30/sensor.py +1 -1
- 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/dashboard/web_server.py +1 -1
- esphome/espota2.py +3 -2
- esphome/loader.py +12 -4
- esphome/log.py +5 -7
- esphome/yaml_util.py +2 -2
- {esphome-2024.12.3.dist-info → esphome-2025.2.0.dist-info}/METADATA +14 -9
- {esphome-2024.12.3.dist-info → esphome-2025.2.0.dist-info}/RECORD +349 -300
- 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.3.dist-info → esphome-2025.2.0.dist-info}/LICENSE +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0.dist-info}/WHEEL +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0.dist-info}/entry_points.txt +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0.dist-info}/top_level.txt +0 -0
esphome/__main__.py
CHANGED
@@ -758,6 +758,14 @@ def parse_args(argv):
|
|
758
758
|
options_parser.add_argument(
|
759
759
|
"-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"
|
760
760
|
)
|
761
|
+
options_parser.add_argument(
|
762
|
+
"-l",
|
763
|
+
"--log-level",
|
764
|
+
help="Set the log level.",
|
765
|
+
default=os.getenv("ESPHOME_LOG_LEVEL", "INFO"),
|
766
|
+
action="store",
|
767
|
+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
768
|
+
)
|
761
769
|
options_parser.add_argument(
|
762
770
|
"--dashboard", help=argparse.SUPPRESS, action="store_true"
|
763
771
|
)
|
@@ -987,11 +995,16 @@ def run_esphome(argv):
|
|
987
995
|
args = parse_args(argv)
|
988
996
|
CORE.dashboard = args.dashboard
|
989
997
|
|
998
|
+
# Override log level if verbose is set
|
999
|
+
if args.verbose:
|
1000
|
+
args.log_level = "DEBUG"
|
1001
|
+
elif args.quiet:
|
1002
|
+
args.log_level = "CRITICAL"
|
1003
|
+
|
990
1004
|
setup_log(
|
991
|
-
args.
|
992
|
-
args.quiet,
|
1005
|
+
log_level=args.log_level,
|
993
1006
|
# Show timestamp for dashboard access logs
|
994
|
-
args.command == "dashboard",
|
1007
|
+
include_timestamp=args.command == "dashboard",
|
995
1008
|
)
|
996
1009
|
|
997
1010
|
if args.command in PRE_CONFIG_ACTIONS:
|
@@ -1,11 +1,6 @@
|
|
1
|
-
import esphome.codegen as cg
|
2
|
-
import esphome.config_validation as cv
|
3
1
|
from esphome import pins
|
4
|
-
|
5
|
-
|
6
|
-
from esphome.core import CORE
|
2
|
+
import esphome.codegen as cg
|
7
3
|
from esphome.components.esp32 import get_esp32_variant
|
8
|
-
from esphome.const import PLATFORM_ESP8266
|
9
4
|
from esphome.components.esp32.const import (
|
10
5
|
VARIANT_ESP32,
|
11
6
|
VARIANT_ESP32C2,
|
@@ -15,6 +10,9 @@ from esphome.components.esp32.const import (
|
|
15
10
|
VARIANT_ESP32S2,
|
16
11
|
VARIANT_ESP32S3,
|
17
12
|
)
|
13
|
+
import esphome.config_validation as cv
|
14
|
+
from esphome.const import CONF_ANALOG, CONF_INPUT, CONF_NUMBER, PLATFORM_ESP8266
|
15
|
+
from esphome.core import CORE
|
18
16
|
|
19
17
|
CODEOWNERS = ["@esphome/core"]
|
20
18
|
|
@@ -38,6 +36,14 @@ ATTENUATION_MODES = {
|
|
38
36
|
"auto": "auto",
|
39
37
|
}
|
40
38
|
|
39
|
+
sampling_mode = adc_ns.enum("SamplingMode", is_class=True)
|
40
|
+
|
41
|
+
SAMPLING_MODES = {
|
42
|
+
"avg": sampling_mode.AVG,
|
43
|
+
"min": sampling_mode.MIN,
|
44
|
+
"max": sampling_mode.MAX,
|
45
|
+
}
|
46
|
+
|
41
47
|
adc1_channel_t = cg.global_ns.enum("adc1_channel_t")
|
42
48
|
adc2_channel_t = cg.global_ns.enum("adc2_channel_t")
|
43
49
|
|
@@ -102,11 +108,11 @@ ESP32_VARIANT_ADC1_PIN_TO_CHANNEL = {
|
|
102
108
|
6: adc1_channel_t.ADC1_CHANNEL_6,
|
103
109
|
},
|
104
110
|
VARIANT_ESP32H2: {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
111
|
+
1: adc1_channel_t.ADC1_CHANNEL_0,
|
112
|
+
2: adc1_channel_t.ADC1_CHANNEL_1,
|
113
|
+
3: adc1_channel_t.ADC1_CHANNEL_2,
|
114
|
+
4: adc1_channel_t.ADC1_CHANNEL_3,
|
115
|
+
5: adc1_channel_t.ADC1_CHANNEL_4,
|
110
116
|
},
|
111
117
|
}
|
112
118
|
|
@@ -28,6 +28,21 @@ static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_11;
|
|
28
28
|
#endif
|
29
29
|
#endif // USE_ESP32
|
30
30
|
|
31
|
+
enum class SamplingMode : uint8_t { AVG = 0, MIN = 1, MAX = 2 };
|
32
|
+
const LogString *sampling_mode_to_str(SamplingMode mode);
|
33
|
+
|
34
|
+
class Aggregator {
|
35
|
+
public:
|
36
|
+
void add_sample(uint32_t value);
|
37
|
+
uint32_t aggregate();
|
38
|
+
Aggregator(SamplingMode mode);
|
39
|
+
|
40
|
+
protected:
|
41
|
+
SamplingMode mode_{SamplingMode::AVG};
|
42
|
+
uint32_t aggr_{0};
|
43
|
+
uint32_t samples_{0};
|
44
|
+
};
|
45
|
+
|
31
46
|
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
32
47
|
public:
|
33
48
|
#ifdef USE_ESP32
|
@@ -54,6 +69,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
|
54
69
|
void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
|
55
70
|
void set_output_raw(bool output_raw) { this->output_raw_ = output_raw; }
|
56
71
|
void set_sample_count(uint8_t sample_count);
|
72
|
+
void set_sampling_mode(SamplingMode sampling_mode);
|
57
73
|
float sample() override;
|
58
74
|
|
59
75
|
#ifdef USE_ESP8266
|
@@ -68,6 +84,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
|
68
84
|
InternalGPIOPin *pin_;
|
69
85
|
bool output_raw_{false};
|
70
86
|
uint8_t sample_count_{1};
|
87
|
+
SamplingMode sampling_mode_{SamplingMode::AVG};
|
71
88
|
|
72
89
|
#ifdef USE_RP2040
|
73
90
|
bool is_temperature_{false};
|
@@ -6,6 +6,59 @@ namespace adc {
|
|
6
6
|
|
7
7
|
static const char *const TAG = "adc.common";
|
8
8
|
|
9
|
+
const LogString *sampling_mode_to_str(SamplingMode mode) {
|
10
|
+
switch (mode) {
|
11
|
+
case SamplingMode::AVG:
|
12
|
+
return LOG_STR("average");
|
13
|
+
case SamplingMode::MIN:
|
14
|
+
return LOG_STR("minimum");
|
15
|
+
case SamplingMode::MAX:
|
16
|
+
return LOG_STR("maximum");
|
17
|
+
}
|
18
|
+
return LOG_STR("unknown");
|
19
|
+
}
|
20
|
+
|
21
|
+
Aggregator::Aggregator(SamplingMode mode) {
|
22
|
+
this->mode_ = mode;
|
23
|
+
// set to max uint if mode is "min"
|
24
|
+
if (mode == SamplingMode::MIN) {
|
25
|
+
this->aggr_ = UINT32_MAX;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
void Aggregator::add_sample(uint32_t value) {
|
30
|
+
this->samples_ += 1;
|
31
|
+
|
32
|
+
switch (this->mode_) {
|
33
|
+
case SamplingMode::AVG:
|
34
|
+
this->aggr_ += value;
|
35
|
+
break;
|
36
|
+
|
37
|
+
case SamplingMode::MIN:
|
38
|
+
if (value < this->aggr_) {
|
39
|
+
this->aggr_ = value;
|
40
|
+
}
|
41
|
+
break;
|
42
|
+
|
43
|
+
case SamplingMode::MAX:
|
44
|
+
if (value > this->aggr_) {
|
45
|
+
this->aggr_ = value;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
uint32_t Aggregator::aggregate() {
|
51
|
+
if (this->mode_ == SamplingMode::AVG) {
|
52
|
+
if (this->samples_ == 0) {
|
53
|
+
return this->aggr_;
|
54
|
+
}
|
55
|
+
|
56
|
+
return (this->aggr_ + (this->samples_ >> 1)) / this->samples_; // NOLINT(clang-analyzer-core.DivideZero)
|
57
|
+
}
|
58
|
+
|
59
|
+
return this->aggr_;
|
60
|
+
}
|
61
|
+
|
9
62
|
void ADCSensor::update() {
|
10
63
|
float value_v = this->sample();
|
11
64
|
ESP_LOGV(TAG, "'%s': Got voltage=%.4fV", this->get_name().c_str(), value_v);
|
@@ -18,6 +71,8 @@ void ADCSensor::set_sample_count(uint8_t sample_count) {
|
|
18
71
|
}
|
19
72
|
}
|
20
73
|
|
74
|
+
void ADCSensor::set_sampling_mode(SamplingMode sampling_mode) { this->sampling_mode_ = sampling_mode; }
|
75
|
+
|
21
76
|
float ADCSensor::get_setup_priority() const { return setup_priority::DATA; }
|
22
77
|
|
23
78
|
} // namespace adc
|
@@ -78,12 +78,14 @@ void ADCSensor::dump_config() {
|
|
78
78
|
}
|
79
79
|
}
|
80
80
|
ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
|
81
|
+
ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
81
82
|
LOG_UPDATE_INTERVAL(this);
|
82
83
|
}
|
83
84
|
|
84
85
|
float ADCSensor::sample() {
|
85
86
|
if (!this->autorange_) {
|
86
|
-
|
87
|
+
auto aggr = Aggregator(this->sampling_mode_);
|
88
|
+
|
87
89
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
88
90
|
int raw = -1;
|
89
91
|
if (this->channel1_ != ADC1_CHANNEL_MAX) {
|
@@ -94,13 +96,14 @@ float ADCSensor::sample() {
|
|
94
96
|
if (raw == -1) {
|
95
97
|
return NAN;
|
96
98
|
}
|
97
|
-
|
99
|
+
|
100
|
+
aggr.add_sample(raw);
|
98
101
|
}
|
99
|
-
sum = (sum + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
|
100
102
|
if (this->output_raw_) {
|
101
|
-
return
|
103
|
+
return aggr.aggregate();
|
102
104
|
}
|
103
|
-
uint32_t mv =
|
105
|
+
uint32_t mv =
|
106
|
+
esp_adc_cal_raw_to_voltage(aggr.aggregate(), &this->cal_characteristics_[(int32_t) this->attenuation_]);
|
104
107
|
return mv / 1000.0f;
|
105
108
|
}
|
106
109
|
|
@@ -31,23 +31,27 @@ void ADCSensor::dump_config() {
|
|
31
31
|
LOG_PIN(" Pin: ", this->pin_);
|
32
32
|
#endif // USE_ADC_SENSOR_VCC
|
33
33
|
ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
|
34
|
+
ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
34
35
|
LOG_UPDATE_INTERVAL(this);
|
35
36
|
}
|
36
37
|
|
37
38
|
float ADCSensor::sample() {
|
38
|
-
|
39
|
+
auto aggr = Aggregator(this->sampling_mode_);
|
40
|
+
|
39
41
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
42
|
+
uint32_t raw = 0;
|
40
43
|
#ifdef USE_ADC_SENSOR_VCC
|
41
|
-
raw
|
44
|
+
raw = ESP.getVcc(); // NOLINT(readability-static-accessed-through-instance)
|
42
45
|
#else
|
43
|
-
raw
|
46
|
+
raw = analogRead(this->pin_->get_pin()); // NOLINT
|
44
47
|
#endif // USE_ADC_SENSOR_VCC
|
48
|
+
aggr.add_sample(raw);
|
45
49
|
}
|
46
|
-
|
50
|
+
|
47
51
|
if (this->output_raw_) {
|
48
|
-
return
|
52
|
+
return aggr.aggregate();
|
49
53
|
}
|
50
|
-
return
|
54
|
+
return aggr.aggregate() / 1024.0f;
|
51
55
|
}
|
52
56
|
|
53
57
|
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
|
@@ -23,23 +23,28 @@ void ADCSensor::dump_config() {
|
|
23
23
|
LOG_PIN(" Pin: ", this->pin_);
|
24
24
|
#endif // USE_ADC_SENSOR_VCC
|
25
25
|
ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
|
26
|
+
ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
26
27
|
LOG_UPDATE_INTERVAL(this);
|
27
28
|
}
|
28
29
|
|
29
30
|
float ADCSensor::sample() {
|
30
31
|
uint32_t raw = 0;
|
32
|
+
auto aggr = Aggregator(this->sampling_mode_);
|
33
|
+
|
31
34
|
if (this->output_raw_) {
|
32
35
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
33
|
-
raw
|
36
|
+
raw = analogRead(this->pin_->get_pin()); // NOLINT
|
37
|
+
aggr.add_sample(raw);
|
34
38
|
}
|
35
|
-
|
36
|
-
return raw;
|
39
|
+
return aggr.aggregate();
|
37
40
|
}
|
41
|
+
|
38
42
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
39
|
-
raw
|
43
|
+
raw = analogReadVoltage(this->pin_->get_pin()); // NOLINT
|
44
|
+
aggr.add_sample(raw);
|
40
45
|
}
|
41
|
-
|
42
|
-
return
|
46
|
+
|
47
|
+
return aggr.aggregate() / 1000.0f;
|
43
48
|
}
|
44
49
|
|
45
50
|
} // namespace adc
|
@@ -34,24 +34,28 @@ void ADCSensor::dump_config() {
|
|
34
34
|
#endif // USE_ADC_SENSOR_VCC
|
35
35
|
}
|
36
36
|
ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
|
37
|
+
ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
|
37
38
|
LOG_UPDATE_INTERVAL(this);
|
38
39
|
}
|
39
40
|
|
40
41
|
float ADCSensor::sample() {
|
42
|
+
uint32_t raw = 0;
|
43
|
+
auto aggr = Aggregator(this->sampling_mode_);
|
44
|
+
|
41
45
|
if (this->is_temperature_) {
|
42
46
|
adc_set_temp_sensor_enabled(true);
|
43
47
|
delay(1);
|
44
48
|
adc_select_input(4);
|
45
|
-
|
49
|
+
|
46
50
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
47
|
-
raw
|
51
|
+
raw = adc_read();
|
52
|
+
aggr.add_sample(raw);
|
48
53
|
}
|
49
|
-
raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
|
50
54
|
adc_set_temp_sensor_enabled(false);
|
51
55
|
if (this->output_raw_) {
|
52
|
-
return
|
56
|
+
return aggr.aggregate();
|
53
57
|
}
|
54
|
-
return
|
58
|
+
return aggr.aggregate() * 3.3f / 4096.0f;
|
55
59
|
}
|
56
60
|
|
57
61
|
uint8_t pin = this->pin_->get_pin();
|
@@ -68,11 +72,10 @@ float ADCSensor::sample() {
|
|
68
72
|
adc_gpio_init(pin);
|
69
73
|
adc_select_input(pin - 26);
|
70
74
|
|
71
|
-
uint32_t raw = 0;
|
72
75
|
for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
|
73
|
-
raw
|
76
|
+
raw = adc_read();
|
77
|
+
aggr.add_sample(raw);
|
74
78
|
}
|
75
|
-
raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
|
76
79
|
|
77
80
|
#ifdef CYW43_USES_VSYS_PIN
|
78
81
|
if (pin == PICO_VSYS_PIN) {
|
@@ -81,10 +84,10 @@ float ADCSensor::sample() {
|
|
81
84
|
#endif // CYW43_USES_VSYS_PIN
|
82
85
|
|
83
86
|
if (this->output_raw_) {
|
84
|
-
return
|
87
|
+
return aggr.aggregate();
|
85
88
|
}
|
86
89
|
float coeff = pin == PICO_VSYS_PIN ? 3.0f : 1.0f;
|
87
|
-
return
|
90
|
+
return aggr.aggregate() * 3.3f / 4096.0f * coeff;
|
88
91
|
}
|
89
92
|
|
90
93
|
} // namespace adc
|
esphome/components/adc/sensor.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
3
|
import esphome.codegen as cg
|
4
|
-
import esphome.config_validation as cv
|
5
|
-
import esphome.final_validate as fv
|
6
|
-
from esphome.core import CORE
|
7
4
|
from esphome.components import sensor, voltage_sampler
|
8
5
|
from esphome.components.esp32 import get_esp32_variant
|
6
|
+
import esphome.config_validation as cv
|
9
7
|
from esphome.const import (
|
10
8
|
CONF_ATTENUATION,
|
11
9
|
CONF_ID,
|
@@ -17,10 +15,14 @@ from esphome.const import (
|
|
17
15
|
STATE_CLASS_MEASUREMENT,
|
18
16
|
UNIT_VOLT,
|
19
17
|
)
|
18
|
+
from esphome.core import CORE
|
19
|
+
import esphome.final_validate as fv
|
20
|
+
|
20
21
|
from . import (
|
21
22
|
ATTENUATION_MODES,
|
22
23
|
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
|
23
24
|
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
25
|
+
SAMPLING_MODES,
|
24
26
|
adc_ns,
|
25
27
|
validate_adc_pin,
|
26
28
|
)
|
@@ -30,9 +32,11 @@ _LOGGER = logging.getLogger(__name__)
|
|
30
32
|
AUTO_LOAD = ["voltage_sampler"]
|
31
33
|
|
32
34
|
CONF_SAMPLES = "samples"
|
35
|
+
CONF_SAMPLING_MODE = "sampling_mode"
|
33
36
|
|
34
37
|
|
35
38
|
_attenuation = cv.enum(ATTENUATION_MODES, lower=True)
|
39
|
+
_sampling_mode = cv.enum(SAMPLING_MODES, lower=True)
|
36
40
|
|
37
41
|
|
38
42
|
def validate_config(config):
|
@@ -88,6 +92,7 @@ CONFIG_SCHEMA = cv.All(
|
|
88
92
|
cv.only_on_esp32, _attenuation
|
89
93
|
),
|
90
94
|
cv.Optional(CONF_SAMPLES, default=1): cv.int_range(min=1, max=255),
|
95
|
+
cv.Optional(CONF_SAMPLING_MODE, default="avg"): _sampling_mode,
|
91
96
|
}
|
92
97
|
)
|
93
98
|
.extend(cv.polling_component_schema("60s")),
|
@@ -112,6 +117,7 @@ async def to_code(config):
|
|
112
117
|
|
113
118
|
cg.add(var.set_output_raw(config[CONF_RAW]))
|
114
119
|
cg.add(var.set_sample_count(config[CONF_SAMPLES]))
|
120
|
+
cg.add(var.set_sampling_mode(config[CONF_SAMPLING_MODE]))
|
115
121
|
|
116
122
|
if attenuation := config.get(CONF_ATTENUATION):
|
117
123
|
if attenuation == "auto":
|
@@ -9,8 +9,6 @@ static const char *const TAG = "ads1115";
|
|
9
9
|
static const uint8_t ADS1115_REGISTER_CONVERSION = 0x00;
|
10
10
|
static const uint8_t ADS1115_REGISTER_CONFIG = 0x01;
|
11
11
|
|
12
|
-
static const uint8_t ADS1115_DATA_RATE_860_SPS = 0b111; // 3300_SPS for ADS1015
|
13
|
-
|
14
12
|
void ADS1115Component::setup() {
|
15
13
|
ESP_LOGCONFIG(TAG, "Setting up ADS1115...");
|
16
14
|
uint16_t value;
|
@@ -43,9 +41,9 @@ void ADS1115Component::setup() {
|
|
43
41
|
config |= 0b0000000100000000;
|
44
42
|
}
|
45
43
|
|
46
|
-
// Set data rate - 860 samples per second
|
44
|
+
// Set data rate - 860 samples per second
|
47
45
|
// 0bxxxxxxxx100xxxxx
|
48
|
-
config |=
|
46
|
+
config |= ADS1115_860SPS << 5;
|
49
47
|
|
50
48
|
// Set comparator mode - hysteresis
|
51
49
|
// 0bxxxxxxxxxxx0xxxx
|
@@ -77,7 +75,7 @@ void ADS1115Component::dump_config() {
|
|
77
75
|
}
|
78
76
|
}
|
79
77
|
float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain,
|
80
|
-
ADS1115Resolution resolution) {
|
78
|
+
ADS1115Resolution resolution, ADS1115Samplerate samplerate) {
|
81
79
|
uint16_t config = this->prev_config_;
|
82
80
|
// Multiplexer
|
83
81
|
// 0bxBBBxxxxxxxxxxxx
|
@@ -89,6 +87,11 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
|
|
89
87
|
config &= 0b1111000111111111;
|
90
88
|
config |= (gain & 0b111) << 9;
|
91
89
|
|
90
|
+
// Sample rate
|
91
|
+
// 0bxxxxxxxxBBBxxxxx
|
92
|
+
config &= 0b1111111100011111;
|
93
|
+
config |= (samplerate & 0b111) << 5;
|
94
|
+
|
92
95
|
if (!this->continuous_mode_) {
|
93
96
|
// Start conversion
|
94
97
|
config |= 0b1000000000000000;
|
@@ -101,8 +104,54 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
|
|
101
104
|
}
|
102
105
|
this->prev_config_ = config;
|
103
106
|
|
104
|
-
//
|
105
|
-
|
107
|
+
// Delay calculated as: ceil((1000/SPS)+.5)
|
108
|
+
if (resolution == ADS1015_12_BITS) {
|
109
|
+
switch (samplerate) {
|
110
|
+
case ADS1115_8SPS:
|
111
|
+
delay(9);
|
112
|
+
break;
|
113
|
+
case ADS1115_16SPS:
|
114
|
+
delay(5);
|
115
|
+
break;
|
116
|
+
case ADS1115_32SPS:
|
117
|
+
delay(3);
|
118
|
+
break;
|
119
|
+
case ADS1115_64SPS:
|
120
|
+
case ADS1115_128SPS:
|
121
|
+
delay(2);
|
122
|
+
break;
|
123
|
+
default:
|
124
|
+
delay(1);
|
125
|
+
break;
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
switch (samplerate) {
|
129
|
+
case ADS1115_8SPS:
|
130
|
+
delay(126); // NOLINT
|
131
|
+
break;
|
132
|
+
case ADS1115_16SPS:
|
133
|
+
delay(63); // NOLINT
|
134
|
+
break;
|
135
|
+
case ADS1115_32SPS:
|
136
|
+
delay(32);
|
137
|
+
break;
|
138
|
+
case ADS1115_64SPS:
|
139
|
+
delay(17);
|
140
|
+
break;
|
141
|
+
case ADS1115_128SPS:
|
142
|
+
delay(9);
|
143
|
+
break;
|
144
|
+
case ADS1115_250SPS:
|
145
|
+
delay(5);
|
146
|
+
break;
|
147
|
+
case ADS1115_475SPS:
|
148
|
+
delay(3);
|
149
|
+
break;
|
150
|
+
case ADS1115_860SPS:
|
151
|
+
delay(2);
|
152
|
+
break;
|
153
|
+
}
|
154
|
+
}
|
106
155
|
|
107
156
|
// in continuous mode, conversion will always be running, rely on the delay
|
108
157
|
// to ensure conversion is taking place with the correct settings
|
@@ -33,6 +33,17 @@ enum ADS1115Resolution {
|
|
33
33
|
ADS1015_12_BITS = 12,
|
34
34
|
};
|
35
35
|
|
36
|
+
enum ADS1115Samplerate {
|
37
|
+
ADS1115_8SPS = 0b000,
|
38
|
+
ADS1115_16SPS = 0b001,
|
39
|
+
ADS1115_32SPS = 0b010,
|
40
|
+
ADS1115_64SPS = 0b011,
|
41
|
+
ADS1115_128SPS = 0b100,
|
42
|
+
ADS1115_250SPS = 0b101,
|
43
|
+
ADS1115_475SPS = 0b110,
|
44
|
+
ADS1115_860SPS = 0b111
|
45
|
+
};
|
46
|
+
|
36
47
|
class ADS1115Component : public Component, public i2c::I2CDevice {
|
37
48
|
public:
|
38
49
|
void setup() override;
|
@@ -42,7 +53,8 @@ class ADS1115Component : public Component, public i2c::I2CDevice {
|
|
42
53
|
void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; }
|
43
54
|
|
44
55
|
/// Helper method to request a measurement from a sensor.
|
45
|
-
float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution
|
56
|
+
float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution,
|
57
|
+
ADS1115Samplerate samplerate);
|
46
58
|
|
47
59
|
protected:
|
48
60
|
uint16_t prev_config_{0};
|
@@ -5,6 +5,7 @@ from esphome.const import (
|
|
5
5
|
CONF_GAIN,
|
6
6
|
CONF_MULTIPLEXER,
|
7
7
|
CONF_RESOLUTION,
|
8
|
+
CONF_SAMPLE_RATE,
|
8
9
|
DEVICE_CLASS_VOLTAGE,
|
9
10
|
STATE_CLASS_MEASUREMENT,
|
10
11
|
UNIT_VOLT,
|
@@ -43,6 +44,17 @@ RESOLUTION = {
|
|
43
44
|
"12_BITS": ADS1115Resolution.ADS1015_12_BITS,
|
44
45
|
}
|
45
46
|
|
47
|
+
ADS1115Samplerate = ads1115_ns.enum("ADS1115Samplerate")
|
48
|
+
SAMPLERATE = {
|
49
|
+
"8": ADS1115Samplerate.ADS1115_8SPS,
|
50
|
+
"16": ADS1115Samplerate.ADS1115_16SPS,
|
51
|
+
"32": ADS1115Samplerate.ADS1115_32SPS,
|
52
|
+
"64": ADS1115Samplerate.ADS1115_64SPS,
|
53
|
+
"128": ADS1115Samplerate.ADS1115_128SPS,
|
54
|
+
"250": ADS1115Samplerate.ADS1115_250SPS,
|
55
|
+
"475": ADS1115Samplerate.ADS1115_475SPS,
|
56
|
+
"860": ADS1115Samplerate.ADS1115_860SPS,
|
57
|
+
}
|
46
58
|
|
47
59
|
ADS1115Sensor = ads1115_ns.class_(
|
48
60
|
"ADS1115Sensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
@@ -64,6 +76,9 @@ CONFIG_SCHEMA = (
|
|
64
76
|
cv.Optional(CONF_RESOLUTION, default="16_BITS"): cv.enum(
|
65
77
|
RESOLUTION, upper=True, space="_"
|
66
78
|
),
|
79
|
+
cv.Optional(CONF_SAMPLE_RATE, default="860"): cv.enum(
|
80
|
+
SAMPLERATE, string=True
|
81
|
+
),
|
67
82
|
}
|
68
83
|
)
|
69
84
|
.extend(cv.polling_component_schema("60s"))
|
@@ -79,3 +94,4 @@ async def to_code(config):
|
|
79
94
|
cg.add(var.set_multiplexer(config[CONF_MULTIPLEXER]))
|
80
95
|
cg.add(var.set_gain(config[CONF_GAIN]))
|
81
96
|
cg.add(var.set_resolution(config[CONF_RESOLUTION]))
|
97
|
+
cg.add(var.set_samplerate(config[CONF_SAMPLE_RATE]))
|
@@ -8,7 +8,7 @@ namespace ads1115 {
|
|
8
8
|
static const char *const TAG = "ads1115.sensor";
|
9
9
|
|
10
10
|
float ADS1115Sensor::sample() {
|
11
|
-
return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_);
|
11
|
+
return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_, this->samplerate_);
|
12
12
|
}
|
13
13
|
|
14
14
|
void ADS1115Sensor::update() {
|
@@ -24,6 +24,7 @@ void ADS1115Sensor::dump_config() {
|
|
24
24
|
ESP_LOGCONFIG(TAG, " Multiplexer: %u", this->multiplexer_);
|
25
25
|
ESP_LOGCONFIG(TAG, " Gain: %u", this->gain_);
|
26
26
|
ESP_LOGCONFIG(TAG, " Resolution: %u", this->resolution_);
|
27
|
+
ESP_LOGCONFIG(TAG, " Sample rate: %u", this->samplerate_);
|
27
28
|
}
|
28
29
|
|
29
30
|
} // namespace ads1115
|
@@ -21,6 +21,7 @@ class ADS1115Sensor : public sensor::Sensor,
|
|
21
21
|
void set_multiplexer(ADS1115Multiplexer multiplexer) { this->multiplexer_ = multiplexer; }
|
22
22
|
void set_gain(ADS1115Gain gain) { this->gain_ = gain; }
|
23
23
|
void set_resolution(ADS1115Resolution resolution) { this->resolution_ = resolution; }
|
24
|
+
void set_samplerate(ADS1115Samplerate samplerate) { this->samplerate_ = samplerate; }
|
24
25
|
float sample() override;
|
25
26
|
|
26
27
|
void dump_config() override;
|
@@ -29,6 +30,7 @@ class ADS1115Sensor : public sensor::Sensor,
|
|
29
30
|
ADS1115Multiplexer multiplexer_;
|
30
31
|
ADS1115Gain gain_;
|
31
32
|
ADS1115Resolution resolution_;
|
33
|
+
ADS1115Samplerate samplerate_;
|
32
34
|
};
|
33
35
|
|
34
36
|
} // namespace ads1115
|