diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index a8ca63d1580..00000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -# These are supported funding model platforms - -custom: https://www.nabucasa.com diff --git a/.github/actions/restore-python/action.yml b/.github/actions/restore-python/action.yml index 6eb557a5142..3ac91f8ea21 100644 --- a/.github/actions/restore-python/action.yml +++ b/.github/actions/restore-python/action.yml @@ -17,12 +17,12 @@ runs: steps: - name: Set up Python ${{ inputs.python-version }} id: python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: ${{ inputs.python-version }} - name: Restore Python virtual environment id: cache-venv - uses: actions/cache/restore@v4.2.2 + uses: actions/cache/restore@v4.2.3 with: path: venv # yamllint disable-line rule:line-length diff --git a/.github/workflows/ci-api-proto.yml b/.github/workflows/ci-api-proto.yml index d06d8a8eecb..233fb646937 100644 --- a/.github/workflows/ci-api-proto.yml +++ b/.github/workflows/ci-api-proto.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout uses: actions/checkout@v4.1.7 - name: Set up Python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: "3.11" diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 283b6edaebd..0a08e6ffadb 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -42,7 +42,7 @@ jobs: steps: - uses: actions/checkout@v4.1.7 - name: Set up Python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: "3.9" - name: Set up Docker Buildx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b7220d011b..91c40d37c40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,12 +42,12 @@ jobs: run: echo key="${{ hashFiles('requirements.txt', 'requirements_optional.txt', 'requirements_test.txt') }}" >> $GITHUB_OUTPUT - name: Set up Python ${{ env.DEFAULT_PYTHON }} id: python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: ${{ env.DEFAULT_PYTHON }} - name: Restore Python virtual environment id: cache-venv - uses: actions/cache@v4.2.2 + uses: actions/cache@v4.2.3 with: path: venv # yamllint disable-line rule:line-length @@ -303,14 +303,14 @@ jobs: - name: Cache platformio if: github.ref == 'refs/heads/dev' - uses: actions/cache@v4.2.2 + uses: actions/cache@v4.2.3 with: path: ~/.platformio key: platformio-${{ matrix.pio_cache_key }} - name: Cache platformio if: github.ref != 'refs/heads/dev' - uses: actions/cache/restore@v4.2.2 + uses: actions/cache/restore@v4.2.3 with: path: ~/.platformio key: platformio-${{ matrix.pio_cache_key }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3cc668c1132..7793c574fe1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: steps: - uses: actions/checkout@v4.1.7 - name: Set up Python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: "3.x" - name: Set up python environment @@ -84,7 +84,7 @@ jobs: steps: - uses: actions/checkout@v4.1.7 - name: Set up Python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: "3.9" @@ -95,12 +95,12 @@ jobs: uses: docker/setup-qemu-action@v3.6.0 - name: Log in to docker hub - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v3.4.0 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to the GitHub container registry - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v3.4.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -140,7 +140,7 @@ jobs: echo name=$(cat /tmp/platform) >> $GITHUB_OUTPUT - name: Upload digests - uses: actions/upload-artifact@v4.6.1 + uses: actions/upload-artifact@v4.6.2 with: name: digests-${{ steps.sanitize.outputs.name }} path: /tmp/digests @@ -176,7 +176,7 @@ jobs: - uses: actions/checkout@v4.1.7 - name: Download digests - uses: actions/download-artifact@v4.1.9 + uses: actions/download-artifact@v4.2.1 with: pattern: digests-* path: /tmp/digests @@ -187,13 +187,13 @@ jobs: - name: Log in to docker hub if: matrix.registry == 'dockerhub' - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v3.4.0 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to the GitHub container registry if: matrix.registry == 'ghcr' - uses: docker/login-action@v3.3.0 + uses: docker/login-action@v3.4.0 with: registry: ghcr.io username: ${{ github.actor }} diff --git a/.github/workflows/sync-device-classes.yml b/.github/workflows/sync-device-classes.yml index 52adcefc32b..0a0c834a714 100644 --- a/.github/workflows/sync-device-classes.yml +++ b/.github/workflows/sync-device-classes.yml @@ -22,7 +22,7 @@ jobs: path: lib/home-assistant - name: Setup Python - uses: actions/setup-python@v5.4.0 + uses: actions/setup-python@v5.5.0 with: python-version: 3.12 @@ -36,11 +36,11 @@ jobs: python ./script/sync-device_class.py - name: Commit changes - uses: peter-evans/create-pull-request@v7.0.7 + uses: peter-evans/create-pull-request@v7.0.8 with: commit-message: "Synchronise Device Classes from Home Assistant" - committer: esphomebot - author: esphomebot + committer: esphomebot + author: esphomebot branch: sync/device-classes delete-branch: true title: "Synchronise Device Classes from Home Assistant" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 667a8f2e8b1..d11aa067bf9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.9.2 + rev: v0.11.0 hooks: # Run the linter. - id: ruff @@ -12,11 +12,11 @@ repos: # Run the formatter. - id: ruff-format - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.2.0 hooks: - id: flake8 additional_dependencies: - - flake8-docstrings==1.5.0 + - flake8-docstrings==1.7.0 - pydocstyle==5.1.1 files: ^(esphome|tests)/.+\.py$ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/CODEOWNERS b/CODEOWNERS index 204d2b58bd7..f6f7ac6f9c8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -266,6 +266,7 @@ esphome/components/mcp23x17_base/* @jesserockz esphome/components/mcp23xxx_base/* @jesserockz esphome/components/mcp2515/* @danielschramm @mvturnho esphome/components/mcp3204/* @rsumner +esphome/components/mcp4461/* @p1ngb4ck esphome/components/mcp4728/* @berfenger esphome/components/mcp47a1/* @jesserockz esphome/components/mcp9600/* @mreditor97 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b91a3b4f83c..f32d9dafbf4 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at esphome@nabucasa.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at esphome@openhomefoundation.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. diff --git a/docker/Dockerfile b/docker/Dockerfile index ee375ba6908..117ec17ae45 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -55,7 +55,7 @@ RUN \ pip3 install \ --break-system-packages --no-cache-dir \ # Keep platformio version in sync with requirements.txt - platformio==6.1.16 \ + platformio==6.1.18 \ # Change some platformio settings && platformio settings set enable_telemetry No \ && platformio settings set check_platformio_interval 1000000 \ diff --git a/docker/generate_tags.py b/docker/generate_tags.py index 3fc787d4857..31f98c46140 100755 --- a/docker/generate_tags.py +++ b/docker/generate_tags.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import re import argparse +import re CHANNEL_DEV = "dev" CHANNEL_BETA = "beta" diff --git a/esphome/__main__.py b/esphome/__main__.py index 43b55047042..c78eda7e12c 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -133,7 +133,7 @@ def get_port_type(port): return "NETWORK" -def run_miniterm(config, port): +def run_miniterm(config, port, args): import serial from esphome import platformio_api @@ -154,7 +154,7 @@ def run_miniterm(config, port): # We can't set to False by default since it leads to toggling and hence # ESP32 resets on some platforms. - if config["logger"][CONF_DEASSERT_RTS_DTR]: + if config["logger"][CONF_DEASSERT_RTS_DTR] or args.reset: ser.dtr = False ser.rts = False @@ -244,11 +244,11 @@ def compile_program(args, config): return 0 if idedata is not None else 1 -def upload_using_esptool(config, port, file): +def upload_using_esptool(config, port, file, speed): from esphome import platformio_api - first_baudrate = config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get( - "upload_speed", 460800 + first_baudrate = speed or config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get( + "upload_speed", os.getenv("ESPHOME_UPLOAD_SPEED", "460800") ) if file is not None: @@ -348,7 +348,7 @@ def upload_program(config, args, host): check_permissions(host) if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266): file = getattr(args, "file", None) - return upload_using_esptool(config, host, file) + return upload_using_esptool(config, host, file, args.upload_speed) if CORE.target_platform in (PLATFORM_RP2040): return upload_using_platformio(config, args.device) @@ -375,10 +375,12 @@ def upload_program(config, args, host): password = ota_conf.get(CONF_PASSWORD, "") if ( - not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions - and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED]) - and CONF_MQTT in config + CONF_MQTT in config # pylint: disable=too-many-boolean-expressions and (not args.device or args.device in ("MQTT", "OTA")) + and ( + ((config[CONF_MDNS][CONF_DISABLED]) and not is_ip_address(CORE.address)) + or get_port_type(host) == "MQTT" + ) ): from esphome import mqtt @@ -397,7 +399,7 @@ def show_logs(config, args, port): raise EsphomeError("Logger is not configured!") if get_port_type(port) == "SERIAL": check_permissions(port) - return run_miniterm(config, port) + return run_miniterm(config, port, args) if get_port_type(port) == "NETWORK" and "api" in config: if config[CONF_MDNS][CONF_DISABLED] and CONF_MQTT in config: from esphome import mqtt @@ -842,6 +844,10 @@ def parse_args(argv): "--device", help="Manually specify the serial port/address to use, for example /dev/ttyUSB0.", ) + parser_upload.add_argument( + "--upload_speed", + help="Override the default or configured upload speed.", + ) parser_upload.add_argument( "--file", help="Manually specify the binary file to upload.", @@ -860,6 +866,13 @@ def parse_args(argv): "--device", help="Manually specify the serial port/address to use, for example /dev/ttyUSB0.", ) + parser_logs.add_argument( + "--reset", + "-r", + action="store_true", + help="Reset the device before starting serial logs.", + default=os.getenv("ESPHOME_SERIAL_LOGGING_RESET"), + ) parser_discover = subparsers.add_parser( "discover", @@ -882,9 +895,20 @@ def parse_args(argv): "--device", help="Manually specify the serial port/address to use, for example /dev/ttyUSB0.", ) + parser_run.add_argument( + "--upload_speed", + help="Override the default or configured upload speed.", + ) parser_run.add_argument( "--no-logs", help="Disable starting logs.", action="store_true" ) + parser_run.add_argument( + "--reset", + "-r", + action="store_true", + help="Reset the device before starting serial logs.", + default=os.getenv("ESPHOME_SERIAL_LOGGING_RESET"), + ) parser_clean = subparsers.add_parser( "clean-mqtt", diff --git a/esphome/components/a01nyub/sensor.py b/esphome/components/a01nyub/sensor.py index b57daa03570..e5f4f7ef304 100644 --- a/esphome/components/a01nyub/sensor.py +++ b/esphome/components/a01nyub/sensor.py @@ -1,10 +1,10 @@ import esphome.codegen as cg from esphome.components import sensor, uart from esphome.const import ( + DEVICE_CLASS_DISTANCE, + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, - DEVICE_CLASS_DISTANCE, ) CODEOWNERS = ["@MrSuicideParrot"] diff --git a/esphome/components/a02yyuw/sensor.py b/esphome/components/a02yyuw/sensor.py index d491a51be99..f0bc59ae6c0 100644 --- a/esphome/components/a02yyuw/sensor.py +++ b/esphome/components/a02yyuw/sensor.py @@ -1,9 +1,9 @@ import esphome.codegen as cg from esphome.components import sensor, uart from esphome.const import ( - STATE_CLASS_MEASUREMENT, - ICON_ARROW_EXPAND_VERTICAL, DEVICE_CLASS_DISTANCE, + ICON_ARROW_EXPAND_VERTICAL, + STATE_CLASS_MEASUREMENT, UNIT_MILLIMETER, ) diff --git a/esphome/components/a4988/stepper.py b/esphome/components/a4988/stepper.py index 744e9dc1cc5..97f5a6fe0f4 100644 --- a/esphome/components/a4988/stepper.py +++ b/esphome/components/a4988/stepper.py @@ -1,10 +1,9 @@ from esphome import pins +import esphome.codegen as cg from esphome.components import stepper import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_DIR_PIN, CONF_ID, CONF_SLEEP_PIN, CONF_STEP_PIN - a4988_ns = cg.esphome_ns.namespace("a4988") A4988 = a4988_ns.class_("A4988", stepper.Stepper, cg.Component) diff --git a/esphome/components/absolute_humidity/sensor.py b/esphome/components/absolute_humidity/sensor.py index f2b075f4d99..62a2c8ab7c5 100644 --- a/esphome/components/absolute_humidity/sensor.py +++ b/esphome/components/absolute_humidity/sensor.py @@ -1,12 +1,12 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_EQUATION, CONF_HUMIDITY, CONF_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - CONF_EQUATION, ICON_WATER, + STATE_CLASS_MEASUREMENT, UNIT_GRAMS_PER_CUBIC_METER, ) diff --git a/esphome/components/ac_dimmer/output.py b/esphome/components/ac_dimmer/output.py index c39fc382b6b..5e24779510e 100644 --- a/esphome/components/ac_dimmer/output.py +++ b/esphome/components/ac_dimmer/output.py @@ -1,8 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import output -from esphome.const import CONF_ID, CONF_MIN_POWER, CONF_METHOD +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_METHOD, CONF_MIN_POWER CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/adalight/__init__.py b/esphome/components/adalight/__init__.py index 919ffecbeab..5e122676cd5 100644 --- a/esphome/components/adalight/__init__.py +++ b/esphome/components/adalight/__init__.py @@ -1,8 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart -from esphome.components.light.types import AddressableLightEffect from esphome.components.light.effects import register_addressable_effect +from esphome.components.light.types import AddressableLightEffect +import esphome.config_validation as cv from esphome.const import CONF_NAME, CONF_UART_ID DEPENDENCIES = ["uart"] diff --git a/esphome/components/adc128s102/__init__.py b/esphome/components/adc128s102/__init__.py index c4e9d5831e1..a5281aacc76 100644 --- a/esphome/components/adc128s102/__init__.py +++ b/esphome/components/adc128s102/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["spi"] diff --git a/esphome/components/adc128s102/sensor/__init__.py b/esphome/components/adc128s102/sensor/__init__.py index 640a1b628ef..a65ae9d5374 100644 --- a/esphome/components/adc128s102/sensor/__init__.py +++ b/esphome/components/adc128s102/sensor/__init__.py @@ -1,9 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler -from esphome.const import CONF_ID, CONF_CHANNEL +import esphome.config_validation as cv +from esphome.const import CONF_CHANNEL, CONF_ID -from .. import adc128s102_ns, ADC128S102 +from .. import ADC128S102, adc128s102_ns AUTO_LOAD = ["voltage_sampler"] DEPENDENCIES = ["adc128s102"] diff --git a/esphome/components/addressable_light/display.py b/esphome/components/addressable_light/display.py index 327ec8296a3..929d45121c3 100644 --- a/esphome/components/addressable_light/display.py +++ b/esphome/components/addressable_light/display.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display, light +import esphome.config_validation as cv from esphome.const import ( + CONF_ADDRESSABLE_LIGHT_ID, + CONF_HEIGHT, CONF_ID, CONF_LAMBDA, CONF_PAGES, - CONF_ADDRESSABLE_LIGHT_ID, - CONF_HEIGHT, - CONF_WIDTH, - CONF_UPDATE_INTERVAL, CONF_PIXEL_MAPPER, + CONF_UPDATE_INTERVAL, + CONF_WIDTH, ) CODEOWNERS = ["@justfalter"] diff --git a/esphome/components/ade7880/sensor.py b/esphome/components/ade7880/sensor.py index e075adb04c1..3ef5e6bfffb 100644 --- a/esphome/components/ade7880/sensor.py +++ b/esphome/components/ade7880/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor, i2c from esphome import pins +import esphome.codegen as cg +from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ACTIVE_POWER, CONF_APPARENT_POWER, diff --git a/esphome/components/ade7953_base/__init__.py b/esphome/components/ade7953_base/__init__.py index af3f629ca83..42b6c8ba24c 100644 --- a/esphome/components/ade7953_base/__init__.py +++ b/esphome/components/ade7953_base/__init__.py @@ -1,27 +1,27 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor from esphome import pins +import esphome.codegen as cg +from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_FREQUENCY, CONF_IRQ_PIN, CONF_VOLTAGE, - CONF_FREQUENCY, CONF_VOLTAGE_GAIN, - DEVICE_CLASS_CURRENT, DEVICE_CLASS_APPARENT_POWER, - DEVICE_CLASS_POWER, - DEVICE_CLASS_REACTIVE_POWER, - DEVICE_CLASS_POWER_FACTOR, - DEVICE_CLASS_VOLTAGE, + DEVICE_CLASS_CURRENT, DEVICE_CLASS_FREQUENCY, + DEVICE_CLASS_POWER, + DEVICE_CLASS_POWER_FACTOR, + DEVICE_CLASS_REACTIVE_POWER, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, - UNIT_HERTZ, UNIT_AMPERE, - UNIT_VOLT_AMPS, - UNIT_WATT, - UNIT_VOLT_AMPS_REACTIVE, + UNIT_HERTZ, UNIT_PERCENT, + UNIT_VOLT, + UNIT_VOLT_AMPS, + UNIT_VOLT_AMPS_REACTIVE, + UNIT_WATT, ) CONF_CURRENT_A = "current_a" diff --git a/esphome/components/ade7953_i2c/sensor.py b/esphome/components/ade7953_i2c/sensor.py index e52a44eced5..4b55acdafa7 100644 --- a/esphome/components/ade7953_i2c/sensor.py +++ b/esphome/components/ade7953_i2c/sensor.py @@ -1,9 +1,8 @@ import esphome.codegen as cg +from esphome.components import ade7953_base, i2c import esphome.config_validation as cv -from esphome.components import i2c, ade7953_base from esphome.const import CONF_ID - DEPENDENCIES = ["i2c"] AUTO_LOAD = ["ade7953_base"] diff --git a/esphome/components/ade7953_spi/sensor.py b/esphome/components/ade7953_spi/sensor.py index 5f9682c7119..dce021daad6 100644 --- a/esphome/components/ade7953_spi/sensor.py +++ b/esphome/components/ade7953_spi/sensor.py @@ -1,9 +1,8 @@ import esphome.codegen as cg +from esphome.components import ade7953_base, spi import esphome.config_validation as cv -from esphome.components import spi, ade7953_base from esphome.const import CONF_ID - DEPENDENCIES = ["spi"] AUTO_LOAD = ["ade7953_base"] diff --git a/esphome/components/ads1115/__init__.py b/esphome/components/ads1115/__init__.py index a463d8390d7..6d52fc83fdb 100644 --- a/esphome/components/ads1115/__init__.py +++ b/esphome/components/ads1115/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ads1115/sensor/__init__.py b/esphome/components/ads1115/sensor/__init__.py index f346a71198a..afb70d07c82 100644 --- a/esphome/components/ads1115/sensor/__init__.py +++ b/esphome/components/ads1115/sensor/__init__.py @@ -1,17 +1,18 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, + CONF_ID, CONF_MULTIPLEXER, CONF_RESOLUTION, CONF_SAMPLE_RATE, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, UNIT_VOLT, - CONF_ID, ) -from .. import ads1115_ns, ADS1115Component, CONF_ADS1115_ID + +from .. import CONF_ADS1115_ID, ADS1115Component, ads1115_ns AUTO_LOAD = ["voltage_sampler"] DEPENDENCIES = ["ads1115"] diff --git a/esphome/components/ads1118/__init__.py b/esphome/components/ads1118/__init__.py index f8d51101a60..128e0d07013 100644 --- a/esphome/components/ads1118/__init__.py +++ b/esphome/components/ads1118/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@solomondg1"] diff --git a/esphome/components/ads1118/sensor/__init__.py b/esphome/components/ads1118/sensor/__init__.py index 4e891154473..33bfe97789f 100644 --- a/esphome/components/ads1118/sensor/__init__.py +++ b/esphome/components/ads1118/sensor/__init__.py @@ -1,17 +1,18 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, CONF_MULTIPLEXER, - DEVICE_CLASS_VOLTAGE, + CONF_TYPE, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_VOLT, - CONF_TYPE, ) -from .. import ads1118_ns, ADS1118, CONF_ADS1118_ID + +from .. import ADS1118, CONF_ADS1118_ID, ads1118_ns AUTO_LOAD = ["voltage_sampler"] DEPENDENCIES = ["ads1118"] diff --git a/esphome/components/ags10/sensor.py b/esphome/components/ags10/sensor.py index 59aebd636b6..8f0f3729516 100644 --- a/esphome/components/ags10/sensor.py +++ b/esphome/components/ags10/sensor.py @@ -1,21 +1,21 @@ -import esphome.codegen as cg from esphome import automation -import esphome.config_validation as cv +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_ADDRESS, CONF_ID, - ICON_RADIATOR, - ICON_RESTART, + CONF_MODE, + CONF_TVOC, + CONF_VALUE, + CONF_VERSION, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_RADIATOR, + ICON_RESTART, STATE_CLASS_MEASUREMENT, UNIT_OHM, UNIT_PARTS_PER_BILLION, - CONF_ADDRESS, - CONF_TVOC, - CONF_VERSION, - CONF_MODE, - CONF_VALUE, ) CONF_RESISTANCE = "resistance" diff --git a/esphome/components/aht10/sensor.py b/esphome/components/aht10/sensor.py index 31b07c0e736..a5b1cf0ffb8 100644 --- a/esphome/components/aht10/sensor.py +++ b/esphome/components/aht10/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, CONF_TEMPERATURE, + CONF_VARIANT, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - CONF_VARIANT, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/airthings_ble/__init__.py b/esphome/components/airthings_ble/__init__.py index ca940697038..eae400ab39e 100644 --- a/esphome/components/airthings_ble/__init__.py +++ b/esphome/components/airthings_ble/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/airthings_wave_base/__init__.py b/esphome/components/airthings_wave_base/__init__.py index d9b97f1c8dd..6a29683ced7 100644 --- a/esphome/components/airthings_wave_base/__init__.py +++ b/esphome/components/airthings_wave_base/__init__.py @@ -1,18 +1,17 @@ import esphome.codegen as cg +from esphome.components import ble_client, sensor import esphome.config_validation as cv -from esphome.components import sensor, ble_client - from esphome.const import ( CONF_BATTERY_VOLTAGE, CONF_HUMIDITY, CONF_PRESSURE, CONF_TEMPERATURE, CONF_TVOC, - DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, + DEVICE_CLASS_VOLTAGE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, diff --git a/esphome/components/airthings_wave_mini/sensor.py b/esphome/components/airthings_wave_mini/sensor.py index 0f4fd1a13a9..f231be66709 100644 --- a/esphome/components/airthings_wave_mini/sensor.py +++ b/esphome/components/airthings_wave_mini/sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import airthings_wave_base - -from esphome.const import ( - CONF_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID DEPENDENCIES = airthings_wave_base.DEPENDENCIES diff --git a/esphome/components/airthings_wave_plus/sensor.py b/esphome/components/airthings_wave_plus/sensor.py index d28c7e2abcb..e0e90735f0b 100644 --- a/esphome/components/airthings_wave_plus/sensor.py +++ b/esphome/components/airthings_wave_plus/sensor.py @@ -1,20 +1,19 @@ import esphome.codegen as cg +from esphome.components import airthings_wave_base, sensor import esphome.config_validation as cv -from esphome.components import sensor, airthings_wave_base - from esphome.const import ( - DEVICE_CLASS_CARBON_DIOXIDE, - STATE_CLASS_MEASUREMENT, - ICON_RADIOACTIVE, + CONF_CO2, CONF_ID, + CONF_ILLUMINANCE, CONF_RADON, CONF_RADON_LONG_TERM, - CONF_CO2, - UNIT_BECQUEREL_PER_CUBIC_METER, - UNIT_PARTS_PER_MILLION, - CONF_ILLUMINANCE, - UNIT_LUX, + DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_ILLUMINANCE, + ICON_RADIOACTIVE, + STATE_CLASS_MEASUREMENT, + UNIT_BECQUEREL_PER_CUBIC_METER, + UNIT_LUX, + UNIT_PARTS_PER_MILLION, ) DEPENDENCIES = airthings_wave_base.DEPENDENCIES diff --git a/esphome/components/alpha3/sensor.py b/esphome/components/alpha3/sensor.py index 55a5d7c620e..361e1d101f0 100644 --- a/esphome/components/alpha3/sensor.py +++ b/esphome/components/alpha3/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg +from esphome.components import ble_client, sensor import esphome.config_validation as cv -from esphome.components import sensor, ble_client from esphome.const import ( - CONF_ID, CONF_CURRENT, CONF_FLOW, CONF_HEAD, + CONF_ID, CONF_POWER, CONF_SPEED, CONF_VOLTAGE, UNIT_AMPERE, + UNIT_CUBIC_METER_PER_HOUR, + UNIT_METER, + UNIT_REVOLUTIONS_PER_MINUTE, UNIT_VOLT, UNIT_WATT, - UNIT_METER, - UNIT_CUBIC_METER_PER_HOUR, - UNIT_REVOLUTIONS_PER_MINUTE, ) alpha3_ns = cg.esphome_ns.namespace("alpha3") diff --git a/esphome/components/am2315c/am2315c.cpp b/esphome/components/am2315c/am2315c.cpp index 715251a9df0..90565de7409 100644 --- a/esphome/components/am2315c/am2315c.cpp +++ b/esphome/components/am2315c/am2315c.cpp @@ -128,7 +128,7 @@ void AM2315C::update() { data[2] = 0x00; if (this->write(data, 3) != i2c::ERROR_OK) { ESP_LOGE(TAG, "Write failed!"); - this->mark_failed(); + this->status_set_warning(); return; } @@ -138,12 +138,12 @@ void AM2315C::update() { uint8_t status = 0; if (this->read(&status, 1) != i2c::ERROR_OK) { ESP_LOGE(TAG, "Read failed!"); - this->mark_failed(); + this->status_set_warning(); return; } if ((status & 0x80) == 0x80) { ESP_LOGE(TAG, "HW still busy!"); - this->mark_failed(); + this->status_set_warning(); return; } @@ -151,7 +151,7 @@ void AM2315C::update() { uint8_t data[7]; if (this->read(data, 7) != i2c::ERROR_OK) { ESP_LOGE(TAG, "Read failed!"); - this->mark_failed(); + this->status_set_warning(); return; } diff --git a/esphome/components/am2315c/sensor.py b/esphome/components/am2315c/sensor.py index f3201b05a2e..ec12ab717ed 100644 --- a/esphome/components/am2315c/sensor.py +++ b/esphome/components/am2315c/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/am2320/sensor.py b/esphome/components/am2320/sensor.py index ccd37d02c23..ed4a5fd9220 100644 --- a/esphome/components/am2320/sensor.py +++ b/esphome/components/am2320/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/am43/cover/__init__.py b/esphome/components/am43/cover/__init__.py index 103ac809e6f..d60f9cd4e7d 100644 --- a/esphome/components/am43/cover/__init__.py +++ b/esphome/components/am43/cover/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import ble_client, cover import esphome.config_validation as cv -from esphome.components import cover, ble_client from esphome.const import CONF_ID, CONF_PIN CODEOWNERS = ["@buxtronix"] diff --git a/esphome/components/am43/sensor/__init__.py b/esphome/components/am43/sensor/__init__.py index df068546cd5..4b3e1716a47 100644 --- a/esphome/components/am43/sensor/__init__.py +++ b/esphome/components/am43/sensor/__init__.py @@ -1,12 +1,12 @@ import esphome.codegen as cg +from esphome.components import ble_client, sensor import esphome.config_validation as cv -from esphome.components import sensor, ble_client from esphome.const import ( - CONF_ID, CONF_BATTERY_LEVEL, + CONF_ID, + CONF_ILLUMINANCE, DEVICE_CLASS_BATTERY, ENTITY_CATEGORY_DIAGNOSTIC, - CONF_ILLUMINANCE, ICON_BRIGHTNESS_5, UNIT_PERCENT, ) diff --git a/esphome/components/analog_threshold/binary_sensor.py b/esphome/components/analog_threshold/binary_sensor.py index 7b964dfae6e..775b3e6bbf1 100644 --- a/esphome/components/analog_threshold/binary_sensor.py +++ b/esphome/components/analog_threshold/binary_sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor, sensor -from esphome.const import ( - CONF_SENSOR_ID, - CONF_THRESHOLD, -) +import esphome.config_validation as cv +from esphome.const import CONF_SENSOR_ID, CONF_THRESHOLD analog_threshold_ns = cg.esphome_ns.namespace("analog_threshold") diff --git a/esphome/components/anova/climate.py b/esphome/components/anova/climate.py index bdd77d6a338..052296294bc 100644 --- a/esphome/components/anova/climate.py +++ b/esphome/components/anova/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import ble_client, climate import esphome.config_validation as cv -from esphome.components import climate, ble_client from esphome.const import CONF_ID, CONF_UNIT_OF_MEASUREMENT UNITS = { diff --git a/esphome/components/apds9306/sensor.py b/esphome/components/apds9306/sensor.py index 25b301444f7..c3cba96fbfc 100644 --- a/esphome/components/apds9306/sensor.py +++ b/esphome/components/apds9306/sensor.py @@ -2,8 +2,8 @@ # https://www.mouser.ca/datasheet/2/678/AVGO_S_A0002854364_1-2574547.pdf import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, DEVICE_CLASS_ILLUMINANCE, diff --git a/esphome/components/apds9960/__init__.py b/esphome/components/apds9960/__init__.py index 06b3c85aee4..99e37d3764c 100644 --- a/esphome/components/apds9960/__init__.py +++ b/esphome/components/apds9960/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/apds9960/binary_sensor.py b/esphome/components/apds9960/binary_sensor.py index 46b08d8d69b..48e923ab2be 100644 --- a/esphome/components/apds9960/binary_sensor.py +++ b/esphome/components/apds9960/binary_sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_DIRECTION, DEVICE_CLASS_MOVING + from . import APDS9960, CONF_APDS9960_ID DEPENDENCIES = ["apds9960"] diff --git a/esphome/components/apds9960/sensor.py b/esphome/components/apds9960/sensor.py index c9865f86871..468eb0995f1 100644 --- a/esphome/components/apds9960/sensor.py +++ b/esphome/components/apds9960/sensor.py @@ -1,12 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_TYPE, + ICON_LIGHTBULB, STATE_CLASS_MEASUREMENT, UNIT_PERCENT, - ICON_LIGHTBULB, ) + from . import APDS9960, CONF_APDS9960_ID DEPENDENCIES = ["apds9960"] diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 62f375508cb..3d6bc951632 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -311,6 +311,10 @@ APIError APINoiseFrameHelper::state_action_() { const std::string &name = App.get_name(); const uint8_t *name_ptr = reinterpret_cast(name.c_str()); msg.insert(msg.end(), name_ptr, name_ptr + name.size() + 1); + // node mac, terminated by null byte + const std::string &mac = get_mac_address(); + const uint8_t *mac_ptr = reinterpret_cast(mac.c_str()); + msg.insert(msg.end(), mac_ptr, mac_ptr + mac.size() + 1); aerr = write_frame_(msg.data(), msg.size()); if (aerr != APIError::OK) @@ -893,8 +897,28 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) { ParsedFrame frame; aerr = try_read_frame_(&frame); - if (aerr != APIError::OK) + if (aerr != APIError::OK) { + if (aerr == APIError::BAD_INDICATOR) { + // Make sure to tell the remote that we don't + // understand the indicator byte so it knows + // we do not support it. + struct iovec iov[1]; + // The \x00 first byte is the marker for plaintext. + // + // The remote will know how to handle the indicator byte, + // but it likely won't understand the rest of the message. + // + // We must send at least 3 bytes to be read, so we add + // a message after the indicator byte to ensures its long + // enough and can aid in debugging. + const char msg[] = "\x00" + "Bad indicator byte"; + iov[0].iov_base = (void *) msg; + iov[0].iov_len = 19; + write_raw_(iov, 1); + } return aerr; + } buffer->container = std::move(frame.msg); buffer->data_offset = 0; diff --git a/esphome/components/as3935/__init__.py b/esphome/components/as3935/__init__.py index 2ec7c508598..70015c53b97 100644 --- a/esphome/components/as3935/__init__.py +++ b/esphome/components/as3935/__init__.py @@ -1,17 +1,17 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( + CONF_CALIBRATION, CONF_CAPACITANCE, CONF_DIV_RATIO, CONF_INDOOR, CONF_IRQ_PIN, CONF_LIGHTNING_THRESHOLD, CONF_MASK_DISTURBER, - CONF_CALIBRATION, - CONF_TUNE_ANTENNA, CONF_NOISE_LEVEL, CONF_SPIKE_REJECTION, + CONF_TUNE_ANTENNA, CONF_WATCHDOG_THRESHOLD, ) diff --git a/esphome/components/as3935/binary_sensor.py b/esphome/components/as3935/binary_sensor.py index 3081d2115fc..10004e69dc9 100644 --- a/esphome/components/as3935/binary_sensor.py +++ b/esphome/components/as3935/binary_sensor.py @@ -1,6 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv + from . import AS3935, CONF_AS3935_ID DEPENDENCIES = ["as3935"] diff --git a/esphome/components/as3935/sensor.py b/esphome/components/as3935/sensor.py index ff78b8a0505..79bc7af4a9e 100644 --- a/esphome/components/as3935/sensor.py +++ b/esphome/components/as3935/sensor.py @@ -1,13 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_DISTANCE, CONF_LIGHTNING_ENERGY, - UNIT_KILOMETER, - ICON_SIGNAL_DISTANCE_VARIANT, ICON_FLASH, + ICON_SIGNAL_DISTANCE_VARIANT, + UNIT_KILOMETER, ) + from . import AS3935, CONF_AS3935_ID DEPENDENCIES = ["as3935"] diff --git a/esphome/components/as3935_i2c/__init__.py b/esphome/components/as3935_i2c/__init__.py index aa741b2ea67..09b588cb0cc 100644 --- a/esphome/components/as3935_i2c/__init__.py +++ b/esphome/components/as3935_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import as3935, i2c +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["as3935"] diff --git a/esphome/components/as3935_spi/__init__.py b/esphome/components/as3935_spi/__init__.py index 849539f092d..f4cf07a906b 100644 --- a/esphome/components/as3935_spi/__init__.py +++ b/esphome/components/as3935_spi/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import as3935, spi +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["as3935"] diff --git a/esphome/components/as5600/__init__.py b/esphome/components/as5600/__init__.py index feeae107a76..1a437a68a2e 100644 --- a/esphome/components/as5600/__init__.py +++ b/esphome/components/as5600/__init__.py @@ -1,12 +1,12 @@ from esphome import pins import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_DIR_PIN, CONF_DIRECTION, CONF_HYSTERESIS, + CONF_ID, CONF_RANGE, ) diff --git a/esphome/components/as5600/sensor/__init__.py b/esphome/components/as5600/sensor/__init__.py index 30337ab61bf..cfc38d796d1 100644 --- a/esphome/components/as5600/sensor/__init__.py +++ b/esphome/components/as5600/sensor/__init__.py @@ -1,19 +1,20 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_ANGLE, + CONF_GAIN, CONF_ID, - STATE_CLASS_MEASUREMENT, + CONF_MAGNITUDE, + CONF_POSITION, + CONF_STATUS, + ENTITY_CATEGORY_DIAGNOSTIC, ICON_MAGNET, ICON_ROTATE_RIGHT, - CONF_GAIN, - ENTITY_CATEGORY_DIAGNOSTIC, - CONF_MAGNITUDE, - CONF_STATUS, - CONF_POSITION, - CONF_ANGLE, + STATE_CLASS_MEASUREMENT, ) -from .. import as5600_ns, AS5600Component + +from .. import AS5600Component, as5600_ns CODEOWNERS = ["@ammmze"] DEPENDENCIES = ["as5600"] diff --git a/esphome/components/as7341/sensor.py b/esphome/components/as7341/sensor.py index de60444aedb..2832b7c3df6 100644 --- a/esphome/components/as7341/sensor.py +++ b/esphome/components/as7341/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, CONF_ID, @@ -9,7 +9,6 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, ) - CODEOWNERS = ["@mrgnr"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/at581x/__init__.py b/esphome/components/at581x/__init__.py index e636510a4bc..117ada123db 100644 --- a/esphome/components/at581x/__init__.py +++ b/esphome/components/at581x/__init__.py @@ -1,13 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation, core -from esphome.components import i2c from esphome.automation import maybe_simple_id -from esphome.const import ( - CONF_ID, - CONF_FREQUENCY, -) - +import esphome.codegen as cg +from esphome.components import i2c +import esphome.config_validation as cv +from esphome.const import CONF_FREQUENCY, CONF_ID CODEOWNERS = ["@X-Ryl669"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/at581x/switch/__init__.py b/esphome/components/at581x/switch/__init__.py index c441b381a39..8e1b82b356f 100644 --- a/esphome/components/at581x/switch/__init__.py +++ b/esphome/components/at581x/switch/__init__.py @@ -1,10 +1,8 @@ import esphome.codegen as cg from esphome.components import switch import esphome.config_validation as cv -from esphome.const import ( - DEVICE_CLASS_SWITCH, - ICON_WIFI, -) +from esphome.const import DEVICE_CLASS_SWITCH, ICON_WIFI + from .. import CONF_AT581X_ID, AT581XComponent, at581x_ns DEPENDENCIES = ["at581x"] diff --git a/esphome/components/atc_mithermometer/sensor.py b/esphome/components/atc_mithermometer/sensor.py index e86afa500d6..5286d29d1bd 100644 --- a/esphome/components/atc_mithermometer/sensor.py +++ b/esphome/components/atc_mithermometer/sensor.py @@ -1,14 +1,14 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_BATTERY_VOLTAGE, - CONF_MAC_ADDRESS, CONF_HUMIDITY, + CONF_ID, + CONF_MAC_ADDRESS, CONF_SIGNAL_STRENGTH, CONF_TEMPERATURE, - CONF_ID, DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_SIGNAL_STRENGTH, diff --git a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp index 54b39a6bb91..c7646bcf2f0 100644 --- a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp +++ b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp @@ -30,8 +30,12 @@ void AXS15231Touchscreen::setup() { this->interrupt_pin_->setup(); this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE); } - this->x_raw_max_ = this->display_->get_native_width(); - this->y_raw_max_ = this->display_->get_native_height(); + if (this->x_raw_max_ == 0) { + this->x_raw_max_ = this->display_->get_native_width(); + } + if (this->y_raw_max_ == 0) { + this->y_raw_max_ = this->display_->get_native_height(); + } ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen setup complete"); } @@ -44,7 +48,7 @@ void AXS15231Touchscreen::update_touches() { err = this->read(data, sizeof(data)); ERROR_CHECK(err); this->status_clear_warning(); - if (data[0] != 0) // no touches + if (data[0] != 0 || data[1] == 0) // no touches return; uint16_t x = encode_uint16(data[2] & 0xF, data[3]); uint16_t y = encode_uint16(data[4] & 0xF, data[5]); diff --git a/esphome/components/b_parasite/sensor.py b/esphome/components/b_parasite/sensor.py index 86eef29b148..041303ad8b8 100644 --- a/esphome/components/b_parasite/sensor.py +++ b/esphome/components/b_parasite/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_VOLTAGE, CONF_HUMIDITY, CONF_ID, CONF_ILLUMINANCE, - CONF_MOISTURE, CONF_MAC_ADDRESS, + CONF_MOISTURE, CONF_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, diff --git a/esphome/components/ballu/climate.py b/esphome/components/ballu/climate.py index 82e9fead1e0..416fa250cc9 100644 --- a/esphome/components/ballu/climate.py +++ b/esphome/components/ballu/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/bang_bang/climate.py b/esphome/components/bang_bang/climate.py index 9dde0ae1ac4..6511270f608 100644 --- a/esphome/components/bang_bang/climate.py +++ b/esphome/components/bang_bang/climate.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import climate, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_AWAY_CONFIG, CONF_COOL_ACTION, diff --git a/esphome/components/bedjet/__init__.py b/esphome/components/bedjet/__init__.py index a4b8a50eaba..d4bf8138466 100644 --- a/esphome/components/bedjet/__init__.py +++ b/esphome/components/bedjet/__init__.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import ble_client, time -from esphome.const import ( - CONF_ID, - CONF_RECEIVE_TIMEOUT, - CONF_TIME_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_RECEIVE_TIMEOUT, CONF_TIME_ID CODEOWNERS = ["@jhansche"] DEPENDENCIES = ["ble_client"] diff --git a/esphome/components/bedjet/climate/__init__.py b/esphome/components/bedjet/climate/__init__.py index e454b0922be..7ba3e439b23 100644 --- a/esphome/components/bedjet/climate/__init__.py +++ b/esphome/components/bedjet/climate/__init__.py @@ -1,8 +1,8 @@ import logging import esphome.codegen as cg +from esphome.components import ble_client, climate import esphome.config_validation as cv -from esphome.components import climate, ble_client from esphome.const import ( CONF_HEAT_MODE, CONF_ID, @@ -10,11 +10,8 @@ from esphome.const import ( CONF_TEMPERATURE_SOURCE, CONF_TIME_ID, ) -from .. import ( - BEDJET_CLIENT_SCHEMA, - bedjet_ns, - register_bedjet_child, -) + +from .. import BEDJET_CLIENT_SCHEMA, bedjet_ns, register_bedjet_child _LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@jhansche"] diff --git a/esphome/components/bedjet/fan/__init__.py b/esphome/components/bedjet/fan/__init__.py index 06e81ea979c..fdf06361530 100644 --- a/esphome/components/bedjet/fan/__init__.py +++ b/esphome/components/bedjet/fan/__init__.py @@ -1,16 +1,11 @@ import logging import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import fan -from esphome.const import ( - CONF_ID, -) -from .. import ( - BEDJET_CLIENT_SCHEMA, - bedjet_ns, - register_bedjet_child, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID + +from .. import BEDJET_CLIENT_SCHEMA, bedjet_ns, register_bedjet_child _LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@jhansche"] diff --git a/esphome/components/bedjet/sensor/__init__.py b/esphome/components/bedjet/sensor/__init__.py index 756b31de539..fa9ca7953ea 100644 --- a/esphome/components/bedjet/sensor/__init__.py +++ b/esphome/components/bedjet/sensor/__init__.py @@ -1,19 +1,16 @@ import logging import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, ) -from .. import ( - BEDJET_CLIENT_SCHEMA, - bedjet_ns, - register_bedjet_child, -) + +from .. import BEDJET_CLIENT_SCHEMA, bedjet_ns, register_bedjet_child _LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@jhansche", "@javawizard"] diff --git a/esphome/components/beken_spi_led_strip/light.py b/esphome/components/beken_spi_led_strip/light.py index 2a1aa05c79c..31572cd8001 100644 --- a/esphome/components/beken_spi_led_strip/light.py +++ b/esphome/components/beken_spi_led_strip/light.py @@ -1,9 +1,9 @@ from dataclasses import dataclass -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import libretiny, light +import esphome.config_validation as cv from esphome.const import ( CONF_CHIPSET, CONF_IS_RGBW, diff --git a/esphome/components/bh1750/sensor.py b/esphome/components/bh1750/sensor.py index 69778f49ce5..7c7eecb88cd 100644 --- a/esphome/components/bh1750/sensor.py +++ b/esphome/components/bh1750/sensor.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor -from esphome.const import ( - DEVICE_CLASS_ILLUMINANCE, - STATE_CLASS_MEASUREMENT, - UNIT_LUX, -) +import esphome.config_validation as cv +from esphome.const import DEVICE_CLASS_ILLUMINANCE, STATE_CLASS_MEASUREMENT, UNIT_LUX DEPENDENCIES = ["i2c"] CODEOWNERS = ["@OttoWinter"] diff --git a/esphome/components/binary/fan/__init__.py b/esphome/components/binary/fan/__init__.py index 73d6b9339fc..a504ef642c1 100644 --- a/esphome/components/binary/fan/__init__.py +++ b/esphome/components/binary/fan/__init__.py @@ -1,12 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import fan, output +import esphome.config_validation as cv from esphome.const import ( CONF_DIRECTION_OUTPUT, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT, CONF_OUTPUT_ID, ) + from .. import binary_ns BinaryFan = binary_ns.class_("BinaryFan", fan.Fan, cg.Component) diff --git a/esphome/components/binary/light/__init__.py b/esphome/components/binary/light/__init__.py index 49227ccadc4..ebb22f44095 100644 --- a/esphome/components/binary/light/__init__.py +++ b/esphome/components/binary/light/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output -from esphome.const import CONF_OUTPUT_ID, CONF_OUTPUT +import esphome.config_validation as cv +from esphome.const import CONF_OUTPUT, CONF_OUTPUT_ID + from .. import binary_ns BinaryLightOutput = binary_ns.class_("BinaryLightOutput", light.LightOutput) diff --git a/esphome/components/binary_sensor_map/sensor.py b/esphome/components/binary_sensor_map/sensor.py index 1181905f304..965e332e28b 100644 --- a/esphome/components/binary_sensor_map/sensor.py +++ b/esphome/components/binary_sensor_map/sensor.py @@ -1,15 +1,14 @@ import esphome.codegen as cg +from esphome.components import binary_sensor, sensor import esphome.config_validation as cv - -from esphome.components import sensor, binary_sensor from esphome.const import ( - CONF_CHANNELS, - CONF_VALUE, - CONF_TYPE, - ICON_CHECK_CIRCLE_OUTLINE, CONF_BINARY_SENSOR, + CONF_CHANNELS, CONF_GROUP, CONF_SUM, + CONF_TYPE, + CONF_VALUE, + ICON_CHECK_CIRCLE_OUTLINE, ) DEPENDENCIES = ["binary_sensor"] diff --git a/esphome/components/bl0939/sensor.py b/esphome/components/bl0939/sensor.py index 2a85b345670..bd4bdd93e58 100644 --- a/esphome/components/bl0939/sensor.py +++ b/esphome/components/bl0939/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_VOLTAGE, diff --git a/esphome/components/bl0940/sensor.py b/esphome/components/bl0940/sensor.py index 5cb1472d76e..f49e961f0a2 100644 --- a/esphome/components/bl0940/sensor.py +++ b/esphome/components/bl0940/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_CURRENT, CONF_ENERGY, @@ -12,15 +12,15 @@ from esphome.const import ( DEVICE_CLASS_CURRENT, DEVICE_CLASS_ENERGY, DEVICE_CLASS_POWER, - DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, + STATE_CLASS_TOTAL_INCREASING, UNIT_AMPERE, UNIT_CELSIUS, UNIT_KILOWATT_HOURS, UNIT_VOLT, UNIT_WATT, - STATE_CLASS_TOTAL_INCREASING, ) DEPENDENCIES = ["uart"] diff --git a/esphome/components/ble_client/__init__.py b/esphome/components/ble_client/__init__.py index bc7d5176950..37f8ea32b3a 100644 --- a/esphome/components/ble_client/__init__.py +++ b/esphome/components/ble_client/__init__.py @@ -67,7 +67,7 @@ CONF_AUTO_CONNECT = "auto_connect" MULTI_CONF = True -CONFIG_SCHEMA = ( +CONFIG_SCHEMA = cv.All( cv.Schema( { cv.GenerateID(): cv.declare_id(BLEClient), @@ -114,7 +114,8 @@ CONFIG_SCHEMA = ( } ) .extend(cv.COMPONENT_SCHEMA) - .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) + .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA), + esp32_ble_tracker.consume_connection_slots(1, "ble_client"), ) CONF_BLE_CLIENT_ID = "ble_client_id" diff --git a/esphome/components/ble_client/sensor/__init__.py b/esphome/components/ble_client/sensor/__init__.py index 960410a5cc2..0975640ece6 100644 --- a/esphome/components/ble_client/sensor/__init__.py +++ b/esphome/components/ble_client/sensor/__init__.py @@ -5,13 +5,13 @@ import esphome.config_validation as cv from esphome.const import ( CONF_CHARACTERISTIC_UUID, CONF_LAMBDA, + CONF_NOTIFY, CONF_SERVICE_UUID, CONF_TRIGGER_ID, CONF_TYPE, DEVICE_CLASS_SIGNAL_STRENGTH, STATE_CLASS_MEASUREMENT, UNIT_DECIBEL_MILLIWATT, - CONF_NOTIFY, ) from .. import ble_client_ns diff --git a/esphome/components/ble_client/text_sensor/__init__.py b/esphome/components/ble_client/text_sensor/__init__.py index a6672e68f58..afa60f6c0c7 100644 --- a/esphome/components/ble_client/text_sensor/__init__.py +++ b/esphome/components/ble_client/text_sensor/__init__.py @@ -5,8 +5,8 @@ import esphome.config_validation as cv from esphome.const import ( CONF_CHARACTERISTIC_UUID, CONF_ID, - CONF_SERVICE_UUID, CONF_NOTIFY, + CONF_SERVICE_UUID, CONF_TRIGGER_ID, ) diff --git a/esphome/components/bluetooth_proxy/__init__.py b/esphome/components/bluetooth_proxy/__init__.py index 5a4ba36666b..04ac9116c7f 100644 --- a/esphome/components/bluetooth_proxy/__init__.py +++ b/esphome/components/bluetooth_proxy/__init__.py @@ -8,9 +8,10 @@ AUTO_LOAD = ["esp32_ble_client", "esp32_ble_tracker"] DEPENDENCIES = ["api", "esp32"] CODEOWNERS = ["@jesserockz"] +CONF_CONNECTION_SLOTS = "connection_slots" CONF_CACHE_SERVICES = "cache_services" CONF_CONNECTIONS = "connections" -MAX_CONNECTIONS = 3 +DEFAULT_CONNECTION_SLOTS = 3 bluetooth_proxy_ns = cg.esphome_ns.namespace("bluetooth_proxy") @@ -34,32 +35,43 @@ def validate_connections(config): raise cv.Invalid( "Connections can only be used if the proxy is set to active" ) - else: - if config[CONF_ACTIVE]: - conf = config.copy() - conf[CONF_CONNECTIONS] = [ - CONNECTION_SCHEMA({}) for _ in range(MAX_CONNECTIONS) - ] - return conf + elif config[CONF_ACTIVE]: + connection_slots: int = config[CONF_CONNECTION_SLOTS] + esp32_ble_tracker.consume_connection_slots(connection_slots, "bluetooth_proxy")( + config + ) + return { + **config, + CONF_CONNECTIONS: [CONNECTION_SCHEMA({}) for _ in range(connection_slots)], + } return config CONFIG_SCHEMA = cv.All( - cv.Schema( - { - cv.GenerateID(): cv.declare_id(BluetoothProxy), - cv.Optional(CONF_ACTIVE, default=False): cv.boolean, - cv.SplitDefault(CONF_CACHE_SERVICES, esp32_idf=True): cv.All( - cv.only_with_esp_idf, cv.boolean - ), - cv.Optional(CONF_CONNECTIONS): cv.All( - cv.ensure_list(CONNECTION_SCHEMA), - cv.Length(min=1, max=MAX_CONNECTIONS), - ), - } - ) - .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) - .extend(cv.COMPONENT_SCHEMA), + ( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(BluetoothProxy), + cv.Optional(CONF_ACTIVE, default=False): cv.boolean, + cv.SplitDefault(CONF_CACHE_SERVICES, esp32_idf=True): cv.All( + cv.only_with_esp_idf, cv.boolean + ), + cv.Optional( + CONF_CONNECTION_SLOTS, + default=DEFAULT_CONNECTION_SLOTS, + ): cv.All( + cv.positive_int, + cv.Range(min=1, max=esp32_ble_tracker.max_connections()), + ), + cv.Optional(CONF_CONNECTIONS): cv.All( + cv.ensure_list(CONNECTION_SCHEMA), + cv.Length(min=1, max=esp32_ble_tracker.max_connections()), + ), + } + ) + .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) + .extend(cv.COMPONENT_SCHEMA) + ), validate_connections, ) diff --git a/esphome/components/bme280_base/__init__.py b/esphome/components/bme280_base/__init__.py index 6a5f7e11270..c37191bc078 100644 --- a/esphome/components/bme280_base/__init__.py +++ b/esphome/components/bme280_base/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/bme280_i2c/sensor.py b/esphome/components/bme280_i2c/sensor.py index f3007ebaac8..1c37033613c 100644 --- a/esphome/components/bme280_i2c/sensor.py +++ b/esphome/components/bme280_i2c/sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c -from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE +import esphome.config_validation as cv + +from ..bme280_base import CONFIG_SCHEMA_BASE, to_code_base AUTO_LOAD = ["bme280_base"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/bme280_spi/sensor.py b/esphome/components/bme280_spi/sensor.py index 33a12318a5c..7f4fb5cf44b 100644 --- a/esphome/components/bme280_spi/sensor.py +++ b/esphome/components/bme280_spi/sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi -from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE +import esphome.config_validation as cv + +from ..bme280_base import CONFIG_SCHEMA_BASE, to_code_base AUTO_LOAD = ["bme280_base"] CODEOWNERS = ["@apbodrov"] diff --git a/esphome/components/bme680/sensor.py b/esphome/components/bme680/sensor.py index 586b454697c..5937ac6ad8a 100644 --- a/esphome/components/bme680/sensor.py +++ b/esphome/components/bme680/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import core +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_DURATION, CONF_GAS_RESISTANCE, @@ -15,11 +15,11 @@ from esphome.const import ( DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_OHM, ICON_GAS_CYLINDER, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_HECTOPASCAL, + UNIT_OHM, UNIT_PERCENT, ) diff --git a/esphome/components/bme680_bsec/__init__.py b/esphome/components/bme680_bsec/__init__.py index 743ef6e85dd..8ee463a59af 100644 --- a/esphome/components/bme680_bsec/__init__.py +++ b/esphome/components/bme680_bsec/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import esp32, i2c import esphome.config_validation as cv -from esphome.components import i2c, esp32 from esphome.const import CONF_ID, CONF_SAMPLE_RATE, CONF_TEMPERATURE_OFFSET CODEOWNERS = ["@trvrnrth"] diff --git a/esphome/components/bme680_bsec/sensor.py b/esphome/components/bme680_bsec/sensor.py index aa96998232e..5107b0bfcd0 100644 --- a/esphome/components/bme680_bsec/sensor.py +++ b/esphome/components/bme680_bsec/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_GAS_RESISTANCE, CONF_HUMIDITY, @@ -22,11 +22,8 @@ from esphome.const import ( UNIT_PARTS_PER_MILLION, UNIT_PERCENT, ) -from . import ( - BME680BSECComponent, - CONF_BME680_BSEC_ID, - SAMPLE_RATE_OPTIONS, -) + +from . import CONF_BME680_BSEC_ID, SAMPLE_RATE_OPTIONS, BME680BSECComponent DEPENDENCIES = ["bme680_bsec"] diff --git a/esphome/components/bme680_bsec/text_sensor.py b/esphome/components/bme680_bsec/text_sensor.py index 6b46e501dae..1fbb9e2aeb8 100644 --- a/esphome/components/bme680_bsec/text_sensor.py +++ b/esphome/components/bme680_bsec/text_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_IAQ_ACCURACY -from . import BME680BSECComponent, CONF_BME680_BSEC_ID + +from . import CONF_BME680_BSEC_ID, BME680BSECComponent DEPENDENCIES = ["bme680_bsec"] diff --git a/esphome/components/bmi160/sensor.py b/esphome/components/bmi160/sensor.py index baf185f95a2..cc4037c1ee7 100644 --- a/esphome/components/bmi160/sensor.py +++ b/esphome/components/bmi160/sensor.py @@ -1,26 +1,26 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, - CONF_TEMPERATURE, CONF_ACCELERATION_X, CONF_ACCELERATION_Y, CONF_ACCELERATION_Z, CONF_GYROSCOPE_X, CONF_GYROSCOPE_Y, CONF_GYROSCOPE_Z, + CONF_ID, + CONF_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_METER_PER_SECOND_SQUARED, ICON_ACCELERATION_X, ICON_ACCELERATION_Y, ICON_ACCELERATION_Z, ICON_GYROSCOPE_X, ICON_GYROSCOPE_Y, ICON_GYROSCOPE_Z, - UNIT_DEGREE_PER_SECOND, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_DEGREE_PER_SECOND, + UNIT_METER_PER_SECOND_SQUARED, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/bmp085/sensor.py b/esphome/components/bmp085/sensor.py index 83f5a0c8218..6e51984e1fb 100644 --- a/esphome/components/bmp085/sensor.py +++ b/esphome/components/bmp085/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PRESSURE, diff --git a/esphome/components/bmp280_base/__init__.py b/esphome/components/bmp280_base/__init__.py index c0f9af9dd75..d612920dd49 100644 --- a/esphome/components/bmp280_base/__init__.py +++ b/esphome/components/bmp280_base/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IIR_FILTER, diff --git a/esphome/components/bmp280_i2c/sensor.py b/esphome/components/bmp280_i2c/sensor.py index 991bb827a3d..3ff556d51a5 100644 --- a/esphome/components/bmp280_i2c/sensor.py +++ b/esphome/components/bmp280_i2c/sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c -from ..bmp280_base import to_code_base, CONFIG_SCHEMA_BASE +import esphome.config_validation as cv + +from ..bmp280_base import CONFIG_SCHEMA_BASE, to_code_base AUTO_LOAD = ["bmp280_base"] CODEOWNERS = ["@ademuri"] diff --git a/esphome/components/bmp280_spi/sensor.py b/esphome/components/bmp280_spi/sensor.py index 511d45b24e8..b3678ec01d9 100644 --- a/esphome/components/bmp280_spi/sensor.py +++ b/esphome/components/bmp280_spi/sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi -from ..bmp280_base import to_code_base, CONFIG_SCHEMA_BASE +import esphome.config_validation as cv + +from ..bmp280_base import CONFIG_SCHEMA_BASE, to_code_base AUTO_LOAD = ["bmp280_base"] CODEOWNERS = ["@ademuri"] diff --git a/esphome/components/bmp3xx_base/__init__.py b/esphome/components/bmp3xx_base/__init__.py index 589d170907a..c31db31761b 100644 --- a/esphome/components/bmp3xx_base/__init__.py +++ b/esphome/components/bmp3xx_base/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IIR_FILTER, diff --git a/esphome/components/bmp3xx_i2c/sensor.py b/esphome/components/bmp3xx_i2c/sensor.py index ae59d29e89e..6fed9fc9ee2 100644 --- a/esphome/components/bmp3xx_i2c/sensor.py +++ b/esphome/components/bmp3xx_i2c/sensor.py @@ -1,6 +1,7 @@ import esphome.codegen as cg from esphome.components import i2c -from ..bmp3xx_base import to_code_base, cv, CONFIG_SCHEMA_BASE + +from ..bmp3xx_base import CONFIG_SCHEMA_BASE, cv, to_code_base AUTO_LOAD = ["bmp3xx_base"] CODEOWNERS = ["@latonita"] diff --git a/esphome/components/bmp3xx_spi/sensor.py b/esphome/components/bmp3xx_spi/sensor.py index 3d1acd3c1b4..22aab71977f 100644 --- a/esphome/components/bmp3xx_spi/sensor.py +++ b/esphome/components/bmp3xx_spi/sensor.py @@ -1,6 +1,7 @@ import esphome.codegen as cg from esphome.components import spi -from ..bmp3xx_base import to_code_base, cv, CONFIG_SCHEMA_BASE + +from ..bmp3xx_base import CONFIG_SCHEMA_BASE, cv, to_code_base AUTO_LOAD = ["bmp3xx_base"] CODEOWNERS = ["@latonita"] diff --git a/esphome/components/bmp581/sensor.py b/esphome/components/bmp581/sensor.py index 1e0350075a9..e2790f83b9b 100644 --- a/esphome/components/bmp581/sensor.py +++ b/esphome/components/bmp581/sensor.py @@ -1,7 +1,8 @@ import math + import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IIR_FILTER, diff --git a/esphome/components/bp1658cj/__init__.py b/esphome/components/bp1658cj/__init__.py index 8388b16df98..dc80c67b44c 100644 --- a/esphome/components/bp1658cj/__init__.py +++ b/esphome/components/bp1658cj/__init__.py @@ -1,11 +1,7 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import ( - CONF_CLOCK_PIN, - CONF_DATA_PIN, - CONF_ID, -) +from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID CODEOWNERS = ["@Cossid"] MULTI_CONF = True diff --git a/esphome/components/bp1658cj/output.py b/esphome/components/bp1658cj/output.py index 3b895186211..023b6ecd1ec 100644 --- a/esphome/components/bp1658cj/output.py +++ b/esphome/components/bp1658cj/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import BP1658CJ DEPENDENCIES = ["bp1658cj"] diff --git a/esphome/components/bp5758d/__init__.py b/esphome/components/bp5758d/__init__.py index eeeab2a1bd4..af78b38ef50 100644 --- a/esphome/components/bp5758d/__init__.py +++ b/esphome/components/bp5758d/__init__.py @@ -1,11 +1,7 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import ( - CONF_CLOCK_PIN, - CONF_DATA_PIN, - CONF_ID, -) +from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID CODEOWNERS = ["@Cossid"] MULTI_CONF = True diff --git a/esphome/components/bp5758d/output.py b/esphome/components/bp5758d/output.py index d0083fb33f4..9adf13de55b 100644 --- a/esphome/components/bp5758d/output.py +++ b/esphome/components/bp5758d/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output -from esphome.const import CONF_CHANNEL, CONF_ID, CONF_CURRENT +import esphome.config_validation as cv +from esphome.const import CONF_CHANNEL, CONF_CURRENT, CONF_ID + from . import BP5758D DEPENDENCIES = ["bp5758d"] diff --git a/esphome/components/canbus/__init__.py b/esphome/components/canbus/__init__.py index 76e77021adc..68671777959 100644 --- a/esphome/components/canbus/__init__.py +++ b/esphome/components/canbus/__init__.py @@ -1,8 +1,9 @@ +import re +from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv -from esphome import automation +from esphome.const import CONF_DATA, CONF_ID, CONF_TRIGGER_ID from esphome.core import CORE -from esphome.const import CONF_ID, CONF_TRIGGER_ID, CONF_DATA CODEOWNERS = ["@mvturnho", "@danielschramm"] IS_PLATFORM_COMPONENT = True @@ -68,6 +69,16 @@ CAN_SPEEDS = { "800KBPS": CanSpeed.CAN_800KBPS, "1000KBPS": CanSpeed.CAN_1000KBPS, } + + +def get_rate(value): + match = re.match(r"(\d+)(?:K(\d+)?)?BPS", value, re.IGNORECASE) + if not match: + raise ValueError(f"Invalid rate format: {value}") + fraction = match.group(2) or "0" + return int((float(match.group(1)) + float(f"0.{fraction}")) * 1000) + + CANBUS_SCHEMA = cv.Schema( { cv.GenerateID(): cv.declare_id(CanbusComponent), diff --git a/esphome/components/canbus/canbus.cpp b/esphome/components/canbus/canbus.cpp index 73b86cba878..696cfff2b77 100644 --- a/esphome/components/canbus/canbus.cpp +++ b/esphome/components/canbus/canbus.cpp @@ -46,7 +46,13 @@ void Canbus::send_data(uint32_t can_id, bool use_extended_id, bool remote_transm ESP_LOGVV(TAG, " data[%d]=%02x", i, can_message.data[i]); } - this->send_message(&can_message); + if (this->send_message(&can_message) != canbus::ERROR_OK) { + if (use_extended_id) { + ESP_LOGW(TAG, "send to extended id=0x%08" PRIx32 " failed!", can_id); + } else { + ESP_LOGW(TAG, "send to standard id=0x%03" PRIx32 " failed!", can_id); + } + } } void Canbus::add_trigger(CanbusTrigger *trigger) { diff --git a/esphome/components/cap1188/__init__.py b/esphome/components/cap1188/__init__.py index f22e6d6c9e6..cde9dd46aec 100644 --- a/esphome/components/cap1188/__init__.py +++ b/esphome/components/cap1188/__init__.py @@ -1,8 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import i2c -from esphome.const import CONF_ID, CONF_RESET_PIN from esphome import pins +import esphome.codegen as cg +from esphome.components import i2c +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_RESET_PIN CONF_TOUCH_THRESHOLD = "touch_threshold" CONF_ALLOW_MULTIPLE_TOUCHES = "allow_multiple_touches" diff --git a/esphome/components/cap1188/binary_sensor.py b/esphome/components/cap1188/binary_sensor.py index 7950774340a..b7af53638a6 100644 --- a/esphome/components/cap1188/binary_sensor.py +++ b/esphome/components/cap1188/binary_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL -from . import cap1188_ns, CAP1188Component, CONF_CAP1188_ID + +from . import CONF_CAP1188_ID, CAP1188Component, cap1188_ns DEPENDENCIES = ["cap1188"] CAP1188Channel = cap1188_ns.class_("CAP1188Channel", binary_sensor.BinarySensor) diff --git a/esphome/components/captive_portal/__init__.py b/esphome/components/captive_portal/__init__.py index a90ea14c4ef..ea11e733acc 100644 --- a/esphome/components/captive_portal/__init__.py +++ b/esphome/components/captive_portal/__init__.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import web_server_base from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID +import esphome.config_validation as cv from esphome.const import ( CONF_ID, + PLATFORM_BK72XX, PLATFORM_ESP32, PLATFORM_ESP8266, - PLATFORM_BK72XX, PLATFORM_RTL87XX, ) -from esphome.core import coroutine_with_priority, CORE +from esphome.core import CORE, coroutine_with_priority AUTO_LOAD = ["web_server_base"] DEPENDENCIES = ["wifi"] diff --git a/esphome/components/ccs811/sensor.py b/esphome/components/ccs811/sensor.py index 66d9274fe89..10565cb3282 100644 --- a/esphome/components/ccs811/sensor.py +++ b/esphome/components/ccs811/sensor.py @@ -1,22 +1,22 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor, text_sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, - ICON_RADIATOR, - ICON_RESTART, - DEVICE_CLASS_CARBON_DIOXIDE, - DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, - UNIT_PARTS_PER_BILLION, CONF_BASELINE, CONF_ECO2, + CONF_HUMIDITY, + CONF_ID, CONF_TEMPERATURE, CONF_TVOC, - CONF_HUMIDITY, CONF_VERSION, + DEVICE_CLASS_CARBON_DIOXIDE, + DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, ICON_MOLECULE_CO2, + ICON_RADIATOR, + ICON_RESTART, + STATE_CLASS_MEASUREMENT, + UNIT_PARTS_PER_BILLION, + UNIT_PARTS_PER_MILLION, ) AUTO_LOAD = ["text_sensor"] diff --git a/esphome/components/cd74hc4067/__init__.py b/esphome/components/cd74hc4067/__init__.py index d57061b7109..9b69576b43c 100644 --- a/esphome/components/cd74hc4067/__init__.py +++ b/esphome/components/cd74hc4067/__init__.py @@ -1,10 +1,7 @@ -import esphome.codegen as cg from esphome import pins +import esphome.codegen as cg import esphome.config_validation as cv -from esphome.const import ( - CONF_DELAY, - CONF_ID, -) +from esphome.const import CONF_DELAY, CONF_ID AUTO_LOAD = ["sensor", "voltage_sampler"] CODEOWNERS = ["@asoehlke"] diff --git a/esphome/components/cd74hc4067/sensor.py b/esphome/components/cd74hc4067/sensor.py index 3eee34b85eb..dceaf6f3715 100644 --- a/esphome/components/cd74hc4067/sensor.py +++ b/esphome/components/cd74hc4067/sensor.py @@ -1,16 +1,17 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_SENSOR, CONF_NUMBER, - ICON_FLASH, - UNIT_VOLT, - STATE_CLASS_MEASUREMENT, + CONF_SENSOR, DEVICE_CLASS_VOLTAGE, + ICON_FLASH, + STATE_CLASS_MEASUREMENT, + UNIT_VOLT, ) -from . import cd74hc4067_ns, CD74HC4067Component + +from . import CD74HC4067Component, cd74hc4067_ns DEPENDENCIES = ["cd74hc4067"] diff --git a/esphome/components/climate_ir/__init__.py b/esphome/components/climate_ir/__init__.py index c7c286d679e..d8be61397ec 100644 --- a/esphome/components/climate_ir/__init__.py +++ b/esphome/components/climate_ir/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg +from esphome.components import climate, remote_base, sensor import esphome.config_validation as cv -from esphome.components import climate, sensor, remote_base -from esphome.const import CONF_SUPPORTS_COOL, CONF_SUPPORTS_HEAT, CONF_SENSOR +from esphome.const import CONF_SENSOR, CONF_SUPPORTS_COOL, CONF_SUPPORTS_HEAT DEPENDENCIES = ["remote_transmitter"] AUTO_LOAD = ["sensor", "remote_base"] diff --git a/esphome/components/climate_ir_lg/climate.py b/esphome/components/climate_ir_lg/climate.py index c58e40f7f43..76d4c00baf2 100644 --- a/esphome/components/climate_ir_lg/climate.py +++ b/esphome/components/climate_ir_lg/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/color/__init__.py b/esphome/components/color/__init__.py index 609d416a0bf..c3381cfd706 100644 --- a/esphome/components/color/__init__.py +++ b/esphome/components/color/__init__.py @@ -1,5 +1,4 @@ -from esphome import config_validation as cv -from esphome import codegen as cg +from esphome import codegen as cg, config_validation as cv from esphome.const import CONF_BLUE, CONF_GREEN, CONF_ID, CONF_RED, CONF_WHITE ColorStruct = cg.esphome_ns.struct("Color") diff --git a/esphome/components/color_temperature/light.py b/esphome/components/color_temperature/light.py index 3e7a0e73aef..045ab265cd2 100644 --- a/esphome/components/color_temperature/light.py +++ b/esphome/components/color_temperature/light.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import ( CONF_BRIGHTNESS, + CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_COLOR_TEMPERATURE, CONF_OUTPUT_ID, - CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_WARM_WHITE_COLOR_TEMPERATURE, ) diff --git a/esphome/components/combination/sensor.py b/esphome/components/combination/sensor.py index fad02770619..f5255fec03a 100644 --- a/esphome/components/combination/sensor.py +++ b/esphome/components/combination/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ACCURACY_DECIMALS, CONF_DEVICE_CLASS, diff --git a/esphome/components/coolix/climate.py b/esphome/components/coolix/climate.py index 2cfd1912e5f..339e7de9061 100644 --- a/esphome/components/coolix/climate.py +++ b/esphome/components/coolix/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/copy/binary_sensor/__init__.py b/esphome/components/copy/binary_sensor/__init__.py index 1b6836fae7d..840200409fb 100644 --- a/esphome/components/copy/binary_sensor/__init__.py +++ b/esphome/components/copy/binary_sensor/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, diff --git a/esphome/components/copy/button/__init__.py b/esphome/components/copy/button/__init__.py index 626a5a8db12..8028d6a2175 100644 --- a/esphome/components/copy/button/__init__.py +++ b/esphome/components/copy/button/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button +import esphome.config_validation as cv from esphome.const import ( CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, diff --git a/esphome/components/copy/cover/__init__.py b/esphome/components/copy/cover/__init__.py index 155e22883bb..7db9034d024 100644 --- a/esphome/components/copy/cover/__init__.py +++ b/esphome/components/copy/cover/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import cover +import esphome.config_validation as cv from esphome.const import ( CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, diff --git a/esphome/components/copy/fan/__init__.py b/esphome/components/copy/fan/__init__.py index 22672c02d84..04872fb029e 100644 --- a/esphome/components/copy/fan/__init__.py +++ b/esphome/components/copy/fan/__init__.py @@ -1,12 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import fan -from esphome.const import ( - CONF_ENTITY_CATEGORY, - CONF_ICON, - CONF_ID, - CONF_SOURCE_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ENTITY_CATEGORY, CONF_ICON, CONF_ID, CONF_SOURCE_ID from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns diff --git a/esphome/components/copy/lock/__init__.py b/esphome/components/copy/lock/__init__.py index d19e4a5807d..ddedea64c0f 100644 --- a/esphome/components/copy/lock/__init__.py +++ b/esphome/components/copy/lock/__init__.py @@ -1,12 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import lock -from esphome.const import ( - CONF_ENTITY_CATEGORY, - CONF_ICON, - CONF_ID, - CONF_SOURCE_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ENTITY_CATEGORY, CONF_ICON, CONF_ID, CONF_SOURCE_ID from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns diff --git a/esphome/components/copy/number/__init__.py b/esphome/components/copy/number/__init__.py index 204518da39e..3e2bbf2aae9 100644 --- a/esphome/components/copy/number/__init__.py +++ b/esphome/components/copy/number/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import number +import esphome.config_validation as cv from esphome.const import ( CONF_ENTITY_CATEGORY, CONF_ICON, diff --git a/esphome/components/copy/select/__init__.py b/esphome/components/copy/select/__init__.py index 6254ed03e15..d7ddc52c444 100644 --- a/esphome/components/copy/select/__init__.py +++ b/esphome/components/copy/select/__init__.py @@ -1,12 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import select -from esphome.const import ( - CONF_ENTITY_CATEGORY, - CONF_ICON, - CONF_ID, - CONF_SOURCE_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ENTITY_CATEGORY, CONF_ICON, CONF_ID, CONF_SOURCE_ID from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns diff --git a/esphome/components/copy/sensor/__init__.py b/esphome/components/copy/sensor/__init__.py index 8e78cda7c7f..57ca06aca7e 100644 --- a/esphome/components/copy/sensor/__init__.py +++ b/esphome/components/copy/sensor/__init__.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_ACCURACY_DECIMALS, CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, CONF_ICON, CONF_SOURCE_ID, CONF_STATE_CLASS, CONF_UNIT_OF_MEASUREMENT, - CONF_ACCURACY_DECIMALS, ) from esphome.core.entity_helpers import inherit_property_from diff --git a/esphome/components/copy/switch/__init__.py b/esphome/components/copy/switch/__init__.py index beffbe7fbb3..ee27e38c5fe 100644 --- a/esphome/components/copy/switch/__init__.py +++ b/esphome/components/copy/switch/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch +import esphome.config_validation as cv from esphome.const import ( CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, diff --git a/esphome/components/copy/text/__init__.py b/esphome/components/copy/text/__init__.py index 7593789250d..aa39225bc2d 100644 --- a/esphome/components/copy/text/__init__.py +++ b/esphome/components/copy/text/__init__.py @@ -1,12 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text -from esphome.const import ( - CONF_ENTITY_CATEGORY, - CONF_ICON, - CONF_MODE, - CONF_SOURCE_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ENTITY_CATEGORY, CONF_ICON, CONF_MODE, CONF_SOURCE_ID from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns diff --git a/esphome/components/copy/text_sensor/__init__.py b/esphome/components/copy/text_sensor/__init__.py index 5b59f21319f..7b38ff1a643 100644 --- a/esphome/components/copy/text_sensor/__init__.py +++ b/esphome/components/copy/text_sensor/__init__.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor -from esphome.const import ( - CONF_ENTITY_CATEGORY, - CONF_ICON, - CONF_SOURCE_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ENTITY_CATEGORY, CONF_ICON, CONF_SOURCE_ID from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns diff --git a/esphome/components/cs5460a/sensor.py b/esphome/components/cs5460a/sensor.py index d8219e1df12..07b5ea1c635 100644 --- a/esphome/components/cs5460a/sensor.py +++ b/esphome/components/cs5460a/sensor.py @@ -1,21 +1,21 @@ +from esphome import automation +from esphome.automation import maybe_simple_id import esphome.codegen as cg +from esphome.components import sensor, spi import esphome.config_validation as cv -from esphome.components import spi, sensor from esphome.const import ( CONF_CURRENT, CONF_ID, CONF_POWER, CONF_VOLTAGE, CONF_VOLTAGE_GAIN, - UNIT_VOLT, - UNIT_AMPERE, - UNIT_WATT, - DEVICE_CLASS_POWER, DEVICE_CLASS_CURRENT, + DEVICE_CLASS_POWER, DEVICE_CLASS_VOLTAGE, + UNIT_AMPERE, + UNIT_VOLT, + UNIT_WATT, ) -from esphome import automation -from esphome.automation import maybe_simple_id CODEOWNERS = ["@balrog-kun"] DEPENDENCIES = ["spi"] diff --git a/esphome/components/cse7761/sensor.py b/esphome/components/cse7761/sensor.py index c5ec3e5b71b..7e8caf1ae1e 100644 --- a/esphome/components/cse7761/sensor.py +++ b/esphome/components/cse7761/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_VOLTAGE, @@ -8,8 +8,8 @@ from esphome.const import ( DEVICE_CLASS_POWER, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, ) diff --git a/esphome/components/cse7766/sensor.py b/esphome/components/cse7766/sensor.py index b5b11a661eb..6572a914aa4 100644 --- a/esphome/components/cse7766/sensor.py +++ b/esphome/components/cse7766/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_APPARENT_POWER, CONF_CURRENT, diff --git a/esphome/components/cst226/touchscreen/__init__.py b/esphome/components/cst226/touchscreen/__init__.py index 76975ffe789..62c2e3b20af 100644 --- a/esphome/components/cst226/touchscreen/__init__.py +++ b/esphome/components/cst226/touchscreen/__init__.py @@ -1,11 +1,10 @@ -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, touchscreen -from esphome.const import CONF_INTERRUPT_PIN, CONF_ID, CONF_RESET_PIN -from .. import cst226_ns +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INTERRUPT_PIN, CONF_RESET_PIN +from .. import cst226_ns CST226Touchscreen = cst226_ns.class_( "CST226Touchscreen", diff --git a/esphome/components/ct_clamp/sensor.py b/esphome/components/ct_clamp/sensor.py index 18ea5877d2f..6ad7990e809 100644 --- a/esphome/components/ct_clamp/sensor.py +++ b/esphome/components/ct_clamp/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import ( CONF_SENSOR, DEVICE_CLASS_CURRENT, diff --git a/esphome/components/current_based/cover.py b/esphome/components/current_based/cover.py index 1fa4eaa03fd..75f083ef143 100644 --- a/esphome/components/current_based/cover.py +++ b/esphome/components/current_based/cover.py @@ -1,18 +1,17 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation -from esphome.components import sensor, cover +import esphome.codegen as cg +from esphome.components import cover, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_ID, + CONF_MAX_DURATION, CONF_OPEN_ACTION, CONF_OPEN_DURATION, CONF_STOP_ACTION, - CONF_MAX_DURATION, ) - CONF_OPEN_SENSOR = "open_sensor" CONF_OPEN_MOVING_CURRENT_THRESHOLD = "open_moving_current_threshold" CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD = "open_obstacle_current_threshold" diff --git a/esphome/components/cwww/light.py b/esphome/components/cwww/light.py index c88a6b0054d..50d84a582db 100644 --- a/esphome/components/cwww/light.py +++ b/esphome/components/cwww/light.py @@ -1,12 +1,12 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import ( + CONF_COLD_WHITE, + CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_CONSTANT_BRIGHTNESS, CONF_OUTPUT_ID, - CONF_COLD_WHITE, CONF_WARM_WHITE, - CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_WARM_WHITE_COLOR_TEMPERATURE, ) diff --git a/esphome/components/dac7678/__init__.py b/esphome/components/dac7678/__init__.py index b6cd2b384e6..842c84832ea 100644 --- a/esphome/components/dac7678/__init__.py +++ b/esphome/components/dac7678/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["output"] diff --git a/esphome/components/dac7678/output.py b/esphome/components/dac7678/output.py index f41e5c24229..cb7739242c3 100644 --- a/esphome/components/dac7678/output.py +++ b/esphome/components/dac7678/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import DAC7678Output, dac7678_ns DEPENDENCIES = ["dac7678"] diff --git a/esphome/components/daikin/climate.py b/esphome/components/daikin/climate.py index af60b174483..39465131918 100644 --- a/esphome/components/daikin/climate.py +++ b/esphome/components/daikin/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/daikin_arc/climate.py b/esphome/components/daikin_arc/climate.py index 51f253e9cb6..967d080c242 100644 --- a/esphome/components/daikin_arc/climate.py +++ b/esphome/components/daikin_arc/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/daikin_brc/climate.py b/esphome/components/daikin_brc/climate.py index 7a5bd9b14d8..aacac408ca7 100644 --- a/esphome/components/daikin_brc/climate.py +++ b/esphome/components/daikin_brc/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_USE_FAHRENHEIT AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/dallas_temp/sensor.py b/esphome/components/dallas_temp/sensor.py index ab14a9afd53..3d358817225 100644 --- a/esphome/components/dallas_temp/sensor.py +++ b/esphome/components/dallas_temp/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import one_wire, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_RESOLUTION, DEVICE_CLASS_TEMPERATURE, diff --git a/esphome/components/daly_bms/__init__.py b/esphome/components/daly_bms/__init__.py index 669d40a68dd..87f00ce507a 100644 --- a/esphome/components/daly_bms/__init__.py +++ b/esphome/components/daly_bms/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart -from esphome.const import CONF_ID, CONF_ADDRESS +import esphome.config_validation as cv +from esphome.const import CONF_ADDRESS, CONF_ID CODEOWNERS = ["@s1lvi0"] MULTI_CONF = True diff --git a/esphome/components/daly_bms/binary_sensor.py b/esphome/components/daly_bms/binary_sensor.py index 724f19315b2..95a2ae3b44e 100644 --- a/esphome/components/daly_bms/binary_sensor.py +++ b/esphome/components/daly_bms/binary_sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from . import DalyBmsComponent, CONF_BMS_DALY_ID +import esphome.config_validation as cv + +from . import CONF_BMS_DALY_ID, DalyBmsComponent CONF_CHARGING_MOS_ENABLED = "charging_mos_enabled" CONF_DISCHARGING_MOS_ENABLED = "discharging_mos_enabled" diff --git a/esphome/components/daly_bms/sensor.py b/esphome/components/daly_bms/sensor.py index 6d78946a024..560bcef64ec 100644 --- a/esphome/components/daly_bms/sensor.py +++ b/esphome/components/daly_bms/sensor.py @@ -1,28 +1,29 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_VOLTAGE, - CONF_CURRENT, CONF_BATTERY_LEVEL, + CONF_CURRENT, CONF_MAX_TEMPERATURE, CONF_MIN_TEMPERATURE, - DEVICE_CLASS_VOLTAGE, - DEVICE_CLASS_CURRENT, + CONF_VOLTAGE, DEVICE_CLASS_BATTERY, + DEVICE_CLASS_CURRENT, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_VOLT, - UNIT_AMPERE, - UNIT_PERCENT, - UNIT_CELSIUS, - ICON_FLASH, - ICON_PERCENT, + DEVICE_CLASS_VOLTAGE, ICON_COUNTER, - ICON_THERMOMETER, + ICON_FLASH, ICON_GAUGE, + ICON_PERCENT, + ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, + UNIT_AMPERE, + UNIT_CELSIUS, + UNIT_PERCENT, + UNIT_VOLT, ) -from . import DalyBmsComponent, CONF_BMS_DALY_ID + +from . import CONF_BMS_DALY_ID, DalyBmsComponent CONF_MAX_CELL_VOLTAGE = "max_cell_voltage" CONF_MAX_CELL_VOLTAGE_NUMBER = "max_cell_voltage_number" diff --git a/esphome/components/daly_bms/text_sensor.py b/esphome/components/daly_bms/text_sensor.py index fcd5ee531b8..9f4e2df85a0 100644 --- a/esphome/components/daly_bms/text_sensor.py +++ b/esphome/components/daly_bms/text_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_STATUS -from . import DalyBmsComponent, CONF_BMS_DALY_ID + +from . import CONF_BMS_DALY_ID, DalyBmsComponent ICON_CAR_BATTERY = "mdi:car-battery" diff --git a/esphome/components/dashboard_import/__init__.py b/esphome/components/dashboard_import/__init__.py index b1b22b816b9..acaadab5448 100644 --- a/esphome/components/dashboard_import/__init__.py +++ b/esphome/components/dashboard_import/__init__.py @@ -1,18 +1,18 @@ import base64 -import secrets from pathlib import Path -from typing import Optional import re +import secrets +from typing import Optional import requests from ruamel.yaml import YAML -import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv from esphome import git +import esphome.codegen as cg from esphome.components.packages import validate_source_shorthand -from esphome.const import CONF_REF, CONF_WIFI, CONF_ESPHOME, CONF_PROJECT +import esphome.config_validation as cv +from esphome.const import CONF_ESPHOME, CONF_PROJECT, CONF_REF, CONF_WIFI +import esphome.final_validate as fv from esphome.yaml_util import dump dashboard_import_ns = cg.esphome_ns.namespace("dashboard_import") diff --git a/esphome/components/debug/sensor.py b/esphome/components/debug/sensor.py index 061c2750e43..0a236589079 100644 --- a/esphome/components/debug/sensor.py +++ b/esphome/components/debug/sensor.py @@ -1,18 +1,19 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_FREE, - CONF_FRAGMENTATION, CONF_BLOCK, + CONF_FRAGMENTATION, + CONF_FREE, CONF_LOOP_TIME, ENTITY_CATEGORY_DIAGNOSTIC, - UNIT_MILLISECOND, - UNIT_PERCENT, - UNIT_BYTES, ICON_COUNTER, ICON_TIMER, + UNIT_BYTES, + UNIT_MILLISECOND, + UNIT_PERCENT, ) + from . import CONF_DEBUG_ID, DebugComponent DEPENDENCIES = ["debug"] diff --git a/esphome/components/debug/text_sensor.py b/esphome/components/debug/text_sensor.py index 24f938a0e28..96ef2318501 100644 --- a/esphome/components/debug/text_sensor.py +++ b/esphome/components/debug/text_sensor.py @@ -1,6 +1,6 @@ +import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( CONF_DEVICE, ENTITY_CATEGORY_DIAGNOSTIC, diff --git a/esphome/components/deep_sleep/__init__.py b/esphome/components/deep_sleep/__init__.py index fd7ef6fcce9..63b359bd5bb 100644 --- a/esphome/components/deep_sleep/__init__.py +++ b/esphome/components/deep_sleep/__init__.py @@ -1,8 +1,19 @@ +from esphome import automation, pins import esphome.codegen as cg from esphome.components import time +from esphome.components.esp32 import get_esp32_variant +from esphome.components.esp32.const import ( + VARIANT_ESP32, + VARIANT_ESP32C2, + VARIANT_ESP32C3, + VARIANT_ESP32C6, + VARIANT_ESP32H2, + VARIANT_ESP32S2, + VARIANT_ESP32S3, +) import esphome.config_validation as cv -from esphome import pins, automation from esphome.const import ( + CONF_DEFAULT, CONF_HOUR, CONF_ID, CONF_MINUTE, @@ -18,17 +29,6 @@ from esphome.const import ( PLATFORM_ESP8266, ) -from esphome.components.esp32 import get_esp32_variant -from esphome.components.esp32.const import ( - VARIANT_ESP32, - VARIANT_ESP32C3, - VARIANT_ESP32S2, - VARIANT_ESP32S3, - VARIANT_ESP32C2, - VARIANT_ESP32C6, - VARIANT_ESP32H2, -) - WAKEUP_PINS = { VARIANT_ESP32: [ 0, @@ -154,7 +154,6 @@ WakeupCauseToRunDuration = deep_sleep_ns.struct("WakeupCauseToRunDuration") CONF_WAKEUP_PIN_MODE = "wakeup_pin_mode" CONF_ESP32_EXT1_WAKEUP = "esp32_ext1_wakeup" CONF_TOUCH_WAKEUP = "touch_wakeup" -CONF_DEFAULT = "default" CONF_GPIO_WAKEUP_REASON = "gpio_wakeup_reason" CONF_TOUCH_WAKEUP_REASON = "touch_wakeup_reason" CONF_UNTIL = "until" diff --git a/esphome/components/delonghi/climate.py b/esphome/components/delonghi/climate.py index 614706defea..0d3bb76c985 100644 --- a/esphome/components/delonghi/climate.py +++ b/esphome/components/delonghi/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/demo/__init__.py b/esphome/components/demo/__init__.py index 05160bf8cb8..349bd8e4cbd 100644 --- a/esphome/components/demo/__init__.py +++ b/esphome/components/demo/__init__.py @@ -1,5 +1,4 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import ( binary_sensor, climate, @@ -11,6 +10,7 @@ from esphome.components import ( switch, text_sensor, ) +import esphome.config_validation as cv from esphome.const import ( CONF_ACCURACY_DECIMALS, CONF_BINARY_SENSORS, diff --git a/esphome/components/dfplayer/__init__.py b/esphome/components/dfplayer/__init__.py index c37c9999aa8..53ebda6bcc8 100644 --- a/esphome/components/dfplayer/__init__.py +++ b/esphome/components/dfplayer/__init__.py @@ -1,8 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation -from esphome.const import CONF_ID, CONF_TRIGGER_ID, CONF_FILE, CONF_DEVICE, CONF_VOLUME +import esphome.codegen as cg from esphome.components import uart +import esphome.config_validation as cv +from esphome.const import CONF_DEVICE, CONF_FILE, CONF_ID, CONF_TRIGGER_ID, CONF_VOLUME DEPENDENCIES = ["uart"] CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/dfrobot_sen0395/__init__.py b/esphome/components/dfrobot_sen0395/__init__.py index 39787ca66b3..8c9438dccbb 100644 --- a/esphome/components/dfrobot_sen0395/__init__.py +++ b/esphome/components/dfrobot_sen0395/__init__.py @@ -1,9 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id -from esphome.const import CONF_FACTORY_RESET, CONF_ID, CONF_SENSITIVITY +import esphome.codegen as cg from esphome.components import uart +import esphome.config_validation as cv +from esphome.const import CONF_FACTORY_RESET, CONF_ID, CONF_SENSITIVITY CODEOWNERS = ["@niklasweber"] DEPENDENCIES = ["uart"] diff --git a/esphome/components/dfrobot_sen0395/binary_sensor.py b/esphome/components/dfrobot_sen0395/binary_sensor.py index 2fd0510476c..193ef925a4b 100644 --- a/esphome/components/dfrobot_sen0395/binary_sensor.py +++ b/esphome/components/dfrobot_sen0395/binary_sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import DEVICE_CLASS_MOTION + from . import CONF_DFROBOT_SEN0395_ID, DfrobotSen0395Component DEPENDENCIES = ["dfrobot_sen0395"] diff --git a/esphome/components/dfrobot_sen0395/switch/__init__.py b/esphome/components/dfrobot_sen0395/switch/__init__.py index b1c35d27acf..f854d08398d 100644 --- a/esphome/components/dfrobot_sen0395/switch/__init__.py +++ b/esphome/components/dfrobot_sen0395/switch/__init__.py @@ -1,11 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch -from esphome.const import ENTITY_CATEGORY_CONFIG, CONF_TYPE +import esphome.config_validation as cv +from esphome.const import CONF_TYPE, ENTITY_CATEGORY_CONFIG from .. import CONF_DFROBOT_SEN0395_ID, DfrobotSen0395Component - DEPENDENCIES = ["dfrobot_sen0395"] dfrobot_sen0395_ns = cg.esphome_ns.namespace("dfrobot_sen0395") diff --git a/esphome/components/dht/sensor.py b/esphome/components/dht/sensor.py index be53df26257..d907495ba2e 100644 --- a/esphome/components/dht/sensor.py +++ b/esphome/components/dht/sensor.py @@ -1,20 +1,19 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, CONF_MODEL, CONF_PIN, CONF_TEMPERATURE, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, ) - from esphome.cpp_helpers import gpio_pin_expression dht_ns = cg.esphome_ns.namespace("dht") diff --git a/esphome/components/dht12/sensor.py b/esphome/components/dht12/sensor.py index ae2173ef225..eb93cbae2cf 100644 --- a/esphome/components/dht12/sensor.py +++ b/esphome/components/dht12/sensor.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, CONF_TEMPERATURE, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/dps310/sensor.py b/esphome/components/dps310/sensor.py index 742c873d9ee..b2a98e5bab6 100644 --- a/esphome/components/dps310/sensor.py +++ b/esphome/components/dps310/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PRESSURE, CONF_TEMPERATURE, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_CELSIUS, ICON_GAUGE, ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, UNIT_HECTOPASCAL, ) diff --git a/esphome/components/ds1307/time.py b/esphome/components/ds1307/time.py index ddc29390386..42b7184db9b 100644 --- a/esphome/components/ds1307/time.py +++ b/esphome/components/ds1307/time.py @@ -1,10 +1,9 @@ -import esphome.config_validation as cv -import esphome.codegen as cg from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, time +import esphome.config_validation as cv from esphome.const import CONF_ID - CODEOWNERS = ["@badbadc0ffee"] DEPENDENCIES = ["i2c"] ds1307_ns = cg.esphome_ns.namespace("ds1307") diff --git a/esphome/components/dsmr/__init__.py b/esphome/components/dsmr/__init__.py index 9f56dc34651..017a11673fc 100644 --- a/esphome/components/dsmr/__init__.py +++ b/esphome/components/dsmr/__init__.py @@ -1,12 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import uart -from esphome.const import ( - CONF_ID, - CONF_UART_ID, - CONF_RECEIVE_TIMEOUT, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_RECEIVE_TIMEOUT, CONF_UART_ID CODEOWNERS = ["@glmnet", "@zuidwijk"] diff --git a/esphome/components/dsmr/sensor.py b/esphome/components/dsmr/sensor.py index f2398d19088..0696fccdf77 100644 --- a/esphome/components/dsmr/sensor.py +++ b/esphome/components/dsmr/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_CURRENT, @@ -13,13 +13,14 @@ from esphome.const import ( STATE_CLASS_TOTAL_INCREASING, UNIT_AMPERE, UNIT_CUBIC_METER, + UNIT_KILOVOLT_AMPS_REACTIVE, + UNIT_KILOVOLT_AMPS_REACTIVE_HOURS, UNIT_KILOWATT, UNIT_KILOWATT_HOURS, - UNIT_KILOVOLT_AMPS_REACTIVE_HOURS, - UNIT_KILOVOLT_AMPS_REACTIVE, UNIT_VOLT, ) -from . import Dsmr, CONF_DSMR_ID + +from . import CONF_DSMR_ID, Dsmr AUTO_LOAD = ["dsmr"] diff --git a/esphome/components/dsmr/text_sensor.py b/esphome/components/dsmr/text_sensor.py index 7c13fe7d581..3223d943bee 100644 --- a/esphome/components/dsmr/text_sensor.py +++ b/esphome/components/dsmr/text_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_INTERNAL -from . import Dsmr, CONF_DSMR_ID + +from . import CONF_DSMR_ID, Dsmr AUTO_LOAD = ["dsmr"] diff --git a/esphome/components/duty_cycle/sensor.py b/esphome/components/duty_cycle/sensor.py index 3dcdf7a818b..37c889cd85b 100644 --- a/esphome/components/duty_cycle/sensor.py +++ b/esphome/components/duty_cycle/sensor.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor -from esphome.const import ( - CONF_PIN, - STATE_CLASS_MEASUREMENT, - UNIT_PERCENT, - ICON_PERCENT, -) +import esphome.config_validation as cv +from esphome.const import CONF_PIN, ICON_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_PERCENT duty_cycle_ns = cg.esphome_ns.namespace("duty_cycle") DutyCycleSensor = duty_cycle_ns.class_( diff --git a/esphome/components/duty_time/sensor.py b/esphome/components/duty_time/sensor.py index 556cd459a5b..1907b3fcfec 100644 --- a/esphome/components/duty_time/sensor.py +++ b/esphome/components/duty_time/sensor.py @@ -1,5 +1,3 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome.automation import ( Action, Condition, @@ -7,17 +5,19 @@ from esphome.automation import ( register_action, register_condition, ) +import esphome.codegen as cg from esphome.components import binary_sensor, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_SENSOR, - CONF_RESTORE, CONF_LAMBDA, - UNIT_SECOND, - STATE_CLASS_TOTAL, - STATE_CLASS_TOTAL_INCREASING, + CONF_RESTORE, + CONF_SENSOR, DEVICE_CLASS_DURATION, ENTITY_CATEGORY_DIAGNOSTIC, + STATE_CLASS_TOTAL, + STATE_CLASS_TOTAL_INCREASING, + UNIT_SECOND, ) CONF_LAST_TIME = "last_time" diff --git a/esphome/components/e131/__init__.py b/esphome/components/e131/__init__.py index cec0bdf4faf..301812e314e 100644 --- a/esphome/components/e131/__init__.py +++ b/esphome/components/e131/__init__.py @@ -1,8 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components.light.types import AddressableLightEffect from esphome.components.light.effects import register_addressable_effect -from esphome.const import CONF_ID, CONF_NAME, CONF_METHOD, CONF_CHANNELS +from esphome.components.light.types import AddressableLightEffect +import esphome.config_validation as cv +from esphome.const import CONF_CHANNELS, CONF_ID, CONF_METHOD, CONF_NAME AUTO_LOAD = ["socket"] DEPENDENCIES = ["network"] diff --git a/esphome/components/ee895/sensor.py b/esphome/components/ee895/sensor.py index d06f9ca02f4..0f8f44c8a24 100644 --- a/esphome/components/ee895/sensor.py +++ b/esphome/components/ee895/sensor.py @@ -1,17 +1,17 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_CO2, CONF_ID, CONF_PRESSURE, CONF_TEMPERATURE, - CONF_CO2, - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_PRESSURE, - STATE_CLASS_MEASUREMENT, - UNIT_HECTOPASCAL, - UNIT_CELSIUS, + DEVICE_CLASS_TEMPERATURE, ICON_MOLECULE_CO2, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_HECTOPASCAL, UNIT_PARTS_PER_MILLION, ) diff --git a/esphome/components/ektf2232/touchscreen/__init__.py b/esphome/components/ektf2232/touchscreen/__init__.py index c1fefb7f091..7d946fdcb90 100644 --- a/esphome/components/ektf2232/touchscreen/__init__.py +++ b/esphome/components/ektf2232/touchscreen/__init__.py @@ -1,8 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, touchscreen +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTERRUPT_PIN CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/emc2101/__init__.py b/esphome/components/emc2101/__init__.py index 8012d3e8977..323195e99af 100644 --- a/esphome/components/emc2101/__init__.py +++ b/esphome/components/emc2101/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INVERTED, CONF_RESOLUTION CODEOWNERS = ["@ellull"] diff --git a/esphome/components/emc2101/output/__init__.py b/esphome/components/emc2101/output/__init__.py index 461ef73de1a..586f0800a6f 100644 --- a/esphome/components/emc2101/output/__init__.py +++ b/esphome/components/emc2101/output/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_ID -from .. import EMC2101_COMPONENT_SCHEMA, CONF_EMC2101_ID, emc2101_ns + +from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns DEPENDENCIES = ["emc2101"] diff --git a/esphome/components/emc2101/sensor/__init__.py b/esphome/components/emc2101/sensor/__init__.py index 10ea3dfae6a..b6a2c8a3331 100644 --- a/esphome/components/emc2101/sensor/__init__.py +++ b/esphome/components/emc2101/sensor/__init__.py @@ -1,19 +1,20 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_EXTERNAL_TEMPERATURE, CONF_ID, CONF_INTERNAL_TEMPERATURE, CONF_SPEED, DEVICE_CLASS_TEMPERATURE, + ICON_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, UNIT_REVOLUTIONS_PER_MINUTE, - ICON_PERCENT, ) -from .. import EMC2101_COMPONENT_SCHEMA, CONF_EMC2101_ID, emc2101_ns + +from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns DEPENDENCIES = ["emc2101"] diff --git a/esphome/components/emmeti/climate.py b/esphome/components/emmeti/climate.py index 36585061e6b..b925f4b61e3 100644 --- a/esphome/components/emmeti/climate.py +++ b/esphome/components/emmeti/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@E440QF"] diff --git a/esphome/components/endstop/cover.py b/esphome/components/endstop/cover.py index 9f3cd395a53..286c876ff68 100644 --- a/esphome/components/endstop/cover.py +++ b/esphome/components/endstop/cover.py @@ -1,17 +1,17 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import binary_sensor, cover +import esphome.config_validation as cv from esphome.const import ( CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_CLOSE_ENDSTOP, CONF_ID, + CONF_MAX_DURATION, CONF_OPEN_ACTION, CONF_OPEN_DURATION, CONF_OPEN_ENDSTOP, CONF_STOP_ACTION, - CONF_MAX_DURATION, ) endstop_ns = cg.esphome_ns.namespace("endstop") diff --git a/esphome/components/ens160_base/__init__.py b/esphome/components/ens160_base/__init__.py index eb6d0880afc..28e77e322bb 100644 --- a/esphome/components/ens160_base/__init__.py +++ b/esphome/components/ens160_base/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_COMPENSATION, CONF_ECO2, diff --git a/esphome/components/ens160_i2c/sensor.py b/esphome/components/ens160_i2c/sensor.py index 96cbbaa7e99..cad4e81afc2 100644 --- a/esphome/components/ens160_i2c/sensor.py +++ b/esphome/components/ens160_i2c/sensor.py @@ -1,6 +1,7 @@ import esphome.codegen as cg from esphome.components import i2c -from ..ens160_base import to_code_base, cv, CONFIG_SCHEMA_BASE + +from ..ens160_base import CONFIG_SCHEMA_BASE, cv, to_code_base AUTO_LOAD = ["ens160_base"] CODEOWNERS = ["@latonita"] diff --git a/esphome/components/ens160_spi/sensor.py b/esphome/components/ens160_spi/sensor.py index 552697fe1b5..1bda05c7bb9 100644 --- a/esphome/components/ens160_spi/sensor.py +++ b/esphome/components/ens160_spi/sensor.py @@ -1,6 +1,7 @@ import esphome.codegen as cg from esphome.components import spi -from ..ens160_base import to_code_base, cv, CONFIG_SCHEMA_BASE + +from ..ens160_base import CONFIG_SCHEMA_BASE, cv, to_code_base AUTO_LOAD = ["ens160_base"] CODEOWNERS = ["@latonita"] diff --git a/esphome/components/ens210/sensor.py b/esphome/components/ens210/sensor.py index 3037156e01e..289a5596739 100644 --- a/esphome/components/ens210/sensor.py +++ b/esphome/components/ens210/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/esp32/__init__.py b/esphome/components/esp32/__init__.py index 23b84f3d137..912a8bf94be 100644 --- a/esphome/components/esp32/__init__.py +++ b/esphome/components/esp32/__init__.py @@ -67,6 +67,7 @@ AUTO_LOAD = ["preferences"] IS_TARGET_PLATFORM = True CONF_RELEASE = "release" +CONF_ENABLE_IDF_EXPERIMENTAL_FEATURES = "enable_idf_experimental_features" def set_core_data(config): @@ -273,6 +274,9 @@ SUPPORTED_PLATFORMIO_ESP_IDF_5X = [ # pioarduino versions that don't require a release number # List based on https://github.com/pioarduino/esp-idf/releases SUPPORTED_PIOARDUINO_ESP_IDF_5X = [ + cv.Version(5, 4, 1), + cv.Version(5, 4, 0), + cv.Version(5, 3, 2), cv.Version(5, 3, 1), cv.Version(5, 3, 0), cv.Version(5, 1, 5), @@ -503,6 +507,7 @@ ESP_IDF_FRAMEWORK_SCHEMA = cv.All( CONF_IGNORE_EFUSE_CUSTOM_MAC, default=False ): cv.boolean, cv.Optional(CONF_IGNORE_EFUSE_MAC_CRC): cv.boolean, + cv.Optional(CONF_ENABLE_IDF_EXPERIMENTAL_FEATURES): cv.boolean, } ), cv.Optional(CONF_COMPONENTS, default=[]): cv.ensure_list( @@ -642,6 +647,11 @@ async def to_code(config): add_idf_sdkconfig_option( "CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE", False ) + if conf[CONF_ADVANCED].get(CONF_ENABLE_IDF_EXPERIMENTAL_FEATURES): + _LOGGER.warning( + "Using experimental features in ESP-IDF may result in unexpected failures." + ) + add_idf_sdkconfig_option("CONFIG_IDF_EXPERIMENTAL_FEATURES", True) cg.add_define( "USE_ESP_IDF_VERSION_CODE", diff --git a/esphome/components/esp32_ble_tracker/__init__.py b/esphome/components/esp32_ble_tracker/__init__.py index 425ce54b9f2..68be2cbbe90 100644 --- a/esphome/components/esp32_ble_tracker/__init__.py +++ b/esphome/components/esp32_ble_tracker/__init__.py @@ -1,3 +1,9 @@ +from __future__ import annotations + +from collections.abc import MutableMapping +import logging +from typing import Any, Callable + from esphome import automation import esphome.codegen as cg from esphome.components import esp32_ble @@ -29,11 +35,21 @@ from esphome.core import CORE AUTO_LOAD = ["esp32_ble"] DEPENDENCIES = ["esp32"] +KEY_ESP32_BLE_TRACKER = "esp32_ble_tracker" +KEY_USED_CONNECTION_SLOTS = "used_connection_slots" + +CONF_MAX_CONNECTIONS = "max_connections" CONF_ESP32_BLE_ID = "esp32_ble_id" CONF_SCAN_PARAMETERS = "scan_parameters" CONF_WINDOW = "window" CONF_CONTINUOUS = "continuous" CONF_ON_SCAN_END = "on_scan_end" + +DEFAULT_MAX_CONNECTIONS = 3 +IDF_MAX_CONNECTIONS = 9 + +_LOGGER = logging.getLogger(__name__) + esp32_ble_tracker_ns = cg.esphome_ns.namespace("esp32_ble_tracker") ESP32BLETracker = esp32_ble_tracker_ns.class_( "ESP32BLETracker", @@ -112,61 +128,126 @@ def as_reversed_hex_array(value): ) -CONFIG_SCHEMA = cv.Schema( - { - cv.GenerateID(): cv.declare_id(ESP32BLETracker), - cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE), - cv.Optional(CONF_SCAN_PARAMETERS, default={}): cv.All( - cv.Schema( +def max_connections() -> int: + return IDF_MAX_CONNECTIONS if CORE.using_esp_idf else DEFAULT_MAX_CONNECTIONS + + +def consume_connection_slots( + value: int, consumer: str +) -> Callable[[MutableMapping], MutableMapping]: + def _consume_connection_slots(config: MutableMapping) -> MutableMapping: + data: dict[str, Any] = CORE.data.setdefault(KEY_ESP32_BLE_TRACKER, {}) + slots: list[str] = data.setdefault(KEY_USED_CONNECTION_SLOTS, []) + slots.extend([consumer] * value) + return config + + return _consume_connection_slots + + +CONFIG_SCHEMA = cv.All( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(ESP32BLETracker), + cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE), + cv.Optional(CONF_MAX_CONNECTIONS, default=DEFAULT_MAX_CONNECTIONS): cv.All( + cv.positive_int, cv.Range(min=0, max=max_connections()) + ), + cv.Optional(CONF_SCAN_PARAMETERS, default={}): cv.All( + cv.Schema( + { + cv.Optional( + CONF_DURATION, default="5min" + ): cv.positive_time_period_seconds, + cv.Optional( + CONF_INTERVAL, default="320ms" + ): cv.positive_time_period_milliseconds, + cv.Optional( + CONF_WINDOW, default="30ms" + ): cv.positive_time_period_milliseconds, + cv.Optional(CONF_ACTIVE, default=True): cv.boolean, + cv.Optional(CONF_CONTINUOUS, default=True): cv.boolean, + } + ), + validate_scan_parameters, + ), + cv.Optional(CONF_ON_BLE_ADVERTISE): automation.validate_automation( { - cv.Optional( - CONF_DURATION, default="5min" - ): cv.positive_time_period_seconds, - cv.Optional( - CONF_INTERVAL, default="320ms" - ): cv.positive_time_period_milliseconds, - cv.Optional( - CONF_WINDOW, default="30ms" - ): cv.positive_time_period_milliseconds, - cv.Optional(CONF_ACTIVE, default=True): cv.boolean, - cv.Optional(CONF_CONTINUOUS, default=True): cv.boolean, + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( + ESPBTAdvertiseTrigger + ), + cv.Optional(CONF_MAC_ADDRESS): cv.ensure_list(cv.mac_address), } ), - validate_scan_parameters, - ), - cv.Optional(CONF_ON_BLE_ADVERTISE): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ESPBTAdvertiseTrigger), - cv.Optional(CONF_MAC_ADDRESS): cv.ensure_list(cv.mac_address), - } - ), - cv.Optional(CONF_ON_BLE_SERVICE_DATA_ADVERTISE): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( - BLEServiceDataAdvertiseTrigger - ), - cv.Optional(CONF_MAC_ADDRESS): cv.mac_address, - cv.Required(CONF_SERVICE_UUID): bt_uuid, - } - ), - cv.Optional( - CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE - ): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( - BLEManufacturerDataAdvertiseTrigger - ), - cv.Optional(CONF_MAC_ADDRESS): cv.mac_address, - cv.Required(CONF_MANUFACTURER_ID): bt_uuid, - } - ), - cv.Optional(CONF_ON_SCAN_END): automation.validate_automation( - {cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(BLEEndOfScanTrigger)} - ), - } -).extend(cv.COMPONENT_SCHEMA) + cv.Optional( + CONF_ON_BLE_SERVICE_DATA_ADVERTISE + ): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( + BLEServiceDataAdvertiseTrigger + ), + cv.Optional(CONF_MAC_ADDRESS): cv.mac_address, + cv.Required(CONF_SERVICE_UUID): bt_uuid, + } + ), + cv.Optional( + CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE + ): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( + BLEManufacturerDataAdvertiseTrigger + ), + cv.Optional(CONF_MAC_ADDRESS): cv.mac_address, + cv.Required(CONF_MANUFACTURER_ID): bt_uuid, + } + ), + cv.Optional(CONF_ON_SCAN_END): automation.validate_automation( + {cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(BLEEndOfScanTrigger)} + ), + } + ).extend(cv.COMPONENT_SCHEMA), +) -FINAL_VALIDATE_SCHEMA = esp32_ble.validate_variant + +def validate_remaining_connections(config): + data: dict[str, Any] = CORE.data.get(KEY_ESP32_BLE_TRACKER, {}) + slots: list[str] = data.get(KEY_USED_CONNECTION_SLOTS, []) + used_slots = len(slots) + if used_slots <= config[CONF_MAX_CONNECTIONS]: + return config + slot_users = ", ".join(slots) + hard_limit = max_connections() + + if used_slots < hard_limit: + _LOGGER.warning( + "esp32_ble_tracker exceeded `%s`: components attempted to consume %d " + "connection slot(s) out of available configured maximum %d connection " + "slot(s); The system automatically increased `%s` to %d to match the " + "number of used connection slot(s) by components: %s.", + CONF_MAX_CONNECTIONS, + used_slots, + config[CONF_MAX_CONNECTIONS], + CONF_MAX_CONNECTIONS, + used_slots, + slot_users, + ) + config[CONF_MAX_CONNECTIONS] = used_slots + return config + + msg = ( + f"esp32_ble_tracker exceeded `{CONF_MAX_CONNECTIONS}`: " + f"components attempted to consume {used_slots} connection slot(s) " + f"out of available configured maximum {config[CONF_MAX_CONNECTIONS]} " + f"connection slot(s); Decrease the number of BLE clients ({slot_users})" + ) + if config[CONF_MAX_CONNECTIONS] < hard_limit: + msg += f" or increase {CONF_MAX_CONNECTIONS}` to {used_slots}" + msg += f" to stay under the {hard_limit} connection slot(s) limit." + raise cv.Invalid(msg) + + +FINAL_VALIDATE_SCHEMA = cv.All( + validate_remaining_connections, esp32_ble.validate_variant +) ESP_BLE_DEVICE_SCHEMA = cv.Schema( { @@ -238,6 +319,9 @@ async def to_code(config): else: add_idf_sdkconfig_option("CONFIG_BTU_TASK_STACK_SIZE", 8192) add_idf_sdkconfig_option("CONFIG_BT_ACL_CONNECTIONS", 9) + add_idf_sdkconfig_option( + "CONFIG_BTDM_CTRL_BLE_MAX_CONN", config[CONF_MAX_CONNECTIONS] + ) # CONFIG_BT_GATTC_NOTIF_REG_MAX controls the number of # max notifications in 5.x, setting CONFIG_BT_ACL_CONNECTIONS # is enough in 4.x diff --git a/esphome/components/esp32_camera/__init__.py b/esphome/components/esp32_camera/__init__.py index 2f1f9b90bb6..e55c54f0971 100644 --- a/esphome/components/esp32_camera/__init__.py +++ b/esphome/components/esp32_camera/__init__.py @@ -1,23 +1,22 @@ +from esphome import automation, pins import esphome.codegen as cg +from esphome.components.esp32 import add_idf_component import esphome.config_validation as cv -from esphome import automation -from esphome import pins from esphome.const import ( + CONF_BRIGHTNESS, + CONF_CONTRAST, + CONF_DATA_PINS, CONF_FREQUENCY, CONF_ID, CONF_PIN, - CONF_SCL, - CONF_SDA, - CONF_DATA_PINS, CONF_RESET_PIN, CONF_RESOLUTION, - CONF_BRIGHTNESS, - CONF_CONTRAST, + CONF_SCL, + CONF_SDA, CONF_TRIGGER_ID, CONF_VSYNC_PIN, ) from esphome.core import CORE -from esphome.components.esp32 import add_idf_component from esphome.cpp_helpers import setup_entity DEPENDENCIES = ["esp32"] diff --git a/esphome/components/esp32_camera_web_server/__init__.py b/esphome/components/esp32_camera_web_server/__init__.py index d8afea27b42..363218bbacb 100644 --- a/esphome/components/esp32_camera_web_server/__init__.py +++ b/esphome/components/esp32_camera_web_server/__init__.py @@ -1,6 +1,6 @@ -import esphome.config_validation as cv import esphome.codegen as cg -from esphome.const import CONF_ID, CONF_PORT, CONF_MODE +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_MODE, CONF_PORT CODEOWNERS = ["@ayufan"] DEPENDENCIES = ["esp32_camera"] diff --git a/esphome/components/esp32_can/canbus.py b/esphome/components/esp32_can/canbus.py index 37bdfa39621..dfa98b2effa 100644 --- a/esphome/components/esp32_can/canbus.py +++ b/esphome/components/esp32_can/canbus.py @@ -1,3 +1,5 @@ +import math + from esphome import pins import esphome.codegen as cg from esphome.components import canbus @@ -23,6 +25,8 @@ from esphome.const import ( CODEOWNERS = ["@Sympatron"] DEPENDENCIES = ["esp32"] +CONF_TX_ENQUEUE_TIMEOUT = "tx_enqueue_timeout" + esp32_can_ns = cg.esphome_ns.namespace("esp32_can") esp32_can = esp32_can_ns.class_("ESP32Can", CanbusComponent) @@ -84,10 +88,20 @@ CONFIG_SCHEMA = canbus.CANBUS_SCHEMA.extend( cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_RX_QUEUE_LEN): cv.uint32_t, cv.Optional(CONF_TX_QUEUE_LEN): cv.uint32_t, + cv.Optional(CONF_TX_ENQUEUE_TIMEOUT): cv.positive_time_period_milliseconds, } ) +def get_default_tx_enqueue_timeout(bit_rate): + bit_rate_numeric = canbus.get_rate(bit_rate) + bits_per_packet = 140 # ~max CAN message length + ms_per_packet = bits_per_packet / bit_rate_numeric * 1000 + return int( + max(min(math.ceil(10 * ms_per_packet), 1000), 1) + ) # ~10 packet lengths, min 1ms, max 1000ms + + async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await canbus.register_canbus(var, config) @@ -98,3 +112,10 @@ async def to_code(config): cg.add(var.set_rx_queue_len(rx_queue_len)) if (tx_queue_len := config.get(CONF_TX_QUEUE_LEN)) is not None: cg.add(var.set_tx_queue_len(tx_queue_len)) + + if CONF_TX_ENQUEUE_TIMEOUT in config: + tx_enqueue_timeout_ms = config[CONF_TX_ENQUEUE_TIMEOUT].total_milliseconds + else: + tx_enqueue_timeout_ms = get_default_tx_enqueue_timeout(config[CONF_BIT_RATE]) + + cg.add(var.set_tx_enqueue_timeout_ms(tx_enqueue_timeout_ms)) diff --git a/esphome/components/esp32_can/esp32_can.cpp b/esphome/components/esp32_can/esp32_can.cpp index 5a45859b1fe..a40f4930755 100644 --- a/esphome/components/esp32_can/esp32_can.cpp +++ b/esphome/components/esp32_can/esp32_can.cpp @@ -124,7 +124,7 @@ canbus::Error ESP32Can::send_message(struct canbus::CanFrame *frame) { memcpy(message.data, frame->data, frame->can_data_length_code); } - if (twai_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) { + if (twai_transmit(&message, this->tx_enqueue_timeout_ticks_) == ESP_OK) { return canbus::ERROR_OK; } else { return canbus::ERROR_ALLTXBUSY; diff --git a/esphome/components/esp32_can/esp32_can.h b/esphome/components/esp32_can/esp32_can.h index b3086f9a48c..416f037083f 100644 --- a/esphome/components/esp32_can/esp32_can.h +++ b/esphome/components/esp32_can/esp32_can.h @@ -14,6 +14,9 @@ class ESP32Can : public canbus::Canbus { void set_tx(int tx) { tx_ = tx; } void set_tx_queue_len(uint32_t tx_queue_len) { this->tx_queue_len_ = tx_queue_len; } void set_rx_queue_len(uint32_t rx_queue_len) { this->rx_queue_len_ = rx_queue_len; } + void set_tx_enqueue_timeout_ms(uint32_t tx_enqueue_timeout_ms) { + this->tx_enqueue_timeout_ticks_ = pdMS_TO_TICKS(tx_enqueue_timeout_ms); + } ESP32Can(){}; protected: @@ -23,6 +26,7 @@ class ESP32Can : public canbus::Canbus { int rx_{-1}; int tx_{-1}; + TickType_t tx_enqueue_timeout_ticks_{}; optional tx_queue_len_{}; optional rx_queue_len_{}; }; diff --git a/esphome/components/esp32_dac/output.py b/esphome/components/esp32_dac/output.py index c80780986fd..cf4f12c46dc 100644 --- a/esphome/components/esp32_dac/output.py +++ b/esphome/components/esp32_dac/output.py @@ -1,9 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import output from esphome.components.esp32 import get_esp32_variant from esphome.components.esp32.const import VARIANT_ESP32, VARIANT_ESP32S2 +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_NUMBER, CONF_PIN DEPENDENCIES = ["esp32"] diff --git a/esphome/components/esp32_hall/sensor.py b/esphome/components/esp32_hall/sensor.py index 0c94224ef80..e7953d4b3d7 100644 --- a/esphome/components/esp32_hall/sensor.py +++ b/esphome/components/esp32_hall/sensor.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor -from esphome.const import ( - STATE_CLASS_MEASUREMENT, - UNIT_MICROTESLA, - ICON_MAGNET, -) +import esphome.config_validation as cv +from esphome.const import ICON_MAGNET, STATE_CLASS_MEASUREMENT, UNIT_MICROTESLA DEPENDENCIES = ["esp32"] diff --git a/esphome/components/esp32_touch/__init__.py b/esphome/components/esp32_touch/__init__.py index fc7bf200e4b..224e3016830 100644 --- a/esphome/components/esp32_touch/__init__.py +++ b/esphome/components/esp32_touch/__init__.py @@ -1,4 +1,11 @@ import esphome.codegen as cg +from esphome.components import esp32 +from esphome.components.esp32 import get_esp32_variant, gpio +from esphome.components.esp32.const import ( + VARIANT_ESP32, + VARIANT_ESP32S2, + VARIANT_ESP32S3, +) import esphome.config_validation as cv from esphome.const import ( CONF_HIGH_VOLTAGE_REFERENCE, @@ -11,13 +18,6 @@ from esphome.const import ( CONF_VOLTAGE_ATTENUATION, ) from esphome.core import TimePeriod -from esphome.components import esp32 -from esphome.components.esp32 import get_esp32_variant, gpio -from esphome.components.esp32.const import ( - VARIANT_ESP32, - VARIANT_ESP32S2, - VARIANT_ESP32S3, -) AUTO_LOAD = ["binary_sensor"] DEPENDENCIES = ["esp32"] diff --git a/esphome/components/esp32_touch/binary_sensor.py b/esphome/components/esp32_touch/binary_sensor.py index e9322b3080b..75560d71b1f 100644 --- a/esphome/components/esp32_touch/binary_sensor.py +++ b/esphome/components/esp32_touch/binary_sensor.py @@ -1,12 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import ( - CONF_PIN, - CONF_THRESHOLD, - CONF_ID, -) -from . import esp32_touch_ns, ESP32TouchComponent, validate_touch_pad +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PIN, CONF_THRESHOLD + +from . import ESP32TouchComponent, esp32_touch_ns, validate_touch_pad DEPENDENCIES = ["esp32_touch", "esp32"] diff --git a/esphome/components/esp8266_pwm/output.py b/esphome/components/esp8266_pwm/output.py index 7feee79ff25..1404ef8ac3d 100644 --- a/esphome/components/esp8266_pwm/output.py +++ b/esphome/components/esp8266_pwm/output.py @@ -1,13 +1,8 @@ -from esphome import pins, automation +from esphome import automation, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg -from esphome.const import ( - CONF_FREQUENCY, - CONF_ID, - CONF_NUMBER, - CONF_PIN, -) +from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_NUMBER, CONF_PIN DEPENDENCIES = ["esp8266"] diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index ab760a9b6cb..cd77ea60532 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -1,4 +1,5 @@ import logging + from esphome import pins import esphome.codegen as cg from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index 08f5fa6642d..68a6e617fc6 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -580,7 +580,7 @@ void EthernetComponent::get_eth_mac_address_raw(uint8_t *mac) { std::string EthernetComponent::get_eth_mac_address_pretty() { uint8_t mac[6]; - get_mac_address_raw(mac); + get_eth_mac_address_raw(mac); return str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } diff --git a/esphome/components/ethernet_info/ethernet_info_text_sensor.h b/esphome/components/ethernet_info/ethernet_info_text_sensor.h index 94eed886e5e..2e67694bbdf 100644 --- a/esphome/components/ethernet_info/ethernet_info_text_sensor.h +++ b/esphome/components/ethernet_info/ethernet_info_text_sensor.h @@ -62,6 +62,7 @@ class DNSAddressEthernetInfo : public PollingComponent, public text_sensor::Text class MACAddressEthernetInfo : public Component, public text_sensor::TextSensor { public: void setup() override { this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty()); } + float get_setup_priority() const override { return setup_priority::ETHERNET; } std::string unique_id() override { return get_mac_address() + "-ethernetinfo-mac"; } void dump_config() override; }; diff --git a/esphome/components/exposure_notifications/__init__.py b/esphome/components/exposure_notifications/__init__.py index 9c285522671..ab7416a2641 100644 --- a/esphome/components/exposure_notifications/__init__.py +++ b/esphome/components/exposure_notifications/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg from esphome import automation -import esphome.config_validation as cv +import esphome.codegen as cg from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_TRIGGER_ID CODEOWNERS = ["@OttoWinter"] diff --git a/esphome/components/external_components/__init__.py b/esphome/components/external_components/__init__.py index f4432a03626..a09217fd21f 100644 --- a/esphome/components/external_components/__init__.py +++ b/esphome/components/external_components/__init__.py @@ -1,8 +1,8 @@ import logging from pathlib import Path -import esphome.config_validation as cv from esphome import git, loader +import esphome.config_validation as cv from esphome.const import ( CONF_COMPONENTS, CONF_EXTERNAL_COMPONENTS, diff --git a/esphome/components/ezo/sensor.py b/esphome/components/ezo/sensor.py index 486ba0126e0..cf240faec32 100644 --- a/esphome/components/ezo/sensor.py +++ b/esphome/components/ezo/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_TRIGGER_ID CODEOWNERS = ["@ssieb"] diff --git a/esphome/components/ezo_pmp/__init__.py b/esphome/components/ezo_pmp/__init__.py index 87cda41f898..c1f72bb05d5 100644 --- a/esphome/components/ezo_pmp/__init__.py +++ b/esphome/components/ezo_pmp/__init__.py @@ -1,15 +1,15 @@ +from esphome import automation +from esphome.automation import maybe_simple_id import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ADDRESS, CONF_COMMAND, - CONF_ID, CONF_DURATION, + CONF_ID, CONF_VOLUME, ) -from esphome import automation -from esphome.automation import maybe_simple_id CODEOWNERS = ["@carlos-sarmiento"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ezo_pmp/binary_sensor.py b/esphome/components/ezo_pmp/binary_sensor.py index 582eb7af257..a81b6c09f05 100644 --- a/esphome/components/ezo_pmp/binary_sensor.py +++ b/esphome/components/ezo_pmp/binary_sensor.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( - ENTITY_CATEGORY_NONE, - DEVICE_CLASS_RUNNING, - DEVICE_CLASS_EMPTY, CONF_ID, + DEVICE_CLASS_EMPTY, + DEVICE_CLASS_RUNNING, + ENTITY_CATEGORY_NONE, ) from . import EzoPMP diff --git a/esphome/components/ezo_pmp/sensor.py b/esphome/components/ezo_pmp/sensor.py index 737985f4c55..a0473b292cf 100644 --- a/esphome/components/ezo_pmp/sensor.py +++ b/esphome/components/ezo_pmp/sensor.py @@ -1,20 +1,19 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - ENTITY_CATEGORY_DIAGNOSTIC, - ENTITY_CATEGORY_NONE, + CONF_ID, DEVICE_CLASS_EMPTY, DEVICE_CLASS_VOLTAGE, + ENTITY_CATEGORY_DIAGNOSTIC, + ENTITY_CATEGORY_NONE, STATE_CLASS_MEASUREMENT, STATE_CLASS_NONE, - CONF_ID, UNIT_VOLT, ) from . import EzoPMP - DEPENDENCIES = ["ezo_pmp"] CONF_CURRENT_VOLUME_DOSED = "current_volume_dosed" diff --git a/esphome/components/ezo_pmp/text_sensor.py b/esphome/components/ezo_pmp/text_sensor.py index f8f133e316c..afae1e5188f 100644 --- a/esphome/components/ezo_pmp/text_sensor.py +++ b/esphome/components/ezo_pmp/text_sensor.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor -from esphome.const import ( - ENTITY_CATEGORY_NONE, - ENTITY_CATEGORY_DIAGNOSTIC, - CONF_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_NONE from . import EzoPMP diff --git a/esphome/components/factory_reset/button/__init__.py b/esphome/components/factory_reset/button/__init__.py index 010691ac7f1..61df5f297b7 100644 --- a/esphome/components/factory_reset/button/__init__.py +++ b/esphome/components/factory_reset/button/__init__.py @@ -1,12 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button +import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_RESTART, ENTITY_CATEGORY_CONFIG, ICON_RESTART_ALERT, ) + from .. import factory_reset_ns FactoryResetButton = factory_reset_ns.class_( diff --git a/esphome/components/factory_reset/switch/__init__.py b/esphome/components/factory_reset/switch/__init__.py index 3cc19a35a31..17f4587e5df 100644 --- a/esphome/components/factory_reset/switch/__init__.py +++ b/esphome/components/factory_reset/switch/__init__.py @@ -1,14 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch +import esphome.config_validation as cv from esphome.const import ( CONF_ENTITY_CATEGORY, + CONF_ICON, CONF_ID, CONF_INVERTED, - CONF_ICON, ENTITY_CATEGORY_CONFIG, ICON_RESTART_ALERT, ) + from .. import factory_reset_ns FactoryResetSwitch = factory_reset_ns.class_( diff --git a/esphome/components/fastled_base/__init__.py b/esphome/components/fastled_base/__init__.py index 62de036e625..1e70e14f10e 100644 --- a/esphome/components/fastled_base/__init__.py +++ b/esphome/components/fastled_base/__init__.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light +import esphome.config_validation as cv from esphome.const import ( - CONF_OUTPUT_ID, - CONF_NUM_LEDS, - CONF_RGB_ORDER, CONF_MAX_REFRESH_RATE, + CONF_NUM_LEDS, + CONF_OUTPUT_ID, + CONF_RGB_ORDER, ) CODEOWNERS = ["@OttoWinter"] diff --git a/esphome/components/fastled_clockless/light.py b/esphome/components/fastled_clockless/light.py index dc456d49594..49a6d390be9 100644 --- a/esphome/components/fastled_clockless/light.py +++ b/esphome/components/fastled_clockless/light.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import fastled_base +import esphome.config_validation as cv from esphome.const import CONF_CHIPSET, CONF_NUM_LEDS, CONF_PIN, CONF_RGB_ORDER AUTO_LOAD = ["fastled_base"] diff --git a/esphome/components/fastled_spi/light.py b/esphome/components/fastled_spi/light.py index b3ce1722ee3..ac30721eb4b 100644 --- a/esphome/components/fastled_spi/light.py +++ b/esphome/components/fastled_spi/light.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import fastled_base +import esphome.config_validation as cv from esphome.const import ( CONF_CHIPSET, CONF_CLOCK_PIN, diff --git a/esphome/components/feedback/cover.py b/esphome/components/feedback/cover.py index 450eb967b12..b90374f6e8a 100644 --- a/esphome/components/feedback/cover.py +++ b/esphome/components/feedback/cover.py @@ -1,18 +1,18 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import binary_sensor, cover +import esphome.config_validation as cv from esphome.const import ( CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_CLOSE_ENDSTOP, CONF_ID, + CONF_MAX_DURATION, CONF_OPEN_ACTION, CONF_OPEN_DURATION, CONF_OPEN_ENDSTOP, CONF_STOP_ACTION, - CONF_MAX_DURATION, CONF_UPDATE_INTERVAL, ) diff --git a/esphome/components/fingerprint_grow/__init__.py b/esphome/components/fingerprint_grow/__init__.py index 23651bd0490..115b89433bc 100644 --- a/esphome/components/fingerprint_grow/__init__.py +++ b/esphome/components/fingerprint_grow/__init__.py @@ -1,8 +1,7 @@ +from esphome import automation, pins import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import automation -from esphome import pins from esphome.components import uart +import esphome.config_validation as cv from esphome.const import ( CONF_COLOR, CONF_COUNT, @@ -13,11 +12,11 @@ from esphome.const import ( CONF_ON_ENROLLMENT_DONE, CONF_ON_ENROLLMENT_FAILED, CONF_ON_ENROLLMENT_SCAN, - CONF_ON_FINGER_SCAN_START, - CONF_ON_FINGER_SCAN_MATCHED, - CONF_ON_FINGER_SCAN_UNMATCHED, - CONF_ON_FINGER_SCAN_MISPLACED, CONF_ON_FINGER_SCAN_INVALID, + CONF_ON_FINGER_SCAN_MATCHED, + CONF_ON_FINGER_SCAN_MISPLACED, + CONF_ON_FINGER_SCAN_START, + CONF_ON_FINGER_SCAN_UNMATCHED, CONF_PASSWORD, CONF_SENSING_PIN, CONF_SPEED, diff --git a/esphome/components/fingerprint_grow/binary_sensor.py b/esphome/components/fingerprint_grow/binary_sensor.py index 8572919e369..5b8441ddfe1 100644 --- a/esphome/components/fingerprint_grow/binary_sensor.py +++ b/esphome/components/fingerprint_grow/binary_sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_ICON, ICON_KEY_PLUS + from . import CONF_FINGERPRINT_GROW_ID, FingerprintGrowComponent DEPENDENCIES = ["fingerprint_grow"] diff --git a/esphome/components/fingerprint_grow/sensor.py b/esphome/components/fingerprint_grow/sensor.py index ed4e431dcc4..d1655a6be16 100644 --- a/esphome/components/fingerprint_grow/sensor.py +++ b/esphome/components/fingerprint_grow/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CAPACITY, CONF_FINGERPRINT_COUNT, @@ -15,6 +15,7 @@ from esphome.const import ( ICON_FINGERPRINT, ICON_SECURITY, ) + from . import CONF_FINGERPRINT_GROW_ID, FingerprintGrowComponent DEPENDENCIES = ["fingerprint_grow"] diff --git a/esphome/components/fs3000/sensor.py b/esphome/components/fs3000/sensor.py index 0c50f529792..a168a36c31a 100644 --- a/esphome/components/fs3000/sensor.py +++ b/esphome/components/fs3000/sensor.py @@ -1,13 +1,9 @@ # initially based off of TMP117 component import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor -from esphome.const import ( - CONF_MODEL, - DEVICE_CLASS_WIND_SPEED, - STATE_CLASS_MEASUREMENT, -) +import esphome.config_validation as cv +from esphome.const import CONF_MODEL, DEVICE_CLASS_WIND_SPEED, STATE_CLASS_MEASUREMENT DEPENDENCIES = ["i2c"] CODEOWNERS = ["@kahrendt"] diff --git a/esphome/components/ft5x06/touchscreen/__init__.py b/esphome/components/ft5x06/touchscreen/__init__.py index 4ceb50c7097..e94791da4e8 100644 --- a/esphome/components/ft5x06/touchscreen/__init__.py +++ b/esphome/components/ft5x06/touchscreen/__init__.py @@ -1,9 +1,9 @@ from esphome import pins import esphome.codegen as cg -import esphome.config_validation as cv - from esphome.components import i2c, touchscreen +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTERRUPT_PIN + from .. import ft5x06_ns FT5x06ButtonListener = ft5x06_ns.class_("FT5x06ButtonListener") diff --git a/esphome/components/ft63x6/touchscreen.py b/esphome/components/ft63x6/touchscreen.py index 95fa3714338..7615b3046fb 100644 --- a/esphome/components/ft63x6/touchscreen.py +++ b/esphome/components/ft63x6/touchscreen.py @@ -1,8 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, touchscreen +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTERRUPT_PIN, CONF_RESET_PIN, CONF_THRESHOLD CODEOWNERS = ["@gpambrozio"] diff --git a/esphome/components/fujitsu_general/climate.py b/esphome/components/fujitsu_general/climate.py index 427721f2db0..6d2e46512e3 100644 --- a/esphome/components/fujitsu_general/climate.py +++ b/esphome/components/fujitsu_general/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/gcja5/sensor.py b/esphome/components/gcja5/sensor.py index 5bcdc572ff5..ec26447ccb8 100644 --- a/esphome/components/gcja5/sensor.py +++ b/esphome/components/gcja5/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import sensor, uart import esphome.config_validation as cv -from esphome.components import uart, sensor from esphome.const import ( CONF_ID, CONF_PM_1_0, @@ -10,13 +10,13 @@ from esphome.const import ( CONF_PMC_1_0, CONF_PMC_2_5, CONF_PMC_10_0, - UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_CHEMICAL_WEAPON, - ICON_COUNTER, DEVICE_CLASS_PM1, DEVICE_CLASS_PM10, DEVICE_CLASS_PM25, + ICON_CHEMICAL_WEAPON, + ICON_COUNTER, STATE_CLASS_MEASUREMENT, + UNIT_MICROGRAMS_PER_CUBIC_METER, ) CODEOWNERS = ["@gcormier"] diff --git a/esphome/components/gdk101/__init__.py b/esphome/components/gdk101/__init__.py index 0d902579643..878f27bc446 100644 --- a/esphome/components/gdk101/__init__.py +++ b/esphome/components/gdk101/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@Szewcson"] diff --git a/esphome/components/gdk101/binary_sensor.py b/esphome/components/gdk101/binary_sensor.py index 2a3d6f07eb9..a80487977fa 100644 --- a/esphome/components/gdk101/binary_sensor.py +++ b/esphome/components/gdk101/binary_sensor.py @@ -1,12 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( CONF_VIBRATIONS, DEVICE_CLASS_VIBRATION, ENTITY_CATEGORY_DIAGNOSTIC, ICON_VIBRATE, ) + from . import CONF_GDK101_ID, GDK101Component DEPENDENCIES = ["gdk101"] diff --git a/esphome/components/gdk101/sensor.py b/esphome/components/gdk101/sensor.py index f7822646150..d04e0b8367b 100644 --- a/esphome/components/gdk101/sensor.py +++ b/esphome/components/gdk101/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - DEVICE_CLASS_DURATION, - DEVICE_CLASS_EMPTY, - ENTITY_CATEGORY_DIAGNOSTIC, CONF_MEASUREMENT_DURATION, CONF_STATUS, CONF_VERSION, + DEVICE_CLASS_DURATION, + DEVICE_CLASS_EMPTY, + ENTITY_CATEGORY_DIAGNOSTIC, ICON_RADIOACTIVE, ICON_TIMER, STATE_CLASS_MEASUREMENT, @@ -15,6 +15,7 @@ from esphome.const import ( UNIT_MICROSILVERTS_PER_HOUR, UNIT_SECOND, ) + from . import CONF_GDK101_ID, GDK101Component CONF_RADIATION_DOSE_PER_1M = "radiation_dose_per_1m" diff --git a/esphome/components/globals/__init__.py b/esphome/components/globals/__init__.py index 8defa4ac24e..e4bce99b0bc 100644 --- a/esphome/components/globals/__init__.py +++ b/esphome/components/globals/__init__.py @@ -1,7 +1,6 @@ import hashlib -from esphome import config_validation as cv, automation -from esphome import codegen as cg +from esphome import automation, codegen as cg, config_validation as cv from esphome.const import ( CONF_ID, CONF_INITIAL_VALUE, diff --git a/esphome/components/gp2y1010au0f/sensor.py b/esphome/components/gp2y1010au0f/sensor.py index 7e1bd277a61..4ff8a382269 100644 --- a/esphome/components/gp2y1010au0f/sensor.py +++ b/esphome/components/gp2y1010au0f/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg +from esphome.components import output, sensor, voltage_sampler import esphome.config_validation as cv -from esphome.components import sensor, voltage_sampler, output from esphome.const import ( - CONF_SENSOR, CONF_OUTPUT, + CONF_SENSOR, DEVICE_CLASS_PM25, + ICON_CHEMICAL_WEAPON, STATE_CLASS_MEASUREMENT, UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_CHEMICAL_WEAPON, ) DEPENDENCIES = ["output"] diff --git a/esphome/components/gp8403/__init__.py b/esphome/components/gp8403/__init__.py index a7a2b46f589..96f1807688d 100644 --- a/esphome/components/gp8403/__init__.py +++ b/esphome/components/gp8403/__init__.py @@ -1,7 +1,6 @@ -import esphome.config_validation as cv import esphome.codegen as cg - from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_VOLTAGE CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/gp8403/output/__init__.py b/esphome/components/gp8403/output/__init__.py index 7f17faa1b17..dc57833f4a7 100644 --- a/esphome/components/gp8403/output/__init__.py +++ b/esphome/components/gp8403/output/__init__.py @@ -1,10 +1,9 @@ -import esphome.config_validation as cv import esphome.codegen as cg - from esphome.components import i2c, output -from esphome.const import CONF_ID, CONF_CHANNEL +import esphome.config_validation as cv +from esphome.const import CONF_CHANNEL, CONF_ID -from .. import gp8403_ns, GP8403, CONF_GP8403_ID +from .. import CONF_GP8403_ID, GP8403, gp8403_ns DEPENDENCIES = ["gp8403"] diff --git a/esphome/components/gpio/binary_sensor/__init__.py b/esphome/components/gpio/binary_sensor/__init__.py index 786c3f4b967..23f27810950 100644 --- a/esphome/components/gpio/binary_sensor/__init__.py +++ b/esphome/components/gpio/binary_sensor/__init__.py @@ -1,8 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_PIN + from .. import gpio_ns GPIOBinarySensor = gpio_ns.class_( diff --git a/esphome/components/gpio/one_wire/__init__.py b/esphome/components/gpio/one_wire/__init__.py index 2166e920836..e2bb94dd666 100644 --- a/esphome/components/gpio/one_wire/__init__.py +++ b/esphome/components/gpio/one_wire/__init__.py @@ -1,8 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins -from esphome.const import CONF_ID, CONF_PIN +import esphome.codegen as cg from esphome.components.one_wire import OneWireBus +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PIN + from .. import gpio_ns CODEOWNERS = ["@ssieb"] diff --git a/esphome/components/gpio/output/__init__.py b/esphome/components/gpio/output/__init__.py index 2fa9f4dc787..786e04bac04 100644 --- a/esphome/components/gpio/output/__init__.py +++ b/esphome/components/gpio/output/__init__.py @@ -1,8 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_PIN + from .. import gpio_ns GPIOBinaryOutput = gpio_ns.class_("GPIOBinaryOutput", output.BinaryOutput, cg.Component) diff --git a/esphome/components/gpio/switch/__init__.py b/esphome/components/gpio/switch/__init__.py index 9da6870a46c..604de6d8092 100644 --- a/esphome/components/gpio/switch/__init__.py +++ b/esphome/components/gpio/switch/__init__.py @@ -1,8 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import switch +import esphome.config_validation as cv from esphome.const import CONF_INTERLOCK, CONF_PIN + from .. import gpio_ns GPIOSwitch = gpio_ns.class_("GPIOSwitch", switch.Switch, cg.Component) diff --git a/esphome/components/gps/__init__.py b/esphome/components/gps/__init__.py index d4cf79b49ef..51288ccc303 100644 --- a/esphome/components/gps/__init__.py +++ b/esphome/components/gps/__init__.py @@ -1,15 +1,14 @@ import esphome.codegen as cg +from esphome.components import sensor, uart import esphome.config_validation as cv -from esphome.components import uart -from esphome.components import sensor from esphome.const import ( + CONF_ALTITUDE, + CONF_COURSE, CONF_ID, CONF_LATITUDE, CONF_LONGITUDE, - CONF_SPEED, - CONF_COURSE, - CONF_ALTITUDE, CONF_SATELLITES, + CONF_SPEED, STATE_CLASS_MEASUREMENT, UNIT_DEGREES, UNIT_KILOMETER_PER_HOUR, diff --git a/esphome/components/gps/time/__init__.py b/esphome/components/gps/time/__init__.py index 1dae22a2b23..bdeeb86e007 100644 --- a/esphome/components/gps/time/__init__.py +++ b/esphome/components/gps/time/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import time as time_ import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_ID -from .. import gps_ns, GPSListener, CONF_GPS_ID, GPS + +from .. import CONF_GPS_ID, GPS, GPSListener, gps_ns DEPENDENCIES = ["gps"] diff --git a/esphome/components/graph/__init__.py b/esphome/components/graph/__init__.py index 0b83b71fe49..254294619ef 100644 --- a/esphome/components/graph/__init__.py +++ b/esphome/components/graph/__init__.py @@ -1,32 +1,32 @@ -from esphome.components.font import Font -from esphome.components import sensor, color -import esphome.config_validation as cv import esphome.codegen as cg +from esphome.components import color, sensor +from esphome.components.font import Font +import esphome.config_validation as cv from esphome.const import ( + CONF_BORDER, CONF_COLOR, CONF_DIRECTION, CONF_DURATION, + CONF_HEIGHT, CONF_ID, CONF_LEGEND, + CONF_LINE_THICKNESS, + CONF_LINE_TYPE, + CONF_MAX_RANGE, + CONF_MAX_VALUE, + CONF_MIN_RANGE, + CONF_MIN_VALUE, CONF_NAME, CONF_NAME_FONT, + CONF_SENSOR, CONF_SHOW_LINES, CONF_SHOW_UNITS, CONF_SHOW_VALUES, + CONF_TRACES, CONF_VALUE_FONT, CONF_WIDTH, - CONF_SENSOR, - CONF_HEIGHT, - CONF_MIN_VALUE, - CONF_MAX_VALUE, - CONF_MIN_RANGE, - CONF_MAX_RANGE, - CONF_LINE_THICKNESS, - CONF_LINE_TYPE, CONF_X_GRID, CONF_Y_GRID, - CONF_BORDER, - CONF_TRACES, ) CODEOWNERS = ["@synco"] diff --git a/esphome/components/grove_tb6612fng/__init__.py b/esphome/components/grove_tb6612fng/__init__.py index 7db0198a89e..869c05387ff 100644 --- a/esphome/components/grove_tb6612fng/__init__.py +++ b/esphome/components/grove_tb6612fng/__init__.py @@ -1,14 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import i2c - +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, - CONF_CHANNEL, - CONF_SPEED, - CONF_DIRECTION, CONF_ADDRESS, + CONF_CHANNEL, + CONF_DIRECTION, + CONF_ID, + CONF_SPEED, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/growatt_solar/sensor.py b/esphome/components/growatt_solar/sensor.py index 0db15ae53e5..19f3adfd0e1 100644 --- a/esphome/components/growatt_solar/sensor.py +++ b/esphome/components/growatt_solar/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import modbus, sensor import esphome.config_validation as cv -from esphome.components import sensor, modbus from esphome.const import ( CONF_ACTIVE_POWER, CONF_CURRENT, diff --git a/esphome/components/gt911/binary_sensor/__init__.py b/esphome/components/gt911/binary_sensor/__init__.py index 18f5c49dbd5..941b7bb847b 100644 --- a/esphome/components/gt911/binary_sensor/__init__.py +++ b/esphome/components/gt911/binary_sensor/__init__.py @@ -1,10 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_INDEX from .. import gt911_ns -from ..touchscreen import GT911Touchscreen, GT911ButtonListener +from ..touchscreen import GT911ButtonListener, GT911Touchscreen CONF_GT911_ID = "gt911_id" diff --git a/esphome/components/haier/binary_sensor/__init__.py b/esphome/components/haier/binary_sensor/__init__.py index 3a4935b22dc..2486b631557 100644 --- a/esphome/components/haier/binary_sensor/__init__.py +++ b/esphome/components/haier/binary_sensor/__init__.py @@ -1,15 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import ( - ENTITY_CATEGORY_DIAGNOSTIC, - ICON_FAN, - ICON_RADIATOR, -) -from ..climate import ( - CONF_HAIER_ID, - HonClimate, -) +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_DIAGNOSTIC, ICON_FAN, ICON_RADIATOR + +from ..climate import CONF_HAIER_ID, HonClimate CODEOWNERS = ["@paveldn"] BinarySensorTypeEnum = HonClimate.enum("SubBinarySensorType", True) diff --git a/esphome/components/haier/button/__init__.py b/esphome/components/haier/button/__init__.py index 745ad95fb66..28bb5045c36 100644 --- a/esphome/components/haier/button/__init__.py +++ b/esphome/components/haier/button/__init__.py @@ -1,11 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button -from ..climate import ( - CONF_HAIER_ID, - HonClimate, - haier_ns, -) +import esphome.config_validation as cv + +from ..climate import CONF_HAIER_ID, HonClimate, haier_ns CODEOWNERS = ["@paveldn"] SelfCleaningButton = haier_ns.class_("SelfCleaningButton", button.Button) diff --git a/esphome/components/haier/sensor/__init__.py b/esphome/components/haier/sensor/__init__.py index 23c1d6f0085..e9025b560ee 100644 --- a/esphome/components/haier/sensor/__init__.py +++ b/esphome/components/haier/sensor/__init__.py @@ -1,10 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_HUMIDITY, CONF_OUTDOOR_TEMPERATURE, CONF_POWER, - CONF_HUMIDITY, DEVICE_CLASS_CURRENT, DEVICE_CLASS_FREQUENCY, DEVICE_CLASS_HUMIDITY, @@ -26,10 +26,8 @@ from esphome.const import ( UNIT_PERCENT, UNIT_WATT, ) -from ..climate import ( - CONF_HAIER_ID, - HonClimate, -) + +from ..climate import CONF_HAIER_ID, HonClimate CODEOWNERS = ["@paveldn"] SensorTypeEnum = HonClimate.enum("SubSensorType", True) diff --git a/esphome/components/haier/switch/__init__.py b/esphome/components/haier/switch/__init__.py index 6076cb0bd59..acff0cf265c 100644 --- a/esphome/components/haier/switch/__init__.py +++ b/esphome/components/haier/switch/__init__.py @@ -1,18 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv from esphome.components import switch -from esphome.const import ( - CONF_BEEPER, - CONF_DISPLAY, - ENTITY_CATEGORY_CONFIG, -) +import esphome.config_validation as cv +from esphome.const import CONF_BEEPER, CONF_DISPLAY, ENTITY_CATEGORY_CONFIG +import esphome.final_validate as fv + from ..climate import ( CONF_HAIER_ID, CONF_PROTOCOL, + PROTOCOL_HON, HaierClimateBase, haier_ns, - PROTOCOL_HON, ) CODEOWNERS = ["@paveldn"] diff --git a/esphome/components/haier/text_sensor/__init__.py b/esphome/components/haier/text_sensor/__init__.py index d28c5a8c0e2..67f9fe12245 100644 --- a/esphome/components/haier/text_sensor/__init__.py +++ b/esphome/components/haier/text_sensor/__init__.py @@ -1,14 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor -from esphome.const import ( - ENTITY_CATEGORY_DIAGNOSTIC, - ENTITY_CATEGORY_NONE, -) -from ..climate import ( - CONF_HAIER_ID, - HonClimate, -) +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_NONE + +from ..climate import CONF_HAIER_ID, HonClimate CODEOWNERS = ["@paveldn"] TextSensorTypeEnum = HonClimate.enum("SubTextSensorType", True) diff --git a/esphome/components/havells_solar/sensor.py b/esphome/components/havells_solar/sensor.py index 66b72f9e3e9..532315a1d16 100644 --- a/esphome/components/havells_solar/sensor.py +++ b/esphome/components/havells_solar/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import modbus, sensor import esphome.config_validation as cv -from esphome.components import sensor, modbus from esphome.const import ( CONF_ACTIVE_POWER, CONF_CURRENT, diff --git a/esphome/components/hbridge/fan/__init__.py b/esphome/components/hbridge/fan/__init__.py index 424e944290e..4309a643593 100644 --- a/esphome/components/hbridge/fan/__init__.py +++ b/esphome/components/hbridge/fan/__init__.py @@ -1,20 +1,20 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg from esphome.components import fan, output from esphome.components.fan import validate_preset_modes +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_DECAY_MODE, - CONF_SPEED_COUNT, + CONF_ENABLE_PIN, + CONF_ID, CONF_PIN_A, CONF_PIN_B, - CONF_ENABLE_PIN, CONF_PRESET_MODES, + CONF_SPEED_COUNT, ) -from .. import hbridge_ns +from .. import hbridge_ns CODEOWNERS = ["@WeekendWarrior"] diff --git a/esphome/components/hbridge/light/__init__.py b/esphome/components/hbridge/light/__init__.py index fe5c3e98454..65dd3196dff 100644 --- a/esphome/components/hbridge/light/__init__.py +++ b/esphome/components/hbridge/light/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import CONF_OUTPUT_ID, CONF_PIN_A, CONF_PIN_B + from .. import hbridge_ns CODEOWNERS = ["@DotNetDann"] diff --git a/esphome/components/hdc1080/sensor.py b/esphome/components/hdc1080/sensor.py index 39727f7159b..e47a88545b1 100644 --- a/esphome/components/hdc1080/sensor.py +++ b/esphome/components/hdc1080/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/he60r/cover.py b/esphome/components/he60r/cover.py index fd4c746016c..a483d2a5714 100644 --- a/esphome/components/he60r/cover.py +++ b/esphome/components/he60r/cover.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import cover, uart -from esphome.const import ( - CONF_CLOSE_DURATION, - CONF_ID, - CONF_OPEN_DURATION, -) +import esphome.config_validation as cv +from esphome.const import CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_DURATION he60r_ns = cg.esphome_ns.namespace("he60r") HE60rCover = he60r_ns.class_("HE60rCover", cover.Cover, cg.Component) diff --git a/esphome/components/heatpumpir/climate.py b/esphome/components/heatpumpir/climate.py index 598071590bc..612b0d6123b 100644 --- a/esphome/components/heatpumpir/climate.py +++ b/esphome/components/heatpumpir/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_MAX_TEMPERATURE, diff --git a/esphome/components/hitachi_ac344/climate.py b/esphome/components/hitachi_ac344/climate.py index 94b34eb9553..0988d639954 100644 --- a/esphome/components/hitachi_ac344/climate.py +++ b/esphome/components/hitachi_ac344/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/hitachi_ac424/climate.py b/esphome/components/hitachi_ac424/climate.py index 33532230df9..74f3c2fa144 100644 --- a/esphome/components/hitachi_ac424/climate.py +++ b/esphome/components/hitachi_ac424/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/hlw8012/sensor.py b/esphome/components/hlw8012/sensor.py index 2687edaca2c..201ea4451f3 100644 --- a/esphome/components/hlw8012/sensor.py +++ b/esphome/components/hlw8012/sensor.py @@ -1,17 +1,17 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CHANGE_MODE_EVERY, - CONF_INITIAL_MODE, CONF_CURRENT, CONF_CURRENT_RESISTOR, - CONF_ID, - CONF_POWER, CONF_ENERGY, - CONF_SEL_PIN, + CONF_ID, + CONF_INITIAL_MODE, CONF_MODEL, + CONF_POWER, + CONF_SEL_PIN, CONF_VOLTAGE, CONF_VOLTAGE_DIVIDER, DEVICE_CLASS_CURRENT, @@ -20,8 +20,8 @@ from esphome.const import ( DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, UNIT_WATT_HOURS, ) diff --git a/esphome/components/hm3301/sensor.py b/esphome/components/hm3301/sensor.py index 27af0b5b6b4..5eb17735184 100644 --- a/esphome/components/hm3301/sensor.py +++ b/esphome/components/hm3301/sensor.py @@ -1,18 +1,18 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, + CONF_PM_1_0, CONF_PM_2_5, CONF_PM_10_0, - CONF_PM_1_0, DEVICE_CLASS_AQI, DEVICE_CLASS_PM1, DEVICE_CLASS_PM10, DEVICE_CLASS_PM25, + ICON_CHEMICAL_WEAPON, STATE_CLASS_MEASUREMENT, UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_CHEMICAL_WEAPON, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/hmc5883l/sensor.py b/esphome/components/hmc5883l/sensor.py index f2decea1502..96d03130081 100644 --- a/esphome/components/hmc5883l/sensor.py +++ b/esphome/components/hmc5883l/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ADDRESS, CONF_FIELD_STRENGTH_X, @@ -10,12 +10,12 @@ from esphome.const import ( CONF_ID, CONF_OVERSAMPLING, CONF_RANGE, - ICON_MAGNET, - STATE_CLASS_MEASUREMENT, - UNIT_MICROTESLA, - UNIT_DEGREES, - ICON_SCREEN_ROTATION, CONF_UPDATE_INTERVAL, + ICON_MAGNET, + ICON_SCREEN_ROTATION, + STATE_CLASS_MEASUREMENT, + UNIT_DEGREES, + UNIT_MICROTESLA, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/homeassistant/time/__init__.py b/esphome/components/homeassistant/time/__init__.py index 0040988794c..62cb96a25a9 100644 --- a/esphome/components/homeassistant/time/__init__.py +++ b/esphome/components/homeassistant/time/__init__.py @@ -1,7 +1,8 @@ +import esphome.codegen as cg from esphome.components import time as time_ import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_ID + from .. import homeassistant_ns DEPENDENCIES = ["api"] diff --git a/esphome/components/honeywell_hih_i2c/sensor.py b/esphome/components/honeywell_hih_i2c/sensor.py index f5a6ad2398c..93ae2b60566 100644 --- a/esphome/components/honeywell_hih_i2c/sensor.py +++ b/esphome/components/honeywell_hih_i2c/sensor.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, CONF_TEMPERATURE, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/honeywellabp/sensor.py b/esphome/components/honeywellabp/sensor.py index ed8bff6e9b4..25d03d31a66 100644 --- a/esphome/components/honeywellabp/sensor.py +++ b/esphome/components/honeywellabp/sensor.py @@ -1,7 +1,6 @@ import esphome.codegen as cg +from esphome.components import sensor, spi import esphome.config_validation as cv -from esphome.components import sensor -from esphome.components import spi from esphome.const import ( CONF_ID, CONF_PRESSURE, diff --git a/esphome/components/honeywellabp2_i2c/sensor.py b/esphome/components/honeywellabp2_i2c/sensor.py index c38a380127b..2708e5d423f 100644 --- a/esphome/components/honeywellabp2_i2c/sensor.py +++ b/esphome/components/honeywellabp2_i2c/sensor.py @@ -1,7 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, sensor import esphome.config_validation as cv -from esphome.components import sensor -from esphome.components import i2c from esphome.const import ( CONF_ID, CONF_PRESSURE, diff --git a/esphome/components/host/time/__init__.py b/esphome/components/host/time/__init__.py index 76a88d98a14..d9a2f1207c3 100644 --- a/esphome/components/host/time/__init__.py +++ b/esphome/components/host/time/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -from esphome.const import CONF_ID -import esphome.config_validation as cv from esphome.components import time as time_ +import esphome.config_validation as cv +from esphome.const import CONF_ID CODEOWNERS = ["@clydebarrow"] diff --git a/esphome/components/hrxl_maxsonar_wr/sensor.py b/esphome/components/hrxl_maxsonar_wr/sensor.py index a78ae574b17..d335d76dfa6 100644 --- a/esphome/components/hrxl_maxsonar_wr/sensor.py +++ b/esphome/components/hrxl_maxsonar_wr/sensor.py @@ -1,9 +1,9 @@ import esphome.codegen as cg from esphome.components import sensor, uart from esphome.const import ( + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, ) CODEOWNERS = ["@netmikey"] diff --git a/esphome/components/hte501/sensor.py b/esphome/components/hte501/sensor.py index 8bd6160038f..7eef641c4a3 100644 --- a/esphome/components/hte501/sensor.py +++ b/esphome/components/hte501/sensor.py @@ -1,12 +1,12 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_HUMIDITY, + CONF_ID, CONF_TEMPERATURE, - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, diff --git a/esphome/components/http_request/ota/__init__.py b/esphome/components/http_request/ota/__init__.py index 0ef1fc23483..a3f6d5840c6 100644 --- a/esphome/components/http_request/ota/__init__.py +++ b/esphome/components/http_request/ota/__init__.py @@ -1,15 +1,11 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation -from esphome.const import ( - CONF_ID, - CONF_PASSWORD, - CONF_URL, - CONF_USERNAME, -) -from esphome.components.ota import BASE_OTA_SCHEMA, ota_to_code, OTAComponent +import esphome.codegen as cg +from esphome.components.ota import BASE_OTA_SCHEMA, OTAComponent, ota_to_code +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PASSWORD, CONF_URL, CONF_USERNAME from esphome.core import coroutine_with_priority -from .. import CONF_HTTP_REQUEST_ID, http_request_ns, HttpRequestComponent + +from .. import CONF_HTTP_REQUEST_ID, HttpRequestComponent, http_request_ns CODEOWNERS = ["@oarcher"] diff --git a/esphome/components/http_request/update/__init__.py b/esphome/components/http_request/update/__init__.py index 356afa14320..f1b282d8919 100644 --- a/esphome/components/http_request/update/__init__.py +++ b/esphome/components/http_request/update/__init__.py @@ -1,15 +1,11 @@ -import esphome.config_validation as cv import esphome.codegen as cg - from esphome.components import update -from esphome.const import ( - CONF_SOURCE, -) +import esphome.config_validation as cv +from esphome.const import CONF_SOURCE -from .. import http_request_ns, CONF_HTTP_REQUEST_ID, HttpRequestComponent +from .. import CONF_HTTP_REQUEST_ID, HttpRequestComponent, http_request_ns from ..ota import OtaHttpRequestComponent - AUTO_LOAD = ["json"] CODEOWNERS = ["@jesserockz"] DEPENDENCIES = ["ota.http_request"] diff --git a/esphome/components/htu21d/sensor.py b/esphome/components/htu21d/sensor.py index bf0b9a23fbf..a578670e375 100644 --- a/esphome/components/htu21d/sensor.py +++ b/esphome/components/htu21d/sensor.py @@ -1,21 +1,21 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import i2c, sensor from esphome import automation +import esphome.codegen as cg +from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_HEATER, CONF_HUMIDITY, CONF_ID, + CONF_LEVEL, CONF_MODEL, + CONF_STATUS, CONF_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - UNIT_PERCENT, - CONF_HEATER, UNIT_EMPTY, - CONF_LEVEL, - CONF_STATUS, + UNIT_PERCENT, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/htu31d/sensor.py b/esphome/components/htu31d/sensor.py index fe53aa376e5..638a8d77c53 100644 --- a/esphome/components/htu31d/sensor.py +++ b/esphome/components/htu31d/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/hx711/sensor.py b/esphome/components/hx711/sensor.py index 88a0bb85b78..a5d11e92413 100644 --- a/esphome/components/hx711/sensor.py +++ b/esphome/components/hx711/sensor.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor -from esphome.const import ( - CONF_CLK_PIN, - CONF_GAIN, - ICON_SCALE, - STATE_CLASS_MEASUREMENT, -) +import esphome.config_validation as cv +from esphome.const import CONF_CLK_PIN, CONF_GAIN, ICON_SCALE, STATE_CLASS_MEASUREMENT hx711_ns = cg.esphome_ns.namespace("hx711") HX711Sensor = hx711_ns.class_("HX711Sensor", sensor.Sensor, cg.PollingComponent) diff --git a/esphome/components/hydreon_rgxx/binary_sensor.py b/esphome/components/hydreon_rgxx/binary_sensor.py index 776be8a5d8f..f899ce71ced 100644 --- a/esphome/components/hydreon_rgxx/binary_sensor.py +++ b/esphome/components/hydreon_rgxx/binary_sensor.py @@ -1,13 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import ( - CONF_ID, - DEVICE_CLASS_COLD, - DEVICE_CLASS_PROBLEM, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, DEVICE_CLASS_COLD, DEVICE_CLASS_PROBLEM -from . import hydreon_rgxx_ns, HydreonRGxxComponent +from . import HydreonRGxxComponent, hydreon_rgxx_ns CONF_HYDREON_RGXX_ID = "hydreon_rgxx_id" CONF_TOO_COLD = "too_cold" diff --git a/esphome/components/hydreon_rgxx/sensor.py b/esphome/components/hydreon_rgxx/sensor.py index fb2099c85ec..f81703c087c 100644 --- a/esphome/components/hydreon_rgxx/sensor.py +++ b/esphome/components/hydreon_rgxx/sensor.py @@ -1,22 +1,22 @@ import esphome.codegen as cg +from esphome.components import sensor, uart import esphome.config_validation as cv -from esphome.components import uart, sensor from esphome.const import ( CONF_ID, CONF_MODEL, CONF_MOISTURE, CONF_RESOLUTION, CONF_TEMPERATURE, - DEVICE_CLASS_PRECIPITATION_INTENSITY, DEVICE_CLASS_PRECIPITATION, + DEVICE_CLASS_PRECIPITATION_INTENSITY, + ICON_THERMOMETER, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, UNIT_CELSIUS, UNIT_MILLIMETER, - ICON_THERMOMETER, ) -from . import RGModel, RG15Resolution, HydreonRGxxComponent +from . import HydreonRGxxComponent, RG15Resolution, RGModel UNIT_INTENSITY = "intensity" UNIT_MILLIMETERS_PER_HOUR = "mm/h" diff --git a/esphome/components/hyt271/sensor.py b/esphome/components/hyt271/sensor.py index 2ec2836461a..22364ce8541 100644 --- a/esphome/components/hyt271/sensor.py +++ b/esphome/components/hyt271/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/i2c_device/__init__.py b/esphome/components/i2c_device/__init__.py index e145ba56f81..531c363bd1e 100644 --- a/esphome/components/i2c_device/__init__.py +++ b/esphome/components/i2c_device/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/i2s_audio/media_player/__init__.py b/esphome/components/i2s_audio/media_player/__init__.py index dfa69ecadd3..2882729b1e0 100644 --- a/esphome/components/i2s_audio/media_player/__init__.py +++ b/esphome/components/i2s_audio/media_player/__init__.py @@ -1,21 +1,19 @@ -import esphome.codegen as cg -from esphome.components import media_player, esp32 -import esphome.config_validation as cv - from esphome import pins - +import esphome.codegen as cg +from esphome.components import esp32, media_player +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_MODE from .. import ( - i2s_audio_ns, - I2SAudioComponent, - I2SAudioOut, CONF_I2S_AUDIO_ID, CONF_I2S_DOUT_PIN, CONF_LEFT, - CONF_RIGHT, CONF_MONO, + CONF_RIGHT, CONF_STEREO, + I2SAudioComponent, + I2SAudioOut, + i2s_audio_ns, ) CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/iaqcore/sensor.py b/esphome/components/iaqcore/sensor.py index 51c5b283b75..d3306fd0f86 100644 --- a/esphome/components/iaqcore/sensor.py +++ b/esphome/components/iaqcore/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CO2, CONF_ID, @@ -8,8 +8,8 @@ from esphome.const import ( DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_BILLION, + UNIT_PARTS_PER_MILLION, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ina219/sensor.py b/esphome/components/ina219/sensor.py index 020be9bc6e7..621fd62e82b 100644 --- a/esphome/components/ina219/sensor.py +++ b/esphome/components/ina219/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_BUS_VOLTAGE, CONF_CURRENT, @@ -14,8 +14,8 @@ from esphome.const import ( DEVICE_CLASS_POWER, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, ) diff --git a/esphome/components/ina226/sensor.py b/esphome/components/ina226/sensor.py index 0accc58c005..2a7b3fc2128 100644 --- a/esphome/components/ina226/sensor.py +++ b/esphome/components/ina226/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_BUS_VOLTAGE, CONF_CURRENT, @@ -9,14 +9,14 @@ from esphome.const import ( CONF_POWER, CONF_SHUNT_RESISTANCE, CONF_SHUNT_VOLTAGE, - DEVICE_CLASS_VOLTAGE, + CONF_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, - CONF_VOLTAGE, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ina260/sensor.py b/esphome/components/ina260/sensor.py index 732d15d9ca3..b98b4ce6cb9 100644 --- a/esphome/components/ina260/sensor.py +++ b/esphome/components/ina260/sensor.py @@ -1,17 +1,17 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_BUS_VOLTAGE, CONF_CURRENT, + CONF_ID, CONF_POWER, - DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, ) diff --git a/esphome/components/ina2xx_base/__init__.py b/esphome/components/ina2xx_base/__init__.py index 35b5baa83ec..7c3d3c88999 100644 --- a/esphome/components/ina2xx_base/__init__.py +++ b/esphome/components/ina2xx_base/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_BUS_VOLTAGE, CONF_CURRENT, @@ -21,8 +21,8 @@ from esphome.const import ( UNIT_AMPERE, UNIT_CELSIUS, UNIT_VOLT, - UNIT_WATT_HOURS, UNIT_WATT, + UNIT_WATT_HOURS, ) CODEOWNERS = ["@latonita"] diff --git a/esphome/components/ina2xx_i2c/sensor.py b/esphome/components/ina2xx_i2c/sensor.py index 57ddcef17a7..1a470aa6286 100644 --- a/esphome/components/ina2xx_i2c/sensor.py +++ b/esphome/components/ina2xx_i2c/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, ina2xx_base import esphome.config_validation as cv -from esphome.components import ina2xx_base, i2c from esphome.const import CONF_ID, CONF_MODEL AUTO_LOAD = ["ina2xx_base"] diff --git a/esphome/components/ina2xx_spi/sensor.py b/esphome/components/ina2xx_spi/sensor.py index e7ae51d516d..3ebe2cac733 100644 --- a/esphome/components/ina2xx_spi/sensor.py +++ b/esphome/components/ina2xx_spi/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import ina2xx_base, spi +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_MODEL AUTO_LOAD = ["ina2xx_base"] diff --git a/esphome/components/ina3221/sensor.py b/esphome/components/ina3221/sensor.py index 9c42ecbb9dc..acf7d7cdf0f 100644 --- a/esphome/components/ina3221/sensor.py +++ b/esphome/components/ina3221/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_BUS_VOLTAGE, CONF_CURRENT, @@ -8,12 +8,12 @@ from esphome.const import ( CONF_POWER, CONF_SHUNT_RESISTANCE, CONF_SHUNT_VOLTAGE, - DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, ) diff --git a/esphome/components/inkbird_ibsth1_mini/sensor.py b/esphome/components/inkbird_ibsth1_mini/sensor.py index cdd0b5ade59..b446c9f1e23 100644 --- a/esphome/components/inkbird_ibsth1_mini/sensor.py +++ b/esphome/components/inkbird_ibsth1_mini/sensor.py @@ -1,10 +1,11 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_EXTERNAL_TEMPERATURE, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, DEVICE_CLASS_BATTERY, @@ -14,7 +15,6 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - CONF_ID, ) CODEOWNERS = ["@fkirill"] diff --git a/esphome/components/inkplate6/display.py b/esphome/components/inkplate6/display.py index 8fe7f7d41dc..56d20508ecd 100644 --- a/esphome/components/inkplate6/display.py +++ b/esphome/components/inkplate6/display.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display, i2c +import esphome.config_validation as cv from esphome.const import ( CONF_FULL_UPDATE_EVERY, CONF_ID, diff --git a/esphome/components/integration/sensor.py b/esphome/components/integration/sensor.py index d57f9096625..3c04a338dde 100644 --- a/esphome/components/integration/sensor.py +++ b/esphome/components/integration/sensor.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_ACCURACY_DECIMALS, CONF_ICON, CONF_ID, - CONF_SENSOR, CONF_RESTORE, + CONF_SENSOR, CONF_UNIT_OF_MEASUREMENT, - CONF_ACCURACY_DECIMALS, ) from esphome.core.entity_helpers import inherit_property_from diff --git a/esphome/components/internal_temperature/sensor.py b/esphome/components/internal_temperature/sensor.py index 809d7a40b9c..9bfa3739c8a 100644 --- a/esphome/components/internal_temperature/sensor.py +++ b/esphome/components/internal_temperature/sensor.py @@ -1,20 +1,18 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor from esphome.components.esp32 import get_esp32_variant -from esphome.components.esp32.const import ( - VARIANT_ESP32S3, -) +from esphome.components.esp32.const import VARIANT_ESP32S3 +import esphome.config_validation as cv from esphome.const import ( - STATE_CLASS_MEASUREMENT, - UNIT_CELSIUS, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, KEY_CORE, KEY_FRAMEWORK_VERSION, + PLATFORM_BK72XX, PLATFORM_ESP32, PLATFORM_RP2040, - PLATFORM_BK72XX, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, ) from esphome.core import CORE diff --git a/esphome/components/interval/__init__.py b/esphome/components/interval/__init__.py index db3232c4b02..ac9219ff6a7 100644 --- a/esphome/components/interval/__init__.py +++ b/esphome/components/interval/__init__.py @@ -1,6 +1,6 @@ +from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv -from esphome import automation from esphome.const import CONF_ID, CONF_INTERVAL, CONF_STARTUP_DELAY CODEOWNERS = ["@esphome/core"] diff --git a/esphome/components/jsn_sr04t/sensor.py b/esphome/components/jsn_sr04t/sensor.py index 682cf06570f..214724aa3f8 100644 --- a/esphome/components/jsn_sr04t/sensor.py +++ b/esphome/components/jsn_sr04t/sensor.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( + CONF_MODEL, + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, - CONF_MODEL, ) CODEOWNERS = ["@Mafus1"] diff --git a/esphome/components/kamstrup_kmp/sensor.py b/esphome/components/kamstrup_kmp/sensor.py index c9024e4a2b2..fb37ac2c8da 100644 --- a/esphome/components/kamstrup_kmp/sensor.py +++ b/esphome/components/kamstrup_kmp/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_COMMAND, CONF_CUSTOM, diff --git a/esphome/components/key_collector/__init__.py b/esphome/components/key_collector/__init__.py index fd142b3cd77..5750812f5c5 100644 --- a/esphome/components/key_collector/__init__.py +++ b/esphome/components/key_collector/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import key_provider +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_MAX_LENGTH, diff --git a/esphome/components/kmeteriso/sensor.py b/esphome/components/kmeteriso/sensor.py index 082a055701d..4f6cb7d091a 100644 --- a/esphome/components/kmeteriso/sensor.py +++ b/esphome/components/kmeteriso/sensor.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INTERNAL_TEMPERATURE, CONF_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, + ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - ENTITY_CATEGORY_DIAGNOSTIC, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/kuntze/sensor.py b/esphome/components/kuntze/sensor.py index 96c874fa5c3..96b6334730d 100644 --- a/esphome/components/kuntze/sensor.py +++ b/esphome/components/kuntze/sensor.py @@ -1,19 +1,19 @@ import esphome.codegen as cg +from esphome.components import modbus, sensor import esphome.config_validation as cv -from esphome.components import sensor, modbus from esphome.const import ( - CONF_ID, CONF_EC, + CONF_ID, CONF_PH, CONF_TEMPERATURE, + DEVICE_CLASS_EMPTY, + DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_EMPTY, UNIT_PH, - STATE_CLASS_MEASUREMENT, - DEVICE_CLASS_EMPTY, - DEVICE_CLASS_TEMPERATURE, ) CODEOWNERS = ["@ssieb"] diff --git a/esphome/components/lcd_base/__init__.py b/esphome/components/lcd_base/__init__.py index 693211c6fe2..bf1072ce667 100644 --- a/esphome/components/lcd_base/__init__.py +++ b/esphome/components/lcd_base/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display -from esphome.const import CONF_DIMENSIONS, CONF_POSITION, CONF_DATA +import esphome.config_validation as cv +from esphome.const import CONF_DATA, CONF_DIMENSIONS, CONF_POSITION CONF_USER_CHARACTERS = "user_characters" diff --git a/esphome/components/lcd_gpio/display.py b/esphome/components/lcd_gpio/display.py index bfef4020581..caa73194c98 100644 --- a/esphome/components/lcd_gpio/display.py +++ b/esphome/components/lcd_gpio/display.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import lcd_base +import esphome.config_validation as cv from esphome.const import ( CONF_DATA_PINS, CONF_ENABLE_PIN, - CONF_RS_PIN, - CONF_RW_PIN, CONF_ID, CONF_LAMBDA, + CONF_RS_PIN, + CONF_RW_PIN, ) AUTO_LOAD = ["lcd_base"] diff --git a/esphome/components/lcd_menu/__init__.py b/esphome/components/lcd_menu/__init__.py index b57a4a0f6c1..3f3162e31e7 100644 --- a/esphome/components/lcd_menu/__init__.py +++ b/esphome/components/lcd_menu/__init__.py @@ -1,17 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.const import ( - CONF_ID, - CONF_DIMENSIONS, - CONF_DISPLAY_ID, -) -from esphome.core.entity_helpers import inherit_property_from from esphome.components import lcd_base from esphome.components.display_menu_base import ( DISPLAY_MENU_BASE_SCHEMA, DisplayMenuComponent, display_menu_to_code, ) +import esphome.config_validation as cv +from esphome.const import CONF_DIMENSIONS, CONF_DISPLAY_ID, CONF_ID +from esphome.core.entity_helpers import inherit_property_from CODEOWNERS = ["@numo68"] diff --git a/esphome/components/lcd_pcf8574/display.py b/esphome/components/lcd_pcf8574/display.py index 5d9dd7adba3..410c7f81b7e 100644 --- a/esphome/components/lcd_pcf8574/display.py +++ b/esphome/components/lcd_pcf8574/display.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, lcd_base import esphome.config_validation as cv -from esphome.components import lcd_base, i2c from esphome.const import CONF_ID, CONF_LAMBDA DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ld2410/__init__.py b/esphome/components/ld2410/__init__.py index 2b30b65f46b..c58b9a4017d 100644 --- a/esphome/components/ld2410/__init__.py +++ b/esphome/components/ld2410/__init__.py @@ -1,9 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import uart -from esphome.const import CONF_ID, CONF_THROTTLE, CONF_TIMEOUT, CONF_PASSWORD from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg +from esphome.components import uart +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PASSWORD, CONF_THROTTLE, CONF_TIMEOUT DEPENDENCIES = ["uart"] CODEOWNERS = ["@sebcaps", "@regevbr"] diff --git a/esphome/components/ld2410/binary_sensor.py b/esphome/components/ld2410/binary_sensor.py index e00ab93be2d..d2938754e96 100644 --- a/esphome/components/ld2410/binary_sensor.py +++ b/esphome/components/ld2410/binary_sensor.py @@ -2,16 +2,17 @@ import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv from esphome.const import ( + CONF_HAS_MOVING_TARGET, + CONF_HAS_STILL_TARGET, + CONF_HAS_TARGET, DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_PRESENCE, ENTITY_CATEGORY_DIAGNOSTIC, - ICON_MOTION_SENSOR, ICON_ACCOUNT, - CONF_HAS_TARGET, - CONF_HAS_MOVING_TARGET, - CONF_HAS_STILL_TARGET, + ICON_MOTION_SENSOR, ) + from . import CONF_LD2410_ID, LD2410Component DEPENDENCIES = ["ld2410"] diff --git a/esphome/components/ld2410/button/__init__.py b/esphome/components/ld2410/button/__init__.py index 34b18e8bddc..4cb50d707bb 100644 --- a/esphome/components/ld2410/button/__init__.py +++ b/esphome/components/ld2410/button/__init__.py @@ -5,12 +5,13 @@ from esphome.const import ( CONF_FACTORY_RESET, CONF_RESTART, DEVICE_CLASS_RESTART, - ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_CONFIG, + ENTITY_CATEGORY_DIAGNOSTIC, + ICON_DATABASE, ICON_RESTART, ICON_RESTART_ALERT, - ICON_DATABASE, ) + from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns QueryButton = ld2410_ns.class_("QueryButton", button.Button) diff --git a/esphome/components/ld2410/number/__init__.py b/esphome/components/ld2410/number/__init__.py index 557b226dfee..1f9c50db1f5 100644 --- a/esphome/components/ld2410/number/__init__.py +++ b/esphome/components/ld2410/number/__init__.py @@ -5,15 +5,16 @@ from esphome.const import ( CONF_ID, CONF_TIMEOUT, DEVICE_CLASS_DISTANCE, - DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_ILLUMINANCE, - UNIT_SECOND, - UNIT_PERCENT, + DEVICE_CLASS_SIGNAL_STRENGTH, ENTITY_CATEGORY_CONFIG, + ICON_LIGHTBULB, ICON_MOTION_SENSOR, ICON_TIMELAPSE, - ICON_LIGHTBULB, + UNIT_PERCENT, + UNIT_SECOND, ) + from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns GateThresholdNumber = ld2410_ns.class_("GateThresholdNumber", number.Number) diff --git a/esphome/components/ld2410/select/__init__.py b/esphome/components/ld2410/select/__init__.py index 6c34a85ac66..686afdef14c 100644 --- a/esphome/components/ld2410/select/__init__.py +++ b/esphome/components/ld2410/select/__init__.py @@ -2,13 +2,14 @@ import esphome.codegen as cg from esphome.components import select import esphome.config_validation as cv from esphome.const import ( - ENTITY_CATEGORY_CONFIG, CONF_BAUD_RATE, - ICON_THERMOMETER, - ICON_SCALE, + ENTITY_CATEGORY_CONFIG, ICON_LIGHTBULB, ICON_RULER, + ICON_SCALE, + ICON_THERMOMETER, ) + from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns BaudRateSelect = ld2410_ns.class_("BaudRateSelect", select.Select) diff --git a/esphome/components/ld2410/sensor.py b/esphome/components/ld2410/sensor.py index 83361db58ac..38de1799cce 100644 --- a/esphome/components/ld2410/sensor.py +++ b/esphome/components/ld2410/sensor.py @@ -2,17 +2,18 @@ import esphome.codegen as cg from esphome.components import sensor import esphome.config_validation as cv from esphome.const import ( - DEVICE_CLASS_DISTANCE, - UNIT_CENTIMETER, - UNIT_PERCENT, CONF_LIGHT, + DEVICE_CLASS_DISTANCE, DEVICE_CLASS_ILLUMINANCE, ENTITY_CATEGORY_DIAGNOSTIC, - ICON_SIGNAL, ICON_FLASH, - ICON_MOTION_SENSOR, ICON_LIGHTBULB, + ICON_MOTION_SENSOR, + ICON_SIGNAL, + UNIT_CENTIMETER, + UNIT_PERCENT, ) + from . import CONF_LD2410_ID, LD2410Component DEPENDENCIES = ["ld2410"] diff --git a/esphome/components/ld2410/switch/__init__.py b/esphome/components/ld2410/switch/__init__.py index 096cb5f67aa..aecad606bef 100644 --- a/esphome/components/ld2410/switch/__init__.py +++ b/esphome/components/ld2410/switch/__init__.py @@ -3,10 +3,11 @@ from esphome.components import switch import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_SWITCH, - ICON_BLUETOOTH, ENTITY_CATEGORY_CONFIG, + ICON_BLUETOOTH, ICON_PULSE, ) + from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns BluetoothSwitch = ld2410_ns.class_("BluetoothSwitch", switch.Switch) diff --git a/esphome/components/ld2410/text_sensor.py b/esphome/components/ld2410/text_sensor.py index d64472a7d39..5a021d91638 100644 --- a/esphome/components/ld2410/text_sensor.py +++ b/esphome/components/ld2410/text_sensor.py @@ -2,12 +2,13 @@ import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv from esphome.const import ( - ENTITY_CATEGORY_DIAGNOSTIC, - CONF_VERSION, CONF_MAC_ADDRESS, + CONF_VERSION, + ENTITY_CATEGORY_DIAGNOSTIC, ICON_BLUETOOTH, ICON_CHIP, ) + from . import CONF_LD2410_ID, LD2410Component DEPENDENCIES = ["ld2410"] diff --git a/esphome/components/ld2420/__init__.py b/esphome/components/ld2420/__init__.py index c701423081f..71a5fa13e48 100644 --- a/esphome/components/ld2420/__init__.py +++ b/esphome/components/ld2420/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@descipher"] diff --git a/esphome/components/ld2420/binary_sensor/__init__.py b/esphome/components/ld2420/binary_sensor/__init__.py index 43e22d03488..5ebc4a9f635 100644 --- a/esphome/components/ld2420/binary_sensor/__init__.py +++ b/esphome/components/ld2420/binary_sensor/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import CONF_ID, DEVICE_CLASS_OCCUPANCY, CONF_HAS_TARGET -from .. import ld2420_ns, LD2420Component, CONF_LD2420_ID +import esphome.config_validation as cv +from esphome.const import CONF_HAS_TARGET, CONF_ID, DEVICE_CLASS_OCCUPANCY + +from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns LD2420BinarySensor = ld2420_ns.class_( "LD2420BinarySensor", binary_sensor.BinarySensor, cg.Component diff --git a/esphome/components/ld2420/button/__init__.py b/esphome/components/ld2420/button/__init__.py index df774ad7bcc..dfeb121c91f 100644 --- a/esphome/components/ld2420/button/__init__.py +++ b/esphome/components/ld2420/button/__init__.py @@ -4,12 +4,13 @@ import esphome.config_validation as cv from esphome.const import ( CONF_FACTORY_RESET, DEVICE_CLASS_RESTART, - ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_CONFIG, + ENTITY_CATEGORY_DIAGNOSTIC, + ICON_DATABASE, ICON_RESTART, ICON_RESTART_ALERT, - ICON_DATABASE, ) + from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns LD2420ApplyConfigButton = ld2420_ns.class_("LD2420ApplyConfigButton", button.Button) diff --git a/esphome/components/ld2420/number/__init__.py b/esphome/components/ld2420/number/__init__.py index 4ae08356fc1..1558243cc2f 100644 --- a/esphome/components/ld2420/number/__init__.py +++ b/esphome/components/ld2420/number/__init__.py @@ -4,12 +4,13 @@ import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_DISTANCE, - UNIT_SECOND, ENTITY_CATEGORY_CONFIG, ICON_MOTION_SENSOR, - ICON_TIMELAPSE, ICON_SCALE, + ICON_TIMELAPSE, + UNIT_SECOND, ) + from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns LD2420TimeoutNumber = ld2420_ns.class_("LD2420TimeoutNumber", number.Number) diff --git a/esphome/components/ld2420/select/__init__.py b/esphome/components/ld2420/select/__init__.py index 554bd4147da..6ccc00b41c1 100644 --- a/esphome/components/ld2420/select/__init__.py +++ b/esphome/components/ld2420/select/__init__.py @@ -2,6 +2,7 @@ import esphome.codegen as cg from esphome.components import select import esphome.config_validation as cv from esphome.const import ENTITY_CATEGORY_CONFIG + from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns CONF_OPERATING_MODE = "operating_mode" diff --git a/esphome/components/ld2420/sensor/__init__.py b/esphome/components/ld2420/sensor/__init__.py index 6a67d1fc419..e39ca99ae16 100644 --- a/esphome/components/ld2420/sensor/__init__.py +++ b/esphome/components/ld2420/sensor/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import CONF_ID, DEVICE_CLASS_DISTANCE, UNIT_CENTIMETER -from .. import ld2420_ns, LD2420Component, CONF_LD2420_ID + +from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns LD2420Sensor = ld2420_ns.class_("LD2420Sensor", sensor.Sensor, cg.Component) diff --git a/esphome/components/ld2420/text_sensor/__init__.py b/esphome/components/ld2420/text_sensor/__init__.py index b6d8c7c0e44..14d982e5fb8 100644 --- a/esphome/components/ld2420/text_sensor/__init__.py +++ b/esphome/components/ld2420/text_sensor/__init__.py @@ -1,13 +1,9 @@ import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -from esphome.const import ( - CONF_ID, - ENTITY_CATEGORY_DIAGNOSTIC, - ICON_CHIP, -) +from esphome.const import CONF_ID, ENTITY_CATEGORY_DIAGNOSTIC, ICON_CHIP -from .. import ld2420_ns, LD2420Component, CONF_LD2420_ID +from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns LD2420TextSensor = ld2420_ns.class_( "LD2420TextSensor", text_sensor.TextSensor, cg.Component diff --git a/esphome/components/ld2450/__init__.py b/esphome/components/ld2450/__init__.py index 37f68a8f3e5..442fdaa125c 100644 --- a/esphome/components/ld2450/__init__.py +++ b/esphome/components/ld2450/__init__.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart -from esphome.const import ( - CONF_ID, - CONF_THROTTLE, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_THROTTLE DEPENDENCIES = ["uart"] CODEOWNERS = ["@hareeshmu"] diff --git a/esphome/components/ledc/output.py b/esphome/components/ledc/output.py index 32c68f8d244..2133c4daf98 100644 --- a/esphome/components/ledc/output.py +++ b/esphome/components/ledc/output.py @@ -1,12 +1,12 @@ -from esphome import pins, automation +from esphome import automation, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( - CONF_PHASE_ANGLE, CONF_CHANNEL, CONF_FREQUENCY, CONF_ID, + CONF_PHASE_ANGLE, CONF_PIN, ) diff --git a/esphome/components/libretiny/text_sensor.py b/esphome/components/libretiny/text_sensor.py index df10ee72298..fa33fb6c029 100644 --- a/esphome/components/libretiny/text_sensor.py +++ b/esphome/components/libretiny/text_sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import ( CONF_VERSION, ENTITY_CATEGORY_DIAGNOSTIC, diff --git a/esphome/components/libretiny_pwm/output.py b/esphome/components/libretiny_pwm/output.py index e74bc8f1291..1eb4869da3e 100644 --- a/esphome/components/libretiny_pwm/output.py +++ b/esphome/components/libretiny_pwm/output.py @@ -1,12 +1,8 @@ -from esphome import pins, automation +from esphome import automation, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg -from esphome.const import ( - CONF_FREQUENCY, - CONF_ID, - CONF_PIN, -) +from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_PIN DEPENDENCIES = ["libretiny"] diff --git a/esphome/components/lightwaverf/__init__.py b/esphome/components/lightwaverf/__init__.py index 4e96dda663c..802b341601b 100644 --- a/esphome/components/lightwaverf/__init__.py +++ b/esphome/components/lightwaverf/__init__.py @@ -1,17 +1,15 @@ +from esphome import automation, pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome import automation - from esphome.const import ( - CONF_READ_PIN, - CONF_ID, - CONF_NAME, - CONF_WRITE_PIN, - CONF_REPEAT, - CONF_INVERTED, - CONF_PULSE_LENGTH, CONF_CODE, + CONF_ID, + CONF_INVERTED, + CONF_NAME, + CONF_PULSE_LENGTH, + CONF_READ_PIN, + CONF_REPEAT, + CONF_WRITE_PIN, ) from esphome.cpp_helpers import gpio_pin_expression diff --git a/esphome/components/lilygo_t5_47/touchscreen/__init__.py b/esphome/components/lilygo_t5_47/touchscreen/__init__.py index 17f72627850..93687846e2b 100644 --- a/esphome/components/lilygo_t5_47/touchscreen/__init__.py +++ b/esphome/components/lilygo_t5_47/touchscreen/__init__.py @@ -1,8 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, touchscreen +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTERRUPT_PIN from .. import lilygo_t5_47_ns diff --git a/esphome/components/ltr390/sensor.py b/esphome/components/ltr390/sensor.py index 62c3edf8cb5..579adb90516 100644 --- a/esphome/components/ltr390/sensor.py +++ b/esphome/components/ltr390/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_AMBIENT_LIGHT, CONF_GAIN, diff --git a/esphome/components/ltr501/sensor.py b/esphome/components/ltr501/sensor.py index 153d1b3ad10..adaf669a729 100644 --- a/esphome/components/ltr501/sensor.py +++ b/esphome/components/ltr501/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ACTUAL_GAIN, CONF_ACTUAL_INTEGRATION_TIME, diff --git a/esphome/components/ltr_als_ps/sensor.py b/esphome/components/ltr_als_ps/sensor.py index e9a52649414..27263d0bffb 100644 --- a/esphome/components/ltr_als_ps/sensor.py +++ b/esphome/components/ltr_als_ps/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ACTUAL_GAIN, CONF_ACTUAL_INTEGRATION_TIME, diff --git a/esphome/components/lvgl/__init__.py b/esphome/components/lvgl/__init__.py index 22571c25508..30fa58c380f 100644 --- a/esphome/components/lvgl/__init__.py +++ b/esphome/components/lvgl/__init__.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_GROUP, CONF_ID, CONF_LAMBDA, + CONF_ON_BOOT, CONF_ON_IDLE, CONF_PAGES, CONF_TIMEOUT, @@ -38,19 +39,18 @@ from .lvcode import LvContext, LvglComponent, lvgl_static from .schemas import ( DISP_BG_SCHEMA, FLEX_OBJ_SCHEMA, + FULL_STYLE_SCHEMA, GRID_CELL_SCHEMA, LAYOUT_SCHEMAS, - STYLE_SCHEMA, WIDGET_TYPES, any_widget_schema, container_schema, create_modify_schema, - grid_alignments, obj_schema, ) from .styles import add_top_layer, styles_to_code, theme_to_code from .touchscreens import touchscreen_schema, touchscreens_to_code -from .trigger import generate_triggers +from .trigger import add_on_boot_triggers, generate_triggers from .types import ( FontEngine, IdleTrigger, @@ -73,6 +73,7 @@ from .widgets.animimg import animimg_spec from .widgets.arc import arc_spec from .widgets.button import button_spec from .widgets.buttonmatrix import buttonmatrix_spec +from .widgets.canvas import canvas_spec from .widgets.checkbox import checkbox_spec from .widgets.dropdown import dropdown_spec from .widgets.img import img_spec @@ -125,6 +126,7 @@ for w_type in ( keyboard_spec, tileview_spec, qr_code_spec, + canvas_spec, ): WIDGET_TYPES[w_type.name] = w_type @@ -365,6 +367,7 @@ async def to_code(configs): conf[CONF_TRIGGER_ID], lv_component, False ) await build_automation(resume_trigger, [], conf) + await add_on_boot_triggers(config.get(CONF_ON_BOOT, ())) # This must be done after all widgets are created for comp in helpers.lvgl_components_required: @@ -373,6 +376,7 @@ async def to_code(configs): add_define("LV_COLOR_SCREEN_TRANSP", "1") for use in helpers.lv_uses: add_define(f"LV_USE_{use.upper()}") + cg.add_define(f"USE_LVGL_{use.upper()}") lv_conf_h_file = CORE.relative_src_path(LV_CONF_FILENAME) write_file_if_changed(lv_conf_h_file, generate_lv_conf_h()) cg.add_build_flag("-DLV_CONF_H=1") @@ -418,15 +422,8 @@ LVGL_SCHEMA = cv.All( "big_endian", "little_endian" ), cv.Optional(df.CONF_STYLE_DEFINITIONS): cv.ensure_list( - cv.Schema({cv.Required(CONF_ID): cv.declare_id(lv_style_t)}) - .extend(STYLE_SCHEMA) - .extend( - { - cv.Optional(df.CONF_GRID_CELL_X_ALIGN): grid_alignments, - cv.Optional(df.CONF_GRID_CELL_Y_ALIGN): grid_alignments, - cv.Optional(df.CONF_PAD_ROW): lvalid.pixels, - cv.Optional(df.CONF_PAD_COLUMN): lvalid.pixels, - } + cv.Schema({cv.Required(CONF_ID): cv.declare_id(lv_style_t)}).extend( + FULL_STYLE_SCHEMA ) ), cv.Optional(CONF_ON_IDLE): validate_automation( diff --git a/esphome/components/lvgl/automation.py b/esphome/components/lvgl/automation.py index 168fc03cb7f..4a718720227 100644 --- a/esphome/components/lvgl/automation.py +++ b/esphome/components/lvgl/automation.py @@ -4,6 +4,7 @@ from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv from esphome.const import CONF_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT +from esphome.core import Lambda from esphome.cpp_generator import TemplateArguments, get_variable from esphome.cpp_types import nullptr @@ -17,6 +18,7 @@ from .defines import ( CONF_SHOW_SNOW, PARTS, literal, + static_cast, ) from .lv_validation import lv_bool, lv_color, lv_image, opacity from .lvcode import ( @@ -32,7 +34,6 @@ from .lvcode import ( lv_expr, lv_obj, lvgl_comp, - static_cast, ) from .schemas import DISP_BG_SCHEMA, LIST_ACTION_SCHEMA, LVGL_SCHEMA, base_update_schema from .types import ( @@ -64,7 +65,14 @@ async def action_to_code( action_id, template_arg, args, + config=None, ): + # Ensure all required ids have been processed, so our LambdaContext doesn't get context-switched. + if config: + for lamb in config.values(): + if isinstance(lamb, Lambda): + for id_ in lamb.requires_ids: + await get_variable(id_) await wait_for_widgets() async with LambdaContext(parameters=args, where=action_id) as context: for widget in widgets: @@ -84,7 +92,9 @@ async def update_to_code(config, action_id, template_arg, args): lv.event_send(widget.obj, UPDATE_EVENT, nullptr) widgets = await get_widgets(config[CONF_ID]) - return await action_to_code(widgets, do_update, action_id, template_arg, args) + return await action_to_code( + widgets, do_update, action_id, template_arg, args, config + ) @automation.register_condition( @@ -348,4 +358,6 @@ async def obj_update_to_code(config, action_id, template_arg, args): await set_obj_properties(widget, config) widgets = await get_widgets(config[CONF_ID]) - return await action_to_code(widgets, do_update, action_id, template_arg, args) + return await action_to_code( + widgets, do_update, action_id, template_arg, args, config + ) diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 56a5a4b9e48..7dedb55418d 100644 --- a/esphome/components/lvgl/defines.py +++ b/esphome/components/lvgl/defines.py @@ -29,12 +29,16 @@ def add_define(macro, value="1"): lv_defines[macro] = value -def literal(arg): +def literal(arg) -> MockObj: if isinstance(arg, str): return MockObj(arg) return arg +def static_cast(type, value): + return literal(f"static_cast<{type}>({value})") + + def call_lambda(lamb: LambdaExpression): expr = lamb.content.strip() if expr.startswith("return") and expr.endswith(";"): @@ -416,7 +420,6 @@ CONF_CHANGE_RATE = "change_rate" CONF_CLOSE_BUTTON = "close_button" CONF_COLOR_DEPTH = "color_depth" CONF_CONTROL = "control" -CONF_DEFAULT = "default" CONF_DEFAULT_FONT = "default_font" CONF_DEFAULT_GROUP = "default_group" CONF_DIR = "dir" diff --git a/esphome/components/lvgl/encoders.py b/esphome/components/lvgl/encoders.py index 952572df43a..259c3440306 100644 --- a/esphome/components/lvgl/encoders.py +++ b/esphome/components/lvgl/encoders.py @@ -18,6 +18,7 @@ from .helpers import lvgl_components_required, requires_component from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable from .schemas import ENCODER_SCHEMA from .types import lv_group_t, lv_indev_type_t, lv_key_t +from .widgets import get_widgets ENCODERS_CONFIG = cv.ensure_list( ENCODER_SCHEMA.extend( @@ -76,5 +77,5 @@ async def encoders_to_code(var, config, default_group): async def initial_focus_to_code(config): for enc_conf in config[CONF_ENCODERS]: if default_focus := enc_conf.get(CONF_INITIAL_FOCUS): - obj = await cg.get_variable(default_focus) - lv.group_focus_obj(obj) + widget = await get_widgets(default_focus) + lv.group_focus_obj(widget[0].obj) diff --git a/esphome/components/lvgl/lv_validation.py b/esphome/components/lvgl/lv_validation.py index f91ed893f26..a3b7cc8ed37 100644 --- a/esphome/components/lvgl/lv_validation.py +++ b/esphome/components/lvgl/lv_validation.py @@ -254,11 +254,27 @@ def pixels_or_percent_validator(value): pixels_or_percent = LValidator(pixels_or_percent_validator, uint32, retmapper=literal) -def zoom(value): +def pixels_validator(value): + if isinstance(value, str) and value.lower().endswith("px"): + value = value[:-2] + return cv.positive_int(value) + + +pixels = LValidator(pixels_validator, uint32, retmapper=literal) + + +def zoom_validator(value): value = cv.float_range(0.1, 10.0)(value) + return value + + +def zoom_retmapper(value): return int(value * 256) +zoom = LValidator(zoom_validator, uint32, retmapper=zoom_retmapper) + + def angle(value): """ Validation for an angle in degrees, converted to an integer representing 0.1deg units @@ -286,14 +302,6 @@ def size_validator(value): size = LValidator(size_validator, uint32, retmapper=literal) -def pixels_validator(value): - if isinstance(value, str) and value.lower().endswith("px"): - return cv.int_(value[:-2]) - return cv.int_(value) - - -pixels = LValidator(pixels_validator, uint32, retmapper=literal) - radius_consts = LvConstant("LV_RADIUS_", "CIRCLE") diff --git a/esphome/components/lvgl/lvcode.py b/esphome/components/lvgl/lvcode.py index 6b98cc42518..67a87d24bf1 100644 --- a/esphome/components/lvgl/lvcode.py +++ b/esphome/components/lvgl/lvcode.py @@ -173,7 +173,8 @@ class LambdaContext(CodeContext): class LvContext(LambdaContext): """ - Code generation into the LVGL initialisation code (called in `setup()`) + Code generation into the LVGL initialisation code, called before setup() and loop() + Basically just does cg.add, so now fairly redundant. """ added_lambda_count = 0 @@ -206,11 +207,16 @@ class LocalVariable(MockObj): def __enter__(self): CodeContext.start_block() - CodeContext.append( - VariableDeclarationExpression(self.base.type, self.modifier, self.base.id) - ) if self.rhs is not None: - CodeContext.append(AssignmentExpression(None, "", self.base, self.rhs)) + CodeContext.append( + AssignmentExpression(self.base.type, self.modifier, self.base, self.rhs) + ) + else: + CodeContext.append( + VariableDeclarationExpression( + self.base.type, self.modifier, self.base.id + ) + ) return MockObj(self.base) def __exit__(self, *args): @@ -285,10 +291,6 @@ class LvExpr(MockLv): pass -def static_cast(type, value): - return literal(f"static_cast<{type}>({value})") - - # Top level mock for generic lv_ calls to be recorded lv = MockLv("lv_") # Just generate an expression diff --git a/esphome/components/lvgl/lvgl_esphome.h b/esphome/components/lvgl/lvgl_esphome.h index 69fa808d53e..3ae67e8a0bf 100644 --- a/esphome/components/lvgl/lvgl_esphome.h +++ b/esphome/components/lvgl/lvgl_esphome.h @@ -63,6 +63,13 @@ inline void lv_disp_set_bg_image(lv_disp_t *disp, esphome::image::Image *image) inline void lv_obj_set_style_bg_img_src(lv_obj_t *obj, esphome::image::Image *image, lv_style_selector_t selector) { lv_obj_set_style_bg_img_src(obj, image->get_lv_img_dsc(), selector); } +#ifdef USE_LVGL_CANVAS +inline void lv_canvas_draw_img(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y, image::Image *image, + lv_draw_img_dsc_t *dsc) { + lv_canvas_draw_img(canvas, x, y, image->get_lv_img_dsc(), dsc); +} +#endif + #ifdef USE_LVGL_METER inline lv_meter_indicator_t *lv_meter_add_needle_img(lv_obj_t *obj, lv_meter_scale_t *scale, esphome::image::Image *src, lv_coord_t pivot_x, lv_coord_t pivot_y) { @@ -90,6 +97,7 @@ inline void lv_animimg_set_src(lv_obj_t *img, std::vector images // Parent class for things that wrap an LVGL object class LvCompound { public: + virtual ~LvCompound() = default; virtual void set_obj(lv_obj_t *lv_obj) { this->obj = lv_obj; } lv_obj_t *obj{}; }; @@ -330,6 +338,19 @@ class LVEncoderListener : public Parented { }; #endif // USE_LVGL_KEY_LISTENER +#ifdef USE_LVGL_LINE +class LvLineType : public LvCompound { + public: + std::vector get_points() { return this->points_; } + void set_points(std::vector points) { + this->points_ = std::move(points); + lv_line_set_points(this->obj, this->points_.data(), this->points_.size()); + } + + protected: + std::vector points_{}; +}; +#endif #if defined(USE_LVGL_DROPDOWN) || defined(LV_USE_ROLLER) class LvSelectable : public LvCompound { public: diff --git a/esphome/components/lvgl/number/__init__.py b/esphome/components/lvgl/number/__init__.py index b41a36bc0ff..98f8423b7c0 100644 --- a/esphome/components/lvgl/number/__init__.py +++ b/esphome/components/lvgl/number/__init__.py @@ -1,6 +1,7 @@ import esphome.codegen as cg from esphome.components import number import esphome.config_validation as cv +from esphome.const import CONF_RESTORE_VALUE from esphome.cpp_generator import MockObj from ..defines import CONF_ANIMATED, CONF_UPDATE_ON_RELEASE, CONF_WIDGET @@ -10,21 +11,21 @@ from ..lvcode import ( EVENT_ARG, UPDATE_EVENT, LambdaContext, - LvContext, + ReturnStatement, lv, - lv_add, lvgl_static, ) from ..types import LV_EVENT, LvNumber, lvgl_ns from ..widgets import get_widgets, wait_for_widgets -LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number) +LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number, cg.Component) CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend( { cv.Required(CONF_WIDGET): cv.use_id(LvNumber), cv.Optional(CONF_ANIMATED, default=True): animated, cv.Optional(CONF_UPDATE_ON_RELEASE, default=False): cv.boolean, + cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean, } ) @@ -32,32 +33,34 @@ CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend( async def to_code(config): widget = await get_widgets(config, CONF_WIDGET) widget = widget[0] - var = await number.new_number( - config, - max_value=widget.get_max(), - min_value=widget.get_min(), - step=widget.get_step(), - ) - await wait_for_widgets() + async with LambdaContext([], return_type=cg.float_) as value: + value.add(ReturnStatement(widget.get_value())) async with LambdaContext([(cg.float_, "v")]) as control: await widget.set_property( "value", MockObj("v") * MockObj(widget.get_scale()), config[CONF_ANIMATED] ) lv.event_send(widget.obj, API_EVENT, cg.nullptr) - control.add(var.publish_state(widget.get_value())) - async with LambdaContext(EVENT_ARG) as event: - event.add(var.publish_state(widget.get_value())) event_code = ( LV_EVENT.VALUE_CHANGED if not config[CONF_UPDATE_ON_RELEASE] else LV_EVENT.RELEASED ) - async with LvContext(): - lv_add(var.set_control_lambda(await control.get_lambda())) - lv_add( - lvgl_static.add_event_cb( - widget.obj, await event.get_lambda(), UPDATE_EVENT, event_code - ) + var = await number.new_number( + config, + await control.get_lambda(), + await value.get_lambda(), + event_code, + config[CONF_RESTORE_VALUE], + max_value=widget.get_max(), + min_value=widget.get_min(), + step=widget.get_step(), + ) + async with LambdaContext(EVENT_ARG) as event: + event.add(var.on_value()) + await cg.register_component(var, config) + cg.add( + lvgl_static.add_event_cb( + widget.obj, await event.get_lambda(), UPDATE_EVENT, event_code ) - lv_add(var.publish_state(widget.get_value())) + ) diff --git a/esphome/components/lvgl/number/lvgl_number.h b/esphome/components/lvgl/number/lvgl_number.h index 77fadd2a292..277494673b5 100644 --- a/esphome/components/lvgl/number/lvgl_number.h +++ b/esphome/components/lvgl/number/lvgl_number.h @@ -3,33 +3,46 @@ #include #include "esphome/components/number/number.h" -#include "esphome/core/automation.h" #include "esphome/core/component.h" #include "esphome/core/preferences.h" namespace esphome { namespace lvgl { -class LVGLNumber : public number::Number { +class LVGLNumber : public number::Number, public Component { public: - void set_control_lambda(std::function control_lambda) { - this->control_lambda_ = std::move(control_lambda); - if (this->initial_state_.has_value()) { - this->control_lambda_(this->initial_state_.value()); - this->initial_state_.reset(); + LVGLNumber(std::function control_lambda, std::function value_lambda, lv_event_code_t event, + bool restore) + : control_lambda_(std::move(control_lambda)), + value_lambda_(std::move(value_lambda)), + event_(event), + restore_(restore) {} + + void setup() override { + float value = this->value_lambda_(); + if (this->restore_) { + this->pref_ = global_preferences->make_preference(this->get_object_id_hash()); + if (this->pref_.load(&value)) { + this->control_lambda_(value); + } } + this->publish_state(value); } + void on_value() { this->publish_state(this->value_lambda_()); } + protected: void control(float value) override { - if (this->control_lambda_ != nullptr) { - this->control_lambda_(value); - } else { - this->initial_state_ = value; - } + this->control_lambda_(value); + this->publish_state(value); + if (this->restore_) + this->pref_.save(&value); } - std::function control_lambda_{}; - optional initial_state_{}; + std::function control_lambda_; + std::function value_lambda_; + lv_event_code_t event_; + bool restore_; + ESPPreferenceObject pref_{}; }; } // namespace lvgl diff --git a/esphome/components/lvgl/schemas.py b/esphome/components/lvgl/schemas.py index ae50d5b2e1c..051dbe5e0e9 100644 --- a/esphome/components/lvgl/schemas.py +++ b/esphome/components/lvgl/schemas.py @@ -6,6 +6,7 @@ from esphome.const import ( CONF_FORMAT, CONF_GROUP, CONF_ID, + CONF_ON_BOOT, CONF_ON_VALUE, CONF_STATE, CONF_TEXT, @@ -14,10 +15,11 @@ from esphome.const import ( CONF_TYPE, ) from esphome.core import TimePeriod +from esphome.core.config import StartupTrigger from esphome.schema_extractors import SCHEMA_EXTRACT from . import defines as df, lv_validation as lvalid -from .defines import CONF_TIME_FORMAT, LV_GRAD_DIR +from .defines import CONF_TIME_FORMAT, CONF_X, CONF_Y, LV_GRAD_DIR from .helpers import add_lv_use, requires_component, validate_printf from .lv_validation import lv_color, lv_font, lv_gradient, lv_image, opacity from .lvcode import LvglComponent, lv_event_t_ptr @@ -79,12 +81,39 @@ ENCODER_SCHEMA = cv.Schema( cv.declare_id(LVEncoderListener), requires_component("binary_sensor") ), cv.Optional(CONF_GROUP): cv.declare_id(lv_group_t), - cv.Optional(df.CONF_INITIAL_FOCUS): cv.use_id(lv_obj_t), + cv.Optional(df.CONF_INITIAL_FOCUS): cv.All( + LIST_ACTION_SCHEMA, cv.Length(min=1, max=1) + ), cv.Optional(df.CONF_LONG_PRESS_TIME, default="400ms"): PRESS_TIME, cv.Optional(df.CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME, } ) +POINT_SCHEMA = cv.Schema( + { + cv.Required(CONF_X): cv.templatable(cv.int_), + cv.Required(CONF_Y): cv.templatable(cv.int_), + } +) + + +def point_schema(value): + """ + A shorthand for a point in the form of x,y + :param value: The value to check + :return: The value as a tuple of x,y + """ + if isinstance(value, dict): + return POINT_SCHEMA(value) + try: + x, y = map(int, value.split(",")) + return {CONF_X: x, CONF_Y: y} + except ValueError: + pass + # not raising this in the catch block because pylint doesn't like it + raise cv.Invalid("Invalid point format, should be , ") + + # All LVGL styles and their validators STYLE_PROPS = { "align": df.CHILD_ALIGNMENTS.one_of, @@ -103,6 +132,7 @@ STYLE_PROPS = { "bg_image_recolor": lvalid.lv_color, "bg_image_recolor_opa": lvalid.opacity, "bg_image_src": lvalid.lv_image, + "bg_image_tiled": lvalid.lv_bool, "bg_main_stop": lvalid.stop_value, "bg_opa": lvalid.opacity, "border_color": lvalid.lv_color, @@ -117,9 +147,9 @@ STYLE_PROPS = { "height": lvalid.size, "image_recolor": lvalid.lv_color, "image_recolor_opa": lvalid.opacity, - "line_width": cv.positive_int, - "line_dash_width": cv.positive_int, - "line_dash_gap": cv.positive_int, + "line_width": lvalid.lv_positive_int, + "line_dash_width": lvalid.lv_positive_int, + "line_dash_gap": lvalid.lv_positive_int, "line_rounded": lvalid.lv_bool, "line_color": lvalid.lv_color, "opa": lvalid.opacity, @@ -147,8 +177,8 @@ STYLE_PROPS = { "LV_TEXT_DECOR_", "NONE", "UNDERLINE", "STRIKETHROUGH" ).several_of, "text_font": lv_font, - "text_letter_space": cv.positive_int, - "text_line_space": cv.positive_int, + "text_letter_space": lvalid.lv_positive_int, + "text_line_space": lvalid.lv_positive_int, "text_opa": lvalid.opacity, "transform_angle": lvalid.lv_angle, "transform_height": lvalid.pixels_or_percent, @@ -172,10 +202,15 @@ STYLE_REMAP = { "bg_image_recolor": "bg_img_recolor", "bg_image_recolor_opa": "bg_img_recolor_opa", "bg_image_src": "bg_img_src", + "bg_image_tiled": "bg_img_tiled", "image_recolor": "img_recolor", "image_recolor_opa": "img_recolor_opa", } +cell_alignments = df.LV_CELL_ALIGNMENTS.one_of +grid_alignments = df.LV_GRID_ALIGNMENTS.one_of +flex_alignments = df.LV_FLEX_ALIGNMENTS.one_of + # Complete object style schema STYLE_SCHEMA = cv.Schema({cv.Optional(k): v for k, v in STYLE_PROPS.items()}).extend( { @@ -186,6 +221,16 @@ STYLE_SCHEMA = cv.Schema({cv.Optional(k): v for k, v in STYLE_PROPS.items()}).ex } ) +# Also allow widget specific properties for use in style definitions +FULL_STYLE_SCHEMA = STYLE_SCHEMA.extend( + { + cv.Optional(df.CONF_GRID_CELL_X_ALIGN): grid_alignments, + cv.Optional(df.CONF_GRID_CELL_Y_ALIGN): grid_alignments, + cv.Optional(df.CONF_PAD_ROW): lvalid.pixels, + cv.Optional(df.CONF_PAD_COLUMN): lvalid.pixels, + } +) + # Object states. Top level properties apply to MAIN STATE_SCHEMA = cv.Schema( {cv.Optional(state): STYLE_SCHEMA for state in df.STATES} @@ -216,14 +261,24 @@ def automation_schema(typ: LvType): events = events + (CONF_ON_VALUE,) args = typ.get_arg_type() if isinstance(typ, LvType) else [] args.append(lv_event_t_ptr) - return { - cv.Optional(event): validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template(*args)), - } - ) - for event in events - } + return cv.Schema( + { + cv.Optional(event): validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( + Trigger.template(*args) + ), + } + ) + for event in events + } + ).extend( + { + cv.Optional(CONF_ON_BOOT): validate_automation( + {cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger)} + ) + } + ) def base_update_schema(widget_type, parts): @@ -307,10 +362,6 @@ grid_spec = cv.Any( lvalid.size, df.LvConstant("LV_GRID_", "CONTENT").one_of, grid_free_space ) -cell_alignments = df.LV_CELL_ALIGNMENTS.one_of -grid_alignments = df.LV_GRID_ALIGNMENTS.one_of -flex_alignments = df.LV_FLEX_ALIGNMENTS.one_of - LAYOUT_SCHEMA = { cv.Optional(df.CONF_LAYOUT): cv.typed_schema( { diff --git a/esphome/components/lvgl/select/__init__.py b/esphome/components/lvgl/select/__init__.py index bd5ef8f237b..4f9d12266e3 100644 --- a/esphome/components/lvgl/select/__init__.py +++ b/esphome/components/lvgl/select/__init__.py @@ -1,18 +1,19 @@ +import esphome.codegen as cg from esphome.components import select import esphome.config_validation as cv -from esphome.const import CONF_OPTIONS +from esphome.const import CONF_ID, CONF_OPTIONS, CONF_RESTORE_VALUE from ..defines import CONF_ANIMATED, CONF_WIDGET, literal -from ..lvcode import LvContext from ..types import LvSelect, lvgl_ns -from ..widgets import get_widgets, wait_for_widgets +from ..widgets import get_widgets -LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select) +LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select, cg.Component) CONFIG_SCHEMA = select.select_schema(LVGLSelect).extend( { cv.Required(CONF_WIDGET): cv.use_id(LvSelect), cv.Optional(CONF_ANIMATED, default=False): cv.boolean, + cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean, } ) @@ -21,12 +22,9 @@ async def to_code(config): widget = await get_widgets(config, CONF_WIDGET) widget = widget[0] options = widget.config.get(CONF_OPTIONS, []) - selector = await select.new_select(config, options=options) - await wait_for_widgets() - async with LvContext() as ctx: - ctx.add( - selector.set_widget( - widget.var, - literal("LV_ANIM_ON" if config[CONF_ANIMATED] else "LV_ANIM_OFF"), - ) - ) + animated = literal("LV_ANIM_ON" if config[CONF_ANIMATED] else "LV_ANIM_OFF") + selector = cg.new_Pvariable( + config[CONF_ID], widget.var, animated, config[CONF_RESTORE_VALUE] + ) + await select.register_select(selector, config, options=options) + await cg.register_component(selector, config) diff --git a/esphome/components/lvgl/select/lvgl_select.h b/esphome/components/lvgl/select/lvgl_select.h index 4538e339c37..5b43209a5fb 100644 --- a/esphome/components/lvgl/select/lvgl_select.h +++ b/esphome/components/lvgl/select/lvgl_select.h @@ -11,12 +11,20 @@ namespace esphome { namespace lvgl { -class LVGLSelect : public select::Select { +class LVGLSelect : public select::Select, public Component { public: - void set_widget(LvSelectable *widget, lv_anim_enable_t anim = LV_ANIM_OFF) { - this->widget_ = widget; - this->anim_ = anim; + LVGLSelect(LvSelectable *widget, lv_anim_enable_t anim, bool restore) + : widget_(widget), anim_(anim), restore_(restore) {} + + void setup() override { this->set_options_(); + if (this->restore_) { + size_t index; + this->pref_ = global_preferences->make_preference(this->get_object_id_hash()); + if (this->pref_.load(&index)) + this->widget_->set_selected_index(index, LV_ANIM_OFF); + } + this->publish(); lv_obj_add_event_cb( this->widget_->obj, [](lv_event_t *e) { @@ -24,11 +32,6 @@ class LVGLSelect : public select::Select { it->set_options_(); }, LV_EVENT_REFRESH, this); - if (this->initial_state_.has_value()) { - this->control(this->initial_state_.value()); - this->initial_state_.reset(); - } - this->publish(); auto lamb = [](lv_event_t *e) { auto *self = static_cast(e->user_data); self->publish(); @@ -37,21 +40,25 @@ class LVGLSelect : public select::Select { lv_obj_add_event_cb(this->widget_->obj, lamb, lv_update_event, this); } - void publish() { this->publish_state(this->widget_->get_selected_text()); } + void publish() { + this->publish_state(this->widget_->get_selected_text()); + if (this->restore_) { + auto index = this->widget_->get_selected_index(); + this->pref_.save(&index); + } + } protected: void control(const std::string &value) override { - if (this->widget_ != nullptr) { - this->widget_->set_selected_text(value, this->anim_); - } else { - this->initial_state_ = value; - } + this->widget_->set_selected_text(value, this->anim_); + this->publish(); } void set_options_() { this->traits.set_options(this->widget_->get_options()); } - LvSelectable *widget_{}; - optional initial_state_{}; - lv_anim_enable_t anim_{LV_ANIM_OFF}; + LvSelectable *widget_; + lv_anim_enable_t anim_; + bool restore_; + ESPPreferenceObject pref_{}; }; } // namespace lvgl diff --git a/esphome/components/lvgl/styles.py b/esphome/components/lvgl/styles.py index 6332e0976f8..b59ff513e29 100644 --- a/esphome/components/lvgl/styles.py +++ b/esphome/components/lvgl/styles.py @@ -1,4 +1,6 @@ +from esphome import automation import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID from esphome.core import ID from esphome.cpp_generator import MockObj @@ -12,25 +14,54 @@ from .defines import ( ) from .helpers import add_lv_use from .lvcode import LambdaContext, LocalVariable, lv, lv_assign, lv_variable -from .schemas import ALL_STYLES, STYLE_REMAP -from .types import lv_lambda_t, lv_obj_t, lv_obj_t_ptr -from .widgets import Widget, add_widgets, set_obj_properties, theme_widget_map +from .schemas import ALL_STYLES, FULL_STYLE_SCHEMA, STYLE_REMAP +from .types import ObjUpdateAction, lv_lambda_t, lv_obj_t, lv_obj_t_ptr, lv_style_t +from .widgets import ( + Widget, + add_widgets, + set_obj_properties, + theme_widget_map, + wait_for_widgets, +) from .widgets.obj import obj_spec +async def style_set(svar, style): + for prop, validator in ALL_STYLES.items(): + if (value := style.get(prop)) is not None: + if isinstance(validator, LValidator): + value = await validator.process(value) + if isinstance(value, list): + value = "|".join(value) + remapped_prop = STYLE_REMAP.get(prop, prop) + lv.call(f"style_set_{remapped_prop}", svar, literal(value)) + + async def styles_to_code(config): """Convert styles to C__ code.""" for style in config.get(CONF_STYLE_DEFINITIONS, ()): svar = cg.new_Pvariable(style[CONF_ID]) lv.style_init(svar) - for prop, validator in ALL_STYLES.items(): - if (value := style.get(prop)) is not None: - if isinstance(validator, LValidator): - value = await validator.process(value) - if isinstance(value, list): - value = "|".join(value) - remapped_prop = STYLE_REMAP.get(prop, prop) - lv.call(f"style_set_{remapped_prop}", svar, literal(value)) + await style_set(svar, style) + + +@automation.register_action( + "lvgl.style.update", + ObjUpdateAction, + FULL_STYLE_SCHEMA.extend( + { + cv.Required(CONF_ID): cv.use_id(lv_style_t), + } + ), +) +async def style_update_to_code(config, action_id, template_arg, args): + await wait_for_widgets() + style = await cg.get_variable(config[CONF_ID]) + async with LambdaContext(parameters=args, where=action_id) as context: + await style_set(style, config) + + var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) + return var async def theme_to_code(config): diff --git a/esphome/components/lvgl/trigger.py b/esphome/components/lvgl/trigger.py index b76f90fecde..283c9a5e567 100644 --- a/esphome/components/lvgl/trigger.py +++ b/esphome/components/lvgl/trigger.py @@ -1,6 +1,6 @@ from esphome import automation import esphome.codegen as cg -from esphome.const import CONF_ID, CONF_ON_VALUE, CONF_TRIGGER_ID +from esphome.const import CONF_ID, CONF_ON_BOOT, CONF_ON_VALUE, CONF_TRIGGER_ID from .defines import ( CONF_ALIGN, @@ -28,6 +28,13 @@ from .types import LV_EVENT from .widgets import LvScrActType, get_scr_act, widget_map +async def add_on_boot_triggers(triggers): + for conf in triggers: + trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], 390) + await cg.register_component(trigger, conf) + await automation.build_automation(trigger, [], conf) + + async def generate_triggers(): """ Generate LVGL triggers for all defined widgets @@ -75,6 +82,8 @@ async def generate_triggers(): UPDATE_EVENT, ) + await add_on_boot_triggers(w.config.get(CONF_ON_BOOT, ())) + # Generate align to directives while we're here if align_to := w.config.get(CONF_ALIGN_TO): target = widget_map[align_to[CONF_ID]].obj diff --git a/esphome/components/lvgl/widgets/__init__.py b/esphome/components/lvgl/widgets/__init__.py index e946a960007..ccad45bdc62 100644 --- a/esphome/components/lvgl/widgets/__init__.py +++ b/esphome/components/lvgl/widgets/__init__.py @@ -3,13 +3,12 @@ from typing import Any, Union from esphome import codegen as cg, config_validation as cv from esphome.config_validation import Invalid -from esphome.const import CONF_GROUP, CONF_ID, CONF_STATE, CONF_TYPE +from esphome.const import CONF_DEFAULT, CONF_GROUP, CONF_ID, CONF_STATE, CONF_TYPE from esphome.core import ID, TimePeriod from esphome.coroutine import FakeAwaitable from esphome.cpp_generator import CallExpression, MockObj from ..defines import ( - CONF_DEFAULT, CONF_FLEX_ALIGN_CROSS, CONF_FLEX_ALIGN_MAIN, CONF_FLEX_ALIGN_TRACK, diff --git a/esphome/components/lvgl/widgets/buttonmatrix.py b/esphome/components/lvgl/widgets/buttonmatrix.py index c65bb4b354e..0ba1fe4ae17 100644 --- a/esphome/components/lvgl/widgets/buttonmatrix.py +++ b/esphome/components/lvgl/widgets/buttonmatrix.py @@ -250,7 +250,7 @@ async def button_update_to_code(config, action_id, template_arg, args): widgets = await get_widgets(config[CONF_ID]) assert all(isinstance(w, MatrixButton) for w in widgets) - async def do_button_update(w: MatrixButton): + async def do_button_update(w): if (width := config.get(CONF_WIDTH)) is not None: lv.btnmatrix_set_btn_width(w.obj, w.index, width) if config.get(CONF_SELECTED): @@ -275,5 +275,5 @@ async def button_update_to_code(config, action_id, template_arg, args): ) return await action_to_code( - widgets, do_button_update, action_id, template_arg, args + widgets, do_button_update, action_id, template_arg, args, config ) diff --git a/esphome/components/lvgl/widgets/canvas.py b/esphome/components/lvgl/widgets/canvas.py new file mode 100644 index 00000000000..60812093d58 --- /dev/null +++ b/esphome/components/lvgl/widgets/canvas.py @@ -0,0 +1,407 @@ +from esphome import automation, codegen as cg, config_validation as cv +from esphome.components.display_menu_base import CONF_LABEL +from esphome.const import CONF_COLOR, CONF_HEIGHT, CONF_ID, CONF_TEXT, CONF_WIDTH +from esphome.cpp_generator import Literal, MockObj + +from ..automation import action_to_code +from ..defines import ( + CONF_END_ANGLE, + CONF_MAIN, + CONF_OPA, + CONF_PIVOT_X, + CONF_PIVOT_Y, + CONF_POINTS, + CONF_SRC, + CONF_START_ANGLE, + CONF_X, + CONF_Y, + literal, +) +from ..lv_validation import ( + lv_angle, + lv_bool, + lv_color, + lv_image, + lv_text, + opacity, + pixels, + size, +) +from ..lvcode import LocalVariable, lv, lv_assign +from ..schemas import STYLE_PROPS, STYLE_REMAP, TEXT_SCHEMA, point_schema +from ..types import LvType, ObjUpdateAction, WidgetType +from . import Widget, get_widgets +from .line import lv_point_t, process_coord + +CONF_CANVAS = "canvas" +CONF_BUFFER_ID = "buffer_id" +CONF_MAX_WIDTH = "max_width" +CONF_TRANSPARENT = "transparent" +CONF_RADIUS = "radius" + +lv_canvas_t = LvType("lv_canvas_t") + + +class CanvasType(WidgetType): + def __init__(self): + super().__init__( + CONF_CANVAS, + lv_canvas_t, + (CONF_MAIN,), + cv.Schema( + { + cv.Required(CONF_WIDTH): size, + cv.Required(CONF_HEIGHT): size, + cv.Optional(CONF_TRANSPARENT, default=False): cv.boolean, + } + ), + ) + + def get_uses(self): + return "img", CONF_LABEL + + async def to_code(self, w: Widget, config): + width = config[CONF_WIDTH] + height = config[CONF_HEIGHT] + use_alpha = "_ALPHA" if config[CONF_TRANSPARENT] else "" + lv.canvas_set_buffer( + w.obj, + lv.custom_mem_alloc( + literal(f"LV_CANVAS_BUF_SIZE_TRUE_COLOR{use_alpha}({width}, {height})") + ), + width, + height, + literal(f"LV_IMG_CF_TRUE_COLOR{use_alpha}"), + ) + + +canvas_spec = CanvasType() + + +@automation.register_action( + "lvgl.canvas.fill", + ObjUpdateAction, + cv.Schema( + { + cv.GenerateID(CONF_ID): cv.use_id(lv_canvas_t), + cv.Required(CONF_COLOR): lv_color, + cv.Optional(CONF_OPA, default="COVER"): opacity, + }, + ), +) +async def canvas_fill(config, action_id, template_arg, args): + widget = await get_widgets(config) + color = await lv_color.process(config[CONF_COLOR]) + opa = await opacity.process(config[CONF_OPA]) + + async def do_fill(w: Widget): + lv.canvas_fill_bg(w.obj, color, opa) + + return await action_to_code(widget, do_fill, action_id, template_arg, args, config) + + +@automation.register_action( + "lvgl.canvas.set_pixels", + ObjUpdateAction, + cv.Schema( + { + cv.GenerateID(CONF_ID): cv.use_id(lv_canvas_t), + cv.Required(CONF_COLOR): lv_color, + cv.Optional(CONF_OPA): opacity, + cv.Required(CONF_POINTS): cv.ensure_list(point_schema), + }, + ), +) +async def canvas_set_pixel(config, action_id, template_arg, args): + widget = await get_widgets(config) + color = await lv_color.process(config[CONF_COLOR]) + opa = await opacity.process(config.get(CONF_OPA)) + points = [ + ( + await pixels.process(p[CONF_X]), + await pixels.process(p[CONF_Y]), + ) + for p in config[CONF_POINTS] + ] + + async def do_set_pixels(w: Widget): + if isinstance(color, MockObj): + for point in points: + x, y = point + lv.canvas_set_px_color(w.obj, x, y, color) + else: + with LocalVariable("color", "lv_color_t", color, modifier="") as color_var: + for point in points: + x, y = point + lv.canvas_set_px_color(w.obj, x, y, color_var) + if opa: + if isinstance(opa, Literal): + for point in points: + x, y = point + lv.canvas_set_px_opa(w.obj, x, y, opa) + else: + with LocalVariable("opa", "lv_opa_t", opa, modifier="") as opa_var: + for point in points: + x, y = point + lv.canvas_set_px_opa(w.obj, x, y, opa_var) + + return await action_to_code( + widget, do_set_pixels, action_id, template_arg, args, config + ) + + +DRAW_SCHEMA = cv.Schema( + { + cv.GenerateID(CONF_ID): cv.use_id(lv_canvas_t), + cv.Required(CONF_X): pixels, + cv.Required(CONF_Y): pixels, + } +) +DRAW_OPA_SCHEMA = DRAW_SCHEMA.extend( + { + cv.Optional(CONF_OPA): opacity, + } +) + + +async def draw_to_code(config, dsc_type, props, do_draw, action_id, template_arg, args): + widget = await get_widgets(config) + x = await pixels.process(config.get(CONF_X)) + y = await pixels.process(config.get(CONF_Y)) + + async def action_func(w: Widget): + with LocalVariable("dsc", f"lv_draw_{dsc_type}_dsc_t", modifier="") as dsc: + dsc_addr = literal(f"&{dsc}") + lv.call(f"draw_{dsc_type}_dsc_init", dsc_addr) + if CONF_OPA in config: + opa = await opacity.process(config[CONF_OPA]) + lv_assign(dsc.opa, opa) + for prop, validator in props.items(): + if prop in config: + value = await validator.process(config[prop]) + mapped_prop = STYLE_REMAP.get(prop, prop) + lv_assign(getattr(dsc, mapped_prop), value) + await do_draw(w, x, y, dsc_addr) + + return await action_to_code( + widget, action_func, action_id, template_arg, args, config + ) + + +RECT_PROPS = { + p: STYLE_PROPS[p] + for p in ( + "radius", + "bg_opa", + "bg_color", + "bg_grad", + "border_color", + "border_width", + "border_opa", + "outline_color", + "outline_width", + "outline_pad", + "outline_opa", + "shadow_color", + "shadow_width", + "shadow_ofs_x", + "shadow_ofs_y", + "shadow_spread", + "shadow_opa", + ) +} + + +@automation.register_action( + "lvgl.canvas.draw_rectangle", + ObjUpdateAction, + DRAW_SCHEMA.extend( + { + cv.Required(CONF_WIDTH): cv.templatable(cv.int_), + cv.Required(CONF_HEIGHT): cv.templatable(cv.int_), + }, + ).extend({cv.Optional(prop): STYLE_PROPS[prop] for prop in RECT_PROPS}), +) +async def canvas_draw_rect(config, action_id, template_arg, args): + width = await pixels.process(config[CONF_WIDTH]) + height = await pixels.process(config[CONF_HEIGHT]) + + async def do_draw_rect(w: Widget, x, y, dsc_addr): + lv.canvas_draw_rect(w.obj, x, y, width, height, dsc_addr) + + return await draw_to_code( + config, "rect", RECT_PROPS, do_draw_rect, action_id, template_arg, args + ) + + +TEXT_PROPS = { + p: STYLE_PROPS[f"text_{p}"] + for p in ( + "font", + "color", + # "sel_color", + # "sel_bg_color", + "line_space", + "letter_space", + "align", + "decor", + ) +} + + +@automation.register_action( + "lvgl.canvas.draw_text", + ObjUpdateAction, + TEXT_SCHEMA.extend(DRAW_OPA_SCHEMA) + .extend( + { + cv.Required(CONF_MAX_WIDTH): cv.templatable(cv.int_), + }, + ) + .extend({cv.Optional(prop): STYLE_PROPS[f"text_{prop}"] for prop in TEXT_PROPS}), +) +async def canvas_draw_text(config, action_id, template_arg, args): + text = await lv_text.process(config[CONF_TEXT]) + max_width = await pixels.process(config[CONF_MAX_WIDTH]) + + async def do_draw_text(w: Widget, x, y, dsc_addr): + lv.canvas_draw_text(w.obj, x, y, max_width, dsc_addr, text) + + return await draw_to_code( + config, "label", TEXT_PROPS, do_draw_text, action_id, template_arg, args + ) + + +IMG_PROPS = { + "angle": STYLE_PROPS["transform_angle"], + "zoom": STYLE_PROPS["transform_zoom"], + "recolor": STYLE_PROPS["image_recolor"], + "recolor_opa": STYLE_PROPS["image_recolor_opa"], + "opa": STYLE_PROPS["opa"], +} + + +@automation.register_action( + "lvgl.canvas.draw_image", + ObjUpdateAction, + DRAW_OPA_SCHEMA.extend( + { + cv.Required(CONF_SRC): lv_image, + cv.Optional(CONF_PIVOT_X, default=0): pixels, + cv.Optional(CONF_PIVOT_Y, default=0): pixels, + }, + ).extend({cv.Optional(prop): validator for prop, validator in IMG_PROPS.items()}), +) +async def canvas_draw_image(config, action_id, template_arg, args): + src = await lv_image.process(config[CONF_SRC]) + pivot_x = await pixels.process(config[CONF_PIVOT_X]) + pivot_y = await pixels.process(config[CONF_PIVOT_Y]) + + async def do_draw_image(w: Widget, x, y, dsc_addr): + dsc = MockObj(f"(*{dsc_addr})") + if pivot_x or pivot_y: + # pylint :disable=no-member + lv_assign(dsc.pivot, literal(f"{{{pivot_x}, {pivot_y}}}")) + lv.canvas_draw_img(w.obj, x, y, src, dsc_addr) + + return await draw_to_code( + config, "img", IMG_PROPS, do_draw_image, action_id, template_arg, args + ) + + +LINE_PROPS = { + "width": STYLE_PROPS["line_width"], + "color": STYLE_PROPS["line_color"], + "dash-width": STYLE_PROPS["line_dash_width"], + "dash-gap": STYLE_PROPS["line_dash_gap"], + "round_start": lv_bool, + "round_end": lv_bool, +} + + +@automation.register_action( + "lvgl.canvas.draw_line", + ObjUpdateAction, + cv.Schema( + { + cv.GenerateID(CONF_ID): cv.use_id(lv_canvas_t), + cv.Optional(CONF_OPA): opacity, + cv.Required(CONF_POINTS): cv.ensure_list(point_schema), + }, + ).extend({cv.Optional(prop): validator for prop, validator in LINE_PROPS.items()}), +) +async def canvas_draw_line(config, action_id, template_arg, args): + points = [ + [await process_coord(p[CONF_X]), await process_coord(p[CONF_Y])] + for p in config[CONF_POINTS] + ] + + async def do_draw_line(w: Widget, x, y, dsc_addr): + with LocalVariable( + "points", cg.std_vector.template(lv_point_t), points, modifier="" + ) as points_var: + lv.canvas_draw_line(w.obj, points_var.data(), points_var.size(), dsc_addr) + + return await draw_to_code( + config, "line", LINE_PROPS, do_draw_line, action_id, template_arg, args + ) + + +@automation.register_action( + "lvgl.canvas.draw_polygon", + ObjUpdateAction, + cv.Schema( + { + cv.GenerateID(CONF_ID): cv.use_id(lv_canvas_t), + cv.Required(CONF_POINTS): cv.ensure_list(point_schema), + }, + ).extend({cv.Optional(prop): STYLE_PROPS[prop] for prop in RECT_PROPS}), +) +async def canvas_draw_polygon(config, action_id, template_arg, args): + points = [ + [await process_coord(p[CONF_X]), await process_coord(p[CONF_Y])] + for p in config[CONF_POINTS] + ] + + async def do_draw_polygon(w: Widget, x, y, dsc_addr): + with LocalVariable( + "points", cg.std_vector.template(lv_point_t), points, modifier="" + ) as points_var: + lv.canvas_draw_polygon( + w.obj, points_var.data(), points_var.size(), dsc_addr + ) + + return await draw_to_code( + config, "rect", RECT_PROPS, do_draw_polygon, action_id, template_arg, args + ) + + +ARC_PROPS = { + "width": STYLE_PROPS["arc_width"], + "color": STYLE_PROPS["arc_color"], + "rounded": STYLE_PROPS["arc_rounded"], +} + + +@automation.register_action( + "lvgl.canvas.draw_arc", + ObjUpdateAction, + DRAW_OPA_SCHEMA.extend( + { + cv.Required(CONF_RADIUS): pixels, + cv.Required(CONF_START_ANGLE): lv_angle, + cv.Required(CONF_END_ANGLE): lv_angle, + } + ).extend({cv.Optional(prop): validator for prop, validator in ARC_PROPS.items()}), +) +async def canvas_draw_arc(config, action_id, template_arg, args): + radius = await size.process(config[CONF_RADIUS]) + start_angle = await lv_angle.process(config[CONF_START_ANGLE]) + end_angle = await lv_angle.process(config[CONF_END_ANGLE]) + + async def do_draw_arc(w: Widget, x, y, dsc_addr): + lv.canvas_draw_arc(w.obj, x, y, radius, start_angle, end_angle, dsc_addr) + + return await draw_to_code( + config, "arc", ARC_PROPS, do_draw_arc, action_id, template_arg, args + ) diff --git a/esphome/components/lvgl/widgets/line.py b/esphome/components/lvgl/widgets/line.py index 0156fb17809..94fdfe23461 100644 --- a/esphome/components/lvgl/widgets/line.py +++ b/esphome/components/lvgl/widgets/line.py @@ -1,11 +1,11 @@ -import functools - import esphome.codegen as cg import esphome.config_validation as cv +from esphome.core import Lambda -from ..defines import CONF_MAIN -from ..lvcode import lv -from ..types import LvType +from ..defines import CONF_MAIN, CONF_X, CONF_Y, call_lambda +from ..lvcode import lv_add +from ..schemas import point_schema +from ..types import LvCompound, LvType from . import Widget, WidgetType CONF_LINE = "line" @@ -15,47 +15,37 @@ CONF_POINT_LIST_ID = "point_list_id" lv_point_t = cg.global_ns.struct("lv_point_t") -def point_list(il): - il = cv.string(il) - nl = il.replace(" ", "").split(",") - return [int(n) for n in nl] - - -def cv_point_list(value): - if not isinstance(value, list): - raise cv.Invalid("List of points required") - values = [point_list(v) for v in value] - if not functools.reduce(lambda f, v: f and len(v) == 2, values, True): - raise cv.Invalid("Points must be a list of x,y integer pairs") - return values - - LINE_SCHEMA = { - cv.Required(CONF_POINTS): cv_point_list, - cv.GenerateID(CONF_POINT_LIST_ID): cv.declare_id(lv_point_t), + cv.Required(CONF_POINTS): cv.ensure_list(point_schema), } -LINE_MODIFY_SCHEMA = { - cv.Optional(CONF_POINTS): cv_point_list, - cv.GenerateID(CONF_POINT_LIST_ID): cv.declare_id(lv_point_t), -} + +async def process_coord(coord): + if isinstance(coord, Lambda): + coord = call_lambda( + await cg.process_lambda(coord, [], return_type="lv_coord_t") + ) + if not coord.endswith("()"): + coord = f"static_cast({coord})" + return cg.RawExpression(coord) + return cg.safe_exp(coord) class LineType(WidgetType): def __init__(self): super().__init__( CONF_LINE, - LvType("lv_line_t"), + LvType("LvLineType", parents=(LvCompound,)), (CONF_MAIN,), LINE_SCHEMA, - modify_schema=LINE_MODIFY_SCHEMA, ) async def to_code(self, w: Widget, config): - """For a line object, create and add the points""" - if data := config.get(CONF_POINTS): - points = cg.static_const_array(config[CONF_POINT_LIST_ID], data) - lv.line_set_points(w.obj, points, len(data)) + points = [ + [await process_coord(p[CONF_X]), await process_coord(p[CONF_Y])] + for p in config[CONF_POINTS] + ] + lv_add(w.var.set_points(points)) line_spec = LineType() diff --git a/esphome/components/lvgl/widgets/meter.py b/esphome/components/lvgl/widgets/meter.py index 29a382f7cfd..840511da69a 100644 --- a/esphome/components/lvgl/widgets/meter.py +++ b/esphome/components/lvgl/widgets/meter.py @@ -297,7 +297,9 @@ async def indicator_update_to_code(config, action_id, template_arg, args): async def set_value(w: Widget): await set_indicator_values(w.var, w.obj, config) - return await action_to_code(widget, set_value, action_id, template_arg, args) + return await action_to_code( + widget, set_value, action_id, template_arg, args, config + ) async def set_indicator_values(meter, indicator, config): diff --git a/esphome/components/m5stack_8angle/__init__.py b/esphome/components/m5stack_8angle/__init__.py index 1aaa86a6fd1..a1c197b3811 100644 --- a/esphome/components/m5stack_8angle/__init__.py +++ b/esphome/components/m5stack_8angle/__init__.py @@ -1,9 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID - DEPENDENCIES = ["i2c"] CODEOWNERS = ["@rnauber"] MULTI_CONF = True diff --git a/esphome/components/m5stack_8angle/binary_sensor/__init__.py b/esphome/components/m5stack_8angle/binary_sensor/__init__.py index a8b26900833..22ab73e9015 100644 --- a/esphome/components/m5stack_8angle/binary_sensor/__init__.py +++ b/esphome/components/m5stack_8angle/binary_sensor/__init__.py @@ -1,9 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv -from .. import M5Stack8AngleComponent, m5stack_8angle_ns, CONF_M5STACK_8ANGLE_ID - +from .. import CONF_M5STACK_8ANGLE_ID, M5Stack8AngleComponent, m5stack_8angle_ns M5Stack8AngleSwitchBinarySensor = m5stack_8angle_ns.class_( "M5Stack8AngleSwitchBinarySensor", diff --git a/esphome/components/m5stack_8angle/light/__init__.py b/esphome/components/m5stack_8angle/light/__init__.py index 07384ecd61b..806ecaabf4d 100644 --- a/esphome/components/m5stack_8angle/light/__init__.py +++ b/esphome/components/m5stack_8angle/light/__init__.py @@ -1,11 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light - +import esphome.config_validation as cv from esphome.const import CONF_OUTPUT_ID -from .. import M5Stack8AngleComponent, m5stack_8angle_ns, CONF_M5STACK_8ANGLE_ID - +from .. import CONF_M5STACK_8ANGLE_ID, M5Stack8AngleComponent, m5stack_8angle_ns M5Stack8AngleLightsComponent = m5stack_8angle_ns.class_( "M5Stack8AngleLightOutput", diff --git a/esphome/components/m5stack_8angle/sensor/__init__.py b/esphome/components/m5stack_8angle/sensor/__init__.py index 70744a59e63..2132eaa4c22 100644 --- a/esphome/components/m5stack_8angle/sensor/__init__.py +++ b/esphome/components/m5stack_8angle/sensor/__init__.py @@ -1,7 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor - +import esphome.config_validation as cv from esphome.const import ( CONF_BIT_DEPTH, CONF_CHANNEL, @@ -11,13 +10,12 @@ from esphome.const import ( ) from .. import ( + CONF_M5STACK_8ANGLE_ID, AnalogBits, M5Stack8AngleComponent, m5stack_8angle_ns, - CONF_M5STACK_8ANGLE_ID, ) - M5Stack8AngleKnobSensor = m5stack_8angle_ns.class_( "M5Stack8AngleKnobSensor", sensor.Sensor, diff --git a/esphome/components/matrix_keypad/binary_sensor/__init__.py b/esphome/components/matrix_keypad/binary_sensor/__init__.py index edebf7b772c..8e63ed43ce4 100644 --- a/esphome/components/matrix_keypad/binary_sensor/__init__.py +++ b/esphome/components/matrix_keypad/binary_sensor/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import CONF_ID, CONF_KEY, CONF_ROW, CONF_COL -from .. import MatrixKeypad, matrix_keypad_ns, CONF_KEYPAD_ID +import esphome.config_validation as cv +from esphome.const import CONF_COL, CONF_ID, CONF_KEY, CONF_ROW + +from .. import CONF_KEYPAD_ID, MatrixKeypad, matrix_keypad_ns DEPENDENCIES = ["matrix_keypad"] diff --git a/esphome/components/max31855/sensor.py b/esphome/components/max31855/sensor.py index 0cdedb54641..93e48beee02 100644 --- a/esphome/components/max31855/sensor.py +++ b/esphome/components/max31855/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, spi +import esphome.config_validation as cv from esphome.const import ( CONF_REFERENCE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, diff --git a/esphome/components/max31865/sensor.py b/esphome/components/max31865/sensor.py index 704f9451713..d4498b062f8 100644 --- a/esphome/components/max31865/sensor.py +++ b/esphome/components/max31865/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, spi +import esphome.config_validation as cv from esphome.const import ( CONF_MAINS_FILTER, CONF_REFERENCE_RESISTANCE, diff --git a/esphome/components/max44009/sensor.py b/esphome/components/max44009/sensor.py index 498cccb77b8..5aea7f0be2e 100644 --- a/esphome/components/max44009/sensor.py +++ b/esphome/components/max44009/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, sensor import esphome.config_validation as cv -from esphome.components import sensor, i2c from esphome.const import ( CONF_ID, CONF_MODE, diff --git a/esphome/components/max6675/sensor.py b/esphome/components/max6675/sensor.py index 23fc86d2c24..e42abb68d1c 100644 --- a/esphome/components/max6675/sensor.py +++ b/esphome/components/max6675/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, spi +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/max6956/__init__.py b/esphome/components/max6956/__init__.py index bb71dba8bf1..0d2ff527c7d 100644 --- a/esphome/components/max6956/__init__.py +++ b/esphome/components/max6956/__init__.py @@ -1,13 +1,13 @@ +from esphome import automation, pins import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import pins, automation from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_NUMBER, - CONF_MODE, - CONF_INVERTED, CONF_INPUT, + CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OUTPUT, CONF_PULLUP, ) diff --git a/esphome/components/max6956/output/__init__.py b/esphome/components/max6956/output/__init__.py index 1caf8c8a449..352ba04a95e 100644 --- a/esphome/components/max6956/output/__init__.py +++ b/esphome/components/max6956/output/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output -from esphome.const import CONF_PIN, CONF_ID -from .. import MAX6956, max6956_ns, CONF_MAX6956 +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PIN + +from .. import CONF_MAX6956, MAX6956, max6956_ns DEPENDENCIES = ["max6956"] diff --git a/esphome/components/max7219/display.py b/esphome/components/max7219/display.py index 13807b0dbd1..c9d10f3c459 100644 --- a/esphome/components/max7219/display.py +++ b/esphome/components/max7219/display.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display, spi +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS DEPENDENCIES = ["spi"] diff --git a/esphome/components/max7219digit/display.py b/esphome/components/max7219digit/display.py index 779e385ab1f..582d11bf4ff 100644 --- a/esphome/components/max7219digit/display.py +++ b/esphome/components/max7219digit/display.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display, spi +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS CODEOWNERS = ["@rspaargaren"] diff --git a/esphome/components/max9611/sensor.py b/esphome/components/max9611/sensor.py index 246d332a866..8405a3f75af 100644 --- a/esphome/components/max9611/sensor.py +++ b/esphome/components/max9611/sensor.py @@ -1,23 +1,23 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, - CONF_SHUNT_RESISTANCE, - CONF_GAIN, - CONF_VOLTAGE, CONF_CURRENT, + CONF_GAIN, + CONF_ID, CONF_POWER, + CONF_SHUNT_RESISTANCE, CONF_TEMPERATURE, - UNIT_VOLT, - UNIT_AMPERE, - UNIT_WATT, - UNIT_CELSIUS, - DEVICE_CLASS_VOLTAGE, + CONF_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, + UNIT_AMPERE, + UNIT_CELSIUS, + UNIT_VOLT, + UNIT_WATT, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/mcp23008/__init__.py b/esphome/components/mcp23008/__init__.py index a534c9f87f0..ed48eb06a64 100644 --- a/esphome/components/mcp23008/__init__.py +++ b/esphome/components/mcp23008/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, mcp23x08_base, mcp23xxx_base +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["mcp23x08_base"] diff --git a/esphome/components/mcp23016/__init__.py b/esphome/components/mcp23016/__init__.py index 55722e3ae07..e15c6433498 100644 --- a/esphome/components/mcp23016/__init__.py +++ b/esphome/components/mcp23016/__init__.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OUTPUT, ) diff --git a/esphome/components/mcp23017/__init__.py b/esphome/components/mcp23017/__init__.py index 42fc37dd1df..33b8a680cf7 100644 --- a/esphome/components/mcp23017/__init__.py +++ b/esphome/components/mcp23017/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, mcp23x17_base, mcp23xxx_base +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["mcp23x17_base"] diff --git a/esphome/components/mcp23s08/__init__.py b/esphome/components/mcp23s08/__init__.py index 4d3998def88..c6152d58c0e 100644 --- a/esphome/components/mcp23s08/__init__.py +++ b/esphome/components/mcp23s08/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import mcp23x08_base, mcp23xxx_base, spi import esphome.config_validation as cv -from esphome.components import spi, mcp23x08_base, mcp23xxx_base from esphome.const import CONF_ID AUTO_LOAD = ["mcp23x08_base"] diff --git a/esphome/components/mcp23s17/__init__.py b/esphome/components/mcp23s17/__init__.py index 9e199f79c43..9a763d09b0e 100644 --- a/esphome/components/mcp23s17/__init__.py +++ b/esphome/components/mcp23s17/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import mcp23x17_base, mcp23xxx_base, spi import esphome.config_validation as cv -from esphome.components import spi, mcp23x17_base, mcp23xxx_base from esphome.const import CONF_ID AUTO_LOAD = ["mcp23x17_base"] diff --git a/esphome/components/mcp23xxx_base/__init__.py b/esphome/components/mcp23xxx_base/__init__.py index 1e41a8ddff6..c0e44d72ded 100644 --- a/esphome/components/mcp23xxx_base/__init__.py +++ b/esphome/components/mcp23xxx_base/__init__.py @@ -1,13 +1,13 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, - CONF_INVERTED, CONF_INTERRUPT, + CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OPEN_DRAIN_INTERRUPT, CONF_OUTPUT, CONF_PULLUP, diff --git a/esphome/components/mcp2515/canbus.py b/esphome/components/mcp2515/canbus.py index 4353cd7bc61..d34a77248ca 100644 --- a/esphome/components/mcp2515/canbus.py +++ b/esphome/components/mcp2515/canbus.py @@ -1,8 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import spi, canbus -from esphome.const import CONF_ID, CONF_MODE +from esphome.components import canbus, spi from esphome.components.canbus import CanbusComponent +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_MODE CODEOWNERS = ["@mvturnho", "@danielschramm"] DEPENDENCIES = ["spi"] diff --git a/esphome/components/mcp3008/__init__.py b/esphome/components/mcp3008/__init__.py index 24a48664c1b..41ccdd403a4 100644 --- a/esphome/components/mcp3008/__init__.py +++ b/esphome/components/mcp3008/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["spi"] diff --git a/esphome/components/mcp3008/sensor/__init__.py b/esphome/components/mcp3008/sensor/__init__.py index 8ae00ef29e6..e85ce2955d6 100644 --- a/esphome/components/mcp3008/sensor/__init__.py +++ b/esphome/components/mcp3008/sensor/__init__.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_NUMBER, CONF_REFERENCE_VOLTAGE, - UNIT_VOLT, - STATE_CLASS_MEASUREMENT, DEVICE_CLASS_VOLTAGE, + STATE_CLASS_MEASUREMENT, + UNIT_VOLT, ) -from .. import mcp3008_ns, MCP3008 +from .. import MCP3008, mcp3008_ns AUTO_LOAD = ["voltage_sampler"] diff --git a/esphome/components/mcp3204/__init__.py b/esphome/components/mcp3204/__init__.py index 98129fc3892..612297f934b 100644 --- a/esphome/components/mcp3204/__init__.py +++ b/esphome/components/mcp3204/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_REFERENCE_VOLTAGE DEPENDENCIES = ["spi"] diff --git a/esphome/components/mcp3204/sensor/__init__.py b/esphome/components/mcp3204/sensor/__init__.py index 6a81c6ec84b..a4b177cbcfa 100644 --- a/esphome/components/mcp3204/sensor/__init__.py +++ b/esphome/components/mcp3204/sensor/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, voltage_sampler +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_NUMBER -from .. import mcp3204_ns, MCP3204 + +from .. import MCP3204, mcp3204_ns AUTO_LOAD = ["voltage_sampler"] diff --git a/esphome/components/mcp4461/__init__.py b/esphome/components/mcp4461/__init__.py new file mode 100644 index 00000000000..1764629ff3b --- /dev/null +++ b/esphome/components/mcp4461/__init__.py @@ -0,0 +1,42 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import i2c +from esphome.const import CONF_ID + +CODEOWNERS = ["@p1ngb4ck"] +DEPENDENCIES = ["i2c"] +MULTI_CONF = True +CONF_DISABLE_WIPER_0 = "disable_wiper_0" +CONF_DISABLE_WIPER_1 = "disable_wiper_1" +CONF_DISABLE_WIPER_2 = "disable_wiper_2" +CONF_DISABLE_WIPER_3 = "disable_wiper_3" + +mcp4461_ns = cg.esphome_ns.namespace("mcp4461") +Mcp4461Component = mcp4461_ns.class_("Mcp4461Component", cg.Component, i2c.I2CDevice) +CONF_MCP4461_ID = "mcp4461_id" + +CONFIG_SCHEMA = ( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(Mcp4461Component), + cv.Optional(CONF_DISABLE_WIPER_0, default=False): cv.boolean, + cv.Optional(CONF_DISABLE_WIPER_1, default=False): cv.boolean, + cv.Optional(CONF_DISABLE_WIPER_2, default=False): cv.boolean, + cv.Optional(CONF_DISABLE_WIPER_3, default=False): cv.boolean, + } + ) + .extend(cv.COMPONENT_SCHEMA) + .extend(i2c.i2c_device_schema(0x2C)) +) + + +async def to_code(config): + var = cg.new_Pvariable( + config[CONF_ID], + config[CONF_DISABLE_WIPER_0], + config[CONF_DISABLE_WIPER_1], + config[CONF_DISABLE_WIPER_2], + config[CONF_DISABLE_WIPER_3], + ) + await cg.register_component(var, config) + await i2c.register_i2c_device(var, config) diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp new file mode 100644 index 00000000000..5393241281d --- /dev/null +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -0,0 +1,618 @@ +#include "mcp4461.h" + +#include "esphome/core/helpers.h" +#include "esphome/core/hal.h" + +namespace esphome { +namespace mcp4461 { + +static const char *const TAG = "mcp4461"; +constexpr uint8_t EEPROM_WRITE_TIMEOUT_MS = 10; + +void Mcp4461Component::setup() { + ESP_LOGCONFIG(TAG, "Setting up mcp4461 using address (0x%02X)...", this->address_); + auto err = this->write(nullptr, 0); + if (err != i2c::ERROR_OK) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->mark_failed(); + return; + } + // save WP/WL status + this->update_write_protection_status_(); + for (uint8_t i = 0; i < 8; i++) { + if (this->reg_[i].initial_value.has_value()) { + uint16_t initial_state = static_cast(*this->reg_[i].initial_value * 256.0f); + this->write_wiper_level_(i, initial_state); + } + if (this->reg_[i].enabled) { + this->reg_[i].state = this->read_wiper_level_(i); + } else { + // only volatile wipers can be set disabled on hw level + if (i < 4) { + this->reg_[i].state = 0; + Mcp4461WiperIdx wiper_idx = static_cast(i); + this->disable_wiper_(wiper_idx); + } + } + } +} + +void Mcp4461Component::set_initial_value(Mcp4461WiperIdx wiper, float initial_value) { + uint8_t wiper_idx = static_cast(wiper); + this->reg_[wiper_idx].initial_value = initial_value; +} + +void Mcp4461Component::initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal) { + uint8_t wiper_idx = static_cast(wiper); + switch (terminal) { + case 'a': + this->reg_[wiper_idx].terminal_a = false; + break; + case 'b': + this->reg_[wiper_idx].terminal_b = false; + break; + case 'w': + this->reg_[wiper_idx].terminal_w = false; + break; + } +} + +void Mcp4461Component::update_write_protection_status_() { + uint8_t status_register_value = this->get_status_register_(); + this->write_protected_ = static_cast((status_register_value >> 0) & 0x01); + this->reg_[0].wiper_lock_active = static_cast((status_register_value >> 2) & 0x01); + this->reg_[1].wiper_lock_active = static_cast((status_register_value >> 3) & 0x01); + this->reg_[2].wiper_lock_active = static_cast((status_register_value >> 5) & 0x01); + this->reg_[3].wiper_lock_active = static_cast((status_register_value >> 6) & 0x01); +} + +void Mcp4461Component::dump_config() { + ESP_LOGCONFIG(TAG, "mcp4461:"); + LOG_I2C_DEVICE(this); + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + } + // log wiper status + for (uint8_t i = 0; i < 8; ++i) { + // terminals only valid for volatile wipers 0-3 - enable/disable is terminal hw + // so also invalid for nonvolatile. For these, only print current level. + // reworked to be a one-line intentionally, as output would not be in order + if (i < 4) { + ESP_LOGCONFIG(TAG, " ├── Volatile wiper [%u] level: %u, Status: %s, HW: %s, A: %s, B: %s, W: %s", i, + this->reg_[i].state, ONOFF(this->reg_[i].terminal_hw), ONOFF(this->reg_[i].terminal_a), + ONOFF(this->reg_[i].terminal_b), ONOFF(this->reg_[i].terminal_w), ONOFF(this->reg_[i].enabled)); + } else { + ESP_LOGCONFIG(TAG, " ├── Nonvolatile wiper [%u] level: %u", i, this->reg_[i].state); + } + } +} + +void Mcp4461Component::loop() { + if (this->status_has_warning()) { + this->get_status_register_(); + } + for (uint8_t i = 0; i < 8; i++) { + if (this->reg_[i].update_level) { + // set wiper i state if changed + if (this->reg_[i].state != this->read_wiper_level_(i)) { + this->write_wiper_level_(i, this->reg_[i].state); + } + } + this->reg_[i].update_level = false; + // can be true only for wipers 0-3 + // setting changes for terminals of nonvolatile wipers + // is prohibited in public methods + if (this->reg_[i].update_terminal) { + // set terminal register changes + Mcp4461TerminalIdx terminal_connector = + i < 2 ? Mcp4461TerminalIdx::MCP4461_TERMINAL_0 : Mcp4461TerminalIdx::MCP4461_TERMINAL_1; + uint8_t new_terminal_value = this->calc_terminal_connector_byte_(terminal_connector); + ESP_LOGV(TAG, "updating terminal %u to new value %u", static_cast(terminal_connector), + new_terminal_value); + this->set_terminal_register_(terminal_connector, new_terminal_value); + } + this->reg_[i].update_terminal = false; + } +} + +uint8_t Mcp4461Component::get_status_register_() { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return 0; + } + uint8_t addr = static_cast(Mcp4461Addresses::MCP4461_STATUS); + uint8_t reg = addr | static_cast(Mcp4461Commands::READ); + uint16_t buf; + if (!this->read_byte_16(reg, &buf)) { + this->error_code_ = MCP4461_STATUS_REGISTER_ERROR; + this->mark_failed(); + return 0; + } + uint8_t msb = buf >> 8; + uint8_t lsb = static_cast(buf & 0x00ff); + if (msb != 1 || ((lsb >> 7) & 0x01) != 1 || ((lsb >> 1) & 0x01) != 1) { + // D8, D7 and R1 bits are hardlocked to 1 -> a status msb bit 0 (bit 9 of status register) of 0 or lsb bit 1/7 = 0 + // indicate device/communication issues, therefore mark component failed + this->error_code_ = MCP4461_STATUS_REGISTER_INVALID; + this->mark_failed(); + return 0; + } + this->status_clear_warning(); + return lsb; +} + +void Mcp4461Component::read_status_register_to_log() { + uint8_t status_register_value = this->get_status_register_(); + ESP_LOGI(TAG, "D7: %u, WL3: %u, WL2: %u, EEWA: %u, WL1: %u, WL0: %u, R1: %u, WP: %u", + ((status_register_value >> 7) & 0x01), ((status_register_value >> 6) & 0x01), + ((status_register_value >> 5) & 0x01), ((status_register_value >> 4) & 0x01), + ((status_register_value >> 3) & 0x01), ((status_register_value >> 2) & 0x01), + ((status_register_value >> 1) & 0x01), ((status_register_value >> 0) & 0x01)); +} + +uint8_t Mcp4461Component::get_wiper_address_(uint8_t wiper) { + uint8_t addr; + bool nonvolatile = false; + if (wiper > 3) { + nonvolatile = true; + wiper = wiper - 4; + } + switch (wiper) { + case 0: + addr = static_cast(Mcp4461Addresses::MCP4461_VW0); + break; + case 1: + addr = static_cast(Mcp4461Addresses::MCP4461_VW1); + break; + case 2: + addr = static_cast(Mcp4461Addresses::MCP4461_VW2); + break; + case 3: + addr = static_cast(Mcp4461Addresses::MCP4461_VW3); + break; + default: + ESP_LOGW(TAG, "unknown wiper specified"); + return 0; + } + if (nonvolatile) { + addr = addr + 0x20; + } + return addr; +} + +uint16_t Mcp4461Component::get_wiper_level_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return 0; + } + uint8_t wiper_idx = static_cast(wiper); + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return 0; + } + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "reading from disabled volatile wiper %u, returning 0", wiper_idx); + return 0; + } + return this->read_wiper_level_(wiper_idx); +} + +uint16_t Mcp4461Component::read_wiper_level_(uint8_t wiper_idx) { + uint8_t addr = this->get_wiper_address_(wiper_idx); + uint8_t reg = addr | static_cast(Mcp4461Commands::INCREMENT); + if (wiper_idx > 3) { + if (!this->is_eeprom_ready_for_writing_(true)) { + return 0; + } + } + uint16_t buf = 0; + if (!(this->read_byte_16(reg, &buf))) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + ESP_LOGW(TAG, "Error fetching %swiper %u value", (wiper_idx > 3) ? "nonvolatile " : "", wiper_idx); + return 0; + } + return buf; +} + +bool Mcp4461Component::update_wiper_level_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t wiper_idx = static_cast(wiper); + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return false; + } + uint16_t data = this->get_wiper_level_(wiper); + ESP_LOGV(TAG, "Got value %u from wiper %u", data, wiper_idx); + this->reg_[wiper_idx].state = data; + return true; +} + +bool Mcp4461Component::set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t wiper_idx = static_cast(wiper); + if (value > 0x100) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_VALUE_INVALID))); + return false; + } + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return false; + } + if (this->reg_[wiper_idx].wiper_lock_active) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_LOCKED))); + return false; + } + ESP_LOGV(TAG, "Setting MCP4461 wiper %u to %u", wiper_idx, value); + this->reg_[wiper_idx].state = value; + this->reg_[wiper_idx].update_level = true; + return true; +} + +void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) { + bool nonvolatile = wiper > 3; + if (!(this->mcp4461_write_(this->get_wiper_address_(wiper), value, nonvolatile))) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + ESP_LOGW(TAG, "Error writing %swiper %u level %u", (wiper > 3) ? "nonvolatile " : "", wiper, value); + } +} + +void Mcp4461Component::enable_wiper_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return; + } + uint8_t wiper_idx = static_cast(wiper); + if ((this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_ENABLED))); + return; + } + if (this->reg_[wiper_idx].wiper_lock_active) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_LOCKED))); + return; + } + ESP_LOGV(TAG, "Enabling wiper %u", wiper_idx); + this->reg_[wiper_idx].enabled = true; + if (wiper_idx < 4) { + this->reg_[wiper_idx].terminal_hw = true; + this->reg_[wiper_idx].update_terminal = true; + } +} + +void Mcp4461Component::disable_wiper_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return; + } + uint8_t wiper_idx = static_cast(wiper); + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return; + } + if (this->reg_[wiper_idx].wiper_lock_active) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_LOCKED))); + return; + } + ESP_LOGV(TAG, "Disabling wiper %u", wiper_idx); + this->reg_[wiper_idx].enabled = true; + if (wiper_idx < 4) { + this->reg_[wiper_idx].terminal_hw = true; + this->reg_[wiper_idx].update_terminal = true; + } +} + +bool Mcp4461Component::increase_wiper_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t wiper_idx = static_cast(wiper); + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return false; + } + if (this->reg_[wiper_idx].wiper_lock_active) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_LOCKED))); + return false; + } + if (this->reg_[wiper_idx].state == 256) { + ESP_LOGV(TAG, "Maximum wiper level reached, further increase of wiper %u prohibited", wiper_idx); + return false; + } + ESP_LOGV(TAG, "Increasing wiper %u", wiper_idx); + uint8_t addr = this->get_wiper_address_(wiper_idx); + uint8_t reg = addr | static_cast(Mcp4461Commands::INCREMENT); + auto err = this->write(&this->address_, reg, sizeof(reg)); + if (err != i2c::ERROR_OK) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + return false; + } + this->reg_[wiper_idx].state++; + return true; +} + +bool Mcp4461Component::decrease_wiper_(Mcp4461WiperIdx wiper) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t wiper_idx = static_cast(wiper); + if (!(this->reg_[wiper_idx].enabled)) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_DISABLED))); + return false; + } + if (this->reg_[wiper_idx].wiper_lock_active) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WIPER_LOCKED))); + return false; + } + if (this->reg_[wiper_idx].state == 0) { + ESP_LOGV(TAG, "Minimum wiper level reached, further decrease of wiper %u prohibited", wiper_idx); + return false; + } + ESP_LOGV(TAG, "Decreasing wiper %u", wiper_idx); + uint8_t addr = this->get_wiper_address_(wiper_idx); + uint8_t reg = addr | static_cast(Mcp4461Commands::DECREMENT); + auto err = this->write(&this->address_, reg, sizeof(reg)); + if (err != i2c::ERROR_OK) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + return false; + } + this->reg_[wiper_idx].state--; + return true; +} + +uint8_t Mcp4461Component::calc_terminal_connector_byte_(Mcp4461TerminalIdx terminal_connector) { + uint8_t i = static_cast(terminal_connector) <= 1 ? 0 : 2; + uint8_t new_value_byte = 0; + new_value_byte += static_cast(this->reg_[i].terminal_b); + new_value_byte += static_cast(this->reg_[i].terminal_w) << 1; + new_value_byte += static_cast(this->reg_[i].terminal_a) << 2; + new_value_byte += static_cast(this->reg_[i].terminal_hw) << 3; + new_value_byte += static_cast(this->reg_[(i + 1)].terminal_b) << 4; + new_value_byte += static_cast(this->reg_[(i + 1)].terminal_w) << 5; + new_value_byte += static_cast(this->reg_[(i + 1)].terminal_a) << 6; + new_value_byte += static_cast(this->reg_[(i + 1)].terminal_hw) << 7; + return new_value_byte; +} + +uint8_t Mcp4461Component::get_terminal_register_(Mcp4461TerminalIdx terminal_connector) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return 0; + } + uint8_t reg = static_cast(terminal_connector) == 0 ? static_cast(Mcp4461Addresses::MCP4461_TCON0) + : static_cast(Mcp4461Addresses::MCP4461_TCON1); + reg |= static_cast(Mcp4461Commands::READ); + uint16_t buf; + if (this->read_byte_16(reg, &buf)) { + return static_cast(buf & 0x00ff); + } else { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + ESP_LOGW(TAG, "Error fetching terminal register value"); + return 0; + } +} + +void Mcp4461Component::update_terminal_register_(Mcp4461TerminalIdx terminal_connector) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return; + } + if ((static_cast(terminal_connector) != 0 && static_cast(terminal_connector) != 1)) { + return; + } + uint8_t terminal_data = this->get_terminal_register_(terminal_connector); + if (terminal_data == 0) { + return; + } + ESP_LOGV(TAG, "Got terminal register %u data 0x%02X", static_cast(terminal_connector), terminal_data); + uint8_t wiper_index = 0; + if (static_cast(terminal_connector) == 1) { + wiper_index = 2; + } + this->reg_[wiper_index].terminal_b = ((terminal_data >> 0) & 0x01); + this->reg_[wiper_index].terminal_w = ((terminal_data >> 1) & 0x01); + this->reg_[wiper_index].terminal_a = ((terminal_data >> 2) & 0x01); + this->reg_[wiper_index].terminal_hw = ((terminal_data >> 3) & 0x01); + this->reg_[(wiper_index + 1)].terminal_b = ((terminal_data >> 4) & 0x01); + this->reg_[(wiper_index + 1)].terminal_w = ((terminal_data >> 5) & 0x01); + this->reg_[(wiper_index + 1)].terminal_a = ((terminal_data >> 6) & 0x01); + this->reg_[(wiper_index + 1)].terminal_hw = ((terminal_data >> 7) & 0x01); +} + +bool Mcp4461Component::set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t addr; + if (static_cast(terminal_connector) == 0) { + addr = static_cast(Mcp4461Addresses::MCP4461_TCON0); + } else if (static_cast(terminal_connector) == 1) { + addr = static_cast(Mcp4461Addresses::MCP4461_TCON1); + } else { + ESP_LOGW(TAG, "Invalid terminal connector id %u specified", static_cast(terminal_connector)); + return false; + } + if (!(this->mcp4461_write_(addr, data))) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + return false; + } + return true; +} + +void Mcp4461Component::enable_terminal_(Mcp4461WiperIdx wiper, char terminal) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return; + } + uint8_t wiper_idx = static_cast(wiper); + ESP_LOGV(TAG, "Enabling terminal %c of wiper %u", terminal, wiper_idx); + switch (terminal) { + case 'h': + this->reg_[wiper_idx].terminal_hw = true; + break; + case 'a': + this->reg_[wiper_idx].terminal_a = true; + break; + case 'b': + this->reg_[wiper_idx].terminal_b = true; + break; + case 'w': + this->reg_[wiper_idx].terminal_w = true; + break; + default: + ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); + return; + } + this->reg_[wiper_idx].update_terminal = false; +} + +void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return; + } + uint8_t wiper_idx = static_cast(wiper); + ESP_LOGV(TAG, "Disabling terminal %c of wiper %u", terminal, wiper_idx); + switch (terminal) { + case 'h': + this->reg_[wiper_idx].terminal_hw = false; + break; + case 'a': + this->reg_[wiper_idx].terminal_a = false; + break; + case 'b': + this->reg_[wiper_idx].terminal_b = false; + break; + case 'w': + this->reg_[wiper_idx].terminal_w = false; + break; + default: + ESP_LOGW(TAG, "Unknown terminal %c specified", terminal); + return; + } + this->reg_[wiper_idx].update_terminal = false; +} + +uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return 0; + } + uint8_t reg = 0; + reg |= static_cast(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast(location) * 0x10); + reg |= static_cast(Mcp4461Commands::READ); + uint16_t buf; + if (!this->is_eeprom_ready_for_writing_(true)) { + return 0; + } + if (!this->read_byte_16(reg, &buf)) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + ESP_LOGW(TAG, "Error fetching EEPROM location value"); + return 0; + } + return buf; +} + +bool Mcp4461Component::set_eeprom_value(Mcp4461EepromLocation location, uint16_t value) { + if (this->is_failed()) { + ESP_LOGE(TAG, "%s", LOG_STR_ARG(this->get_message_string(this->error_code_))); + return false; + } + uint8_t addr = 0; + if (value > 511) { + return false; + } + if (value > 256) { + addr = 1; + } + addr |= static_cast(Mcp4461EepromLocation::MCP4461_EEPROM_1) + (static_cast(location) * 0x10); + if (!(this->mcp4461_write_(addr, value, true))) { + this->error_code_ = MCP4461_STATUS_I2C_ERROR; + this->status_set_warning(); + ESP_LOGW(TAG, "Error writing EEPROM value"); + return false; + } + return true; +} + +bool Mcp4461Component::is_writing_() { + /* Read the EEPROM write-active status from the status register */ + bool writing = static_cast((this->get_status_register_() >> 4) & 0x01); + + /* If EEPROM is no longer writing, reset the timeout flag */ + if (!writing) { + /* This is protected boolean flag in Mcp4461Component class */ + this->last_eeprom_write_timed_out_ = false; + } + + return writing; +} + +bool Mcp4461Component::is_eeprom_ready_for_writing_(bool wait_if_not_ready) { + /* Check initial write status */ + bool ready_for_write = !this->is_writing_(); + + /* Return early if no waiting is required or EEPROM is already ready */ + if (ready_for_write || !wait_if_not_ready || this->last_eeprom_write_timed_out_) { + return ready_for_write; + } + + /* Timestamp before starting the loop */ + const uint32_t start_millis = millis(); + + ESP_LOGV(TAG, "Waiting until EEPROM is ready for write, start_millis = %" PRIu32, start_millis); + + /* Loop until EEPROM is ready or timeout is reached */ + while (!ready_for_write && ((millis() - start_millis) < EEPROM_WRITE_TIMEOUT_MS)) { + ready_for_write = !this->is_writing_(); + + /* If ready, exit early */ + if (ready_for_write) { + ESP_LOGV(TAG, "EEPROM is ready for new write, elapsed_millis = %" PRIu32, millis() - start_millis); + return true; + } + + /* Not ready yet, yield before checking again */ + yield(); + } + + /* If still not ready after timeout, log error and mark the timeout */ + ESP_LOGE(TAG, "EEPROM write timeout exceeded (%u ms)", EEPROM_WRITE_TIMEOUT_MS); + this->last_eeprom_write_timed_out_ = true; + + return false; +} + +bool Mcp4461Component::mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolatile) { + uint8_t reg = data > 0xff ? 1 : 0; + uint8_t value_byte = static_cast(data & 0x00ff); + ESP_LOGV(TAG, "Writing value %u to address %u", data, addr); + reg |= addr; + reg |= static_cast(Mcp4461Commands::WRITE); + if (nonvolatile) { + if (this->write_protected_) { + ESP_LOGW(TAG, "%s", LOG_STR_ARG(this->get_message_string(MCP4461_WRITE_PROTECTED))); + return false; + } + if (!this->is_eeprom_ready_for_writing_(true)) { + return false; + } + } + return this->write_byte(reg, value_byte); +} +} // namespace mcp4461 +} // namespace esphome diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h new file mode 100644 index 00000000000..9b7f60f2011 --- /dev/null +++ b/esphome/components/mcp4461/mcp4461.h @@ -0,0 +1,171 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/core/log.h" +#include "esphome/components/i2c/i2c.h" + +namespace esphome { +namespace mcp4461 { + +struct WiperState { + bool enabled = true; + uint16_t state = 0; + optional initial_value; + bool terminal_a = true; + bool terminal_b = true; + bool terminal_w = true; + bool terminal_hw = true; + bool wiper_lock_active = false; + bool update_level = false; + bool update_terminal = false; +}; + +// default wiper state is 128 / 0x80h +enum class Mcp4461Commands : uint8_t { WRITE = 0x00, INCREMENT = 0x04, DECREMENT = 0x08, READ = 0x0C }; + +enum class Mcp4461Addresses : uint8_t { + MCP4461_VW0 = 0x00, + MCP4461_VW1 = 0x10, + MCP4461_VW2 = 0x60, + MCP4461_VW3 = 0x70, + MCP4461_STATUS = 0x50, + MCP4461_TCON0 = 0x40, + MCP4461_TCON1 = 0xA0, + MCP4461_EEPROM_1 = 0xB0 +}; + +enum class Mcp4461WiperIdx : uint8_t { + MCP4461_WIPER_0 = 0, + MCP4461_WIPER_1 = 1, + MCP4461_WIPER_2 = 2, + MCP4461_WIPER_3 = 3, + MCP4461_WIPER_4 = 4, + MCP4461_WIPER_5 = 5, + MCP4461_WIPER_6 = 6, + MCP4461_WIPER_7 = 7 +}; + +enum class Mcp4461EepromLocation : uint8_t { + MCP4461_EEPROM_0 = 0, + MCP4461_EEPROM_1 = 1, + MCP4461_EEPROM_2 = 2, + MCP4461_EEPROM_3 = 3, + MCP4461_EEPROM_4 = 4 +}; + +enum class Mcp4461TerminalIdx : uint8_t { MCP4461_TERMINAL_0 = 0, MCP4461_TERMINAL_1 = 1 }; + +class Mcp4461Wiper; + +// Mcp4461Component +class Mcp4461Component : public Component, public i2c::I2CDevice { + public: + Mcp4461Component(bool disable_wiper_0, bool disable_wiper_1, bool disable_wiper_2, bool disable_wiper_3) + : wiper_0_disabled_(disable_wiper_0), + wiper_1_disabled_(disable_wiper_1), + wiper_2_disabled_(disable_wiper_2), + wiper_3_disabled_(disable_wiper_3) { + this->reg_[0].enabled = !wiper_0_disabled_; + this->reg_[1].enabled = !wiper_1_disabled_; + this->reg_[2].enabled = !wiper_2_disabled_; + this->reg_[3].enabled = !wiper_3_disabled_; + } + + void setup() override; + void dump_config() override; + float get_setup_priority() const override { return setup_priority::HARDWARE; } + void loop() override; + /// @brief get eeprom value from location + /// @param[in] location - eeprom location 0-4 + /// @return eeprom value of specified location (9 bits max) + uint16_t get_eeprom_value(Mcp4461EepromLocation location); + /// @brief set eeprom value at specified location + /// @param[in] location - eeprom location 0-4 + /// @param[in] value - 9 bits value to store + bool set_eeprom_value(Mcp4461EepromLocation location, uint16_t value); + /// @brief public function used to set initial value + /// @param[in] wiper - the wiper to set the value for + /// @param[in] initial_value - the initial value in range 0-1.0 as float + void set_initial_value(Mcp4461WiperIdx wiper, float initial_value); + /// @brief public function used to set disable terminal config + /// @param[in] wiper - the wiper to set the value for + /// @param[in] terminal - the terminal to disable, one of ['a','b','w','h'] + void initialize_terminal_disabled(Mcp4461WiperIdx wiper, char terminal); + /// @brief read status register to log + void read_status_register_to_log(); + + protected: + friend class Mcp4461Wiper; + void update_write_protection_status_(); + uint8_t get_wiper_address_(uint8_t wiper); + uint16_t read_wiper_level_(uint8_t wiper); + uint8_t get_status_register_(); + uint16_t get_wiper_level_(Mcp4461WiperIdx wiper); + bool set_wiper_level_(Mcp4461WiperIdx wiper, uint16_t value); + bool update_wiper_level_(Mcp4461WiperIdx wiper); + void enable_wiper_(Mcp4461WiperIdx wiper); + void disable_wiper_(Mcp4461WiperIdx wiper); + bool increase_wiper_(Mcp4461WiperIdx wiper); + bool decrease_wiper_(Mcp4461WiperIdx wiper); + void enable_terminal_(Mcp4461WiperIdx wiper, char terminal); + void disable_terminal_(Mcp4461WiperIdx, char terminal); + bool is_writing_(); + bool is_eeprom_ready_for_writing_(bool wait_if_not_ready); + void write_wiper_level_(uint8_t wiper, uint16_t value); + bool mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolatile = false); + uint8_t calc_terminal_connector_byte_(Mcp4461TerminalIdx terminal_connector); + void update_terminal_register_(Mcp4461TerminalIdx terminal_connector); + uint8_t get_terminal_register_(Mcp4461TerminalIdx terminal_connector); + bool set_terminal_register_(Mcp4461TerminalIdx terminal_connector, uint8_t data); + + // Converts a status to a human readable string + static const LogString *get_message_string(int status) { + switch (status) { + case MCP4461_STATUS_I2C_ERROR: + return LOG_STR("I2C error - communication with MCP4461 failed!"); + case MCP4461_STATUS_REGISTER_ERROR: + return LOG_STR("Status register could not be read"); + case MCP4461_STATUS_REGISTER_INVALID: + return LOG_STR("Invalid status register value - bits 1,7 or 8 are 0"); + case MCP4461_VALUE_INVALID: + return LOG_STR("Invalid value for wiper given"); + case MCP4461_WRITE_PROTECTED: + return LOG_STR("MCP4461 is write protected. Setting nonvolatile wipers/eeprom values is prohibited."); + case MCP4461_WIPER_ENABLED: + return LOG_STR("MCP4461 Wiper is already enabled, ignoring cmd to enable."); + case MCP4461_WIPER_DISABLED: + return LOG_STR("MCP4461 Wiper is disabled. All actions on this wiper are prohibited."); + case MCP4461_WIPER_LOCKED: + return LOG_STR("MCP4461 Wiper is locked using WiperLock-technology. All actions on this wiper are prohibited."); + case MCP4461_STATUS_OK: + return LOG_STR("Status OK"); + default: + return LOG_STR("Unknown"); + } + } + + enum ErrorCode { + MCP4461_STATUS_OK = 0, // CMD completed successfully + MCP4461_FAILED, // component failed + MCP4461_STATUS_I2C_ERROR, // Unable to communicate with device + MCP4461_STATUS_REGISTER_INVALID, // Status register value was invalid + MCP4461_STATUS_REGISTER_ERROR, // Error fetching status register + MCP4461_PROHIBITED_FOR_NONVOLATILE, // + MCP4461_VALUE_INVALID, // Invalid value given for wiper / eeprom + MCP4461_WRITE_PROTECTED, // The value was read, but the CRC over the payload (valid and data) does not match + MCP4461_WIPER_ENABLED, // The wiper is enabled, discard additional enabling actions + MCP4461_WIPER_DISABLED, // The wiper is disabled - all actions for this wiper will be aborted/discarded + MCP4461_WIPER_LOCKED, // The wiper is locked using WiperLock-technology - all actions for this wiper will be + // aborted/discarded + } error_code_{MCP4461_STATUS_OK}; + + WiperState reg_[8]; + bool last_eeprom_write_timed_out_{false}; + bool write_protected_{false}; + bool wiper_0_disabled_{false}; + bool wiper_1_disabled_{false}; + bool wiper_2_disabled_{false}; + bool wiper_3_disabled_{false}; +}; +} // namespace mcp4461 +} // namespace esphome diff --git a/esphome/components/mcp4461/output/__init__.py b/esphome/components/mcp4461/output/__init__.py new file mode 100644 index 00000000000..ba59f976438 --- /dev/null +++ b/esphome/components/mcp4461/output/__init__.py @@ -0,0 +1,60 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import output +from esphome.const import CONF_CHANNEL, CONF_ID, CONF_INITIAL_VALUE +from .. import Mcp4461Component, CONF_MCP4461_ID, mcp4461_ns + +DEPENDENCIES = ["mcp4461"] + +Mcp4461Wiper = mcp4461_ns.class_( + "Mcp4461Wiper", output.FloatOutput, cg.Parented.template(Mcp4461Component) +) + +Mcp4461WiperIdx = mcp4461_ns.enum("Mcp4461WiperIdx", is_class=True) +CHANNEL_OPTIONS = { + "A": Mcp4461WiperIdx.MCP4461_WIPER_0, + "B": Mcp4461WiperIdx.MCP4461_WIPER_1, + "C": Mcp4461WiperIdx.MCP4461_WIPER_2, + "D": Mcp4461WiperIdx.MCP4461_WIPER_3, + "E": Mcp4461WiperIdx.MCP4461_WIPER_4, + "F": Mcp4461WiperIdx.MCP4461_WIPER_5, + "G": Mcp4461WiperIdx.MCP4461_WIPER_6, + "H": Mcp4461WiperIdx.MCP4461_WIPER_7, +} + +CONF_TERMINAL_A = "terminal_a" +CONF_TERMINAL_B = "terminal_b" +CONF_TERMINAL_W = "terminal_w" + +CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( + { + cv.Required(CONF_ID): cv.declare_id(Mcp4461Wiper), + cv.GenerateID(CONF_MCP4461_ID): cv.use_id(Mcp4461Component), + cv.Required(CONF_CHANNEL): cv.enum(CHANNEL_OPTIONS, upper=True), + cv.Optional(CONF_TERMINAL_A, default=True): cv.boolean, + cv.Optional(CONF_TERMINAL_B, default=True): cv.boolean, + cv.Optional(CONF_TERMINAL_W, default=True): cv.boolean, + cv.Optional(CONF_INITIAL_VALUE): cv.float_range(min=0.0, max=1.0), + } +) + + +async def to_code(config): + parent = await cg.get_variable(config[CONF_MCP4461_ID]) + var = cg.new_Pvariable( + config[CONF_ID], + parent, + config[CONF_CHANNEL], + ) + if not config[CONF_TERMINAL_A]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], "a")) + if not config[CONF_TERMINAL_B]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], "b")) + if not config[CONF_TERMINAL_W]: + cg.add(parent.initialize_terminal_disabled(config[CONF_CHANNEL], "w")) + if CONF_INITIAL_VALUE in config: + cg.add( + parent.set_initial_value(config[CONF_CHANNEL], config[CONF_INITIAL_VALUE]) + ) + await output.register_output(var, config) + await cg.register_parented(var, config[CONF_MCP4461_ID]) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp new file mode 100644 index 00000000000..2d85a5df61e --- /dev/null +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -0,0 +1,73 @@ +#include "mcp4461_output.h" +#include + +#include "esphome/core/helpers.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace mcp4461 { + +static const char *const TAG = "mcp4461.output"; + +// public set_level function +void Mcp4461Wiper::set_level(float state) { + if (!std::isfinite(state)) { + ESP_LOGW(TAG, "Finite state state value is required."); + return; + } + state = clamp(state, 0.0f, 1.0f); + if (this->is_inverted()) { + state = 1.0f - state; + } + this->write_state(state); +} + +// floats from other components (like light etc.) are passed as "percentage floats" +// this function converts them to the 0 - 256 range used by the MCP4461 +void Mcp4461Wiper::write_state(float state) { + if (this->parent_->set_wiper_level_(this->wiper_, static_cast(std::roundf(state * 256)))) { + this->state_ = state; + } +} + +float Mcp4461Wiper::read_state() { return (static_cast(this->parent_->get_wiper_level_(this->wiper_)) / 256.0); } + +float Mcp4461Wiper::update_state() { + this->state_ = this->read_state(); + return this->state_; +} + +void Mcp4461Wiper::set_state(bool state) { + if (state) { + this->turn_on(); + } else { + this->turn_off(); + } +} + +void Mcp4461Wiper::turn_on() { this->parent_->enable_wiper_(this->wiper_); } + +void Mcp4461Wiper::turn_off() { this->parent_->disable_wiper_(this->wiper_); } + +void Mcp4461Wiper::increase_wiper() { + if (this->parent_->increase_wiper_(this->wiper_)) { + this->state_ = this->update_state(); + ESP_LOGV(TAG, "Increased wiper %u to %u", static_cast(this->wiper_), + static_cast(std::roundf(this->state_ * 256))); + } +} + +void Mcp4461Wiper::decrease_wiper() { + if (this->parent_->decrease_wiper_(this->wiper_)) { + this->state_ = this->update_state(); + ESP_LOGV(TAG, "Decreased wiper %u to %u", static_cast(this->wiper_), + static_cast(std::roundf(this->state_ * 256))); + } +} + +void Mcp4461Wiper::enable_terminal(char terminal) { this->parent_->enable_terminal_(this->wiper_, terminal); } + +void Mcp4461Wiper::disable_terminal(char terminal) { this->parent_->disable_terminal_(this->wiper_, terminal); } + +} // namespace mcp4461 +} // namespace esphome diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h new file mode 100644 index 00000000000..4055cef30a5 --- /dev/null +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -0,0 +1,49 @@ +#pragma once + +#include "../mcp4461.h" +#include "esphome/core/component.h" +#include "esphome/components/output/float_output.h" +#include "esphome/components/i2c/i2c.h" + +namespace esphome { +namespace mcp4461 { + +class Mcp4461Wiper : public output::FloatOutput, public Parented { + public: + Mcp4461Wiper(Mcp4461Component *parent, Mcp4461WiperIdx wiper) : parent_(parent), wiper_(wiper) {} + /// @brief Set level of wiper + /// @param[in] state - The desired float level in range 0-1.0 + void set_level(float state); + /// @brief Enables/Disables current output using bool parameter + /// @param[in] state boolean var representing desired state (true=ON, false=OFF) + void set_state(bool state) override; + /// @brief Enables current output + void turn_on() override; + /// @brief Disables current output + void turn_off() override; + /// @brief Read current device wiper state without updating internal output state + /// @return float - current device state as float in range 0 - 1.0 + float read_state(); + /// @brief Update current output state using device wiper state + /// @return float - current updated output state as float in range 0 - 1.0 + float update_state(); + /// @brief Increase wiper by 1 tap + void increase_wiper(); + /// @brief Decrease wiper by 1 tap + void decrease_wiper(); + /// @brief Enable given terminal + /// @param[in] terminal single char parameter defining desired terminal to enable, one of { 'a', 'b', 'w', 'h' } + void enable_terminal(char terminal); + /// @brief Disable given terminal + /// @param[in] terminal single char parameter defining desired terminal to disable, one of { 'a', 'b', 'w', 'h' } + void disable_terminal(char terminal); + + protected: + void write_state(float state) override; + Mcp4461Component *parent_; + Mcp4461WiperIdx wiper_; + float state_; +}; + +} // namespace mcp4461 +} // namespace esphome diff --git a/esphome/components/mcp4725/output.py b/esphome/components/mcp4725/output.py index 8f8b80d927e..5ec6a9d6863 100644 --- a/esphome/components/mcp4725/output.py +++ b/esphome/components/mcp4725/output.py @@ -1,6 +1,6 @@ -import esphome.config_validation as cv import esphome.codegen as cg -from esphome.components import output, i2c +from esphome.components import i2c, output +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/mcp4728/__init__.py b/esphome/components/mcp4728/__init__.py index a0702c415cd..da3244be84a 100644 --- a/esphome/components/mcp4728/__init__.py +++ b/esphome/components/mcp4728/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@berfenger"] diff --git a/esphome/components/mcp4728/output/__init__.py b/esphome/components/mcp4728/output/__init__.py index 20b196ca2c3..6f4a41510f2 100644 --- a/esphome/components/mcp4728/output/__init__.py +++ b/esphome/components/mcp4728/output/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output -from esphome.const import CONF_CHANNEL, CONF_ID, CONF_GAIN -from .. import MCP4728Component, CONF_MCP4728_ID, mcp4728_ns +import esphome.config_validation as cv +from esphome.const import CONF_CHANNEL, CONF_GAIN, CONF_ID + +from .. import CONF_MCP4728_ID, MCP4728Component, mcp4728_ns DEPENDENCIES = ["mcp4728"] diff --git a/esphome/components/mcp47a1/output.py b/esphome/components/mcp47a1/output.py index 60235107e95..ebd597cfeb4 100644 --- a/esphome/components/mcp47a1/output.py +++ b/esphome/components/mcp47a1/output.py @@ -1,6 +1,6 @@ -import esphome.config_validation as cv import esphome.codegen as cg -from esphome.components import output, i2c +from esphome.components import i2c, output +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/mcp9808/sensor.py b/esphome/components/mcp9808/sensor.py index 2d7874fe20a..ba6718ca569 100644 --- a/esphome/components/mcp9808/sensor.py +++ b/esphome/components/mcp9808/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/mhz19/sensor.py b/esphome/components/mhz19/sensor.py index 3956727981a..10428b1e4a6 100644 --- a/esphome/components/mhz19/sensor.py +++ b/esphome/components/mhz19/sensor.py @@ -1,18 +1,18 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_CO2, CONF_ID, CONF_TEMPERATURE, - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_CARBON_DIOXIDE, + DEVICE_CLASS_TEMPERATURE, ICON_MOLECULE_CO2, STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, UNIT_CELSIUS, + UNIT_PARTS_PER_MILLION, ) DEPENDENCIES = ["uart"] diff --git a/esphome/components/micronova/__init__.py b/esphome/components/micronova/__init__.py index bd253f8ebd2..31abc11abf8 100644 --- a/esphome/components/micronova/__init__.py +++ b/esphome/components/micronova/__init__.py @@ -1,10 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import uart -from esphome.const import ( - CONF_ID, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID CODEOWNERS = ["@jorre05"] diff --git a/esphome/components/micronova/button/__init__.py b/esphome/components/micronova/button/__init__.py index 442f69c08bd..813d24efefe 100644 --- a/esphome/components/micronova/button/__init__.py +++ b/esphome/components/micronova/button/__init__.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button +import esphome.config_validation as cv from .. import ( + CONF_MEMORY_ADDRESS, + CONF_MEMORY_LOCATION, + CONF_MICRONOVA_ID, + MICRONOVA_LISTENER_SCHEMA, MicroNova, MicroNovaFunctions, - CONF_MICRONOVA_ID, - CONF_MEMORY_LOCATION, - CONF_MEMORY_ADDRESS, - MICRONOVA_LISTENER_SCHEMA, micronova_ns, ) diff --git a/esphome/components/micronova/number/__init__.py b/esphome/components/micronova/number/__init__.py index 7124bf50d02..b0eeaf8dd1a 100644 --- a/esphome/components/micronova/number/__init__.py +++ b/esphome/components/micronova/number/__init__.py @@ -1,19 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import number -from esphome.const import ( - DEVICE_CLASS_TEMPERATURE, - UNIT_CELSIUS, - CONF_STEP, -) +import esphome.config_validation as cv +from esphome.const import CONF_STEP, DEVICE_CLASS_TEMPERATURE, UNIT_CELSIUS from .. import ( + CONF_MEMORY_ADDRESS, + CONF_MEMORY_LOCATION, + CONF_MICRONOVA_ID, + MICRONOVA_LISTENER_SCHEMA, MicroNova, MicroNovaFunctions, - CONF_MICRONOVA_ID, - CONF_MEMORY_LOCATION, - CONF_MEMORY_ADDRESS, - MICRONOVA_LISTENER_SCHEMA, micronova_ns, ) diff --git a/esphome/components/micronova/sensor/__init__.py b/esphome/components/micronova/sensor/__init__.py index 32e42f38882..ceb4a9ef776 100644 --- a/esphome/components/micronova/sensor/__init__.py +++ b/esphome/components/micronova/sensor/__init__.py @@ -1,21 +1,21 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_PRESSURE, + DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_REVOLUTIONS_PER_MINUTE, ) from .. import ( + CONF_MEMORY_ADDRESS, + CONF_MEMORY_LOCATION, + CONF_MICRONOVA_ID, + MICRONOVA_LISTENER_SCHEMA, MicroNova, MicroNovaFunctions, - CONF_MICRONOVA_ID, - CONF_MEMORY_LOCATION, - CONF_MEMORY_ADDRESS, - MICRONOVA_LISTENER_SCHEMA, micronova_ns, ) diff --git a/esphome/components/micronova/switch/__init__.py b/esphome/components/micronova/switch/__init__.py index 9846d46cc64..43e5c9d8442 100644 --- a/esphome/components/micronova/switch/__init__.py +++ b/esphome/components/micronova/switch/__init__.py @@ -1,17 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch -from esphome.const import ( - ICON_POWER, -) +import esphome.config_validation as cv +from esphome.const import ICON_POWER from .. import ( + CONF_MEMORY_ADDRESS, + CONF_MEMORY_LOCATION, + CONF_MICRONOVA_ID, + MICRONOVA_LISTENER_SCHEMA, MicroNova, MicroNovaFunctions, - CONF_MICRONOVA_ID, - CONF_MEMORY_LOCATION, - CONF_MEMORY_ADDRESS, - MICRONOVA_LISTENER_SCHEMA, micronova_ns, ) diff --git a/esphome/components/micronova/text_sensor/__init__.py b/esphome/components/micronova/text_sensor/__init__.py index dc27c4f32ce..474c30e13b3 100644 --- a/esphome/components/micronova/text_sensor/__init__.py +++ b/esphome/components/micronova/text_sensor/__init__.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from .. import ( + CONF_MEMORY_ADDRESS, + CONF_MEMORY_LOCATION, + CONF_MICRONOVA_ID, + MICRONOVA_LISTENER_SCHEMA, MicroNova, MicroNovaFunctions, - CONF_MICRONOVA_ID, - CONF_MEMORY_LOCATION, - CONF_MEMORY_ADDRESS, - MICRONOVA_LISTENER_SCHEMA, micronova_ns, ) diff --git a/esphome/components/microphone/__init__.py b/esphome/components/microphone/__init__.py index d99500bbed7..4e5471b117f 100644 --- a/esphome/components/microphone/__init__.py +++ b/esphome/components/microphone/__init__.py @@ -1,13 +1,11 @@ from esphome import automation -import esphome.config_validation as cv -import esphome.codegen as cg - from esphome.automation import maybe_simple_id +import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_TRIGGER_ID from esphome.core import CORE from esphome.coroutine import coroutine_with_priority - CODEOWNERS = ["@jesserockz"] IS_PLATFORM_COMPONENT = True diff --git a/esphome/components/midea/climate.py b/esphome/components/midea/climate.py index b7fef5e1ab3..1d3cac66ba2 100644 --- a/esphome/components/midea/climate.py +++ b/esphome/components/midea/climate.py @@ -1,9 +1,9 @@ -from esphome.core import coroutine from esphome import automation -from esphome.components import climate, sensor, uart, remote_transmitter +import esphome.codegen as cg +from esphome.components import climate, remote_transmitter, sensor, uart +from esphome.components.climate import ClimateMode, ClimatePreset, ClimateSwingMode from esphome.components.remote_base import CONF_TRANSMITTER_ID import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( CONF_AUTOCONF, CONF_BEEPER, @@ -16,12 +16,12 @@ from esphome.const import ( CONF_SUPPORTED_MODES, CONF_SUPPORTED_PRESETS, CONF_SUPPORTED_SWING_MODES, - CONF_TIMEOUT, CONF_TEMPERATURE, + CONF_TIMEOUT, CONF_USE_FAHRENHEIT, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, ICON_POWER, ICON_THERMOMETER, ICON_WATER_PERCENT, @@ -30,11 +30,7 @@ from esphome.const import ( UNIT_PERCENT, UNIT_WATT, ) -from esphome.components.climate import ( - ClimateMode, - ClimatePreset, - ClimateSwingMode, -) +from esphome.core import coroutine CODEOWNERS = ["@dudanov"] DEPENDENCIES = ["climate", "uart"] diff --git a/esphome/components/midea_ir/climate.py b/esphome/components/midea_ir/climate.py index 8fea6b192b2..21fa5f4f567 100644 --- a/esphome/components/midea_ir/climate.py +++ b/esphome/components/midea_ir/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_USE_FAHRENHEIT AUTO_LOAD = ["climate_ir", "coolix"] diff --git a/esphome/components/mitsubishi/climate.py b/esphome/components/mitsubishi/climate.py index 5e865c636f7..23f8ed21fa5 100644 --- a/esphome/components/mitsubishi/climate.py +++ b/esphome/components/mitsubishi/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@RubyBailey"] diff --git a/esphome/components/mlx90614/sensor.py b/esphome/components/mlx90614/sensor.py index 3e90d19e45c..6a34c4bdc00 100644 --- a/esphome/components/mlx90614/sensor.py +++ b/esphome/components/mlx90614/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_TEMPERATURE, diff --git a/esphome/components/mmc5603/sensor.py b/esphome/components/mmc5603/sensor.py index cf161324702..3223225271a 100644 --- a/esphome/components/mmc5603/sensor.py +++ b/esphome/components/mmc5603/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ADDRESS, CONF_FIELD_STRENGTH_X, @@ -8,12 +8,12 @@ from esphome.const import ( CONF_FIELD_STRENGTH_Z, CONF_HEADING, CONF_ID, - ICON_MAGNET, - STATE_CLASS_MEASUREMENT, - UNIT_MICROTESLA, - UNIT_DEGREES, - ICON_SCREEN_ROTATION, CONF_UPDATE_INTERVAL, + ICON_MAGNET, + ICON_SCREEN_ROTATION, + STATE_CLASS_MEASUREMENT, + UNIT_DEGREES, + UNIT_MICROTESLA, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/mmc5983/sensor.py b/esphome/components/mmc5983/sensor.py index e3f4209cf97..aaff2946f24 100644 --- a/esphome/components/mmc5983/sensor.py +++ b/esphome/components/mmc5983/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_FIELD_STRENGTH_X, CONF_FIELD_STRENGTH_Y, diff --git a/esphome/components/modbus/__init__.py b/esphome/components/modbus/__init__.py index ae0c818c289..2bd85c6121f 100644 --- a/esphome/components/modbus/__init__.py +++ b/esphome/components/modbus/__init__.py @@ -1,18 +1,14 @@ from __future__ import annotations + from typing import Literal -import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv -from esphome.cpp_helpers import gpio_pin_expression -from esphome.components import uart -from esphome.const import ( - CONF_FLOW_CONTROL_PIN, - CONF_ID, - CONF_ADDRESS, - CONF_DISABLE_CRC, -) from esphome import pins +import esphome.codegen as cg +from esphome.components import uart +import esphome.config_validation as cv +from esphome.const import CONF_ADDRESS, CONF_DISABLE_CRC, CONF_FLOW_CONTROL_PIN, CONF_ID +from esphome.cpp_helpers import gpio_pin_expression +import esphome.final_validate as fv DEPENDENCIES = ["uart"] diff --git a/esphome/components/modbus_controller/__init__.py b/esphome/components/modbus_controller/__init__.py index 2a080758318..61b60498d09 100644 --- a/esphome/components/modbus_controller/__init__.py +++ b/esphome/components/modbus_controller/__init__.py @@ -25,8 +25,8 @@ from .const import ( CONF_MODBUS_CONTROLLER_ID, CONF_OFFLINE_SKIP_UPDATES, CONF_ON_COMMAND_SENT, - CONF_ON_ONLINE, CONF_ON_OFFLINE, + CONF_ON_ONLINE, CONF_REGISTER_COUNT, CONF_REGISTER_TYPE, CONF_RESPONSE_SIZE, diff --git a/esphome/components/monochromatic/light.py b/esphome/components/monochromatic/light.py index 8f13f58f89c..4ce0202d25e 100644 --- a/esphome/components/monochromatic/light.py +++ b/esphome/components/monochromatic/light.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output -from esphome.const import CONF_OUTPUT_ID, CONF_OUTPUT +import esphome.config_validation as cv +from esphome.const import CONF_OUTPUT, CONF_OUTPUT_ID monochromatic_ns = cg.esphome_ns.namespace("monochromatic") MonochromaticLightOutput = monochromatic_ns.class_( diff --git a/esphome/components/mopeka_ble/__init__.py b/esphome/components/mopeka_ble/__init__.py index c89eae7933b..c8648cbc635 100644 --- a/esphome/components/mopeka_ble/__init__.py +++ b/esphome/components/mopeka_ble/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@spbrogan", "@Fabian-Schmidt"] diff --git a/esphome/components/mopeka_pro_check/sensor.py b/esphome/components/mopeka_pro_check/sensor.py index 95ade530130..4e84fb708cd 100644 --- a/esphome/components/mopeka_pro_check/sensor.py +++ b/esphome/components/mopeka_pro_check/sensor.py @@ -1,25 +1,25 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( + CONF_BATTERY_LEVEL, CONF_DISTANCE, - CONF_MAC_ADDRESS, CONF_ID, + CONF_LEVEL, + CONF_MAC_ADDRESS, + CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_TEMPERATURE, + ENTITY_CATEGORY_DIAGNOSTIC, ICON_COUNTER, - ICON_THERMOMETER, ICON_RULER, ICON_SIGNAL, - UNIT_PERCENT, - UNIT_EMPTY, - CONF_LEVEL, - CONF_TEMPERATURE, - DEVICE_CLASS_TEMPERATURE, - UNIT_CELSIUS, - UNIT_MILLIMETER, + ICON_THERMOMETER, STATE_CLASS_MEASUREMENT, - CONF_BATTERY_LEVEL, - DEVICE_CLASS_BATTERY, - ENTITY_CATEGORY_DIAGNOSTIC, + UNIT_CELSIUS, + UNIT_EMPTY, + UNIT_MILLIMETER, + UNIT_PERCENT, ) CONF_TANK_TYPE = "tank_type" diff --git a/esphome/components/mopeka_std_check/sensor.py b/esphome/components/mopeka_std_check/sensor.py index ac745cf3d55..d4535d96710 100644 --- a/esphome/components/mopeka_std_check/sensor.py +++ b/esphome/components/mopeka_std_check/sensor.py @@ -1,21 +1,21 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( + CONF_BATTERY_LEVEL, CONF_DISTANCE, - CONF_MAC_ADDRESS, CONF_ID, - ICON_THERMOMETER, - ICON_RULER, - UNIT_PERCENT, CONF_LEVEL, + CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, DEVICE_CLASS_TEMPERATURE, + ICON_RULER, + ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_MILLIMETER, - STATE_CLASS_MEASUREMENT, - CONF_BATTERY_LEVEL, - DEVICE_CLASS_BATTERY, + UNIT_PERCENT, ) CONF_TANK_TYPE = "tank_type" diff --git a/esphome/components/mpl3115a2/sensor.py b/esphome/components/mpl3115a2/sensor.py index 68ed0e08a86..b2cd1fb5351 100644 --- a/esphome/components/mpl3115a2/sensor.py +++ b/esphome/components/mpl3115a2/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ALTITUDE, CONF_ID, diff --git a/esphome/components/mpr121/__init__.py b/esphome/components/mpr121/__init__.py index 1f8e804e88d..b736a7e4f03 100644 --- a/esphome/components/mpr121/__init__.py +++ b/esphome/components/mpr121/__init__.py @@ -1,8 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_BINARY_SENSOR, CONF_CHANNEL, @@ -13,6 +12,7 @@ from esphome.const import ( CONF_NUMBER, CONF_OUTPUT, ) +import esphome.final_validate as fv CONF_TOUCH_THRESHOLD = "touch_threshold" CONF_RELEASE_THRESHOLD = "release_threshold" diff --git a/esphome/components/mpr121/binary_sensor/__init__.py b/esphome/components/mpr121/binary_sensor/__init__.py index dfae92a9af5..1252a65a841 100644 --- a/esphome/components/mpr121/binary_sensor/__init__.py +++ b/esphome/components/mpr121/binary_sensor/__init__.py @@ -1,13 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL + from .. import ( - mpr121_ns, - MPR121Component, CONF_MPR121_ID, - CONF_TOUCH_THRESHOLD, CONF_RELEASE_THRESHOLD, + CONF_TOUCH_THRESHOLD, + MPR121Component, + mpr121_ns, ) DEPENDENCIES = ["mpr121"] diff --git a/esphome/components/mpu6050/sensor.py b/esphome/components/mpu6050/sensor.py index f9b61dcadc9..377958fbe73 100644 --- a/esphome/components/mpu6050/sensor.py +++ b/esphome/components/mpu6050/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, ICON_BRIEFCASE_DOWNLOAD, - STATE_CLASS_MEASUREMENT, - UNIT_METER_PER_SECOND_SQUARED, ICON_SCREEN_ROTATION, - UNIT_DEGREE_PER_SECOND, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_DEGREE_PER_SECOND, + UNIT_METER_PER_SECOND_SQUARED, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/mpu6886/sensor.py b/esphome/components/mpu6886/sensor.py index 535007d008d..580fad7c23f 100644 --- a/esphome/components/mpu6886/sensor.py +++ b/esphome/components/mpu6886/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, ICON_BRIEFCASE_DOWNLOAD, - STATE_CLASS_MEASUREMENT, - UNIT_METER_PER_SECOND_SQUARED, ICON_SCREEN_ROTATION, - UNIT_DEGREE_PER_SECOND, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_DEGREE_PER_SECOND, + UNIT_METER_PER_SECOND_SQUARED, ) CODEOWNERS = ["@fabaff"] diff --git a/esphome/components/mqtt_subscribe/sensor/__init__.py b/esphome/components/mqtt_subscribe/sensor/__init__.py index 6fe0c48ae0c..56efb3f67ef 100644 --- a/esphome/components/mqtt_subscribe/sensor/__init__.py +++ b/esphome/components/mqtt_subscribe/sensor/__init__.py @@ -1,10 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import mqtt, sensor -from esphome.const import ( - CONF_QOS, - CONF_TOPIC, -) +import esphome.config_validation as cv +from esphome.const import CONF_QOS, CONF_TOPIC + from .. import mqtt_subscribe_ns DEPENDENCIES = ["mqtt"] diff --git a/esphome/components/mqtt_subscribe/text_sensor/__init__.py b/esphome/components/mqtt_subscribe/text_sensor/__init__.py index 5b5c0ae17f2..9c5d3a81eb8 100644 --- a/esphome/components/mqtt_subscribe/text_sensor/__init__.py +++ b/esphome/components/mqtt_subscribe/text_sensor/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import mqtt, text_sensor import esphome.config_validation as cv -from esphome.components import text_sensor, mqtt from esphome.const import CONF_QOS, CONF_TOPIC from .. import mqtt_subscribe_ns diff --git a/esphome/components/ms5611/sensor.py b/esphome/components/ms5611/sensor.py index 5decb134369..168ca0c5c8c 100644 --- a/esphome/components/ms5611/sensor.py +++ b/esphome/components/ms5611/sensor.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PRESSURE, CONF_TEMPERATURE, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, + ICON_GAUGE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - ICON_GAUGE, UNIT_HECTOPASCAL, ) diff --git a/esphome/components/ms8607/sensor.py b/esphome/components/ms8607/sensor.py index 1113e14af23..7ed7c61750b 100644 --- a/esphome/components/ms8607/sensor.py +++ b/esphome/components/ms8607/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/my9231/__init__.py b/esphome/components/my9231/__init__.py index 58419450cd8..e5a879a0f01 100644 --- a/esphome/components/my9231/__init__.py +++ b/esphome/components/my9231/__init__.py @@ -1,6 +1,6 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( CONF_BIT_DEPTH, CONF_CLOCK_PIN, diff --git a/esphome/components/my9231/output.py b/esphome/components/my9231/output.py index a3c16fd49a9..b4fad82c5f6 100644 --- a/esphome/components/my9231/output.py +++ b/esphome/components/my9231/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import MY9231OutputComponent DEPENDENCIES = ["my9231"] diff --git a/esphome/components/nau7802/nau7802.cpp b/esphome/components/nau7802/nau7802.cpp index ea6c0258af8..d7149e5697a 100644 --- a/esphome/components/nau7802/nau7802.cpp +++ b/esphome/components/nau7802/nau7802.cpp @@ -120,8 +120,6 @@ void NAU7802Sensor::complete_setup_() { // PGA stabilizer cap on output i2c::I2CRegister pwr_reg = this->reg(POWER_REG); pwr_reg |= POWER_PGA_CAP_EN; - - this->setup_complete_ = true; } void NAU7802Sensor::dump_config() { @@ -317,7 +315,5 @@ void NAU7802Sensor::update() { bool NAU7802Sensor::is_data_ready_() { return this->reg(PU_CTRL_REG).get() & PU_CTRL_CYCLE_READY; } -bool NAU7802Sensor::can_proceed() { return this->setup_complete_; } - } // namespace nau7802 } // namespace esphome diff --git a/esphome/components/nau7802/nau7802.h b/esphome/components/nau7802/nau7802.h index 3b0372aa897..17e426ccc6c 100644 --- a/esphome/components/nau7802/nau7802.h +++ b/esphome/components/nau7802/nau7802.h @@ -61,7 +61,6 @@ class NAU7802Sensor : public sensor::Sensor, public PollingComponent, public i2c void setup() override; void loop() override; - bool can_proceed() override; void dump_config() override; float get_setup_priority() const override; void update() override; @@ -80,7 +79,6 @@ class NAU7802Sensor : public sensor::Sensor, public PollingComponent, public i2c int32_t offset_calibration_; bool offset_calibration_failed_ = false; bool gain_calibration_failed_ = false; - bool setup_complete_ = false; // // Config values diff --git a/esphome/components/neopixelbus/_methods.py b/esphome/components/neopixelbus/_methods.py index 4059d040d04..5a00fa28048 100644 --- a/esphome/components/neopixelbus/_methods.py +++ b/esphome/components/neopixelbus/_methods.py @@ -1,6 +1,14 @@ from dataclasses import dataclass from typing import Any + import esphome.codegen as cg +from esphome.components.esp32 import get_esp32_variant +from esphome.components.esp32.const import ( + VARIANT_ESP32, + VARIANT_ESP32C3, + VARIANT_ESP32S2, + VARIANT_ESP32S3, +) import esphome.config_validation as cv from esphome.const import ( CONF_CHANNEL, @@ -10,17 +18,9 @@ from esphome.const import ( CONF_PIN, CONF_SPEED, ) -from esphome.components.esp32 import get_esp32_variant -from esphome.components.esp32.const import ( - VARIANT_ESP32, - VARIANT_ESP32C3, - VARIANT_ESP32S2, - VARIANT_ESP32S3, -) from esphome.core import CORE + from .const import ( - CONF_ASYNC, - CONF_BUS, CHIP_400KBPS, CHIP_800KBPS, CHIP_APA106, @@ -38,6 +38,8 @@ from .const import ( CHIP_WS2812, CHIP_WS2812X, CHIP_WS2813, + CONF_ASYNC, + CONF_BUS, ONE_WIRE_CHIPS, TWO_WIRE_CHIPS, ) diff --git a/esphome/components/neopixelbus/light.py b/esphome/components/neopixelbus/light.py index 9bd92159364..affeb2de8f9 100644 --- a/esphome/components/neopixelbus/light.py +++ b/esphome/components/neopixelbus/light.py @@ -1,40 +1,33 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import light +from esphome.components.esp32 import get_esp32_variant +from esphome.components.esp32.const import VARIANT_ESP32C3, VARIANT_ESP32S3 +import esphome.config_validation as cv from esphome.const import ( CONF_CHANNEL, CONF_CLOCK_PIN, CONF_DATA_PIN, + CONF_INVERT, CONF_METHOD, CONF_NUM_LEDS, + CONF_OUTPUT_ID, CONF_PIN, CONF_TYPE, CONF_VARIANT, - CONF_OUTPUT_ID, - CONF_INVERT, -) -from esphome.components.esp32 import get_esp32_variant -from esphome.components.esp32.const import ( - VARIANT_ESP32C3, - VARIANT_ESP32S3, ) from esphome.core import CORE + from ._methods import ( - METHODS, - METHOD_SPI, - METHOD_ESP8266_UART, METHOD_BIT_BANG, METHOD_ESP32_I2S, METHOD_ESP32_RMT, METHOD_ESP8266_DMA, + METHOD_ESP8266_UART, + METHOD_SPI, + METHODS, ) -from .const import ( - CHIP_TYPES, - CONF_ASYNC, - CONF_BUS, - ONE_WIRE_CHIPS, -) +from .const import CHIP_TYPES, CONF_ASYNC, CONF_BUS, ONE_WIRE_CHIPS neopixelbus_ns = cg.esphome_ns.namespace("neopixelbus") NeoPixelBusLightOutputBase = neopixelbus_ns.class_( diff --git a/esphome/components/nextion/binary_sensor/__init__.py b/esphome/components/nextion/binary_sensor/__init__.py index a257587e137..7ef72c6491b 100644 --- a/esphome/components/nextion/binary_sensor/__init__.py +++ b/esphome/components/nextion/binary_sensor/__init__.py @@ -1,23 +1,15 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv +from esphome.const import CONF_COMPONENT_ID, CONF_ID, CONF_PAGE_ID, CONF_STATE -from esphome.const import ( - CONF_ID, - CONF_STATE, - CONF_COMPONENT_ID, - CONF_PAGE_ID, -) - -from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION - - +from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns from ..base_component import ( - setup_component_core_, - CONFIG_BINARY_SENSOR_SCHEMA, - CONF_VARIABLE_NAME, CONF_COMPONENT_NAME, + CONF_VARIABLE_NAME, + CONFIG_BINARY_SENSOR_SCHEMA, + setup_component_core_, ) CODEOWNERS = ["@senexcrenshaw"] diff --git a/esphome/components/nextion/sensor/__init__.py b/esphome/components/nextion/sensor/__init__.py index 1058c2a04b2..9802762ff35 100644 --- a/esphome/components/nextion/sensor/__init__.py +++ b/esphome/components/nextion/sensor/__init__.py @@ -1,25 +1,22 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv +from esphome.const import CONF_COMPONENT_ID, CONF_ID, CONF_STATE -from esphome.const import CONF_ID, CONF_COMPONENT_ID, CONF_STATE - -from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION - +from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns from ..base_component import ( - setup_component_core_, - CONFIG_SENSOR_COMPONENT_SCHEMA, - CONF_VARIABLE_NAME, CONF_COMPONENT_NAME, CONF_PRECISION, + CONF_VARIABLE_NAME, CONF_WAVE_CHANNEL_ID, + CONF_WAVE_MAX_LENGTH, CONF_WAVE_MAX_VALUE, CONF_WAVEFORM_SEND_LAST_VALUE, - CONF_WAVE_MAX_LENGTH, + CONFIG_SENSOR_COMPONENT_SCHEMA, + setup_component_core_, ) - CODEOWNERS = ["@senexcrenshaw"] NextionSensor = nextion_ns.class_("NextionSensor", sensor.Sensor, cg.PollingComponent) diff --git a/esphome/components/nextion/switch/__init__.py b/esphome/components/nextion/switch/__init__.py index de1a061478d..1974ff3b9ea 100644 --- a/esphome/components/nextion/switch/__init__.py +++ b/esphome/components/nextion/switch/__init__.py @@ -1,17 +1,15 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch - +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_STATE -from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION - +from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns from ..base_component import ( - setup_component_core_, CONF_COMPONENT_NAME, CONF_VARIABLE_NAME, CONFIG_SWITCH_COMPONENT_SCHEMA, + setup_component_core_, ) CODEOWNERS = ["@senexcrenshaw"] diff --git a/esphome/components/nextion/text_sensor/__init__.py b/esphome/components/nextion/text_sensor/__init__.py index 793397b1f44..8fc0a8ceaf0 100644 --- a/esphome/components/nextion/text_sensor/__init__.py +++ b/esphome/components/nextion/text_sensor/__init__.py @@ -1,15 +1,11 @@ from esphome import automation +import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_ID, CONF_STATE -from .. import nextion_ns, CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION - -from ..base_component import ( - setup_component_core_, - CONFIG_TEXT_COMPONENT_SCHEMA, -) +from .. import CONF_NEXTION_ID, CONF_PUBLISH_STATE, CONF_SEND_TO_NEXTION, nextion_ns +from ..base_component import CONFIG_TEXT_COMPONENT_SCHEMA, setup_component_core_ CODEOWNERS = ["@senexcrenshaw"] diff --git a/esphome/components/noblex/climate.py b/esphome/components/noblex/climate.py index 2025cb5d9e8..7f4e8e64883 100644 --- a/esphome/components/noblex/climate.py +++ b/esphome/components/noblex/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/ntc/sensor.py b/esphome/components/ntc/sensor.py index bd5f4a18416..d47052cac68 100644 --- a/esphome/components/ntc/sensor.py +++ b/esphome/components/ntc/sensor.py @@ -1,8 +1,8 @@ from math import log -import esphome.config_validation as cv import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CALIBRATION, CONF_REFERENCE_RESISTANCE, diff --git a/esphome/components/opentherm/__init__.py b/esphome/components/opentherm/__init__.py index 42b476eb87a..8cbee1eed24 100644 --- a/esphome/components/opentherm/__init__.py +++ b/esphome/components/opentherm/__init__.py @@ -1,13 +1,13 @@ +import logging from typing import Any -import logging -from esphome import automation +from esphome import automation, pins import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import pins from esphome.components import sensor -from esphome.const import CONF_ID, PLATFORM_ESP32, PLATFORM_ESP8266, CONF_TRIGGER_ID -from . import const, schema, validate, generate +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_TRIGGER_ID, PLATFORM_ESP32, PLATFORM_ESP8266 + +from . import const, generate, schema, validate CODEOWNERS = ["@olegtarasov"] MULTI_CONF = True diff --git a/esphome/components/opentherm/input.py b/esphome/components/opentherm/input.py index 7897747be1a..c5814f74e2c 100644 --- a/esphome/components/opentherm/input.py +++ b/esphome/components/opentherm/input.py @@ -2,7 +2,8 @@ from typing import Any import esphome.codegen as cg import esphome.config_validation as cv -from . import schema, generate + +from . import generate, schema CONF_min_value = "min_value" CONF_max_value = "max_value" diff --git a/esphome/components/opentherm/number/__init__.py b/esphome/components/opentherm/number/__init__.py index bbf3e87586a..00aa62483c9 100644 --- a/esphome/components/opentherm/number/__init__.py +++ b/esphome/components/opentherm/number/__init__.py @@ -1,16 +1,17 @@ from typing import Any import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import number +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_UNIT_OF_MEASUREMENT, - CONF_STEP, CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, + CONF_STEP, + CONF_UNIT_OF_MEASUREMENT, ) -from .. import const, schema, validate, input, generate + +from .. import const, generate, input, schema, validate DEPENDENCIES = [const.OPENTHERM] COMPONENT_TYPE = const.NUMBER diff --git a/esphome/components/opentherm/output/__init__.py b/esphome/components/opentherm/output/__init__.py index 3a53c9d4f4c..87307eb051f 100644 --- a/esphome/components/opentherm/output/__init__.py +++ b/esphome/components/opentherm/output/__init__.py @@ -1,10 +1,11 @@ from typing import Any import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_ID -from .. import const, schema, validate, input, generate + +from .. import const, generate, input, schema, validate DEPENDENCIES = [const.OPENTHERM] COMPONENT_TYPE = const.OUTPUT diff --git a/esphome/components/opentherm/schema.py b/esphome/components/opentherm/schema.py index a58de8e2dab..791ba215e0b 100644 --- a/esphome/components/opentherm/schema.py +++ b/esphome/components/opentherm/schema.py @@ -2,16 +2,10 @@ # inputs of the OpenTherm component. from dataclasses import dataclass -from typing import Optional, TypeVar, Any +from typing import Any, Optional, TypeVar import esphome.config_validation as cv from esphome.const import ( - UNIT_CELSIUS, - UNIT_EMPTY, - UNIT_KILOWATT, - UNIT_MICROAMP, - UNIT_PERCENT, - UNIT_REVOLUTIONS_PER_MINUTE, DEVICE_CLASS_COLD, DEVICE_CLASS_CURRENT, DEVICE_CLASS_EMPTY, @@ -22,6 +16,12 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, STATE_CLASS_NONE, STATE_CLASS_TOTAL_INCREASING, + UNIT_CELSIUS, + UNIT_EMPTY, + UNIT_KILOWATT, + UNIT_MICROAMP, + UNIT_PERCENT, + UNIT_REVOLUTIONS_PER_MINUTE, ) diff --git a/esphome/components/opentherm/switch/__init__.py b/esphome/components/opentherm/switch/__init__.py index 94ec25e36c7..ead086d24bd 100644 --- a/esphome/components/opentherm/switch/__init__.py +++ b/esphome/components/opentherm/switch/__init__.py @@ -1,10 +1,11 @@ from typing import Any import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch +import esphome.config_validation as cv from esphome.const import CONF_ID -from .. import const, schema, validate, generate + +from .. import const, generate, schema, validate DEPENDENCIES = [const.OPENTHERM] COMPONENT_TYPE = const.SWITCH diff --git a/esphome/components/opentherm/validate.py b/esphome/components/opentherm/validate.py index 055cbfa827c..2b80e59f7b5 100644 --- a/esphome/components/opentherm/validate.py +++ b/esphome/components/opentherm/validate.py @@ -4,7 +4,7 @@ from voluptuous import Schema import esphome.config_validation as cv -from . import const, schema, generate +from . import const, generate, schema from .schema import TSchema diff --git a/esphome/components/output/__init__.py b/esphome/components/output/__init__.py index 726d1ac0848..78bfa045e15 100644 --- a/esphome/components/output/__init__.py +++ b/esphome/components/output/__init__.py @@ -1,8 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg from esphome.components import power_supply +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INVERTED, @@ -13,7 +13,6 @@ from esphome.const import ( ) from esphome.core import CORE - CODEOWNERS = ["@esphome/core"] IS_PLATFORM_COMPONENT = True diff --git a/esphome/components/output/button/__init__.py b/esphome/components/output/button/__init__.py index c31865ccfb2..1d14fa5755f 100644 --- a/esphome/components/output/button/__init__.py +++ b/esphome/components/output/button/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button, output -from esphome.const import CONF_ID, CONF_OUTPUT, CONF_DURATION +import esphome.config_validation as cv +from esphome.const import CONF_DURATION, CONF_ID, CONF_OUTPUT + from .. import output_ns OutputButton = output_ns.class_("OutputButton", button.Button, cg.Component) diff --git a/esphome/components/output/lock/__init__.py b/esphome/components/output/lock/__init__.py index 3be2cb09aa2..c9bdba0f753 100644 --- a/esphome/components/output/lock/__init__.py +++ b/esphome/components/output/lock/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg +from esphome.components import lock, output import esphome.config_validation as cv -from esphome.components import output, lock from esphome.const import CONF_ID, CONF_OUTPUT + from .. import output_ns OutputLock = output_ns.class_("OutputLock", lock.Lock, cg.Component) diff --git a/esphome/components/output/switch/__init__.py b/esphome/components/output/switch/__init__.py index f5325643a79..e896b183cad 100644 --- a/esphome/components/output/switch/__init__.py +++ b/esphome/components/output/switch/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output, switch +import esphome.config_validation as cv from esphome.const import CONF_OUTPUT + from .. import output_ns OutputSwitch = output_ns.class_("OutputSwitch", switch.Switch, cg.Component) diff --git a/esphome/components/partition/light.py b/esphome/components/partition/light.py index 8e45915cf3a..58de1183ffa 100644 --- a/esphome/components/partition/light.py +++ b/esphome/components/partition/light.py @@ -1,19 +1,19 @@ import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv from esphome.components import light +import esphome.config_validation as cv from esphome.const import ( CONF_ADDRESSABLE_LIGHT_ID, CONF_FROM, CONF_ID, CONF_LIGHT_ID, CONF_NUM_LEDS, + CONF_OUTPUT_ID, + CONF_REVERSED, CONF_SEGMENTS, CONF_SINGLE_LIGHT_ID, CONF_TO, - CONF_OUTPUT_ID, - CONF_REVERSED, ) +import esphome.final_validate as fv partitions_ns = cg.esphome_ns.namespace("partition") AddressableSegment = partitions_ns.class_("AddressableSegment") diff --git a/esphome/components/pca6416a/__init__.py b/esphome/components/pca6416a/__init__.py index 93be1481692..da6c4623c9a 100644 --- a/esphome/components/pca6416a/__init__.py +++ b/esphome/components/pca6416a/__init__.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OUTPUT, CONF_PULLUP, ) diff --git a/esphome/components/pca9554/__init__.py b/esphome/components/pca9554/__init__.py index da31dbd9d91..05713cccdab 100644 --- a/esphome/components/pca9554/__init__.py +++ b/esphome/components/pca9554/__init__.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OUTPUT, ) diff --git a/esphome/components/pca9685/__init__.py b/esphome/components/pca9685/__init__.py index b22577bf9fa..50f58cdfb97 100644 --- a/esphome/components/pca9685/__init__.py +++ b/esphome/components/pca9685/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c -from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_EXTERNAL_CLOCK_INPUT +import esphome.config_validation as cv +from esphome.const import CONF_EXTERNAL_CLOCK_INPUT, CONF_FREQUENCY, CONF_ID DEPENDENCIES = ["i2c"] MULTI_CONF = True diff --git a/esphome/components/pca9685/output.py b/esphome/components/pca9685/output.py index b7681f9ba0b..302c2f78c02 100644 --- a/esphome/components/pca9685/output.py +++ b/esphome/components/pca9685/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import PCA9685Output, pca9685_ns DEPENDENCIES = ["pca9685"] diff --git a/esphome/components/pcf85063/time.py b/esphome/components/pcf85063/time.py index 67ec230b5f8..f3c0c3230f6 100644 --- a/esphome/components/pcf85063/time.py +++ b/esphome/components/pcf85063/time.py @@ -1,10 +1,9 @@ -import esphome.config_validation as cv -import esphome.codegen as cg from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, time +import esphome.config_validation as cv from esphome.const import CONF_ID - CODEOWNERS = ["@brogon"] DEPENDENCIES = ["i2c"] pcf85063_ns = cg.esphome_ns.namespace("pcf85063") diff --git a/esphome/components/pcf8563/time.py b/esphome/components/pcf8563/time.py index 2e6456a72d1..e3b3b572aa3 100644 --- a/esphome/components/pcf8563/time.py +++ b/esphome/components/pcf8563/time.py @@ -1,7 +1,7 @@ -import esphome.config_validation as cv -import esphome.codegen as cg from esphome import automation +import esphome.codegen as cg from esphome.components import i2c, time +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@KoenBreeman"] diff --git a/esphome/components/pcf8574/__init__.py b/esphome/components/pcf8574/__init__.py index ebf112b85ba..64bef86443f 100644 --- a/esphome/components/pcf8574/__init__.py +++ b/esphome/components/pcf8574/__init__.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, CONF_OUTPUT, ) diff --git a/esphome/components/pid/climate.py b/esphome/components/pid/climate.py index 2c4ef688a59..aab7ee5c001 100644 --- a/esphome/components/pid/climate.py +++ b/esphome/components/pid/climate.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation -from esphome.components import climate, sensor, output +import esphome.codegen as cg +from esphome.components import climate, output, sensor +import esphome.config_validation as cv from esphome.const import CONF_HUMIDITY_SENSOR, CONF_ID, CONF_SENSOR pid_ns = cg.esphome_ns.namespace("pid") diff --git a/esphome/components/pid/sensor/__init__.py b/esphome/components/pid/sensor/__init__.py index d1c65dfb398..4547f4d7082 100644 --- a/esphome/components/pid/sensor/__init__.py +++ b/esphome/components/pid/sensor/__init__.py @@ -1,13 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor -from esphome.const import ( - STATE_CLASS_MEASUREMENT, - UNIT_PERCENT, - ICON_GAUGE, - CONF_TYPE, -) -from ..climate import pid_ns, PIDClimate +import esphome.config_validation as cv +from esphome.const import CONF_TYPE, ICON_GAUGE, STATE_CLASS_MEASUREMENT, UNIT_PERCENT + +from ..climate import PIDClimate, pid_ns PIDClimateSensor = pid_ns.class_("PIDClimateSensor", sensor.Sensor, cg.Component) PIDClimateSensorType = pid_ns.enum("PIDClimateSensorType") diff --git a/esphome/components/pipsolar/__init__.py b/esphome/components/pipsolar/__init__.py index 875de057131..1e4ea8492b3 100644 --- a/esphome/components/pipsolar/__init__.py +++ b/esphome/components/pipsolar/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg +from esphome.components import uart import esphome.config_validation as cv from esphome.const import CONF_ID -from esphome.components import uart DEPENDENCIES = ["uart"] CODEOWNERS = ["@andreashergert1984"] diff --git a/esphome/components/pipsolar/binary_sensor/__init__.py b/esphome/components/pipsolar/binary_sensor/__init__.py index f4b34fd594b..625c232ed56 100644 --- a/esphome/components/pipsolar/binary_sensor/__init__.py +++ b/esphome/components/pipsolar/binary_sensor/__init__.py @@ -1,8 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv -from .. import PIPSOLAR_COMPONENT_SCHEMA, CONF_PIPSOLAR_ID +from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA DEPENDENCIES = ["uart"] diff --git a/esphome/components/pipsolar/output/__init__.py b/esphome/components/pipsolar/output/__init__.py index b518d485e7c..1eb72491199 100644 --- a/esphome/components/pipsolar/output/__init__.py +++ b/esphome/components/pipsolar/output/__init__.py @@ -1,9 +1,10 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_VALUE -from .. import PIPSOLAR_COMPONENT_SCHEMA, CONF_PIPSOLAR_ID, pipsolar_ns + +from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA, pipsolar_ns DEPENDENCIES = ["pipsolar"] diff --git a/esphome/components/pipsolar/sensor/__init__.py b/esphome/components/pipsolar/sensor/__init__.py index 3a6f94d6ac8..0d00ba00836 100644 --- a/esphome/components/pipsolar/sensor/__init__.py +++ b/esphome/components/pipsolar/sensor/__init__.py @@ -1,7 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_BATTERY_VOLTAGE, + CONF_BUS_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, @@ -14,10 +16,9 @@ from esphome.const import ( UNIT_VOLT, UNIT_VOLT_AMPS, UNIT_WATT, - CONF_BUS_VOLTAGE, - CONF_BATTERY_VOLTAGE, ) -from .. import PIPSOLAR_COMPONENT_SCHEMA, CONF_PIPSOLAR_ID + +from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA DEPENDENCIES = ["uart"] diff --git a/esphome/components/pipsolar/switch/__init__.py b/esphome/components/pipsolar/switch/__init__.py index 80bcdad62eb..11dbc911101 100644 --- a/esphome/components/pipsolar/switch/__init__.py +++ b/esphome/components/pipsolar/switch/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch +import esphome.config_validation as cv from esphome.const import ICON_POWER + from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA, pipsolar_ns DEPENDENCIES = ["uart"] diff --git a/esphome/components/pipsolar/text_sensor/__init__.py b/esphome/components/pipsolar/text_sensor/__init__.py index 856352f8cb9..90ce3a7e557 100644 --- a/esphome/components/pipsolar/text_sensor/__init__.py +++ b/esphome/components/pipsolar/text_sensor/__init__.py @@ -1,6 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv + from .. import CONF_PIPSOLAR_ID, PIPSOLAR_COMPONENT_SCHEMA DEPENDENCIES = ["uart"] diff --git a/esphome/components/pm1006/sensor.py b/esphome/components/pm1006/sensor.py index 2df9edbf45d..c693cfea196 100644 --- a/esphome/components/pm1006/sensor.py +++ b/esphome/components/pm1006/sensor.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PM_2_5, CONF_UPDATE_INTERVAL, DEVICE_CLASS_PM25, + ICON_BLUR, STATE_CLASS_MEASUREMENT, UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_BLUR, ) from esphome.core import TimePeriodMilliseconds diff --git a/esphome/components/pmsa003i/sensor.py b/esphome/components/pmsa003i/sensor.py index ef620614a2a..2a5b9eeac0e 100644 --- a/esphome/components/pmsa003i/sensor.py +++ b/esphome/components/pmsa003i/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PM_1_0, @@ -10,13 +10,13 @@ from esphome.const import ( CONF_PMC_1_0, CONF_PMC_2_5, CONF_PMC_10_0, - UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_CHEMICAL_WEAPON, - ICON_COUNTER, DEVICE_CLASS_PM1, DEVICE_CLASS_PM10, DEVICE_CLASS_PM25, + ICON_CHEMICAL_WEAPON, + ICON_COUNTER, STATE_CLASS_MEASUREMENT, + UNIT_MICROGRAMS_PER_CUBIC_METER, ) CODEOWNERS = ["@sjtrny"] diff --git a/esphome/components/pmsx003/sensor.py b/esphome/components/pmsx003/sensor.py index 08ccd6096e3..1556b3c9838 100644 --- a/esphome/components/pmsx003/sensor.py +++ b/esphome/components/pmsx003/sensor.py @@ -1,36 +1,35 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart - +import esphome.config_validation as cv from esphome.const import ( CONF_FORMALDEHYDE, CONF_HUMIDITY, CONF_ID, - CONF_PM_10_0, - CONF_PM_1_0, - CONF_PM_2_5, - CONF_PM_10_0_STD, - CONF_PM_1_0_STD, - CONF_PM_2_5_STD, CONF_PM_0_3UM, CONF_PM_0_5UM, + CONF_PM_1_0, + CONF_PM_1_0_STD, CONF_PM_1_0UM, + CONF_PM_2_5, + CONF_PM_2_5_STD, CONF_PM_2_5UM, CONF_PM_5_0UM, + CONF_PM_10_0, + CONF_PM_10_0_STD, CONF_PM_10_0UM, - CONF_UPDATE_INTERVAL, CONF_TEMPERATURE, CONF_TYPE, + CONF_UPDATE_INTERVAL, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PM1, DEVICE_CLASS_PM10, DEVICE_CLASS_PM25, - DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ICON_CHEMICAL_WEAPON, STATE_CLASS_MEASUREMENT, - UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_CELSIUS, UNIT_COUNT_DECILITRE, + UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_PERCENT, ) diff --git a/esphome/components/pmwcs3/sensor.py b/esphome/components/pmwcs3/sensor.py index 81be327d14b..d42338ab6f9 100644 --- a/esphome/components/pmwcs3/sensor.py +++ b/esphome/components/pmwcs3/sensor.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg from esphome import automation -import esphome.config_validation as cv +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_ADDRESS, - CONF_TEMPERATURE, CONF_EC, - STATE_CLASS_MEASUREMENT, + CONF_ID, + CONF_TEMPERATURE, ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, ) CODEOWNERS = ["@SeByDocKy"] diff --git a/esphome/components/pn532/__init__.py b/esphome/components/pn532/__init__.py index cdcaf4267c8..3f04e8e1ccb 100644 --- a/esphome/components/pn532/__init__.py +++ b/esphome/components/pn532/__init__.py @@ -1,12 +1,12 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import nfc +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_ON_FINISHED_WRITE, - CONF_ON_TAG_REMOVED, CONF_ON_TAG, + CONF_ON_TAG_REMOVED, CONF_TRIGGER_ID, ) diff --git a/esphome/components/pn532_i2c/__init__.py b/esphome/components/pn532_i2c/__init__.py index f7b8743967c..7304f1b8ad6 100644 --- a/esphome/components/pn532_i2c/__init__.py +++ b/esphome/components/pn532_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, pn532 +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["pn532"] diff --git a/esphome/components/pn532_spi/__init__.py b/esphome/components/pn532_spi/__init__.py index 8a8ab1b1754..67ebc88872c 100644 --- a/esphome/components/pn532_spi/__init__.py +++ b/esphome/components/pn532_spi/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import pn532, spi import esphome.config_validation as cv -from esphome.components import spi, pn532 from esphome.const import CONF_ID AUTO_LOAD = ["pn532"] diff --git a/esphome/components/pn7150/__init__.py b/esphome/components/pn7150/__init__.py index e3589ea4491..131b56e30ea 100644 --- a/esphome/components/pn7150/__init__.py +++ b/esphome/components/pn7150/__init__.py @@ -1,15 +1,15 @@ from esphome import automation, pins from esphome.automation import maybe_simple_id import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import nfc +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IRQ_PIN, CONF_MESSAGE, CONF_ON_FINISHED_WRITE, - CONF_ON_TAG_REMOVED, CONF_ON_TAG, + CONF_ON_TAG_REMOVED, CONF_TRIGGER_ID, ) diff --git a/esphome/components/pn7150_i2c/__init__.py b/esphome/components/pn7150_i2c/__init__.py index 5f48a0f3cb1..00a19ba03c9 100644 --- a/esphome/components/pn7150_i2c/__init__.py +++ b/esphome/components/pn7150_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, pn7150 +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["pn7150"] diff --git a/esphome/components/pn7160/__init__.py b/esphome/components/pn7160/__init__.py index b102b38f980..899ecd595ea 100644 --- a/esphome/components/pn7160/__init__.py +++ b/esphome/components/pn7160/__init__.py @@ -1,15 +1,15 @@ from esphome import automation, pins from esphome.automation import maybe_simple_id import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import nfc +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IRQ_PIN, CONF_MESSAGE, CONF_ON_FINISHED_WRITE, - CONF_ON_TAG_REMOVED, CONF_ON_TAG, + CONF_ON_TAG_REMOVED, CONF_TRIGGER_ID, ) diff --git a/esphome/components/pn7160_i2c/__init__.py b/esphome/components/pn7160_i2c/__init__.py index 87c4719ca85..f8f8ebef985 100644 --- a/esphome/components/pn7160_i2c/__init__.py +++ b/esphome/components/pn7160_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, pn7160 +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["pn7160"] diff --git a/esphome/components/pn7160_spi/__init__.py b/esphome/components/pn7160_spi/__init__.py index ae1235655a7..5498d0ac1b9 100644 --- a/esphome/components/pn7160_spi/__init__.py +++ b/esphome/components/pn7160_spi/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import pn7160, spi import esphome.config_validation as cv -from esphome.components import spi, pn7160 from esphome.const import CONF_ID AUTO_LOAD = ["pn7160"] diff --git a/esphome/components/power_supply/__init__.py b/esphome/components/power_supply/__init__.py index 01b541e4b57..851c1364936 100644 --- a/esphome/components/power_supply/__init__.py +++ b/esphome/components/power_supply/__init__.py @@ -1,6 +1,6 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( CONF_ENABLE_ON_BOOT, CONF_ENABLE_TIME, diff --git a/esphome/components/prometheus/__init__.py b/esphome/components/prometheus/__init__.py index 5b63710c6a2..b899fe7642a 100644 --- a/esphome/components/prometheus/__init__.py +++ b/esphome/components/prometheus/__init__.py @@ -1,13 +1,8 @@ -import esphome.config_validation as cv import esphome.codegen as cg -from esphome.const import ( - CONF_ID, - CONF_NAME, - CONF_INCLUDE_INTERNAL, - CONF_RELABEL, -) -from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID from esphome.components import web_server_base +from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INCLUDE_INTERNAL, CONF_NAME, CONF_RELABEL from esphome.cpp_types import EntityBase AUTO_LOAD = ["web_server_base"] diff --git a/esphome/components/psram/__init__.py b/esphome/components/psram/__init__.py index 796957c315a..f268d5747fb 100644 --- a/esphome/components/psram/__init__.py +++ b/esphome/components/psram/__init__.py @@ -1,21 +1,43 @@ +import logging + import esphome.codegen as cg +from esphome.components.esp32 import ( + CONF_ENABLE_IDF_EXPERIMENTAL_FEATURES, + VARIANT_ESP32, + add_idf_sdkconfig_option, + get_esp32_variant, + only_on_variant, +) +from esphome.components.esp32.const import VARIANT_ESP32S2, VARIANT_ESP32S3 import esphome.config_validation as cv -from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant -from esphome.core import CORE from esphome.const import ( + CONF_ADVANCED, + CONF_FRAMEWORK, CONF_ID, CONF_MODE, CONF_SPEED, + PLATFORM_ESP32, ) +from esphome.core import CORE +import esphome.final_validate as fv CODEOWNERS = ["@esphome/core"] +DEPENDENCIES = [PLATFORM_ESP32] + +_LOGGER = logging.getLogger(__name__) + psram_ns = cg.esphome_ns.namespace("psram") PsramComponent = psram_ns.class_("PsramComponent", cg.Component) +TYPE_QUAD = "quad" +TYPE_OCTAL = "octal" + +CONF_ENABLE_ECC = "enable_ecc" + SPIRAM_MODES = { - "quad": "CONFIG_SPIRAM_MODE_QUAD", - "octal": "CONFIG_SPIRAM_MODE_OCT", + TYPE_QUAD: "CONFIG_SPIRAM_MODE_QUAD", + TYPE_OCTAL: "CONFIG_SPIRAM_MODE_OCT", } SPIRAM_SPEEDS = { @@ -24,21 +46,57 @@ SPIRAM_SPEEDS = { 120e6: "CONFIG_SPIRAM_SPEED_120M", } + +def validate_psram_mode(config): + if config[CONF_MODE] == TYPE_OCTAL and config[CONF_SPEED] == 120e6: + esp32_config = fv.full_config.get()[PLATFORM_ESP32] + if ( + esp32_config[CONF_FRAMEWORK] + .get(CONF_ADVANCED, {}) + .get(CONF_ENABLE_IDF_EXPERIMENTAL_FEATURES) + ): + _LOGGER.warning( + "120MHz PSRAM in octal mode is an experimental feature - use at your own risk" + ) + else: + raise cv.Invalid("PSRAM 120MHz is not supported in octal mode") + if config[CONF_MODE] != TYPE_OCTAL and config[CONF_ENABLE_ECC]: + raise cv.Invalid("ECC is only available in octal mode.") + if config[CONF_MODE] == TYPE_OCTAL: + variant = get_esp32_variant() + if variant != VARIANT_ESP32S3: + raise cv.Invalid( + f"Octal PSRAM is only supported on ESP32-S3, not {variant}" + ) + return config + + CONFIG_SCHEMA = cv.All( cv.Schema( { cv.GenerateID(): cv.declare_id(PsramComponent), - cv.Optional(CONF_MODE): cv.enum(SPIRAM_MODES, lower=True), - cv.Optional(CONF_SPEED): cv.All(cv.frequency, cv.one_of(*SPIRAM_SPEEDS)), + cv.Optional(CONF_MODE, default=TYPE_QUAD): cv.enum( + SPIRAM_MODES, lower=True + ), + cv.Optional(CONF_ENABLE_ECC, default=False): cv.boolean, + cv.Optional(CONF_SPEED, default=40e6): cv.All( + cv.frequency, cv.one_of(*SPIRAM_SPEEDS) + ), } ), - cv.only_on_esp32, + only_on_variant( + supported=[VARIANT_ESP32, VARIANT_ESP32S3, VARIANT_ESP32S2], + ), ) +FINAL_VALIDATE_SCHEMA = validate_psram_mode + async def to_code(config): if CORE.using_arduino: cg.add_build_flag("-DBOARD_HAS_PSRAM") + if config[CONF_MODE] == TYPE_OCTAL: + cg.add_platformio_option("board_build.arduino.memory_type", "qio_opi") if CORE.using_esp_idf: add_idf_sdkconfig_option( @@ -49,10 +107,16 @@ async def to_code(config): add_idf_sdkconfig_option("CONFIG_SPIRAM_USE_CAPS_ALLOC", True) add_idf_sdkconfig_option("CONFIG_SPIRAM_IGNORE_NOTFOUND", True) - if CONF_MODE in config: - add_idf_sdkconfig_option(f"{SPIRAM_MODES[config[CONF_MODE]]}", True) - if CONF_SPEED in config: - add_idf_sdkconfig_option(f"{SPIRAM_SPEEDS[config[CONF_SPEED]]}", True) + add_idf_sdkconfig_option(f"{SPIRAM_MODES[config[CONF_MODE]]}", True) + add_idf_sdkconfig_option(f"{SPIRAM_SPEEDS[config[CONF_SPEED]]}", True) + if config[CONF_MODE] == TYPE_OCTAL and config[CONF_SPEED] == 120e6: + add_idf_sdkconfig_option("CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240", True) + # This works only on IDF 5.4.x but does no harm on earlier versions + add_idf_sdkconfig_option( + "CONFIG_SPIRAM_TIMING_TUNING_POINT_VIA_TEMPERATURE_SENSOR", True + ) + if config[CONF_ENABLE_ECC]: + add_idf_sdkconfig_option("CONFIG_SPIRAM_ECC_ENABLE", True) cg.add_define("USE_PSRAM") diff --git a/esphome/components/psram/psram.cpp b/esphome/components/psram/psram.cpp index d9a5bd101fd..f592ada2462 100644 --- a/esphome/components/psram/psram.cpp +++ b/esphome/components/psram/psram.cpp @@ -1,25 +1,36 @@ -#include "psram.h" #ifdef USE_ESP32 +#include "psram.h" +#ifdef USE_ESP_IDF +#include +#endif // USE_ESP_IDF #include "esphome/core/log.h" #include -#include namespace esphome { namespace psram { - static const char *const TAG = "psram"; void PsramComponent::dump_config() { + ESP_LOGCONFIG(TAG, "PSRAM:"); +#ifdef USE_ESP_IDF + bool available = esp_psram_is_initialized(); + + ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available)); + if (available) { + ESP_LOGCONFIG(TAG, " Size: %zu KB", esp_psram_get_size() / 1024); +#if CONFIG_SPIRAM_ECC_ENABLE + ESP_LOGCONFIG(TAG, " ECC enabled: YES"); +#endif + } +#else // Technically this can be false if the PSRAM is full, but heap_caps_get_total_size() isn't always available, and it's // very unlikely for the PSRAM to be full. bool available = heap_caps_get_free_size(MALLOC_CAP_SPIRAM) > 0; - - ESP_LOGCONFIG(TAG, "PSRAM:"); ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available)); -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0) + if (available) { const size_t psram_total_size_bytes = heap_caps_get_total_size(MALLOC_CAP_SPIRAM); const float psram_total_size_kb = psram_total_size_bytes / 1024.0f; @@ -30,7 +41,7 @@ void PsramComponent::dump_config() { ESP_LOGCONFIG(TAG, " Size: %zu bytes", psram_total_size_bytes); } } -#endif +#endif // USE_ESP_IDF } } // namespace psram diff --git a/esphome/components/pulse_counter/sensor.py b/esphome/components/pulse_counter/sensor.py index 27364a34b30..b3307580006 100644 --- a/esphome/components/pulse_counter/sensor.py +++ b/esphome/components/pulse_counter/sensor.py @@ -1,22 +1,22 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation, pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_COUNT_MODE, CONF_FALLING_EDGE, CONF_ID, CONF_INTERNAL_FILTER, + CONF_NUMBER, CONF_PIN, CONF_RISING_EDGE, - CONF_NUMBER, CONF_TOTAL, CONF_VALUE, ICON_PULSE, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, - UNIT_PULSES_PER_MINUTE, UNIT_PULSES, + UNIT_PULSES_PER_MINUTE, ) from esphome.core import CORE diff --git a/esphome/components/pulse_meter/sensor.py b/esphome/components/pulse_meter/sensor.py index 59ffa58c21a..ca026eefa42 100644 --- a/esphome/components/pulse_meter/sensor.py +++ b/esphome/components/pulse_meter/sensor.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation, pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INTERNAL_FILTER, CONF_INTERNAL_FILTER_MODE, - CONF_PIN, CONF_NUMBER, + CONF_PIN, CONF_TIMEOUT, CONF_TOTAL, CONF_VALUE, diff --git a/esphome/components/pulse_width/sensor.py b/esphome/components/pulse_width/sensor.py index 47d70166d3c..120dc33b7b4 100644 --- a/esphome/components/pulse_width/sensor.py +++ b/esphome/components/pulse_width/sensor.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor -from esphome.const import ( - CONF_PIN, - STATE_CLASS_MEASUREMENT, - UNIT_SECOND, - ICON_TIMER, -) +import esphome.config_validation as cv +from esphome.const import CONF_PIN, ICON_TIMER, STATE_CLASS_MEASUREMENT, UNIT_SECOND pulse_width_ns = cg.esphome_ns.namespace("pulse_width") diff --git a/esphome/components/pvvx_mithermometer/display/__init__.py b/esphome/components/pvvx_mithermometer/display/__init__.py index 70c568c1e37..0cf27b9f1c4 100644 --- a/esphome/components/pvvx_mithermometer/display/__init__.py +++ b/esphome/components/pvvx_mithermometer/display/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import ble_client, display, time +import esphome.config_validation as cv from esphome.const import ( CONF_AUTO_CLEAR_ENABLED, CONF_DISCONNECT_DELAY, diff --git a/esphome/components/pvvx_mithermometer/sensor.py b/esphome/components/pvvx_mithermometer/sensor.py index aa4fc897278..da57c65341f 100644 --- a/esphome/components/pvvx_mithermometer/sensor.py +++ b/esphome/components/pvvx_mithermometer/sensor.py @@ -1,14 +1,14 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_BATTERY_VOLTAGE, - CONF_MAC_ADDRESS, CONF_HUMIDITY, + CONF_ID, + CONF_MAC_ADDRESS, CONF_SIGNAL_STRENGTH, CONF_TEMPERATURE, - CONF_ID, DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_SIGNAL_STRENGTH, diff --git a/esphome/components/pylontech/__init__.py b/esphome/components/pylontech/__init__.py index 197f7e7904a..82b98654a24 100644 --- a/esphome/components/pylontech/__init__.py +++ b/esphome/components/pylontech/__init__.py @@ -1,4 +1,5 @@ import logging + import esphome.codegen as cg from esphome.components import uart import esphome.config_validation as cv diff --git a/esphome/components/pylontech/sensor/__init__.py b/esphome/components/pylontech/sensor/__init__.py index a1477c627f4..716cc1001a3 100644 --- a/esphome/components/pylontech/sensor/__init__.py +++ b/esphome/components/pylontech/sensor/__init__.py @@ -1,27 +1,22 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_VOLTAGE, CONF_CURRENT, + CONF_ID, CONF_TEMPERATURE, - UNIT_VOLT, - UNIT_AMPERE, - DEVICE_CLASS_VOLTAGE, + CONF_VOLTAGE, + DEVICE_CLASS_BATTERY, DEVICE_CLASS_CURRENT, DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_BATTERY, + DEVICE_CLASS_VOLTAGE, + UNIT_AMPERE, UNIT_CELSIUS, UNIT_PERCENT, - CONF_ID, + UNIT_VOLT, ) -from .. import ( - CONF_PYLONTECH_ID, - PYLONTECH_COMPONENT_SCHEMA, - CONF_BATTERY, - pylontech_ns, -) +from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns PylontechSensor = pylontech_ns.class_("PylontechSensor", cg.Component) diff --git a/esphome/components/pylontech/text_sensor/__init__.py b/esphome/components/pylontech/text_sensor/__init__.py index d6ccc678f82..15741ea9d18 100644 --- a/esphome/components/pylontech/text_sensor/__init__.py +++ b/esphome/components/pylontech/text_sensor/__init__.py @@ -1,14 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_ID -from .. import ( - CONF_PYLONTECH_ID, - PYLONTECH_COMPONENT_SCHEMA, - CONF_BATTERY, - pylontech_ns, -) +from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns PylontechTextSensor = pylontech_ns.class_("PylontechTextSensor", cg.Component) diff --git a/esphome/components/pzem004t/sensor.py b/esphome/components/pzem004t/sensor.py index 70dec82c3f5..51b1ab2d80b 100644 --- a/esphome/components/pzem004t/sensor.py +++ b/esphome/components/pzem004t/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_CURRENT, + CONF_ENERGY, CONF_ID, CONF_POWER, CONF_VOLTAGE, - CONF_ENERGY, DEVICE_CLASS_CURRENT, DEVICE_CLASS_ENERGY, DEVICE_CLASS_POWER, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, - UNIT_VOLT, UNIT_AMPERE, + UNIT_VOLT, UNIT_WATT, UNIT_WATT_HOURS, ) diff --git a/esphome/components/pzemac/sensor.py b/esphome/components/pzemac/sensor.py index ab7dd3e202f..3af73b86951 100644 --- a/esphome/components/pzemac/sensor.py +++ b/esphome/components/pzemac/sensor.py @@ -1,27 +1,27 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id -from esphome.components import sensor, modbus +import esphome.codegen as cg +from esphome.components import modbus, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CURRENT, CONF_ENERGY, + CONF_FREQUENCY, CONF_ID, CONF_POWER, - CONF_VOLTAGE, - CONF_FREQUENCY, CONF_POWER_FACTOR, + CONF_VOLTAGE, + DEVICE_CLASS_CURRENT, + DEVICE_CLASS_ENERGY, + DEVICE_CLASS_POWER, DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_VOLTAGE, - DEVICE_CLASS_CURRENT, - DEVICE_CLASS_POWER, - DEVICE_CLASS_ENERGY, ICON_CURRENT_AC, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, + UNIT_AMPERE, UNIT_HERTZ, UNIT_VOLT, - UNIT_AMPERE, UNIT_WATT, UNIT_WATT_HOURS, ) diff --git a/esphome/components/pzemdc/sensor.py b/esphome/components/pzemdc/sensor.py index 097b1c1cfd1..383a9dbb2c5 100644 --- a/esphome/components/pzemdc/sensor.py +++ b/esphome/components/pzemdc/sensor.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id -from esphome.components import sensor, modbus +import esphome.codegen as cg +from esphome.components import modbus, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_CURRENT, + CONF_ENERGY, CONF_ID, CONF_POWER, - CONF_ENERGY, CONF_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_ENERGY, @@ -15,10 +15,10 @@ from esphome.const import ( DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, - UNIT_VOLT, UNIT_AMPERE, - UNIT_WATT, UNIT_KILOWATT_HOURS, + UNIT_VOLT, + UNIT_WATT, ) AUTO_LOAD = ["modbus"] diff --git a/esphome/components/qmc5883l/sensor.py b/esphome/components/qmc5883l/sensor.py index 341c0c3f8a3..ade286cb9e8 100644 --- a/esphome/components/qmc5883l/sensor.py +++ b/esphome/components/qmc5883l/sensor.py @@ -1,24 +1,24 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ADDRESS, CONF_FIELD_STRENGTH_X, CONF_FIELD_STRENGTH_Y, CONF_FIELD_STRENGTH_Z, CONF_HEADING, - CONF_TEMPERATURE, CONF_ID, CONF_OVERSAMPLING, CONF_RANGE, + CONF_TEMPERATURE, + CONF_UPDATE_INTERVAL, DEVICE_CLASS_TEMPERATURE, ICON_MAGNET, + ICON_SCREEN_ROTATION, STATE_CLASS_MEASUREMENT, - UNIT_MICROTESLA, UNIT_CELSIUS, UNIT_DEGREES, - ICON_SCREEN_ROTATION, - CONF_UPDATE_INTERVAL, + UNIT_MICROTESLA, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/qmp6988/sensor.py b/esphome/components/qmp6988/sensor.py index fdcfd4e66b3..05eb7efa276 100644 --- a/esphome/components/qmp6988/sensor.py +++ b/esphome/components/qmp6988/sensor.py @@ -1,8 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, + CONF_IIR_FILTER, + CONF_OVERSAMPLING, CONF_PRESSURE, CONF_TEMPERATURE, DEVICE_CLASS_PRESSURE, @@ -10,8 +12,6 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_HECTOPASCAL, - CONF_IIR_FILTER, - CONF_OVERSAMPLING, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/qr_code/__init__.py b/esphome/components/qr_code/__init__.py index 855db863352..1c5e0471b0d 100644 --- a/esphome/components/qr_code/__init__.py +++ b/esphome/components/qr_code/__init__.py @@ -1,5 +1,5 @@ -import esphome.config_validation as cv import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_VALUE CONF_SCALE = "scale" diff --git a/esphome/components/qspi_dbi/display.py b/esphome/components/qspi_dbi/display.py index ab6dd66cf24..8c29991f371 100644 --- a/esphome/components/qspi_dbi/display.py +++ b/esphome/components/qspi_dbi/display.py @@ -113,7 +113,7 @@ BASE_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend( cs_pin_required=False, default_mode="MODE0", default_data_rate=10e6, - quad=True, + mode=spi.TYPE_QUAD, ) ) ) diff --git a/esphome/components/qspi_dbi/qspi_dbi.cpp b/esphome/components/qspi_dbi/qspi_dbi.cpp index 380c93c400d..fda6300d164 100644 --- a/esphome/components/qspi_dbi/qspi_dbi.cpp +++ b/esphome/components/qspi_dbi/qspi_dbi.cpp @@ -1,4 +1,4 @@ -#ifdef USE_ESP_IDF +#if defined(USE_ESP_IDF) && defined(USE_ESP32_VARIANT_ESP32S3) #include "qspi_dbi.h" #include "esphome/core/log.h" diff --git a/esphome/components/qspi_dbi/qspi_dbi.h b/esphome/components/qspi_dbi/qspi_dbi.h index 2c555f115e9..f35f0e519c7 100644 --- a/esphome/components/qspi_dbi/qspi_dbi.h +++ b/esphome/components/qspi_dbi/qspi_dbi.h @@ -3,7 +3,7 @@ // #pragma once -#ifdef USE_ESP_IDF +#if defined(USE_ESP_IDF) && defined(USE_ESP32_VARIANT_ESP32S3) #include "esphome/components/spi/spi.h" #include "esphome/components/display/display.h" #include "esphome/components/display/display_buffer.h" diff --git a/esphome/components/qwiic_pir/binary_sensor.py b/esphome/components/qwiic_pir/binary_sensor.py index 360f8b506aa..0a549ccb32d 100644 --- a/esphome/components/qwiic_pir/binary_sensor.py +++ b/esphome/components/qwiic_pir/binary_sensor.py @@ -1,11 +1,8 @@ from esphome import core import esphome.codegen as cg +from esphome.components import binary_sensor, i2c import esphome.config_validation as cv -from esphome.components import i2c, binary_sensor -from esphome.const import ( - CONF_DEBOUNCE, - DEVICE_CLASS_MOTION, -) +from esphome.const import CONF_DEBOUNCE, DEVICE_CLASS_MOTION DEPENDENCIES = ["i2c"] CODEOWNERS = ["@kahrendt"] diff --git a/esphome/components/radon_eye_ble/__init__.py b/esphome/components/radon_eye_ble/__init__.py index ffe434d19ba..01910c81a8c 100644 --- a/esphome/components/radon_eye_ble/__init__.py +++ b/esphome/components/radon_eye_ble/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/radon_eye_rd200/sensor.py b/esphome/components/radon_eye_rd200/sensor.py index a9667869b86..da04328218c 100644 --- a/esphome/components/radon_eye_rd200/sensor.py +++ b/esphome/components/radon_eye_rd200/sensor.py @@ -1,14 +1,13 @@ import esphome.codegen as cg +from esphome.components import ble_client, sensor import esphome.config_validation as cv -from esphome.components import sensor, ble_client - from esphome.const import ( - STATE_CLASS_MEASUREMENT, - UNIT_BECQUEREL_PER_CUBIC_METER, CONF_ID, CONF_RADON, CONF_RADON_LONG_TERM, ICON_RADIOACTIVE, + STATE_CLASS_MEASUREMENT, + UNIT_BECQUEREL_PER_CUBIC_METER, ) DEPENDENCIES = ["ble_client"] diff --git a/esphome/components/rc522/__init__.py b/esphome/components/rc522/__init__.py index 1a1e6416236..ce0d408c048 100644 --- a/esphome/components/rc522/__init__.py +++ b/esphome/components/rc522/__init__.py @@ -1,12 +1,12 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation, pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ON_TAG, CONF_ON_TAG_REMOVED, - CONF_TRIGGER_ID, CONF_RESET_PIN, + CONF_TRIGGER_ID, ) CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/rc522_i2c/__init__.py b/esphome/components/rc522_i2c/__init__.py index e42817352c1..7c42a124290 100644 --- a/esphome/components/rc522_i2c/__init__.py +++ b/esphome/components/rc522_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, rc522 +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/rc522_spi/__init__.py b/esphome/components/rc522_spi/__init__.py index 77b0a996628..9ce94d7f31e 100644 --- a/esphome/components/rc522_spi/__init__.py +++ b/esphome/components/rc522_spi/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import rc522, spi import esphome.config_validation as cv -from esphome.components import spi, rc522 from esphome.const import CONF_ID CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/rdm6300/__init__.py b/esphome/components/rdm6300/__init__.py index f57eaaad6a1..cbc54ad02b1 100644 --- a/esphome/components/rdm6300/__init__.py +++ b/esphome/components/rdm6300/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_ON_TAG, CONF_TRIGGER_ID DEPENDENCIES = ["uart"] diff --git a/esphome/components/rdm6300/binary_sensor.py b/esphome/components/rdm6300/binary_sensor.py index cd808b92cce..7eb20b1302b 100644 --- a/esphome/components/rdm6300/binary_sensor.py +++ b/esphome/components/rdm6300/binary_sensor.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor, rdm6300 +import esphome.config_validation as cv from esphome.const import CONF_UID + from . import rdm6300_ns DEPENDENCIES = ["rdm6300"] diff --git a/esphome/components/resistance/sensor.py b/esphome/components/resistance/sensor.py index 3622799a07b..1cb3c6020cf 100644 --- a/esphome/components/resistance/sensor.py +++ b/esphome/components/resistance/sensor.py @@ -1,12 +1,12 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_REFERENCE_VOLTAGE, CONF_SENSOR, + ICON_FLASH, STATE_CLASS_MEASUREMENT, UNIT_OHM, - ICON_FLASH, ) resistance_ns = cg.esphome_ns.namespace("resistance") diff --git a/esphome/components/restart/button/__init__.py b/esphome/components/restart/button/__init__.py index 6aff8cb351f..76757f7504e 100644 --- a/esphome/components/restart/button/__init__.py +++ b/esphome/components/restart/button/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button +import esphome.config_validation as cv from esphome.const import ( CONF_ID, DEVICE_CLASS_RESTART, diff --git a/esphome/components/restart/switch/__init__.py b/esphome/components/restart/switch/__init__.py index 89805b42463..e9283c9e419 100644 --- a/esphome/components/restart/switch/__init__.py +++ b/esphome/components/restart/switch/__init__.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch -from esphome.const import ( - ENTITY_CATEGORY_CONFIG, - ICON_RESTART, -) +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_CONFIG, ICON_RESTART restart_ns = cg.esphome_ns.namespace("restart") RestartSwitch = restart_ns.class_("RestartSwitch", switch.Switch, cg.Component) diff --git a/esphome/components/rf_bridge/__init__.py b/esphome/components/rf_bridge/__init__.py index 228e7d882ba..5ccca823de1 100644 --- a/esphome/components/rf_bridge/__init__.py +++ b/esphome/components/rf_bridge/__init__.py @@ -1,9 +1,10 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import uart +import esphome.config_validation as cv from esphome.const import ( CONF_CODE, + CONF_DURATION, CONF_HIGH, CONF_ID, CONF_LENGTH, @@ -12,7 +13,6 @@ from esphome.const import ( CONF_RAW, CONF_SYNC, CONF_TRIGGER_ID, - CONF_DURATION, ) DEPENDENCIES = ["uart"] diff --git a/esphome/components/rgb/light.py b/esphome/components/rgb/light.py index 3d07855b8ea..b6daaaaa3c6 100644 --- a/esphome/components/rgb/light.py +++ b/esphome/components/rgb/light.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output -from esphome.const import CONF_BLUE, CONF_GREEN, CONF_RED, CONF_OUTPUT_ID +import esphome.config_validation as cv +from esphome.const import CONF_BLUE, CONF_GREEN, CONF_OUTPUT_ID, CONF_RED rgb_ns = cg.esphome_ns.namespace("rgb") RGBLightOutput = rgb_ns.class_("RGBLightOutput", light.LightOutput) diff --git a/esphome/components/rgbct/light.py b/esphome/components/rgbct/light.py index 05650573160..dcd14310e3d 100644 --- a/esphome/components/rgbct/light.py +++ b/esphome/components/rgbct/light.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import ( CONF_BLUE, + CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_COLOR_INTERLOCK, CONF_COLOR_TEMPERATURE, CONF_GREEN, - CONF_RED, CONF_OUTPUT_ID, - CONF_COLD_WHITE_COLOR_TEMPERATURE, + CONF_RED, CONF_WARM_WHITE_COLOR_TEMPERATURE, ) diff --git a/esphome/components/rgbw/light.py b/esphome/components/rgbw/light.py index f747580f619..84425c23c29 100644 --- a/esphome/components/rgbw/light.py +++ b/esphome/components/rgbw/light.py @@ -1,12 +1,12 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import ( CONF_BLUE, CONF_COLOR_INTERLOCK, CONF_GREEN, - CONF_RED, CONF_OUTPUT_ID, + CONF_RED, CONF_WHITE, ) diff --git a/esphome/components/rgbww/light.py b/esphome/components/rgbww/light.py index 35f77b154bb..882ab0cdbcd 100644 --- a/esphome/components/rgbww/light.py +++ b/esphome/components/rgbww/light.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import ( CONF_BLUE, + CONF_COLD_WHITE, + CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_COLOR_INTERLOCK, CONF_CONSTANT_BRIGHTNESS, CONF_GREEN, - CONF_RED, CONF_OUTPUT_ID, - CONF_COLD_WHITE, + CONF_RED, CONF_WARM_WHITE, - CONF_COLD_WHITE_COLOR_TEMPERATURE, CONF_WARM_WHITE_COLOR_TEMPERATURE, ) diff --git a/esphome/components/rotary_encoder/sensor.py b/esphome/components/rotary_encoder/sensor.py index ae6b0ae3bfc..645b4a81c5c 100644 --- a/esphome/components/rotary_encoder/sensor.py +++ b/esphome/components/rotary_encoder/sensor.py @@ -1,19 +1,19 @@ +from esphome import automation, pins import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import pins, automation from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_RESOLUTION, - CONF_MIN_VALUE, CONF_MAX_VALUE, - UNIT_STEPS, - ICON_ROTATE_RIGHT, - CONF_VALUE, + CONF_MIN_VALUE, CONF_PIN_A, CONF_PIN_B, - CONF_TRIGGER_ID, + CONF_RESOLUTION, CONF_RESTORE_MODE, + CONF_TRIGGER_ID, + CONF_VALUE, + ICON_ROTATE_RIGHT, + UNIT_STEPS, ) rotary_encoder_ns = cg.esphome_ns.namespace("rotary_encoder") diff --git a/esphome/components/rp2040_pio/__init__.py b/esphome/components/rp2040_pio/__init__.py index af884d5ac28..4bd46731dfe 100644 --- a/esphome/components/rp2040_pio/__init__.py +++ b/esphome/components/rp2040_pio/__init__.py @@ -2,7 +2,6 @@ import platform import esphome.codegen as cg - DEPENDENCIES = ["rp2040"] diff --git a/esphome/components/rp2040_pio_led_strip/light.py b/esphome/components/rp2040_pio_led_strip/light.py index 8dd2549ad47..4b6a80e78b0 100644 --- a/esphome/components/rp2040_pio_led_strip/light.py +++ b/esphome/components/rp2040_pio_led_strip/light.py @@ -1,7 +1,9 @@ from dataclasses import dataclass from esphome import pins +import esphome.codegen as cg from esphome.components import light, rp2040 +import esphome.config_validation as cv from esphome.const import ( CONF_CHIPSET, CONF_ID, @@ -11,10 +13,6 @@ from esphome.const import ( CONF_PIN, CONF_RGB_ORDER, ) - -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome.util import _LOGGER diff --git a/esphome/components/rp2040_pwm/output.py b/esphome/components/rp2040_pwm/output.py index 8f2972d4a0a..ac1892fa290 100644 --- a/esphome/components/rp2040_pwm/output.py +++ b/esphome/components/rp2040_pwm/output.py @@ -1,12 +1,8 @@ -from esphome import pins, automation +from esphome import automation, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg -from esphome.const import ( - CONF_FREQUENCY, - CONF_ID, - CONF_PIN, -) +from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_PIN CODEOWNERS = ["@jesserockz"] DEPENDENCIES = ["rp2040"] diff --git a/esphome/components/rtttl/__init__.py b/esphome/components/rtttl/__init__.py index 10f13134088..0abd51a6f1d 100644 --- a/esphome/components/rtttl/__init__.py +++ b/esphome/components/rtttl/__init__.py @@ -1,19 +1,19 @@ import logging -import esphome.codegen as cg -import esphome.config_validation as cv -import esphome.final_validate as fv + from esphome import automation +import esphome.codegen as cg from esphome.components.output import FloatOutput from esphome.components.speaker import Speaker - +import esphome.config_validation as cv from esphome.const import ( + CONF_GAIN, CONF_ID, CONF_OUTPUT, CONF_PLATFORM, - CONF_TRIGGER_ID, CONF_SPEAKER, - CONF_GAIN, + CONF_TRIGGER_ID, ) +import esphome.final_validate as fv _LOGGER = logging.getLogger(__name__) diff --git a/esphome/components/ruuvi_ble/__init__.py b/esphome/components/ruuvi_ble/__init__.py index 1e3fb4b003c..13d49d3cfe7 100644 --- a/esphome/components/ruuvi_ble/__init__.py +++ b/esphome/components/ruuvi_ble/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/ruuvitag/sensor.py b/esphome/components/ruuvitag/sensor.py index a46daf88acd..af262b29508 100644 --- a/esphome/components/ruuvitag/sensor.py +++ b/esphome/components/ruuvitag/sensor.py @@ -1,38 +1,38 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( - CONF_HUMIDITY, - CONF_MAC_ADDRESS, - CONF_TEMPERATURE, - CONF_PRESSURE, CONF_ACCELERATION, CONF_ACCELERATION_X, CONF_ACCELERATION_Y, CONF_ACCELERATION_Z, CONF_BATTERY_VOLTAGE, - CONF_TX_POWER, + CONF_HUMIDITY, + CONF_ID, + CONF_MAC_ADDRESS, CONF_MEASUREMENT_SEQUENCE_NUMBER, CONF_MOVEMENT_COUNTER, + CONF_PRESSURE, + CONF_TEMPERATURE, + CONF_TX_POWER, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_VOLTAGE, ENTITY_CATEGORY_DIAGNOSTIC, - STATE_CLASS_MEASUREMENT, - UNIT_CELSIUS, - UNIT_PERCENT, - UNIT_VOLT, - UNIT_HECTOPASCAL, - UNIT_G, - UNIT_DECIBEL_MILLIWATT, - ICON_GAUGE, ICON_ACCELERATION, ICON_ACCELERATION_X, ICON_ACCELERATION_Y, ICON_ACCELERATION_Z, - CONF_ID, + ICON_GAUGE, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_DECIBEL_MILLIWATT, + UNIT_G, + UNIT_HECTOPASCAL, + UNIT_PERCENT, + UNIT_VOLT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/safe_mode/__init__.py b/esphome/components/safe_mode/__init__.py index 185c0e70b12..991747b0891 100644 --- a/esphome/components/safe_mode/__init__.py +++ b/esphome/components/safe_mode/__init__.py @@ -1,4 +1,4 @@ -from esphome.cpp_generator import RawExpression +from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv from esphome.const import ( @@ -11,8 +11,7 @@ from esphome.const import ( KEY_PAST_SAFE_MODE, ) from esphome.core import CORE, coroutine_with_priority -from esphome import automation - +from esphome.cpp_generator import RawExpression CODEOWNERS = ["@paulmonigatti", "@jsuanet", "@kbx81"] diff --git a/esphome/components/safe_mode/button/__init__.py b/esphome/components/safe_mode/button/__init__.py index 5662db8f7e0..0731ca50f52 100644 --- a/esphome/components/safe_mode/button/__init__.py +++ b/esphome/components/safe_mode/button/__init__.py @@ -1,13 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button +import esphome.config_validation as cv from esphome.const import ( CONF_SAFE_MODE, DEVICE_CLASS_RESTART, ENTITY_CATEGORY_CONFIG, ICON_RESTART_ALERT, ) -from .. import safe_mode_ns, SafeModeComponent + +from .. import SafeModeComponent, safe_mode_ns DEPENDENCIES = ["safe_mode"] diff --git a/esphome/components/safe_mode/switch/__init__.py b/esphome/components/safe_mode/switch/__init__.py index 72713581496..d656eee84af 100644 --- a/esphome/components/safe_mode/switch/__init__.py +++ b/esphome/components/safe_mode/switch/__init__.py @@ -1,12 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch -from esphome.const import ( - CONF_SAFE_MODE, - ENTITY_CATEGORY_CONFIG, - ICON_RESTART_ALERT, -) -from .. import safe_mode_ns, SafeModeComponent +import esphome.config_validation as cv +from esphome.const import CONF_SAFE_MODE, ENTITY_CATEGORY_CONFIG, ICON_RESTART_ALERT + +from .. import SafeModeComponent, safe_mode_ns DEPENDENCIES = ["safe_mode"] diff --git a/esphome/components/scd30/sensor.py b/esphome/components/scd30/sensor.py index cee8cc7b712..83fb9738eca 100644 --- a/esphome/components/scd30/sensor.py +++ b/esphome/components/scd30/sensor.py @@ -1,23 +1,22 @@ from esphome import automation, core import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor -from esphome.components import sensirion_common from esphome.const import ( - CONF_ID, - CONF_HUMIDITY, - CONF_TEMPERATURE, CONF_CO2, + CONF_HUMIDITY, + CONF_ID, + CONF_TEMPERATURE, CONF_TEMPERATURE_OFFSET, CONF_UPDATE_INTERVAL, CONF_VALUE, DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_PARTS_PER_MILLION, UNIT_PERCENT, ) diff --git a/esphome/components/scd4x/sensor.py b/esphome/components/scd4x/sensor.py index 13027b6f880..f050c3ec343 100644 --- a/esphome/components/scd4x/sensor.py +++ b/esphome/components/scd4x/sensor.py @@ -1,26 +1,24 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import i2c, sensor -from esphome.components import sensirion_common from esphome import automation from esphome.automation import maybe_simple_id - +import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_CO2, CONF_HUMIDITY, + CONF_ID, CONF_TEMPERATURE, CONF_TEMPERATURE_OFFSET, CONF_VALUE, DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, ICON_THERMOMETER, ICON_WATER_PERCENT, + STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, + UNIT_PARTS_PER_MILLION, UNIT_PERCENT, ) diff --git a/esphome/components/script/__init__.py b/esphome/components/script/__init__.py index 16b1d4c54ef..ee1f6a4ad09 100644 --- a/esphome/components/script/__init__.py +++ b/esphome/components/script/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_MODE, CONF_PARAMETERS, CONF_RESTART from esphome.core import CORE, EsphomeError diff --git a/esphome/components/sdl/display.py b/esphome/components/sdl/display.py index 18dc570f884..66709cc8348 100644 --- a/esphome/components/sdl/display.py +++ b/esphome/components/sdl/display.py @@ -1,14 +1,14 @@ import subprocess import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_DIMENSIONS, - CONF_WIDTH, CONF_HEIGHT, + CONF_ID, CONF_LAMBDA, + CONF_WIDTH, PLATFORM_HOST, ) diff --git a/esphome/components/sdl/touchscreen/__init__.py b/esphome/components/sdl/touchscreen/__init__.py index d6c0ed1c03b..9f84f91c72b 100644 --- a/esphome/components/sdl/touchscreen/__init__.py +++ b/esphome/components/sdl/touchscreen/__init__.py @@ -1,9 +1,9 @@ import esphome.codegen as cg +from esphome.components import touchscreen import esphome.config_validation as cv from esphome.const import CONF_ID -from esphome.components import touchscreen -from ..display import Sdl, sdl_ns, CONF_SDL_ID +from ..display import CONF_SDL_ID, Sdl, sdl_ns SdlTouchscreen = sdl_ns.class_("SdlTouchscreen", touchscreen.Touchscreen) diff --git a/esphome/components/sdm_meter/sensor.py b/esphome/components/sdm_meter/sensor.py index 4f439ac5064..24ae32c7bc3 100644 --- a/esphome/components/sdm_meter/sensor.py +++ b/esphome/components/sdm_meter/sensor.py @@ -1,14 +1,13 @@ -from esphome.components.atm90e32.sensor import CONF_PHASE_A, CONF_PHASE_B, CONF_PHASE_C import esphome.codegen as cg +from esphome.components import modbus, sensor +from esphome.components.atm90e32.sensor import CONF_PHASE_A, CONF_PHASE_B, CONF_PHASE_C import esphome.config_validation as cv -from esphome.components import sensor, modbus from esphome.const import ( CONF_ACTIVE_POWER, CONF_APPARENT_POWER, CONF_CURRENT, CONF_EXPORT_ACTIVE_ENERGY, CONF_EXPORT_REACTIVE_ENERGY, - CONF_TOTAL_POWER, CONF_FREQUENCY, CONF_ID, CONF_IMPORT_ACTIVE_ENERGY, @@ -16,6 +15,7 @@ from esphome.const import ( CONF_PHASE_ANGLE, CONF_POWER_FACTOR, CONF_REACTIVE_POWER, + CONF_TOTAL_POWER, CONF_VOLTAGE, DEVICE_CLASS_CURRENT, DEVICE_CLASS_ENERGY, diff --git a/esphome/components/sdp3x/sensor.py b/esphome/components/sdp3x/sensor.py index 60608818a2f..67f3f9561ff 100644 --- a/esphome/components/sdp3x/sensor.py +++ b/esphome/components/sdp3x/sensor.py @@ -1,7 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor -from esphome.components import sensirion_common from esphome.const import ( DEVICE_CLASS_PRESSURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/sds011/sensor.py b/esphome/components/sds011/sensor.py index 456d47ee915..ae1cc58a950 100644 --- a/esphome/components/sds011/sensor.py +++ b/esphome/components/sds011/sensor.py @@ -1,17 +1,17 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_PM_10_0, CONF_PM_2_5, + CONF_PM_10_0, CONF_RX_ONLY, CONF_UPDATE_INTERVAL, - DEVICE_CLASS_PM25, DEVICE_CLASS_PM10, + DEVICE_CLASS_PM25, + ICON_CHEMICAL_WEAPON, STATE_CLASS_MEASUREMENT, UNIT_MICROGRAMS_PER_CUBIC_METER, - ICON_CHEMICAL_WEAPON, ) DEPENDENCIES = ["uart"] diff --git a/esphome/components/seeed_mr24hpc1/__init__.py b/esphome/components/seeed_mr24hpc1/__init__.py index 52b971e7e46..e80470bde11 100644 --- a/esphome/components/seeed_mr24hpc1/__init__.py +++ b/esphome/components/seeed_mr24hpc1/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["uart"] diff --git a/esphome/components/seeed_mr24hpc1/binary_sensor.py b/esphome/components/seeed_mr24hpc1/binary_sensor.py index 003db9f4a32..26de1e4ac16 100644 --- a/esphome/components/seeed_mr24hpc1/binary_sensor.py +++ b/esphome/components/seeed_mr24hpc1/binary_sensor.py @@ -1,12 +1,9 @@ import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv -from esphome.const import ( - DEVICE_CLASS_OCCUPANCY, - CONF_HAS_TARGET, -) -from . import CONF_MR24HPC1_ID, MR24HPC1Component +from esphome.const import CONF_HAS_TARGET, DEVICE_CLASS_OCCUPANCY +from . import CONF_MR24HPC1_ID, MR24HPC1Component CONFIG_SCHEMA = { cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component), diff --git a/esphome/components/seeed_mr24hpc1/button/__init__.py b/esphome/components/seeed_mr24hpc1/button/__init__.py index 59372e4100d..1e68d7e0719 100644 --- a/esphome/components/seeed_mr24hpc1/button/__init__.py +++ b/esphome/components/seeed_mr24hpc1/button/__init__.py @@ -7,6 +7,7 @@ from esphome.const import ( ENTITY_CATEGORY_CONFIG, ICON_RESTART_ALERT, ) + from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns RestartButton = mr24hpc1_ns.class_("RestartButton", button.Button) diff --git a/esphome/components/seeed_mr24hpc1/number/__init__.py b/esphome/components/seeed_mr24hpc1/number/__init__.py index 2055fc548c7..4de3654e392 100644 --- a/esphome/components/seeed_mr24hpc1/number/__init__.py +++ b/esphome/components/seeed_mr24hpc1/number/__init__.py @@ -1,10 +1,8 @@ import esphome.codegen as cg from esphome.components import number import esphome.config_validation as cv -from esphome.const import ( - CONF_SENSITIVITY, - ENTITY_CATEGORY_CONFIG, -) +from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG + from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns SensitivityNumber = mr24hpc1_ns.class_("SensitivityNumber", number.Number) diff --git a/esphome/components/seeed_mr24hpc1/select/__init__.py b/esphome/components/seeed_mr24hpc1/select/__init__.py index 7da83627b95..14854f07952 100644 --- a/esphome/components/seeed_mr24hpc1/select/__init__.py +++ b/esphome/components/seeed_mr24hpc1/select/__init__.py @@ -1,9 +1,8 @@ import esphome.codegen as cg from esphome.components import select import esphome.config_validation as cv -from esphome.const import ( - ENTITY_CATEGORY_CONFIG, -) +from esphome.const import ENTITY_CATEGORY_CONFIG + from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns SceneModeSelect = mr24hpc1_ns.class_("SceneModeSelect", select.Select) diff --git a/esphome/components/seeed_mr24hpc1/sensor.py b/esphome/components/seeed_mr24hpc1/sensor.py index d5eb09e2656..7b20941aa47 100644 --- a/esphome/components/seeed_mr24hpc1/sensor.py +++ b/esphome/components/seeed_mr24hpc1/sensor.py @@ -7,6 +7,7 @@ from esphome.const import ( DEVICE_CLASS_SPEED, UNIT_METER, ) + from . import CONF_MR24HPC1_ID, MR24HPC1Component CONF_CUSTOM_PRESENCE_OF_DETECTION = "custom_presence_of_detection" diff --git a/esphome/components/seeed_mr24hpc1/switch/__init__.py b/esphome/components/seeed_mr24hpc1/switch/__init__.py index bbf5391a578..741e7de3cab 100644 --- a/esphome/components/seeed_mr24hpc1/switch/__init__.py +++ b/esphome/components/seeed_mr24hpc1/switch/__init__.py @@ -1,10 +1,8 @@ import esphome.codegen as cg from esphome.components import switch import esphome.config_validation as cv -from esphome.const import ( - DEVICE_CLASS_SWITCH, - ENTITY_CATEGORY_CONFIG, -) +from esphome.const import DEVICE_CLASS_SWITCH, ENTITY_CATEGORY_CONFIG + from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns UnderlyingOpenFuncSwitch = mr24hpc1_ns.class_( diff --git a/esphome/components/seeed_mr24hpc1/text_sensor.py b/esphome/components/seeed_mr24hpc1/text_sensor.py index aa50f577d4a..fadd9c6dbc2 100644 --- a/esphome/components/seeed_mr24hpc1/text_sensor.py +++ b/esphome/components/seeed_mr24hpc1/text_sensor.py @@ -2,6 +2,7 @@ import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv from esphome.const import ENTITY_CATEGORY_DIAGNOSTIC + from . import CONF_MR24HPC1_ID, MR24HPC1Component CONF_HEART_BEAT = "heart_beat" diff --git a/esphome/components/seeed_mr60bha2/binary_sensor.py b/esphome/components/seeed_mr60bha2/binary_sensor.py index ae9e1c23e62..99940ebf6dd 100644 --- a/esphome/components/seeed_mr60bha2/binary_sensor.py +++ b/esphome/components/seeed_mr60bha2/binary_sensor.py @@ -1,10 +1,8 @@ import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv -from esphome.const import ( - DEVICE_CLASS_OCCUPANCY, - CONF_HAS_TARGET, -) +from esphome.const import CONF_HAS_TARGET, DEVICE_CLASS_OCCUPANCY + from . import CONF_MR60BHA2_ID, MR60BHA2Component DEPENDENCIES = ["seeed_mr60bha2"] diff --git a/esphome/components/seeed_mr60bha2/sensor.py b/esphome/components/seeed_mr60bha2/sensor.py index 916d4b4ba2d..d7f667d8622 100644 --- a/esphome/components/seeed_mr60bha2/sensor.py +++ b/esphome/components/seeed_mr60bha2/sensor.py @@ -4,10 +4,10 @@ import esphome.config_validation as cv from esphome.const import ( CONF_DISTANCE, DEVICE_CLASS_DISTANCE, + ICON_COUNTER, ICON_HEART_PULSE, ICON_PULSE, ICON_SIGNAL, - ICON_COUNTER, STATE_CLASS_MEASUREMENT, UNIT_BEATS_PER_MINUTE, UNIT_CENTIMETER, diff --git a/esphome/components/seeed_mr60fda2/button/__init__.py b/esphome/components/seeed_mr60fda2/button/__init__.py index 1415dc27ca7..8236248b8c4 100644 --- a/esphome/components/seeed_mr60fda2/button/__init__.py +++ b/esphome/components/seeed_mr60fda2/button/__init__.py @@ -2,11 +2,11 @@ import esphome.codegen as cg from esphome.components import button import esphome.config_validation as cv from esphome.const import ( + CONF_FACTORY_RESET, DEVICE_CLASS_RESTART, DEVICE_CLASS_UPDATE, ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_NONE, - CONF_FACTORY_RESET, ) from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns diff --git a/esphome/components/seeed_mr60fda2/select/__init__.py b/esphome/components/seeed_mr60fda2/select/__init__.py index a6f9eeb920c..2fea150cd26 100644 --- a/esphome/components/seeed_mr60fda2/select/__init__.py +++ b/esphome/components/seeed_mr60fda2/select/__init__.py @@ -5,7 +5,6 @@ from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG, ICON_ACCELER from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns - DEPENDENCIES = ["seeed_mr60fda2"] InstallHeightSelect = mr60fda2_ns.class_("InstallHeightSelect", select.Select) diff --git a/esphome/components/selec_meter/sensor.py b/esphome/components/selec_meter/sensor.py index e698255c252..069b61af5a1 100644 --- a/esphome/components/selec_meter/sensor.py +++ b/esphome/components/selec_meter/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import modbus, sensor import esphome.config_validation as cv -from esphome.components import sensor, modbus from esphome.const import ( CONF_ACTIVE_POWER, CONF_APPARENT_POWER, diff --git a/esphome/components/sen0321/sensor.py b/esphome/components/sen0321/sensor.py index ee613dc4402..e1c1d4e94be 100644 --- a/esphome/components/sen0321/sensor.py +++ b/esphome/components/sen0321/sensor.py @@ -1,10 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( ICON_CHEMICAL_WEAPON, - UNIT_PARTS_PER_BILLION, STATE_CLASS_MEASUREMENT, + UNIT_PARTS_PER_BILLION, ) CODEOWNERS = ["@notjj"] diff --git a/esphome/components/sen21231/sensor.py b/esphome/components/sen21231/sensor.py index fb1dc192785..52cecbfb693 100644 --- a/esphome/components/sen21231/sensor.py +++ b/esphome/components/sen21231/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ICON_MOTION_SENSOR CODEOWNERS = ["@shreyaskarnik"] diff --git a/esphome/components/senseair/sensor.py b/esphome/components/senseair/sensor.py index d423793873b..cd6d85c12bb 100644 --- a/esphome/components/senseair/sensor.py +++ b/esphome/components/senseair/sensor.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_CO2, CONF_ID, - ICON_MOLECULE_CO2, DEVICE_CLASS_CARBON_DIOXIDE, + ICON_MOLECULE_CO2, STATE_CLASS_MEASUREMENT, UNIT_PARTS_PER_MILLION, ) diff --git a/esphome/components/sensirion_common/__init__.py b/esphome/components/sensirion_common/__init__.py index b27f37099d0..5d9424d1e7c 100644 --- a/esphome/components/sensirion_common/__init__.py +++ b/esphome/components/sensirion_common/__init__.py @@ -1,8 +1,6 @@ import esphome.codegen as cg - from esphome.components import i2c - CODEOWNERS = ["@martgras"] sensirion_common_ns = cg.esphome_ns.namespace("sensirion_common") diff --git a/esphome/components/servo/__init__.py b/esphome/components/servo/__init__.py index 7147828a070..2fee2840a5c 100644 --- a/esphome/components/servo/__init__.py +++ b/esphome/components/servo/__init__.py @@ -1,15 +1,15 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg from esphome.components.output import FloatOutput +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_IDLE_LEVEL, + CONF_LEVEL, CONF_MAX_LEVEL, CONF_MIN_LEVEL, CONF_OUTPUT, - CONF_LEVEL, CONF_RESTORE, CONF_TRANSITION_LENGTH, ) diff --git a/esphome/components/sfa30/sensor.py b/esphome/components/sfa30/sensor.py index 428f6b874b9..8e8a57e3415 100644 --- a/esphome/components/sfa30/sensor.py +++ b/esphome/components/sfa30/sensor.py @@ -1,22 +1,21 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common - from esphome.const import ( - CONF_ID, CONF_FORMALDEHYDE, CONF_HUMIDITY, + CONF_ID, CONF_TEMPERATURE, DEVICE_CLASS_GAS, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ICON_RADIATOR, - ICON_WATER_PERCENT, ICON_THERMOMETER, + ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, UNIT_PARTS_PER_BILLION, UNIT_PERCENT, - UNIT_CELSIUS, ) CODEOWNERS = ["@ghsensdev"] diff --git a/esphome/components/sgp4x/sensor.py b/esphome/components/sgp4x/sensor.py index b7cec542bfb..9317187df39 100644 --- a/esphome/components/sgp4x/sensor.py +++ b/esphome/components/sgp4x/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common from esphome.const import ( CONF_COMPENSATION, CONF_ID, CONF_STORE_BASELINE, CONF_TEMPERATURE_SOURCE, - ICON_RADIATOR, DEVICE_CLASS_AQI, + ICON_RADIATOR, STATE_CLASS_MEASUREMENT, ) diff --git a/esphome/components/shelly_dimmer/light.py b/esphome/components/shelly_dimmer/light.py index 625784427f1..bb2c3ceee8e 100644 --- a/esphome/components/shelly_dimmer/light.py +++ b/esphome/components/shelly_dimmer/light.py @@ -1,32 +1,32 @@ -from pathlib import Path import hashlib +from pathlib import Path import re + import requests - -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import light, sensor, uart +import esphome.config_validation as cv from esphome.const import ( - CONF_OUTPUT_ID, - CONF_GAMMA_CORRECT, - CONF_POWER, - CONF_VOLTAGE, CONF_CURRENT, - CONF_VERSION, - CONF_URL, + CONF_GAMMA_CORRECT, + CONF_MAX_BRIGHTNESS, + CONF_MIN_BRIGHTNESS, + CONF_OUTPUT_ID, + CONF_POWER, CONF_UPDATE_INTERVAL, - UNIT_VOLT, - UNIT_AMPERE, - UNIT_WATT, + CONF_URL, + CONF_VERSION, + CONF_VOLTAGE, + DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, DEVICE_CLASS_VOLTAGE, - DEVICE_CLASS_CURRENT, - CONF_MIN_BRIGHTNESS, - CONF_MAX_BRIGHTNESS, + UNIT_AMPERE, + UNIT_VOLT, + UNIT_WATT, ) -from esphome.core import HexInt, CORE +from esphome.core import CORE, HexInt DOMAIN = "shelly_dimmer" AUTO_LOAD = ["sensor"] diff --git a/esphome/components/sht3xd/sensor.py b/esphome/components/sht3xd/sensor.py index 1286489b290..7ad34972d4a 100644 --- a/esphome/components/sht3xd/sensor.py +++ b/esphome/components/sht3xd/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/sht4x/sensor.py b/esphome/components/sht4x/sensor.py index e195bb9acc8..871956f7832 100644 --- a/esphome/components/sht4x/sensor.py +++ b/esphome/components/sht4x/sensor.py @@ -1,17 +1,17 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common from esphome.const import ( + CONF_HUMIDITY, CONF_ID, CONF_TEMPERATURE, - CONF_HUMIDITY, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, + ICON_THERMOMETER, + ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - ICON_THERMOMETER, - ICON_WATER_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, ) CODEOWNERS = ["@sjtrny"] diff --git a/esphome/components/shtcx/sensor.py b/esphome/components/shtcx/sensor.py index c8b56cfe30e..bb83ee44823 100644 --- a/esphome/components/shtcx/sensor.py +++ b/esphome/components/shtcx/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common from esphome.const import ( CONF_HUMIDITY, CONF_ID, diff --git a/esphome/components/shutdown/button/__init__.py b/esphome/components/shutdown/button/__init__.py index 79d0b239357..3423b40089e 100644 --- a/esphome/components/shutdown/button/__init__.py +++ b/esphome/components/shutdown/button/__init__.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button -from esphome.const import ( - CONF_ID, - ENTITY_CATEGORY_CONFIG, - ICON_POWER, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, ENTITY_CATEGORY_CONFIG, ICON_POWER shutdown_ns = cg.esphome_ns.namespace("shutdown") ShutdownButton = shutdown_ns.class_("ShutdownButton", button.Button, cg.Component) diff --git a/esphome/components/shutdown/switch/__init__.py b/esphome/components/shutdown/switch/__init__.py index 5de9f2d1898..12cc477647b 100644 --- a/esphome/components/shutdown/switch/__init__.py +++ b/esphome/components/shutdown/switch/__init__.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch -from esphome.const import ( - ENTITY_CATEGORY_CONFIG, - ICON_POWER, -) +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_CONFIG, ICON_POWER shutdown_ns = cg.esphome_ns.namespace("shutdown") ShutdownSwitch = shutdown_ns.class_("ShutdownSwitch", switch.Switch, cg.Component) diff --git a/esphome/components/sigma_delta_output/output.py b/esphome/components/sigma_delta_output/output.py index 49ac9e685a4..ca5b7a53e07 100644 --- a/esphome/components/sigma_delta_output/output.py +++ b/esphome/components/sigma_delta_output/output.py @@ -1,13 +1,8 @@ from esphome import automation, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg -from esphome.const import ( - CONF_ID, - CONF_PIN, - CONF_TURN_ON_ACTION, - CONF_TURN_OFF_ACTION, -) +from esphome.const import CONF_ID, CONF_PIN, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION DEPENDENCIES = [] diff --git a/esphome/components/sim800l/__init__.py b/esphome/components/sim800l/__init__.py index faa6cefe279..2ca9127d3f1 100644 --- a/esphome/components/sim800l/__init__.py +++ b/esphome/components/sim800l/__init__.py @@ -1,12 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation -from esphome.const import ( - CONF_ID, - CONF_MESSAGE, - CONF_TRIGGER_ID, -) +import esphome.codegen as cg from esphome.components import uart +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_MESSAGE, CONF_TRIGGER_ID DEPENDENCIES = ["uart"] CODEOWNERS = ["@glmnet"] diff --git a/esphome/components/sim800l/binary_sensor.py b/esphome/components/sim800l/binary_sensor.py index f046d031ea1..1cf0b4e1b85 100644 --- a/esphome/components/sim800l/binary_sensor.py +++ b/esphome/components/sim800l/binary_sensor.py @@ -1,10 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import ( - DEVICE_CLASS_CONNECTIVITY, - ENTITY_CATEGORY_DIAGNOSTIC, -) +import esphome.config_validation as cv +from esphome.const import DEVICE_CLASS_CONNECTIVITY, ENTITY_CATEGORY_DIAGNOSTIC + from . import CONF_SIM800L_ID, Sim800LComponent DEPENDENCIES = ["sim800l"] diff --git a/esphome/components/sim800l/sensor.py b/esphome/components/sim800l/sensor.py index 156bd6a0406..010e325df44 100644 --- a/esphome/components/sim800l/sensor.py +++ b/esphome/components/sim800l/sensor.py @@ -1,12 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_SIGNAL_STRENGTH, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_DECIBEL_MILLIWATT, ) + from . import CONF_SIM800L_ID, Sim800LComponent DEPENDENCIES = ["sim800l"] diff --git a/esphome/components/slow_pwm/output.py b/esphome/components/slow_pwm/output.py index 9cce35254b1..73807ba3775 100644 --- a/esphome/components/slow_pwm/output.py +++ b/esphome/components/slow_pwm/output.py @@ -1,14 +1,13 @@ -from esphome import pins, core +from esphome import automation, core, pins +import esphome.codegen as cg from esphome.components import output import esphome.config_validation as cv -import esphome.codegen as cg -from esphome import automation from esphome.const import ( CONF_ID, - CONF_PIN, CONF_PERIOD, - CONF_TURN_ON_ACTION, + CONF_PIN, CONF_TURN_OFF_ACTION, + CONF_TURN_ON_ACTION, ) slow_pwm_ns = cg.esphome_ns.namespace("slow_pwm") diff --git a/esphome/components/sm10bit_base/__init__.py b/esphome/components/sm10bit_base/__init__.py index 8722bd35a9b..81e7c04c0eb 100644 --- a/esphome/components/sm10bit_base/__init__.py +++ b/esphome/components/sm10bit_base/__init__.py @@ -1,11 +1,7 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import ( - CONF_CLOCK_PIN, - CONF_DATA_PIN, - CONF_ID, -) +from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID CODEOWNERS = ["@Cossid"] MULTI_CONF = True diff --git a/esphome/components/sm16716/__init__.py b/esphome/components/sm16716/__init__.py index ec8ed722f3c..e97bc440f41 100644 --- a/esphome/components/sm16716/__init__.py +++ b/esphome/components/sm16716/__init__.py @@ -1,6 +1,6 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( CONF_CLOCK_PIN, CONF_DATA_PIN, diff --git a/esphome/components/sm16716/output.py b/esphome/components/sm16716/output.py index e9b92f68f86..50f6ec759f3 100644 --- a/esphome/components/sm16716/output.py +++ b/esphome/components/sm16716/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import SM16716 DEPENDENCIES = ["sm16716"] diff --git a/esphome/components/sm2135/__init__.py b/esphome/components/sm2135/__init__.py index 52128f1f24d..28c92a42a76 100644 --- a/esphome/components/sm2135/__init__.py +++ b/esphome/components/sm2135/__init__.py @@ -1,11 +1,7 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import ( - CONF_CLOCK_PIN, - CONF_DATA_PIN, - CONF_ID, -) +from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID AUTO_LOAD = ["output"] CODEOWNERS = ["@BoukeHaarsma23", "@matika77", "@dd32"] diff --git a/esphome/components/sm2135/output.py b/esphome/components/sm2135/output.py index 5cd969c6a5f..71c4af2253a 100644 --- a/esphome/components/sm2135/output.py +++ b/esphome/components/sm2135/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import SM2135 DEPENDENCIES = ["sm2135"] diff --git a/esphome/components/sm2235/__init__.py b/esphome/components/sm2235/__init__.py index ae6cb336ad9..1b18a1d342c 100644 --- a/esphome/components/sm2235/__init__.py +++ b/esphome/components/sm2235/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sm10bit_base +import esphome.config_validation as cv AUTO_LOAD = ["sm10bit_base", "output"] CODEOWNERS = ["@Cossid"] diff --git a/esphome/components/sm2235/output.py b/esphome/components/sm2235/output.py index c4f63b451ac..2a9698d645e 100644 --- a/esphome/components/sm2235/output.py +++ b/esphome/components/sm2235/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import SM2235 DEPENDENCIES = ["sm2235"] diff --git a/esphome/components/sm2335/__init__.py b/esphome/components/sm2335/__init__.py index 6d6e0e311cc..02a6d1f697b 100644 --- a/esphome/components/sm2335/__init__.py +++ b/esphome/components/sm2335/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sm10bit_base +import esphome.config_validation as cv AUTO_LOAD = ["sm10bit_base", "output"] CODEOWNERS = ["@Cossid"] diff --git a/esphome/components/sm2335/output.py b/esphome/components/sm2335/output.py index 52b6321db1f..ef7fec7307a 100644 --- a/esphome/components/sm2335/output.py +++ b/esphome/components/sm2335/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import SM2335 DEPENDENCIES = ["sm2335"] diff --git a/esphome/components/sm300d2/sensor.py b/esphome/components/sm300d2/sensor.py index 0c3c54f200c..60c9ccc40d8 100644 --- a/esphome/components/sm300d2/sensor.py +++ b/esphome/components/sm300d2/sensor.py @@ -1,30 +1,30 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_CO2, CONF_FORMALDEHYDE, - CONF_TVOC, + CONF_HUMIDITY, + CONF_ID, CONF_PM_2_5, CONF_PM_10_0, CONF_TEMPERATURE, - CONF_HUMIDITY, + CONF_TVOC, DEVICE_CLASS_CARBON_DIOXIDE, - DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, - DEVICE_CLASS_PM25, - DEVICE_CLASS_PM10, - DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, - UNIT_MICROGRAMS_PER_CUBIC_METER, - UNIT_CELSIUS, - UNIT_PERCENT, - ICON_MOLECULE_CO2, - ICON_FLASK, + DEVICE_CLASS_PM10, + DEVICE_CLASS_PM25, + DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, ICON_CHEMICAL_WEAPON, + ICON_FLASK, ICON_GRAIN, + ICON_MOLECULE_CO2, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_MICROGRAMS_PER_CUBIC_METER, + UNIT_PARTS_PER_MILLION, + UNIT_PERCENT, ) DEPENDENCIES = ["uart"] diff --git a/esphome/components/sml/__init__.py b/esphome/components/sml/__init__.py index 8bcfb69a450..936efd8561b 100644 --- a/esphome/components/sml/__init__.py +++ b/esphome/components/sml/__init__.py @@ -2,8 +2,8 @@ import re from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_TRIGGER_ID CODEOWNERS = ["@alengwenus"] diff --git a/esphome/components/sml/sensor/__init__.py b/esphome/components/sml/sensor/__init__.py index a1fcc5e7aeb..164a31f8a71 100644 --- a/esphome/components/sml/sensor/__init__.py +++ b/esphome/components/sml/sensor/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import CONF_ID from .. import CONF_OBIS_CODE, CONF_SERVER_ID, CONF_SML_ID, Sml, obis_code, sml_ns diff --git a/esphome/components/sml/sml.cpp b/esphome/components/sml/sml.cpp index bac13be9236..7ae9044c72b 100644 --- a/esphome/components/sml/sml.cpp +++ b/esphome/components/sml/sml.cpp @@ -52,9 +52,8 @@ void Sml::loop() { break; // remove start/end sequence - this->sml_data_.erase(this->sml_data_.begin(), this->sml_data_.begin() + START_SEQ.size()); - this->sml_data_.resize(this->sml_data_.size() - 8); - this->process_sml_file_(this->sml_data_); + this->process_sml_file_( + BytesView(this->sml_data_).subview(START_SEQ.size(), this->sml_data_.size() - START_SEQ.size() - 8)); } break; }; @@ -66,8 +65,8 @@ void Sml::add_on_data_callback(std::function, bool)> & this->data_callbacks_.add(std::move(callback)); } -void Sml::process_sml_file_(const bytes &sml_data) { - SmlFile sml_file = SmlFile(sml_data); +void Sml::process_sml_file_(const BytesView &sml_data) { + SmlFile sml_file(sml_data); std::vector obis_info = sml_file.get_obis_info(); this->publish_obis_info_(obis_info); @@ -75,6 +74,7 @@ void Sml::process_sml_file_(const bytes &sml_data) { } void Sml::log_obis_info_(const std::vector &obis_info_vec) { +#ifdef ESPHOME_LOG_HAS_DEBUG ESP_LOGD(TAG, "OBIS info:"); for (auto const &obis_info : obis_info_vec) { std::string info; @@ -83,6 +83,7 @@ void Sml::log_obis_info_(const std::vector &obis_info_vec) { info += " [0x" + bytes_repr(obis_info.value) + "]"; ESP_LOGD(TAG, "%s", info.c_str()); } +#endif } void Sml::publish_obis_info_(const std::vector &obis_info_vec) { @@ -92,10 +93,11 @@ void Sml::publish_obis_info_(const std::vector &obis_info_vec) { } void Sml::publish_value_(const ObisInfo &obis_info) { + const auto obis_code = obis_info.code_repr(); for (auto const &sml_listener : sml_listeners_) { if ((!sml_listener->server_id.empty()) && (bytes_repr(obis_info.server_id) != sml_listener->server_id)) continue; - if (obis_info.code_repr() != sml_listener->obis_code) + if (obis_code != sml_listener->obis_code) continue; sml_listener->publish_val(obis_info); } diff --git a/esphome/components/sml/sml.h b/esphome/components/sml/sml.h index b0c932ca956..15ca43944cb 100644 --- a/esphome/components/sml/sml.h +++ b/esphome/components/sml/sml.h @@ -27,7 +27,7 @@ class Sml : public Component, public uart::UARTDevice { void add_on_data_callback(std::function, bool)> &&callback); protected: - void process_sml_file_(const bytes &sml_data); + void process_sml_file_(const BytesView &sml_data); void log_obis_info_(const std::vector &obis_info_vec); void publish_obis_info_(const std::vector &obis_info_vec); char check_start_end_bytes_(uint8_t byte); diff --git a/esphome/components/sml/sml_parser.cpp b/esphome/components/sml/sml_parser.cpp index 2cc71e87faf..85e5a2da032 100644 --- a/esphome/components/sml/sml_parser.cpp +++ b/esphome/components/sml/sml_parser.cpp @@ -5,17 +5,17 @@ namespace esphome { namespace sml { -SmlFile::SmlFile(bytes buffer) : buffer_(std::move(buffer)) { +SmlFile::SmlFile(const BytesView &buffer) : buffer_(buffer) { // extract messages this->pos_ = 0; while (this->pos_ < this->buffer_.size()) { if (this->buffer_[this->pos_] == 0x00) break; // EndOfSmlMsg - SmlNode message = SmlNode(); + SmlNode message; if (!this->setup_node(&message)) break; - this->messages.emplace_back(message); + this->messages.emplace_back(std::move(message)); } } @@ -62,22 +62,20 @@ bool SmlFile::setup_node(SmlNode *node) { return false; node->type = type; - node->nodes.clear(); - node->value_bytes.clear(); if (type == SML_LIST) { node->nodes.reserve(length); for (size_t i = 0; i != length; i++) { - SmlNode child_node = SmlNode(); + SmlNode child_node; if (!this->setup_node(&child_node)) return false; - node->nodes.emplace_back(child_node); + node->nodes.emplace_back(std::move(child_node)); } } else { // Value starts at the current position // Value ends "length" bytes later, // (since the TL field is counted but already subtracted from length) - node->value_bytes = bytes(this->buffer_.begin() + this->pos_, this->buffer_.begin() + this->pos_ + length); + node->value_bytes = buffer_.subview(this->pos_, length); // Increment the pointer past all consumed bytes this->pos_ += length; } @@ -87,14 +85,14 @@ bool SmlFile::setup_node(SmlNode *node) { std::vector SmlFile::get_obis_info() { std::vector obis_info; for (auto const &message : messages) { - SmlNode message_body = message.nodes[3]; + const auto &message_body = message.nodes[3]; uint16_t message_type = bytes_to_uint(message_body.nodes[0].value_bytes); if (message_type != SML_GET_LIST_RES) continue; - SmlNode get_list_response = message_body.nodes[1]; - bytes server_id = get_list_response.nodes[1].value_bytes; - SmlNode val_list = get_list_response.nodes[4]; + const auto &get_list_response = message_body.nodes[1]; + const auto &server_id = get_list_response.nodes[1].value_bytes; + const auto &val_list = get_list_response.nodes[4]; for (auto const &val_list_entry : val_list.nodes) { obis_info.emplace_back(server_id, val_list_entry); @@ -103,7 +101,7 @@ std::vector SmlFile::get_obis_info() { return obis_info; } -std::string bytes_repr(const bytes &buffer) { +std::string bytes_repr(const BytesView &buffer) { std::string repr; for (auto const value : buffer) { repr += str_sprintf("%02x", value & 0xff); @@ -111,7 +109,7 @@ std::string bytes_repr(const bytes &buffer) { return repr; } -uint64_t bytes_to_uint(const bytes &buffer) { +uint64_t bytes_to_uint(const BytesView &buffer) { uint64_t val = 0; for (auto const value : buffer) { val = (val << 8) + value; @@ -119,7 +117,7 @@ uint64_t bytes_to_uint(const bytes &buffer) { return val; } -int64_t bytes_to_int(const bytes &buffer) { +int64_t bytes_to_int(const BytesView &buffer) { uint64_t tmp = bytes_to_uint(buffer); int64_t val; @@ -135,14 +133,14 @@ int64_t bytes_to_int(const bytes &buffer) { return val; } -std::string bytes_to_string(const bytes &buffer) { return std::string(buffer.begin(), buffer.end()); } +std::string bytes_to_string(const BytesView &buffer) { return std::string(buffer.begin(), buffer.end()); } -ObisInfo::ObisInfo(bytes server_id, SmlNode val_list_entry) : server_id(std::move(server_id)) { +ObisInfo::ObisInfo(const BytesView &server_id, const SmlNode &val_list_entry) : server_id(server_id) { this->code = val_list_entry.nodes[0].value_bytes; this->status = val_list_entry.nodes[1].value_bytes; this->unit = bytes_to_uint(val_list_entry.nodes[3].value_bytes); this->scaler = bytes_to_int(val_list_entry.nodes[4].value_bytes); - SmlNode value_node = val_list_entry.nodes[5]; + const auto &value_node = val_list_entry.nodes[5]; this->value = value_node.value_bytes; this->value_type = value_node.type; } diff --git a/esphome/components/sml/sml_parser.h b/esphome/components/sml/sml_parser.h index fca859d4b8f..bee0c8965bc 100644 --- a/esphome/components/sml/sml_parser.h +++ b/esphome/components/sml/sml_parser.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,44 +12,73 @@ namespace sml { using bytes = std::vector; +class BytesView { + public: + BytesView() noexcept = default; + + explicit BytesView(const uint8_t *first, size_t count) noexcept : data_{first}, count_{count} {} + + explicit BytesView(const bytes &bytes) noexcept : data_{bytes.data()}, count_{bytes.size()} {} + + size_t size() const noexcept { return count_; } + + uint8_t operator[](size_t index) const noexcept { + assert(index < count_); + return data_[index]; + } + + BytesView subview(size_t offset, size_t count) const noexcept { + assert(offset + count <= count_); + return BytesView{data_ + offset, count}; + } + + const uint8_t *begin() const noexcept { return data_; } + + const uint8_t *end() const noexcept { return data_ + count_; } + + private: + const uint8_t *data_ = nullptr; + size_t count_ = 0; +}; + class SmlNode { public: uint8_t type; - bytes value_bytes; + BytesView value_bytes; std::vector nodes; }; class ObisInfo { public: - ObisInfo(bytes server_id, SmlNode val_list_entry); - bytes server_id; - bytes code; - bytes status; + ObisInfo(const BytesView &server_id, const SmlNode &val_list_entry); + BytesView server_id; + BytesView code; + BytesView status; char unit; char scaler; - bytes value; + BytesView value; uint16_t value_type; std::string code_repr() const; }; class SmlFile { public: - SmlFile(bytes buffer); + SmlFile(const BytesView &buffer); bool setup_node(SmlNode *node); std::vector messages; std::vector get_obis_info(); protected: - const bytes buffer_; + const BytesView buffer_; size_t pos_; }; -std::string bytes_repr(const bytes &buffer); +std::string bytes_repr(const BytesView &buffer); -uint64_t bytes_to_uint(const bytes &buffer); +uint64_t bytes_to_uint(const BytesView &buffer); -int64_t bytes_to_int(const bytes &buffer); +int64_t bytes_to_int(const BytesView &buffer); -std::string bytes_to_string(const bytes &buffer); +std::string bytes_to_string(const BytesView &buffer); } // namespace sml } // namespace esphome diff --git a/esphome/components/sml/text_sensor/__init__.py b/esphome/components/sml/text_sensor/__init__.py index 81564bf65ba..401db9c582f 100644 --- a/esphome/components/sml/text_sensor/__init__.py +++ b/esphome/components/sml/text_sensor/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_FORMAT, CONF_ID from .. import CONF_OBIS_CODE, CONF_SERVER_ID, CONF_SML_ID, Sml, obis_code, sml_ns diff --git a/esphome/components/smt100/sensor.py b/esphome/components/smt100/sensor.py index 33eb78b841c..ea424993798 100644 --- a/esphome/components/smt100/sensor.py +++ b/esphome/components/smt100/sensor.py @@ -1,20 +1,19 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart - +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_COUNTS, CONF_DIELECTRIC_CONSTANT, - CONF_TEMPERATURE, + CONF_ID, CONF_MOISTURE, + CONF_TEMPERATURE, CONF_VOLTAGE, - ICON_WATER_PERCENT, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_VOLTAGE, + ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, - UNIT_EMPTY, UNIT_CELSIUS, + UNIT_EMPTY, UNIT_PERCENT, UNIT_VOLT, ) diff --git a/esphome/components/sn74hc165/__init__.py b/esphome/components/sn74hc165/__init__.py index 0f2abd3678e..f2ba5fedd18 100644 --- a/esphome/components/sn74hc165/__init__.py +++ b/esphome/components/sn74hc165/__init__.py @@ -1,14 +1,14 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( + CONF_CLOCK_PIN, + CONF_DATA_PIN, CONF_ID, + CONF_INPUT, + CONF_INVERTED, CONF_MODE, CONF_NUMBER, - CONF_INVERTED, - CONF_DATA_PIN, - CONF_CLOCK_PIN, - CONF_INPUT, ) CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/sn74hc595/__init__.py b/esphome/components/sn74hc595/__init__.py index 2fd49f68247..db18b00cd10 100644 --- a/esphome/components/sn74hc595/__init__.py +++ b/esphome/components/sn74hc595/__init__.py @@ -1,13 +1,13 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import spi +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, - CONF_NUMBER, - CONF_INVERTED, - CONF_DATA_PIN, CONF_CLOCK_PIN, + CONF_DATA_PIN, + CONF_ID, + CONF_INVERTED, + CONF_NUMBER, CONF_OE_PIN, CONF_OUTPUT, CONF_TYPE, diff --git a/esphome/components/socket/__init__.py b/esphome/components/socket/__init__.py index 19952aeece2..77e8fe51f69 100644 --- a/esphome/components/socket/__init__.py +++ b/esphome/components/socket/__init__.py @@ -1,5 +1,5 @@ -import esphome.config_validation as cv import esphome.codegen as cg +import esphome.config_validation as cv CODEOWNERS = ["@esphome/core"] diff --git a/esphome/components/sonoff_d1/light.py b/esphome/components/sonoff_d1/light.py index 8ffe60224e7..06cde45cd66 100644 --- a/esphome/components/sonoff_d1/light.py +++ b/esphome/components/sonoff_d1/light.py @@ -1,11 +1,7 @@ import esphome.codegen as cg +from esphome.components import light, uart import esphome.config_validation as cv -from esphome.components import uart, light -from esphome.const import ( - CONF_OUTPUT_ID, - CONF_MIN_VALUE, - CONF_MAX_VALUE, -) +from esphome.const import CONF_MAX_VALUE, CONF_MIN_VALUE, CONF_OUTPUT_ID CONF_USE_RM433_REMOTE = "use_rm433_remote" diff --git a/esphome/components/speaker/media_player/audio_pipeline.cpp b/esphome/components/speaker/media_player/audio_pipeline.cpp index b49cf3ddda3..60f562cc2c6 100644 --- a/esphome/components/speaker/media_player/audio_pipeline.cpp +++ b/esphome/components/speaker/media_player/audio_pipeline.cpp @@ -441,9 +441,10 @@ void AudioPipeline::decode_task(void *params) { pdFALSE, // Wait for all the bits, portMAX_DELAY); // Block indefinitely until bit is set + xEventGroupClearBits(this_pipeline->event_group_, + EventGroupBits::DECODER_MESSAGE_FINISHED | EventGroupBits::READER_MESSAGE_LOADED_MEDIA_TYPE); + if (!(event_bits & EventGroupBits::PIPELINE_COMMAND_STOP)) { - xEventGroupClearBits(this_pipeline->event_group_, - EventGroupBits::DECODER_MESSAGE_FINISHED | EventGroupBits::READER_MESSAGE_LOADED_MEDIA_TYPE); InfoErrorEvent event; event.source = InfoErrorSource::DECODER; diff --git a/esphome/components/speed/fan/__init__.py b/esphome/components/speed/fan/__init__.py index 5fbf0116695..fe43ac6a3ad 100644 --- a/esphome/components/speed/fan/__init__.py +++ b/esphome/components/speed/fan/__init__.py @@ -1,13 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import fan, output from esphome.components.fan import validate_preset_modes +import esphome.config_validation as cv from esphome.const import ( - CONF_PRESET_MODES, CONF_DIRECTION_OUTPUT, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT, CONF_OUTPUT_ID, + CONF_PRESET_MODES, CONF_SPEED, CONF_SPEED_COUNT, ) diff --git a/esphome/components/spi/__init__.py b/esphome/components/spi/__init__.py index 3e6d680b89b..5b28b3546ba 100644 --- a/esphome/components/spi/__init__.py +++ b/esphome/components/spi/__init__.py @@ -37,6 +37,7 @@ CODEOWNERS = ["@esphome/core", "@clydebarrow"] spi_ns = cg.esphome_ns.namespace("spi") SPIComponent = spi_ns.class_("SPIComponent", cg.Component) QuadSPIComponent = spi_ns.class_("QuadSPIComponent", cg.Component) +OctalSPIComponent = spi_ns.class_("OctalSPIComponent", cg.Component) SPIDevice = spi_ns.class_("SPIDevice") SPIDataRate = spi_ns.enum("SPIDataRate") SPIMode = spi_ns.enum("SPIMode") @@ -78,6 +79,13 @@ CONF_INTERFACE = "interface" CONF_INTERFACE_INDEX = "interface_index" TYPE_SINGLE = "single" TYPE_QUAD = "quad" +TYPE_OCTAL = "octal" + +TYPE_CLASS = { + TYPE_SINGLE: SPIComponent, + TYPE_QUAD: QuadSPIComponent, + TYPE_OCTAL: OctalSPIComponent, +} # RP2040 SPI pin assignments are complicated; # refer to GPIO function select table in https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf @@ -230,7 +238,7 @@ def validate_spi_config(config): ): raise cv.Invalid("Invalid pin selections for hardware SPI interface") if CONF_DATA_PINS in spi and CONF_INTERFACE_INDEX not in spi: - raise cv.Invalid("Quad mode requires a hardware interface") + raise cv.Invalid("Quad and octal modes requires a hardware interface") return config @@ -251,7 +259,7 @@ def get_spi_interface(index): return "new SPIClass(HSPI)" -SPI_SCHEMA = cv.All( +SPI_SINGLE_SCHEMA = cv.All( cv.Schema( { cv.GenerateID(): cv.declare_id(SPIComponent), @@ -266,7 +274,7 @@ SPI_SCHEMA = cv.All( lower=True, ), cv.Optional(CONF_DATA_PINS): cv.invalid( - "'data_pins' should be used with 'type: quad' only" + "'data_pins' should be used with 'type: quad or octal' only" ), } ), @@ -274,38 +282,41 @@ SPI_SCHEMA = cv.All( cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]), ) -SPI_QUAD_SCHEMA = cv.All( - cv.Schema( - { - cv.GenerateID(): cv.declare_id(QuadSPIComponent), - cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, - cv.Required(CONF_DATA_PINS): cv.All( - cv.ensure_list(pins.internal_gpio_output_pin_number), - cv.Length(min=4, max=4), - ), - cv.Optional(CONF_INTERFACE, default="hardware"): cv.one_of( - *sum(get_hw_interface_list(), ["hardware"]), - lower=True, - ), - cv.Optional(CONF_MISO_PIN): cv.invalid( - "'miso_pin' should not be used with quad SPI" - ), - cv.Optional(CONF_MOSI_PIN): cv.invalid( - "'mosi_pin' should not be used with quad SPI" - ), - } - ), - cv.only_on([PLATFORM_ESP32]), - cv.only_with_esp_idf, -) + +def spi_mode_schema(mode): + if mode == TYPE_SINGLE: + return SPI_SINGLE_SCHEMA + pin_count = 4 if mode == TYPE_QUAD else 8 + return cv.All( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(TYPE_CLASS[mode]), + cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, + cv.Required(CONF_DATA_PINS): cv.All( + cv.ensure_list(pins.internal_gpio_output_pin_number), + cv.Length(min=pin_count, max=pin_count), + ), + cv.Optional(CONF_INTERFACE, default="hardware"): cv.one_of( + *sum(get_hw_interface_list(), ["hardware"]), + lower=True, + ), + cv.Optional(CONF_MISO_PIN): cv.invalid( + f"'miso_pin' should not be used with {mode} SPI" + ), + cv.Optional(CONF_MOSI_PIN): cv.invalid( + f"'mosi_pin' should not be used with {mode} SPI" + ), + } + ), + cv.only_on([PLATFORM_ESP32]), + cv.only_with_esp_idf, + ) + CONFIG_SCHEMA = cv.All( cv.ensure_list( cv.typed_schema( - { - TYPE_SINGLE: SPI_SCHEMA, - TYPE_QUAD: SPI_QUAD_SCHEMA, - }, + {k: spi_mode_schema(k) for k in TYPE_CLASS}, default_type=TYPE_SINGLE, ) ), @@ -344,19 +355,17 @@ def spi_device_schema( cs_pin_required=True, default_data_rate=cv.UNDEFINED, default_mode=cv.UNDEFINED, - quad=False, + mode=TYPE_SINGLE, ): """Create a schema for an SPI device. :param cs_pin_required: If true, make the CS_PIN required in the config. :param default_data_rate: Optional data_rate to use as default :param default_mode Optional. The default SPI mode to use. - :param quad If set, will require an SPI component configured as quad data bits. + :param mode Choose single, quad or octal mode. :return: The SPI device schema, `extend` this in your config schema. """ schema = { - cv.GenerateID(CONF_SPI_ID): cv.use_id( - QuadSPIComponent if quad else SPIComponent - ), + cv.GenerateID(CONF_SPI_ID): cv.use_id(TYPE_CLASS[mode]), cv.Optional(CONF_DATA_RATE, default=default_data_rate): SPI_DATA_RATE_SCHEMA, cv.Optional(CONF_SPI_MODE, default=default_mode): cv.enum( SPI_MODE_OPTIONS, upper=True diff --git a/esphome/components/spi/spi.h b/esphome/components/spi/spi.h index 64463747a2d..378d95e7b91 100644 --- a/esphome/components/spi/spi.h +++ b/esphome/components/spi/spi.h @@ -369,6 +369,7 @@ class SPIComponent : public Component { }; using QuadSPIComponent = SPIComponent; +using OctalSPIComponent = SPIComponent; /** * Base class for SPIDevice, un-templated. */ diff --git a/esphome/components/spi/spi_esp_idf.cpp b/esphome/components/spi/spi_esp_idf.cpp index 55680f72d32..a78da2cd9ad 100644 --- a/esphome/components/spi/spi_esp_idf.cpp +++ b/esphome/components/spi/spi_esp_idf.cpp @@ -211,11 +211,19 @@ class SPIBusHw : public SPIBus { buscfg.data1_io_num = data_pins[1]; buscfg.data2_io_num = data_pins[2]; buscfg.data3_io_num = data_pins[3]; - buscfg.data4_io_num = -1; - buscfg.data5_io_num = -1; - buscfg.data6_io_num = -1; - buscfg.data7_io_num = -1; - buscfg.flags |= SPICOMMON_BUSFLAG_QUAD; + if (data_pins.size() == 8) { + buscfg.data4_io_num = data_pins[4]; + buscfg.data5_io_num = data_pins[5]; + buscfg.data6_io_num = data_pins[6]; + buscfg.data7_io_num = data_pins[7]; + buscfg.flags |= SPICOMMON_BUSFLAG_OCTAL; + } else { + buscfg.data4_io_num = -1; + buscfg.data5_io_num = -1; + buscfg.data6_io_num = -1; + buscfg.data7_io_num = -1; + buscfg.flags |= SPICOMMON_BUSFLAG_QUAD; + } } buscfg.max_transfer_sz = MAX_TRANSFER_SIZE; auto err = spi_bus_initialize(channel, &buscfg, SPI_DMA_CH_AUTO); diff --git a/esphome/components/sprinkler/__init__.py b/esphome/components/sprinkler/__init__.py index e5bcf681f4b..2c59309b1fd 100644 --- a/esphome/components/sprinkler/__init__.py +++ b/esphome/components/sprinkler/__init__.py @@ -1,9 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation from esphome.automation import maybe_simple_id -from esphome.components import number -from esphome.components import switch +import esphome.codegen as cg +from esphome.components import number, switch +import esphome.config_validation as cv from esphome.const import ( CONF_ENTITY_CATEGORY, CONF_ID, @@ -14,12 +13,12 @@ from esphome.const import ( CONF_REPEAT, CONF_RESTORE_VALUE, CONF_RUN_DURATION, + CONF_SET_ACTION, CONF_STEP, CONF_UNIT_OF_MEASUREMENT, ENTITY_CATEGORY_CONFIG, UNIT_MINUTE, UNIT_SECOND, - CONF_SET_ACTION, ) AUTO_LOAD = ["number", "switch"] diff --git a/esphome/components/sps30/sensor.py b/esphome/components/sps30/sensor.py index 0f01bab5143..d4f91b4188b 100644 --- a/esphome/components/sps30/sensor.py +++ b/esphome/components/sps30/sensor.py @@ -1,30 +1,30 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common from esphome import automation from esphome.automation import maybe_simple_id +import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PM_1_0, CONF_PM_2_5, CONF_PM_4_0, CONF_PM_10_0, + CONF_PM_SIZE, CONF_PMC_0_5, CONF_PMC_1_0, CONF_PMC_2_5, CONF_PMC_4_0, CONF_PMC_10_0, - CONF_PM_SIZE, DEVICE_CLASS_PM1, DEVICE_CLASS_PM10, DEVICE_CLASS_PM25, - STATE_CLASS_MEASUREMENT, - UNIT_MICROGRAMS_PER_CUBIC_METER, - UNIT_COUNTS_PER_CUBIC_CENTIMETER, - UNIT_MICROMETER, ICON_CHEMICAL_WEAPON, ICON_COUNTER, ICON_RULER, + STATE_CLASS_MEASUREMENT, + UNIT_COUNTS_PER_CUBIC_CENTIMETER, + UNIT_MICROGRAMS_PER_CUBIC_METER, + UNIT_MICROMETER, ) CODEOWNERS = ["@martgras"] diff --git a/esphome/components/ssd1306_i2c/display.py b/esphome/components/ssd1306_i2c/display.py index c51ab5f93ea..2ac0093ef12 100644 --- a/esphome/components/ssd1306_i2c/display.py +++ b/esphome/components/ssd1306_i2c/display.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import ssd1306_base, i2c +from esphome.components import i2c, ssd1306_base from esphome.components.ssd1306_base import _validate +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES AUTO_LOAD = ["ssd1306_base"] diff --git a/esphome/components/ssd1322_base/__init__.py b/esphome/components/ssd1322_base/__init__.py index 471c8749863..3569bbe9576 100644 --- a/esphome/components/ssd1322_base/__init__.py +++ b/esphome/components/ssd1322_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( CONF_BRIGHTNESS, CONF_EXTERNAL_VCC, diff --git a/esphome/components/ssd1325_base/__init__.py b/esphome/components/ssd1325_base/__init__.py index e66cfbc6849..12cbd883a0a 100644 --- a/esphome/components/ssd1325_base/__init__.py +++ b/esphome/components/ssd1325_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( CONF_BRIGHTNESS, CONF_EXTERNAL_VCC, diff --git a/esphome/components/ssd1327_base/__init__.py b/esphome/components/ssd1327_base/__init__.py index 7f2259cf328..d0ec2410e67 100644 --- a/esphome/components/ssd1327_base/__init__.py +++ b/esphome/components/ssd1327_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN CODEOWNERS = ["@kbx81"] diff --git a/esphome/components/ssd1327_i2c/display.py b/esphome/components/ssd1327_i2c/display.py index 7b581cc92cf..95de1c29799 100644 --- a/esphome/components/ssd1327_i2c/display.py +++ b/esphome/components/ssd1327_i2c/display.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, ssd1327_base import esphome.config_validation as cv -from esphome.components import ssd1327_base, i2c from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES CODEOWNERS = ["@kbx81"] diff --git a/esphome/components/ssd1331_base/__init__.py b/esphome/components/ssd1331_base/__init__.py index 80162979fc1..144a95a29f1 100644 --- a/esphome/components/ssd1331_base/__init__.py +++ b/esphome/components/ssd1331_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_RESET_PIN CODEOWNERS = ["@kbx81"] diff --git a/esphome/components/ssd1351_base/__init__.py b/esphome/components/ssd1351_base/__init__.py index 150d89afeda..fc03083ad02 100644 --- a/esphome/components/ssd1351_base/__init__.py +++ b/esphome/components/ssd1351_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN CODEOWNERS = ["@kbx81"] diff --git a/esphome/components/st7567_base/__init__.py b/esphome/components/st7567_base/__init__.py index 7ce50fd99f3..6f93172a1a0 100644 --- a/esphome/components/st7567_base/__init__.py +++ b/esphome/components/st7567_base/__init__.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( + CONF_INVERT_COLORS, CONF_LAMBDA, - CONF_RESET_PIN, CONF_MIRROR_X, CONF_MIRROR_Y, + CONF_RESET_PIN, CONF_TRANSFORM, - CONF_INVERT_COLORS, ) CODEOWNERS = ["@latonita"] diff --git a/esphome/components/st7567_i2c/display.py b/esphome/components/st7567_i2c/display.py index fa92d652d7b..bd62b3b3824 100644 --- a/esphome/components/st7567_i2c/display.py +++ b/esphome/components/st7567_i2c/display.py @@ -1,6 +1,6 @@ import esphome.codegen as cg +from esphome.components import i2c, st7567_base import esphome.config_validation as cv -from esphome.components import st7567_base, i2c from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES CODEOWNERS = ["@latonita"] diff --git a/esphome/components/st7920/display.py b/esphome/components/st7920/display.py index 1267e2ad632..de7b2247dd4 100644 --- a/esphome/components/st7920/display.py +++ b/esphome/components/st7920/display.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import display, spi -from esphome.const import CONF_ID, CONF_LAMBDA, CONF_WIDTH, CONF_HEIGHT +import esphome.config_validation as cv +from esphome.const import CONF_HEIGHT, CONF_ID, CONF_LAMBDA, CONF_WIDTH AUTO_LOAD = ["display"] CODEOWNERS = ["@marsjan155"] diff --git a/esphome/components/statsd/__init__.py b/esphome/components/statsd/__init__.py index 3623338aec5..39188c6b814 100644 --- a/esphome/components/statsd/__init__.py +++ b/esphome/components/statsd/__init__.py @@ -1,12 +1,12 @@ import esphome.codegen as cg +from esphome.components import binary_sensor, sensor import esphome.config_validation as cv -from esphome.components import sensor, binary_sensor from esphome.const import ( - CONF_ID, - CONF_PORT, - CONF_NAME, - CONF_SENSORS, CONF_BINARY_SENSORS, + CONF_ID, + CONF_NAME, + CONF_PORT, + CONF_SENSORS, ) AUTO_LOAD = ["socket"] diff --git a/esphome/components/status/binary_sensor.py b/esphome/components/status/binary_sensor.py index adc342ed4d7..c1a4a52ce2b 100644 --- a/esphome/components/status/binary_sensor.py +++ b/esphome/components/status/binary_sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import ( - DEVICE_CLASS_CONNECTIVITY, - ENTITY_CATEGORY_DIAGNOSTIC, -) +import esphome.config_validation as cv +from esphome.const import DEVICE_CLASS_CONNECTIVITY, ENTITY_CATEGORY_DIAGNOSTIC DEPENDENCIES = ["network"] diff --git a/esphome/components/status_led/__init__.py b/esphome/components/status_led/__init__.py index 92869ee630c..b299ae7ff74 100644 --- a/esphome/components/status_led/__init__.py +++ b/esphome/components/status_led/__init__.py @@ -1,6 +1,6 @@ from esphome import pins -import esphome.config_validation as cv import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_PIN from esphome.core import coroutine_with_priority diff --git a/esphome/components/status_led/light/__init__.py b/esphome/components/status_led/light/__init__.py index d6a4a245e63..f8d03a3b4f6 100644 --- a/esphome/components/status_led/light/__init__.py +++ b/esphome/components/status_led/light/__init__.py @@ -1,8 +1,9 @@ from esphome import pins import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import light, output +import esphome.config_validation as cv from esphome.const import CONF_OUTPUT, CONF_OUTPUT_ID, CONF_PIN + from .. import status_led_ns AUTO_LOAD = ["output"] diff --git a/esphome/components/stepper/__init__.py b/esphome/components/stepper/__init__.py index f2367fd62a1..66fe88c6c44 100644 --- a/esphome/components/stepper/__init__.py +++ b/esphome/components/stepper/__init__.py @@ -1,14 +1,14 @@ +from esphome import automation import esphome.codegen as cg import esphome.config_validation as cv -from esphome import automation from esphome.const import ( CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, CONF_POSITION, - CONF_TARGET, CONF_SPEED, + CONF_TARGET, ) from esphome.core import CORE, coroutine_with_priority diff --git a/esphome/components/sts3x/sensor.py b/esphome/components/sts3x/sensor.py index a99503a2b88..7b04bd58bb9 100644 --- a/esphome/components/sts3x/sensor.py +++ b/esphome/components/sts3x/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/substitutions/__init__.py b/esphome/components/substitutions/__init__.py index fa52200d46b..41e49f70dbd 100644 --- a/esphome/components/substitutions/__init__.py +++ b/esphome/components/substitutions/__init__.py @@ -1,10 +1,10 @@ import logging -import esphome.config_validation as cv from esphome import core +from esphome.config_helpers import Extend, Remove, merge_config +import esphome.config_validation as cv from esphome.const import CONF_SUBSTITUTIONS, VALID_SUBSTITUTIONS_CHARACTERS from esphome.yaml_util import ESPHomeDataBase, make_data_base -from esphome.config_helpers import merge_config, Extend, Remove CODEOWNERS = ["@esphome/core"] _LOGGER = logging.getLogger(__name__) diff --git a/esphome/components/sun/__init__.py b/esphome/components/sun/__init__.py index d00a00661a9..5a2a39c4277 100644 --- a/esphome/components/sun/__init__.py +++ b/esphome/components/sun/__init__.py @@ -1,15 +1,15 @@ import re -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import time +import esphome.config_validation as cv from esphome.const import ( - CONF_TIME_ID, CONF_ID, - CONF_TRIGGER_ID, CONF_LATITUDE, CONF_LONGITUDE, + CONF_TIME_ID, + CONF_TRIGGER_ID, ) CODEOWNERS = ["@OttoWinter"] diff --git a/esphome/components/sun/sensor/__init__.py b/esphome/components/sun/sensor/__init__.py index 10c02373273..a356d9cca82 100644 --- a/esphome/components/sun/sensor/__init__.py +++ b/esphome/components/sun/sensor/__init__.py @@ -1,12 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor -from esphome.const import ( - UNIT_DEGREES, - ICON_WEATHER_SUNSET, - CONF_TYPE, -) -from .. import sun_ns, CONF_SUN_ID, Sun +import esphome.config_validation as cv +from esphome.const import CONF_TYPE, ICON_WEATHER_SUNSET, UNIT_DEGREES + +from .. import CONF_SUN_ID, Sun, sun_ns DEPENDENCIES = ["sun"] diff --git a/esphome/components/sun/text_sensor/__init__.py b/esphome/components/sun/text_sensor/__init__.py index 80737bb9f22..fc733d34354 100644 --- a/esphome/components/sun/text_sensor/__init__.py +++ b/esphome/components/sun/text_sensor/__init__.py @@ -1,14 +1,15 @@ +import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( + CONF_FORMAT, CONF_ICON, + CONF_TYPE, ICON_WEATHER_SUNSET_DOWN, ICON_WEATHER_SUNSET_UP, - CONF_TYPE, - CONF_FORMAT, ) -from .. import sun_ns, CONF_SUN_ID, Sun, CONF_ELEVATION, elevation, DEFAULT_ELEVATION + +from .. import CONF_ELEVATION, CONF_SUN_ID, DEFAULT_ELEVATION, Sun, elevation, sun_ns DEPENDENCIES = ["sun"] diff --git a/esphome/components/sun_gtil2/__init__.py b/esphome/components/sun_gtil2/__init__.py index f4d46fade71..d073c16e4e8 100644 --- a/esphome/components/sun_gtil2/__init__.py +++ b/esphome/components/sun_gtil2/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@Mat931"] diff --git a/esphome/components/sun_gtil2/sensor.py b/esphome/components/sun_gtil2/sensor.py index 6d1be9c7402..d8c59bf1de0 100644 --- a/esphome/components/sun_gtil2/sensor.py +++ b/esphome/components/sun_gtil2/sensor.py @@ -1,18 +1,19 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - DEVICE_CLASS_VOLTAGE, + CONF_TEMPERATURE, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLTAGE, ICON_FLASH, - UNIT_VOLT, ICON_THERMOMETER, - UNIT_WATT, UNIT_CELSIUS, - CONF_TEMPERATURE, + UNIT_VOLT, + UNIT_WATT, ) -from . import SunGTIL2Component, CONF_SUN_GTIL2_ID + +from . import CONF_SUN_GTIL2_ID, SunGTIL2Component CONF_AC_VOLTAGE = "ac_voltage" CONF_DC_VOLTAGE = "dc_voltage" diff --git a/esphome/components/sun_gtil2/text_sensor.py b/esphome/components/sun_gtil2/text_sensor.py index d9d3e3ca66b..f74f89b3b4d 100644 --- a/esphome/components/sun_gtil2/text_sensor.py +++ b/esphome/components/sun_gtil2/text_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor +import esphome.config_validation as cv from esphome.const import CONF_STATE -from . import SunGTIL2Component, CONF_SUN_GTIL2_ID + +from . import CONF_SUN_GTIL2_ID, SunGTIL2Component CONF_SERIAL_NUMBER = "serial_number" diff --git a/esphome/components/sx1509/__init__.py b/esphome/components/sx1509/__init__.py index e4f79dc2bcc..b1702b5ade5 100644 --- a/esphome/components/sx1509/__init__.py +++ b/esphome/components/sx1509/__init__.py @@ -1,17 +1,17 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, - CONF_NUMBER, - CONF_MODE, CONF_INVERTED, + CONF_MODE, + CONF_NUMBER, + CONF_OPEN_DRAIN, CONF_OUTPUT, CONF_PULLDOWN, CONF_PULLUP, - CONF_OPEN_DRAIN, ) CONF_KEYPAD = "keypad" diff --git a/esphome/components/sx1509/binary_sensor/__init__.py b/esphome/components/sx1509/binary_sensor/__init__.py index 280b5ad90ca..0ceca77a5dc 100644 --- a/esphome/components/sx1509/binary_sensor/__init__.py +++ b/esphome/components/sx1509/binary_sensor/__init__.py @@ -1,9 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor -from esphome.const import CONF_ROW, CONF_COL +import esphome.config_validation as cv +from esphome.const import CONF_COL, CONF_ROW -from .. import SX1509Component, sx1509_ns, CONF_SX1509_ID +from .. import CONF_SX1509_ID, SX1509Component, sx1509_ns DEPENDENCIES = ["sx1509"] diff --git a/esphome/components/sx1509/output/__init__.py b/esphome/components/sx1509/output/__init__.py index 7afea0fbf8d..9e2db7bb103 100644 --- a/esphome/components/sx1509/output/__init__.py +++ b/esphome/components/sx1509/output/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output -from esphome.const import CONF_PIN, CONF_ID -from .. import SX1509Component, sx1509_ns, CONF_SX1509_ID +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_PIN + +from .. import CONF_SX1509_ID, SX1509Component, sx1509_ns DEPENDENCIES = ["sx1509"] diff --git a/esphome/components/t6615/sensor.py b/esphome/components/t6615/sensor.py index 71a099d6350..6df40497a99 100644 --- a/esphome/components/t6615/sensor.py +++ b/esphome/components/t6615/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, uart +import esphome.config_validation as cv from esphome.const import ( CONF_CO2, CONF_ID, diff --git a/esphome/components/tca9548a/__init__.py b/esphome/components/tca9548a/__init__.py index 0f222b8fc77..cef779de2e9 100644 --- a/esphome/components/tca9548a/__init__.py +++ b/esphome/components/tca9548a/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_CHANNELS, CONF_ID, CONF_SCAN CODEOWNERS = ["@andreashergert1984"] diff --git a/esphome/components/tcl112/climate.py b/esphome/components/tcl112/climate.py index 9facd6b8db1..9cd193f5c7c 100644 --- a/esphome/components/tcl112/climate.py +++ b/esphome/components/tcl112/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/tcs34725/sensor.py b/esphome/components/tcs34725/sensor.py index d47e9a34c85..34b6c579b6c 100644 --- a/esphome/components/tcs34725/sensor.py +++ b/esphome/components/tcs34725/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_COLOR_TEMPERATURE, CONF_GAIN, + CONF_GLASS_ATTENUATION_FACTOR, CONF_ID, CONF_ILLUMINANCE, - CONF_GLASS_ATTENUATION_FACTOR, CONF_INTEGRATION_TIME, DEVICE_CLASS_ILLUMINANCE, ICON_LIGHTBULB, - STATE_CLASS_MEASUREMENT, - UNIT_PERCENT, ICON_THERMOMETER, + STATE_CLASS_MEASUREMENT, UNIT_KELVIN, UNIT_LUX, + UNIT_PERCENT, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/tee501/sensor.py b/esphome/components/tee501/sensor.py index 329fc724bdb..db8e8d9268a 100644 --- a/esphome/components/tee501/sensor.py +++ b/esphome/components/tee501/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/teleinfo/__init__.py b/esphome/components/teleinfo/__init__.py index e289e42c81c..87c7b9e85c2 100644 --- a/esphome/components/teleinfo/__init__.py +++ b/esphome/components/teleinfo/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@0hax"] diff --git a/esphome/components/teleinfo/sensor/__init__.py b/esphome/components/teleinfo/sensor/__init__.py index ff2d81c95ee..b436c701207 100644 --- a/esphome/components/teleinfo/sensor/__init__.py +++ b/esphome/components/teleinfo/sensor/__init__.py @@ -2,13 +2,7 @@ import esphome.codegen as cg from esphome.components import sensor from esphome.const import CONF_ID, ICON_FLASH, UNIT_WATT_HOURS -from .. import ( - CONF_TAG_NAME, - TELEINFO_LISTENER_SCHEMA, - teleinfo_ns, - CONF_TELEINFO_ID, -) - +from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns TeleInfoSensor = teleinfo_ns.class_("TeleInfoSensor", sensor.Sensor, cg.Component) diff --git a/esphome/components/teleinfo/text_sensor/__init__.py b/esphome/components/teleinfo/text_sensor/__init__.py index df8e4c21fc4..79fabd10d01 100644 --- a/esphome/components/teleinfo/text_sensor/__init__.py +++ b/esphome/components/teleinfo/text_sensor/__init__.py @@ -2,7 +2,7 @@ import esphome.codegen as cg from esphome.components import text_sensor from esphome.const import CONF_ID -from .. import CONF_TAG_NAME, TELEINFO_LISTENER_SCHEMA, teleinfo_ns, CONF_TELEINFO_ID +from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns TeleInfoTextSensor = teleinfo_ns.class_( "TeleInfoTextSensor", text_sensor.TextSensor, cg.Component diff --git a/esphome/components/tem3200/sensor.py b/esphome/components/tem3200/sensor.py index 5cd27433d09..508dc1bcd4a 100644 --- a/esphome/components/tem3200/sensor.py +++ b/esphome/components/tem3200/sensor.py @@ -1,7 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor - +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_TEMPERATURE, diff --git a/esphome/components/template/alarm_control_panel/__init__.py b/esphome/components/template/alarm_control_panel/__init__.py index 3555f2fafdc..0f213857dcd 100644 --- a/esphome/components/template/alarm_control_panel/__init__.py +++ b/esphome/components/template/alarm_control_panel/__init__.py @@ -1,15 +1,8 @@ import esphome.codegen as cg +from esphome.components import alarm_control_panel, binary_sensor import esphome.config_validation as cv -from esphome.components import ( - binary_sensor, - alarm_control_panel, -) -from esphome.const import ( - CONF_ID, - CONF_BINARY_SENSORS, - CONF_INPUT, - CONF_RESTORE_MODE, -) +from esphome.const import CONF_BINARY_SENSORS, CONF_ID, CONF_INPUT, CONF_RESTORE_MODE + from .. import template_ns CODEOWNERS = ["@grahambrown11", "@hwstar"] diff --git a/esphome/components/template/cover/__init__.py b/esphome/components/template/cover/__init__.py index 43d0be99b41..5129e6b1afe 100644 --- a/esphome/components/template/cover/__init__.py +++ b/esphome/components/template/cover/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import cover +import esphome.config_validation as cv from esphome.const import ( CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, @@ -11,14 +11,15 @@ from esphome.const import ( CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_POSITION, + CONF_POSITION_ACTION, CONF_RESTORE_MODE, CONF_STATE, CONF_STOP_ACTION, CONF_TILT, CONF_TILT_ACTION, CONF_TILT_LAMBDA, - CONF_POSITION_ACTION, ) + from .. import template_ns TemplateCover = template_ns.class_("TemplateCover", cover.Cover, cg.Component) diff --git a/esphome/components/template/datetime/__init__.py b/esphome/components/template/datetime/__init__.py index 746ab8a6f35..813d351fd97 100644 --- a/esphome/components/template/datetime/__init__.py +++ b/esphome/components/template/datetime/__init__.py @@ -1,18 +1,18 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import datetime +import esphome.config_validation as cv from esphome.const import ( - CONF_INITIAL_VALUE, - CONF_LAMBDA, - CONF_OPTIMISTIC, - CONF_RESTORE_VALUE, - CONF_SET_ACTION, CONF_DAY, CONF_HOUR, + CONF_INITIAL_VALUE, + CONF_LAMBDA, CONF_MINUTE, CONF_MONTH, + CONF_OPTIMISTIC, + CONF_RESTORE_VALUE, CONF_SECOND, + CONF_SET_ACTION, CONF_TYPE, CONF_YEAR, ) @@ -44,9 +44,8 @@ def validate(config): raise cv.Invalid("initial_value cannot be used with lambda") if CONF_RESTORE_VALUE in config: raise cv.Invalid("restore_value cannot be used with lambda") - else: - if CONF_RESTORE_VALUE not in config: - config[CONF_RESTORE_VALUE] = False + elif CONF_RESTORE_VALUE not in config: + config[CONF_RESTORE_VALUE] = False if not config[CONF_OPTIMISTIC] and CONF_SET_ACTION not in config: raise cv.Invalid( diff --git a/esphome/components/template/event/__init__.py b/esphome/components/template/event/__init__.py index 2a948cfdfd8..cf9c7f4c3df 100644 --- a/esphome/components/template/event/__init__.py +++ b/esphome/components/template/event/__init__.py @@ -1,9 +1,6 @@ -import esphome.config_validation as cv - -from esphome.components import event - import esphome.codegen as cg - +from esphome.components import event +import esphome.config_validation as cv from esphome.const import CONF_EVENT_TYPES from .. import template_ns diff --git a/esphome/components/template/fan/__init__.py b/esphome/components/template/fan/__init__.py index 348ebd281f6..c885866d405 100644 --- a/esphome/components/template/fan/__init__.py +++ b/esphome/components/template/fan/__init__.py @@ -1,12 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import fan from esphome.components.fan import validate_preset_modes -from esphome.const import ( - CONF_OUTPUT_ID, - CONF_PRESET_MODES, - CONF_SPEED_COUNT, -) +import esphome.config_validation as cv +from esphome.const import CONF_OUTPUT_ID, CONF_PRESET_MODES, CONF_SPEED_COUNT from .. import template_ns diff --git a/esphome/components/template/lock/__init__.py b/esphome/components/template/lock/__init__.py index 24709ff4f21..2dcb90e0380 100644 --- a/esphome/components/template/lock/__init__.py +++ b/esphome/components/template/lock/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import lock +import esphome.config_validation as cv from esphome.const import ( CONF_ASSUMED_STATE, CONF_ID, @@ -12,6 +12,7 @@ from esphome.const import ( CONF_STATE, CONF_UNLOCK_ACTION, ) + from .. import template_ns TemplateLock = template_ns.class_("TemplateLock", lock.Lock, cg.Component) diff --git a/esphome/components/template/number/__init__.py b/esphome/components/template/number/__init__.py index c6ed25adda3..2f4c9cbffe6 100644 --- a/esphome/components/template/number/__init__.py +++ b/esphome/components/template/number/__init__.py @@ -1,7 +1,7 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import number +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INITIAL_VALUE, @@ -10,9 +10,10 @@ from esphome.const import ( CONF_MIN_VALUE, CONF_OPTIMISTIC, CONF_RESTORE_VALUE, - CONF_STEP, CONF_SET_ACTION, + CONF_STEP, ) + from .. import template_ns TemplateNumber = template_ns.class_( diff --git a/esphome/components/template/output/__init__.py b/esphome/components/template/output/__init__.py index b42a4be1667..2a37fccdbec 100644 --- a/esphome/components/template/output/__init__.py +++ b/esphome/components/template/output/__init__.py @@ -1,8 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import output -from esphome.const import CONF_ID, CONF_TYPE, CONF_BINARY +import esphome.config_validation as cv +from esphome.const import CONF_BINARY, CONF_ID, CONF_TYPE + from .. import template_ns TemplateBinaryOutput = template_ns.class_("TemplateBinaryOutput", output.BinaryOutput) diff --git a/esphome/components/template/select/__init__.py b/esphome/components/template/select/__init__.py index 75dbd4f5c5c..3282092d639 100644 --- a/esphome/components/template/select/__init__.py +++ b/esphome/components/template/select/__init__.py @@ -1,16 +1,17 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import select +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INITIAL_OPTION, CONF_LAMBDA, - CONF_OPTIONS, CONF_OPTIMISTIC, + CONF_OPTIONS, CONF_RESTORE_VALUE, CONF_SET_ACTION, ) + from .. import template_ns TemplateSelect = template_ns.class_( diff --git a/esphome/components/template/sensor/__init__.py b/esphome/components/template/sensor/__init__.py index 9ed7a83848f..2c325427e99 100644 --- a/esphome/components/template/sensor/__init__.py +++ b/esphome/components/template/sensor/__init__.py @@ -1,12 +1,9 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import sensor -from esphome.const import ( - CONF_ID, - CONF_LAMBDA, - CONF_STATE, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_LAMBDA, CONF_STATE + from .. import template_ns TemplateSensor = template_ns.class_( diff --git a/esphome/components/template/switch/__init__.py b/esphome/components/template/switch/__init__.py index a221cbaa603..e86657510fb 100644 --- a/esphome/components/template/switch/__init__.py +++ b/esphome/components/template/switch/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import switch +import esphome.config_validation as cv from esphome.const import ( CONF_ASSUMED_STATE, CONF_ID, @@ -12,6 +12,7 @@ from esphome.const import ( CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION, ) + from .. import template_ns TemplateSwitch = template_ns.class_("TemplateSwitch", switch.Switch, cg.Component) diff --git a/esphome/components/template/text/__init__.py b/esphome/components/template/text/__init__.py index f73b240197b..b0fea38aafe 100644 --- a/esphome/components/template/text/__init__.py +++ b/esphome/components/template/text/__init__.py @@ -1,17 +1,18 @@ from esphome import automation import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text +import esphome.config_validation as cv from esphome.const import ( CONF_INITIAL_VALUE, CONF_LAMBDA, - CONF_OPTIMISTIC, - CONF_RESTORE_VALUE, CONF_MAX_LENGTH, CONF_MIN_LENGTH, + CONF_OPTIMISTIC, CONF_PATTERN, + CONF_RESTORE_VALUE, CONF_SET_ACTION, ) + from .. import template_ns TemplateText = template_ns.class_("TemplateText", text.Text, cg.PollingComponent) diff --git a/esphome/components/template/text_sensor/__init__.py b/esphome/components/template/text_sensor/__init__.py index 9bd603bbca0..550b27356d1 100644 --- a/esphome/components/template/text_sensor/__init__.py +++ b/esphome/components/template/text_sensor/__init__.py @@ -1,9 +1,10 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import text_sensor from esphome.components.text_sensor import TextSensorPublishAction +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_LAMBDA, CONF_STATE + from .. import template_ns TemplateTextSensor = template_ns.class_( diff --git a/esphome/components/template/valve/__init__.py b/esphome/components/template/valve/__init__.py index 89d776dfdda..12e51741688 100644 --- a/esphome/components/template/valve/__init__.py +++ b/esphome/components/template/valve/__init__.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import valve +import esphome.config_validation as cv from esphome.const import ( CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, @@ -16,6 +16,7 @@ from esphome.const import ( CONF_STATE, CONF_STOP_ACTION, ) + from .. import template_ns TemplateValve = template_ns.class_("TemplateValve", valve.Valve, cg.Component) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 2b9a95c6bd8..11e39e8f678 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -21,10 +21,6 @@ namespace time { static const char *const TAG = "time"; RealTimeClock::RealTimeClock() = default; -void RealTimeClock::call_setup() { - this->apply_timezone_(); - PollingComponent::call_setup(); -} void RealTimeClock::synchronize_epoch_(uint32_t epoch) { // Update UTC epoch time. struct timeval timev { diff --git a/esphome/components/time/real_time_clock.h b/esphome/components/time/real_time_clock.h index a17168ae6f2..401798a5681 100644 --- a/esphome/components/time/real_time_clock.h +++ b/esphome/components/time/real_time_clock.h @@ -21,7 +21,10 @@ class RealTimeClock : public PollingComponent { explicit RealTimeClock(); /// Set the time zone. - void set_timezone(const std::string &tz) { this->timezone_ = tz; } + void set_timezone(const std::string &tz) { + this->timezone_ = tz; + this->apply_timezone_(); + } /// Get the time zone currently in use. std::string get_timezone() { return this->timezone_; } @@ -35,8 +38,6 @@ class RealTimeClock : public PollingComponent { /// Get the current time as the UTC epoch since January 1st 1970. time_t timestamp_now() { return ::time(nullptr); } - void call_setup() override; - void add_on_time_sync_callback(std::function callback) { this->time_sync_callback_.add(std::move(callback)); }; diff --git a/esphome/components/time_based/cover.py b/esphome/components/time_based/cover.py index a14a08ccadb..c7233453701 100644 --- a/esphome/components/time_based/cover.py +++ b/esphome/components/time_based/cover.py @@ -1,15 +1,15 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import automation +import esphome.codegen as cg from esphome.components import cover +import esphome.config_validation as cv from esphome.const import ( + CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_ACTION, CONF_OPEN_DURATION, CONF_STOP_ACTION, - CONF_ASSUMED_STATE, ) time_based_ns = cg.esphome_ns.namespace("time_based") diff --git a/esphome/components/tlc59208f/__init__.py b/esphome/components/tlc59208f/__init__.py index 419fa397b72..b6854237876 100644 --- a/esphome/components/tlc59208f/__init__.py +++ b/esphome/components/tlc59208f/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/tlc59208f/output.py b/esphome/components/tlc59208f/output.py index ac45909673c..a2f4f16554a 100644 --- a/esphome/components/tlc59208f/output.py +++ b/esphome/components/tlc59208f/output.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from . import TLC59208FOutput, tlc59208f_ns DEPENDENCIES = ["tlc59208f"] diff --git a/esphome/components/tlc5947/__init__.py b/esphome/components/tlc5947/__init__.py index 528d690fab5..20e53893aa4 100644 --- a/esphome/components/tlc5947/__init__.py +++ b/esphome/components/tlc5947/__init__.py @@ -1,9 +1,9 @@ # this component is for the "TLC5947 24-Channel, 12-Bit PWM LED Driver" [https://www.ti.com/lit/ds/symlink/tlc5947.pdf], # which is used e.g. on [https://www.adafruit.com/product/1429]. The code is based on the components sm2135 and sm26716. +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins from esphome.const import ( CONF_CLOCK_PIN, CONF_DATA_PIN, diff --git a/esphome/components/tlc5947/output/__init__.py b/esphome/components/tlc5947/output/__init__.py index 1b5dff18541..a1290add816 100644 --- a/esphome/components/tlc5947/output/__init__.py +++ b/esphome/components/tlc5947/output/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from .. import TLC5947, tlc5947_ns DEPENDENCIES = ["tlc5947"] diff --git a/esphome/components/tlc5971/__init__.py b/esphome/components/tlc5971/__init__.py index 0ff2a5d1762..b09924c3d37 100644 --- a/esphome/components/tlc5971/__init__.py +++ b/esphome/components/tlc5971/__init__.py @@ -1,16 +1,10 @@ # this component is for the "TLC5971 12-Channel, 12-Bit PWM LED Driver" [https://www.ti.com/lit/ds/symlink/tlc5971.pdf], # which is used e.g. on [https://www.adafruit.com/product/1455]. The code is based on the TLC5947 component by @rnauber. +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import ( - CONF_CLOCK_PIN, - CONF_DATA_PIN, - CONF_ID, - CONF_NUM_CHIPS, -) - +from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID, CONF_NUM_CHIPS CODEOWNERS = ["@IJIJI"] diff --git a/esphome/components/tlc5971/output/__init__.py b/esphome/components/tlc5971/output/__init__.py index 9fe7b18294c..ae000ae0a9b 100644 --- a/esphome/components/tlc5971/output/__init__.py +++ b/esphome/components/tlc5971/output/__init__.py @@ -1,7 +1,8 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import output +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID + from .. import TLC5971, tlc5971_ns DEPENDENCIES = ["tlc5971"] diff --git a/esphome/components/tm1621/display.py b/esphome/components/tm1621/display.py index a82b680f62f..f521af28424 100644 --- a/esphome/components/tm1621/display.py +++ b/esphome/components/tm1621/display.py @@ -1,10 +1,10 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( - CONF_DATA_PIN, CONF_CS_PIN, + CONF_DATA_PIN, CONF_ID, CONF_LAMBDA, CONF_READ_PIN, diff --git a/esphome/components/tm1637/binary_sensor.py b/esphome/components/tm1637/binary_sensor.py index f14b9bd0188..817231627a8 100644 --- a/esphome/components/tm1637/binary_sensor.py +++ b/esphome/components/tm1637/binary_sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_KEY CONF_TM1637_ID = "tm1637_id" diff --git a/esphome/components/tm1637/display.py b/esphome/components/tm1637/display.py index dcbc64332a9..141ee5a39f8 100644 --- a/esphome/components/tm1637/display.py +++ b/esphome/components/tm1637/display.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import display +import esphome.config_validation as cv from esphome.const import ( CONF_CLK_PIN, CONF_DIO_PIN, CONF_ID, - CONF_LAMBDA, CONF_INTENSITY, CONF_INVERTED, + CONF_LAMBDA, CONF_LENGTH, ) diff --git a/esphome/components/tm1651/__init__.py b/esphome/components/tm1651/__init__.py index 4ef88425710..153cc690e79 100644 --- a/esphome/components/tm1651/__init__.py +++ b/esphome/components/tm1651/__init__.py @@ -1,13 +1,13 @@ +from esphome import automation, pins +from esphome.automation import maybe_simple_id import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins, automation -from esphome.automation import maybe_simple_id from esphome.const import ( - CONF_ID, + CONF_BRIGHTNESS, CONF_CLK_PIN, CONF_DIO_PIN, + CONF_ID, CONF_LEVEL, - CONF_BRIGHTNESS, ) CODEOWNERS = ["@freekode"] diff --git a/esphome/components/tmp102/sensor.py b/esphome/components/tmp102/sensor.py index 2cb1a6d1f5a..862d526ccfd 100644 --- a/esphome/components/tmp102/sensor.py +++ b/esphome/components/tmp102/sensor.py @@ -9,8 +9,8 @@ https://www.sparkfun.com/datasheets/Sensors/Temperature/tmp102.pdf """ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, diff --git a/esphome/components/tmp1075/sensor.py b/esphome/components/tmp1075/sensor.py index 25ec350b7ac..bedeef8e3c7 100644 --- a/esphome/components/tmp1075/sensor.py +++ b/esphome/components/tmp1075/sensor.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( DEVICE_CLASS_TEMPERATURE, + ICON_THERMOMETER, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - ICON_THERMOMETER, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/tmp117/sensor.py b/esphome/components/tmp117/sensor.py index 82d099cf120..e906fe0aeee 100644 --- a/esphome/components/tmp117/sensor.py +++ b/esphome/components/tmp117/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_UPDATE_INTERVAL, DEVICE_CLASS_TEMPERATURE, diff --git a/esphome/components/tof10120/sensor.py b/esphome/components/tof10120/sensor.py index 21d6d486592..d3aeaa814f2 100644 --- a/esphome/components/tof10120/sensor.py +++ b/esphome/components/tof10120/sensor.py @@ -1,10 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, ) CODEOWNERS = ["@wstrzalka"] diff --git a/esphome/components/tormatic/cover.py b/esphome/components/tormatic/cover.py index f1cfe09a05b..627ae6b63df 100644 --- a/esphome/components/tormatic/cover.py +++ b/esphome/components/tormatic/cover.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import cover, uart -from esphome.const import ( - CONF_CLOSE_DURATION, - CONF_ID, - CONF_OPEN_DURATION, -) +import esphome.config_validation as cv +from esphome.const import CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_DURATION tormatic_ns = cg.esphome_ns.namespace("tormatic") Tormatic = tormatic_ns.class_("Tormatic", cover.Cover, cg.PollingComponent) diff --git a/esphome/components/toshiba/climate.py b/esphome/components/toshiba/climate.py index 3f2c644c873..54582b78a91 100644 --- a/esphome/components/toshiba/climate.py +++ b/esphome/components/toshiba/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_MODEL AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/total_daily_energy/sensor.py b/esphome/components/total_daily_energy/sensor.py index 45e9c03c1d2..f026dc9530e 100644 --- a/esphome/components/total_daily_energy/sensor.py +++ b/esphome/components/total_daily_energy/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor, time +import esphome.config_validation as cv from esphome.const import ( + CONF_ACCURACY_DECIMALS, CONF_ICON, CONF_ID, + CONF_METHOD, CONF_RESTORE, CONF_TIME_ID, - DEVICE_CLASS_ENERGY, - CONF_METHOD, - STATE_CLASS_TOTAL_INCREASING, CONF_UNIT_OF_MEASUREMENT, - CONF_ACCURACY_DECIMALS, + DEVICE_CLASS_ENERGY, + STATE_CLASS_TOTAL_INCREASING, ) from esphome.core.entity_helpers import inherit_property_from diff --git a/esphome/components/tsl2561/sensor.py b/esphome/components/tsl2561/sensor.py index fb2c00697b7..cd4b88e7400 100644 --- a/esphome/components/tsl2561/sensor.py +++ b/esphome/components/tsl2561/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, CONF_INTEGRATION_TIME, diff --git a/esphome/components/tsl2591/sensor.py b/esphome/components/tsl2591/sensor.py index 5435ed4b62f..0df3fa66874 100644 --- a/esphome/components/tsl2591/sensor.py +++ b/esphome/components/tsl2591/sensor.py @@ -20,23 +20,23 @@ # place: https://hackaday.io/project/176690-the-water-watcher import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_GAIN, CONF_ACTUAL_GAIN, - CONF_ID, - CONF_NAME, - CONF_INTEGRATION_TIME, - CONF_FULL_SPECTRUM, - CONF_INFRARED, - CONF_POWER_SAVE_MODE, - CONF_VISIBLE, CONF_CALCULATED_LUX, CONF_DEVICE_FACTOR, + CONF_FULL_SPECTRUM, + CONF_GAIN, CONF_GLASS_ATTENUATION_FACTOR, - ICON_BRIGHTNESS_6, + CONF_ID, + CONF_INFRARED, + CONF_INTEGRATION_TIME, + CONF_NAME, + CONF_POWER_SAVE_MODE, + CONF_VISIBLE, DEVICE_CLASS_ILLUMINANCE, + ICON_BRIGHTNESS_6, STATE_CLASS_MEASUREMENT, UNIT_LUX, ) diff --git a/esphome/components/tt21100/binary_sensor/__init__.py b/esphome/components/tt21100/binary_sensor/__init__.py index d5423a01b2e..f79eff0e017 100644 --- a/esphome/components/tt21100/binary_sensor/__init__.py +++ b/esphome/components/tt21100/binary_sensor/__init__.py @@ -1,10 +1,10 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_INDEX from .. import tt21100_ns -from ..touchscreen import TT21100Touchscreen, TT21100ButtonListener +from ..touchscreen import TT21100ButtonListener, TT21100Touchscreen CONF_TT21100_ID = "tt21100_id" diff --git a/esphome/components/tt21100/touchscreen/__init__.py b/esphome/components/tt21100/touchscreen/__init__.py index 510ca2df3a1..9466dcdaa50 100644 --- a/esphome/components/tt21100/touchscreen/__init__.py +++ b/esphome/components/tt21100/touchscreen/__init__.py @@ -1,8 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv - from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, touchscreen +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_INTERRUPT_PIN, CONF_RESET_PIN from .. import tt21100_ns diff --git a/esphome/components/ttp229_bsf/__init__.py b/esphome/components/ttp229_bsf/__init__.py index 9c8208df836..fa1938723dd 100644 --- a/esphome/components/ttp229_bsf/__init__.py +++ b/esphome/components/ttp229_bsf/__init__.py @@ -1,7 +1,7 @@ +from esphome import pins import esphome.codegen as cg import esphome.config_validation as cv -from esphome import pins -from esphome.const import CONF_ID, CONF_SDO_PIN, CONF_SCL_PIN +from esphome.const import CONF_ID, CONF_SCL_PIN, CONF_SDO_PIN AUTO_LOAD = ["binary_sensor"] diff --git a/esphome/components/ttp229_bsf/binary_sensor.py b/esphome/components/ttp229_bsf/binary_sensor.py index 8a0c7fce488..178ad4f0378 100644 --- a/esphome/components/ttp229_bsf/binary_sensor.py +++ b/esphome/components/ttp229_bsf/binary_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL -from . import ttp229_bsf_ns, TTP229BSFComponent, CONF_TTP229_ID + +from . import CONF_TTP229_ID, TTP229BSFComponent, ttp229_bsf_ns DEPENDENCIES = ["ttp229_bsf"] TTP229BSFChannel = ttp229_bsf_ns.class_("TTP229BSFChannel", binary_sensor.BinarySensor) diff --git a/esphome/components/ttp229_lsf/__init__.py b/esphome/components/ttp229_lsf/__init__.py index cba41a79382..412233a6bd5 100644 --- a/esphome/components/ttp229_lsf/__init__.py +++ b/esphome/components/ttp229_lsf/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["i2c"] diff --git a/esphome/components/ttp229_lsf/binary_sensor.py b/esphome/components/ttp229_lsf/binary_sensor.py index 5fba0096de5..07f00df4b46 100644 --- a/esphome/components/ttp229_lsf/binary_sensor.py +++ b/esphome/components/ttp229_lsf/binary_sensor.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import CONF_CHANNEL -from . import ttp229_lsf_ns, TTP229LSFComponent, CONF_TTP229_ID + +from . import CONF_TTP229_ID, TTP229LSFComponent, ttp229_lsf_ns DEPENDENCIES = ["ttp229_lsf"] TTP229Channel = ttp229_lsf_ns.class_("TTP229Channel", binary_sensor.BinarySensor) diff --git a/esphome/components/tuya/__init__.py b/esphome/components/tuya/__init__.py index 0738f9b6a47..2cc60e225c8 100644 --- a/esphome/components/tuya/__init__.py +++ b/esphome/components/tuya/__init__.py @@ -1,10 +1,8 @@ -from esphome.components import time -from esphome import automation -from esphome import pins +from esphome import automation, pins import esphome.codegen as cg +from esphome.components import time, uart import esphome.config_validation as cv -from esphome.components import uart -from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT +from esphome.const import CONF_ID, CONF_SENSOR_DATAPOINT, CONF_TIME_ID, CONF_TRIGGER_ID DEPENDENCIES = ["uart"] diff --git a/esphome/components/tuya/binary_sensor/__init__.py b/esphome/components/tuya/binary_sensor/__init__.py index 856b5eb3232..767d1c636e5 100644 --- a/esphome/components/tuya/binary_sensor/__init__.py +++ b/esphome/components/tuya/binary_sensor/__init__.py @@ -1,9 +1,9 @@ +import esphome.codegen as cg from esphome.components import binary_sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_SENSOR_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/tuya/climate/__init__.py b/esphome/components/tuya/climate/__init__.py index 363e7c764b0..371c599ef73 100644 --- a/esphome/components/tuya/climate/__init__.py +++ b/esphome/components/tuya/climate/__init__.py @@ -1,18 +1,19 @@ from esphome import pins +import esphome.codegen as cg from esphome.components import climate import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( + CONF_FAN_MODE, CONF_ID, - CONF_SWITCH_DATAPOINT, + CONF_PRESET, CONF_SUPPORTS_COOL, CONF_SUPPORTS_HEAT, - CONF_PRESET, CONF_SWING_MODE, - CONF_FAN_MODE, + CONF_SWITCH_DATAPOINT, CONF_TEMPERATURE, ) -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/tuya/cover/__init__.py b/esphome/components/tuya/cover/__init__.py index 2dd66f814d7..61029b6daa3 100644 --- a/esphome/components/tuya/cover/__init__.py +++ b/esphome/components/tuya/cover/__init__.py @@ -1,13 +1,14 @@ +import esphome.codegen as cg from esphome.components import cover import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( - CONF_OUTPUT_ID, - CONF_MIN_VALUE, CONF_MAX_VALUE, + CONF_MIN_VALUE, + CONF_OUTPUT_ID, CONF_RESTORE_MODE, ) -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] diff --git a/esphome/components/tuya/fan/__init__.py b/esphome/components/tuya/fan/__init__.py index 4832fd86385..c732bdaf31a 100644 --- a/esphome/components/tuya/fan/__init__.py +++ b/esphome/components/tuya/fan/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import fan import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_OUTPUT_ID, CONF_SPEED_COUNT, CONF_SWITCH_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] diff --git a/esphome/components/tuya/light/__init__.py b/esphome/components/tuya/light/__init__.py index d8060600181..1d2286e3c73 100644 --- a/esphome/components/tuya/light/__init__.py +++ b/esphome/components/tuya/light/__init__.py @@ -1,18 +1,19 @@ +import esphome.codegen as cg from esphome.components import light import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( - CONF_OUTPUT_ID, - CONF_MIN_VALUE, - CONF_MAX_VALUE, - CONF_GAMMA_CORRECT, - CONF_DEFAULT_TRANSITION_LENGTH, - CONF_SWITCH_DATAPOINT, CONF_COLD_WHITE_COLOR_TEMPERATURE, - CONF_WARM_WHITE_COLOR_TEMPERATURE, CONF_COLOR_INTERLOCK, + CONF_DEFAULT_TRANSITION_LENGTH, + CONF_GAMMA_CORRECT, + CONF_MAX_VALUE, + CONF_MIN_VALUE, + CONF_OUTPUT_ID, + CONF_SWITCH_DATAPOINT, + CONF_WARM_WHITE_COLOR_TEMPERATURE, ) -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] diff --git a/esphome/components/tuya/number/__init__.py b/esphome/components/tuya/number/__init__.py index c00ea08d23b..bd57c8be145 100644 --- a/esphome/components/tuya/number/__init__.py +++ b/esphome/components/tuya/number/__init__.py @@ -1,17 +1,18 @@ +import esphome.codegen as cg from esphome.components import number import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import ( CONF_ID, - CONF_NUMBER_DATAPOINT, + CONF_INITIAL_VALUE, CONF_MAX_VALUE, CONF_MIN_VALUE, CONF_MULTIPLY, - CONF_STEP, - CONF_INITIAL_VALUE, + CONF_NUMBER_DATAPOINT, CONF_RESTORE_VALUE, + CONF_STEP, ) -from .. import tuya_ns, CONF_TUYA_ID, Tuya, TuyaDatapointType + +from .. import CONF_TUYA_ID, Tuya, TuyaDatapointType, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@frankiboy1"] diff --git a/esphome/components/tuya/select/__init__.py b/esphome/components/tuya/select/__init__.py index dc78b2c3db4..a34e2797469 100644 --- a/esphome/components/tuya/select/__init__.py +++ b/esphome/components/tuya/select/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import select import esphome.config_validation as cv -import esphome.codegen as cg -from esphome.const import CONF_OPTIONS, CONF_OPTIMISTIC, CONF_ENUM_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya +from esphome.const import CONF_ENUM_DATAPOINT, CONF_OPTIMISTIC, CONF_OPTIONS + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@bearpawmaxim"] diff --git a/esphome/components/tuya/sensor/__init__.py b/esphome/components/tuya/sensor/__init__.py index 69711204a82..861bbc656aa 100644 --- a/esphome/components/tuya/sensor/__init__.py +++ b/esphome/components/tuya/sensor/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_ID, CONF_SENSOR_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/tuya/switch/__init__.py b/esphome/components/tuya/switch/__init__.py index b4ec53ec591..e9987050cb0 100644 --- a/esphome/components/tuya/switch/__init__.py +++ b/esphome/components/tuya/switch/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import switch import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_SWITCH_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/tuya/text_sensor/__init__.py b/esphome/components/tuya/text_sensor/__init__.py index bc603693773..3bae109b93a 100644 --- a/esphome/components/tuya/text_sensor/__init__.py +++ b/esphome/components/tuya/text_sensor/__init__.py @@ -1,8 +1,9 @@ +import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -import esphome.codegen as cg from esphome.const import CONF_SENSOR_DATAPOINT -from .. import tuya_ns, CONF_TUYA_ID, Tuya + +from .. import CONF_TUYA_ID, Tuya, tuya_ns DEPENDENCIES = ["tuya"] CODEOWNERS = ["@dentra"] diff --git a/esphome/components/tx20/sensor.py b/esphome/components/tx20/sensor.py index f8a0b08d993..4f1582072e6 100644 --- a/esphome/components/tx20/sensor.py +++ b/esphome/components/tx20/sensor.py @@ -1,17 +1,17 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, - CONF_WIND_SPEED, CONF_PIN, CONF_WIND_DIRECTION_DEGREES, - STATE_CLASS_MEASUREMENT, - UNIT_KILOMETER_PER_HOUR, - ICON_WEATHER_WINDY, + CONF_WIND_SPEED, ICON_SIGN_DIRECTION, + ICON_WEATHER_WINDY, + STATE_CLASS_MEASUREMENT, UNIT_DEGREES, + UNIT_KILOMETER_PER_HOUR, ) tx20_ns = cg.esphome_ns.namespace("tx20") diff --git a/esphome/components/uart/__init__.py b/esphome/components/uart/__init__.py index 0738a127e1b..bee037774fb 100644 --- a/esphome/components/uart/__init__.py +++ b/esphome/components/uart/__init__.py @@ -1,36 +1,37 @@ -from typing import Optional import re +from typing import Optional + +from esphome import automation, pins import esphome.codegen as cg import esphome.config_validation as cv -import esphome.final_validate as fv -from esphome.yaml_util import make_data_base -from esphome import pins, automation from esphome.const import ( - CONF_BAUD_RATE, - CONF_ID, - CONF_NUMBER, - CONF_RX_PIN, - CONF_TX_PIN, - CONF_PORT, - CONF_UART_ID, - CONF_DATA, - CONF_RX_BUFFER_SIZE, - CONF_INVERTED, - CONF_INVERT, - CONF_TRIGGER_ID, - CONF_SEQUENCE, - CONF_TIMEOUT, - CONF_DEBUG, - CONF_DIRECTION, CONF_AFTER, + CONF_BAUD_RATE, CONF_BYTES, + CONF_DATA, + CONF_DEBUG, CONF_DELIMITER, + CONF_DIRECTION, CONF_DUMMY_RECEIVER, CONF_DUMMY_RECEIVER_ID, + CONF_ID, + CONF_INVERT, + CONF_INVERTED, CONF_LAMBDA, + CONF_NUMBER, + CONF_PORT, + CONF_RX_BUFFER_SIZE, + CONF_RX_PIN, + CONF_SEQUENCE, + CONF_TIMEOUT, + CONF_TRIGGER_ID, + CONF_TX_PIN, + CONF_UART_ID, PLATFORM_HOST, ) from esphome.core import CORE +import esphome.final_validate as fv +from esphome.yaml_util import make_data_base CODEOWNERS = ["@esphome/core"] uart_ns = cg.esphome_ns.namespace("uart") diff --git a/esphome/components/uart/button/__init__.py b/esphome/components/uart/button/__init__.py index 05909516a0b..5b811de07d5 100644 --- a/esphome/components/uart/button/__init__.py +++ b/esphome/components/uart/button/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import button, uart +import esphome.config_validation as cv from esphome.const import CONF_DATA from esphome.core import HexInt + from .. import uart_ns, validate_raw_data CODEOWNERS = ["@ssieb"] diff --git a/esphome/components/uart/switch/__init__.py b/esphome/components/uart/switch/__init__.py index 8853a61ae30..b25e0704613 100644 --- a/esphome/components/uart/switch/__init__.py +++ b/esphome/components/uart/switch/__init__.py @@ -1,8 +1,9 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import switch, uart +import esphome.config_validation as cv from esphome.const import CONF_DATA, CONF_SEND_EVERY from esphome.core import HexInt + from .. import uart_ns, validate_raw_data DEPENDENCIES = ["uart"] diff --git a/esphome/components/ufire_ise/sensor.py b/esphome/components/ufire_ise/sensor.py index 8f4359d6af2..e57a1155a44 100644 --- a/esphome/components/ufire_ise/sensor.py +++ b/esphome/components/ufire_ise/sensor.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg from esphome import automation -import esphome.config_validation as cv +import esphome.codegen as cg from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PH, diff --git a/esphome/components/uln2003/stepper.py b/esphome/components/uln2003/stepper.py index 88252ead730..b57d7ffb924 100644 --- a/esphome/components/uln2003/stepper.py +++ b/esphome/components/uln2003/stepper.py @@ -1,7 +1,7 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import stepper +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PIN_A, diff --git a/esphome/components/ultrasonic/sensor.py b/esphome/components/ultrasonic/sensor.py index afbd1128c2c..937d9a5261a 100644 --- a/esphome/components/ultrasonic/sensor.py +++ b/esphome/components/ultrasonic/sensor.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ECHO_PIN, - CONF_TRIGGER_PIN, CONF_TIMEOUT, + CONF_TRIGGER_PIN, + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, ) CONF_PULSE_TIME = "pulse_time" diff --git a/esphome/components/uponor_smatrix/__init__.py b/esphome/components/uponor_smatrix/__init__.py index 35c4c4cecd4..d4102d10261 100644 --- a/esphome/components/uponor_smatrix/__init__.py +++ b/esphome/components/uponor_smatrix/__init__.py @@ -1,11 +1,7 @@ import esphome.codegen as cg +from esphome.components import time, uart import esphome.config_validation as cv -from esphome.components import uart, time -from esphome.const import ( - CONF_ADDRESS, - CONF_ID, - CONF_TIME_ID, -) +from esphome.const import CONF_ADDRESS, CONF_ID, CONF_TIME_ID CODEOWNERS = ["@kroimon"] diff --git a/esphome/components/uponor_smatrix/climate/__init__.py b/esphome/components/uponor_smatrix/climate/__init__.py index 0becec2624c..5aeb521fb11 100644 --- a/esphome/components/uponor_smatrix/climate/__init__.py +++ b/esphome/components/uponor_smatrix/climate/__init__.py @@ -1,13 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate +import esphome.config_validation as cv from esphome.const import CONF_ID from .. import ( - uponor_smatrix_ns, - UponorSmatrixDevice, UPONOR_SMATRIX_DEVICE_SCHEMA, + UponorSmatrixDevice, register_uponor_smatrix_device, + uponor_smatrix_ns, ) DEPENDENCIES = ["uponor_smatrix"] diff --git a/esphome/components/vbus/__init__.py b/esphome/components/vbus/__init__.py index 99a473a3dc3..d916d7c0648 100644 --- a/esphome/components/vbus/__init__.py +++ b/esphome/components/vbus/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@ssieb"] diff --git a/esphome/components/vbus/binary_sensor/__init__.py b/esphome/components/vbus/binary_sensor/__init__.py index 70fbda2d1fd..ae927656c08 100644 --- a/esphome/components/vbus/binary_sensor/__init__.py +++ b/esphome/components/vbus/binary_sensor/__init__.py @@ -1,27 +1,28 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_BINARY_SENSORS, CONF_COMMAND, CONF_CUSTOM, CONF_DEST, + CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_SOURCE, DEVICE_CLASS_PROBLEM, ENTITY_CATEGORY_DIAGNOSTIC, ) + from .. import ( - vbus_ns, - VBus, - CONF_VBUS_ID, - CONF_DELTASOL_BS_PLUS, CONF_DELTASOL_BS_2009, + CONF_DELTASOL_BS_PLUS, CONF_DELTASOL_C, CONF_DELTASOL_CS2, CONF_DELTASOL_CS_PLUS, + CONF_VBUS_ID, + VBus, + vbus_ns, ) DeltaSol_BS_Plus = vbus_ns.class_("DeltaSolBSPlusBSensor", cg.Component) diff --git a/esphome/components/vbus/sensor/__init__.py b/esphome/components/vbus/sensor/__init__.py index 2b89da6d324..fcff698ac04 100644 --- a/esphome/components/vbus/sensor/__init__.py +++ b/esphome/components/vbus/sensor/__init__.py @@ -1,11 +1,11 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_COMMAND, CONF_CUSTOM, CONF_DEST, + CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_SENSORS, @@ -29,15 +29,16 @@ from esphome.const import ( UNIT_PERCENT, UNIT_WATT_HOURS, ) + from .. import ( - vbus_ns, - VBus, - CONF_VBUS_ID, - CONF_DELTASOL_BS_PLUS, CONF_DELTASOL_BS_2009, + CONF_DELTASOL_BS_PLUS, CONF_DELTASOL_C, CONF_DELTASOL_CS2, CONF_DELTASOL_CS_PLUS, + CONF_VBUS_ID, + VBus, + vbus_ns, ) DeltaSol_BS_Plus = vbus_ns.class_("DeltaSolBSPlusSensor", cg.Component) diff --git a/esphome/components/veml3235/sensor.py b/esphome/components/veml3235/sensor.py index 79ba510e41f..862fac302f8 100644 --- a/esphome/components/veml3235/sensor.py +++ b/esphome/components/veml3235/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_GAIN, CONF_INTEGRATION_TIME, diff --git a/esphome/components/veml7700/sensor.py b/esphome/components/veml7700/sensor.py index 308f1c1c002..6ad2eb417fa 100644 --- a/esphome/components/veml7700/sensor.py +++ b/esphome/components/veml7700/sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ACTUAL_GAIN, CONF_ACTUAL_INTEGRATION_TIME, diff --git a/esphome/components/version/text_sensor.py b/esphome/components/version/text_sensor.py index c8774bb322e..ba8c493d4ba 100644 --- a/esphome/components/version/text_sensor.py +++ b/esphome/components/version/text_sensor.py @@ -1,11 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor -from esphome.const import ( - ENTITY_CATEGORY_DIAGNOSTIC, - ICON_NEW_BOX, - CONF_HIDE_TIMESTAMP, -) +import esphome.config_validation as cv +from esphome.const import CONF_HIDE_TIMESTAMP, ENTITY_CATEGORY_DIAGNOSTIC, ICON_NEW_BOX version_ns = cg.esphome_ns.namespace("version") VersionTextSensor = version_ns.class_( diff --git a/esphome/components/vl53l0x/sensor.py b/esphome/components/vl53l0x/sensor.py index 7b485e3887e..8055d5ff776 100644 --- a/esphome/components/vl53l0x/sensor.py +++ b/esphome/components/vl53l0x/sensor.py @@ -1,15 +1,15 @@ +from esphome import pins import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_ADDRESS, + CONF_ENABLE_PIN, + CONF_TIMEOUT, + ICON_ARROW_EXPAND_VERTICAL, STATE_CLASS_MEASUREMENT, UNIT_METER, - ICON_ARROW_EXPAND_VERTICAL, - CONF_ADDRESS, - CONF_TIMEOUT, - CONF_ENABLE_PIN, ) -from esphome import pins DEPENDENCIES = ["i2c"] diff --git a/esphome/components/web_server_base/__init__.py b/esphome/components/web_server_base/__init__.py index 115f521d044..f50ee59b9cf 100644 --- a/esphome/components/web_server_base/__init__.py +++ b/esphome/components/web_server_base/__init__.py @@ -1,7 +1,7 @@ -import esphome.config_validation as cv import esphome.codegen as cg +import esphome.config_validation as cv from esphome.const import CONF_ID -from esphome.core import coroutine_with_priority, CORE +from esphome.core import CORE, coroutine_with_priority CODEOWNERS = ["@OttoWinter"] DEPENDENCIES = ["network"] diff --git a/esphome/components/web_server_idf/__init__.py b/esphome/components/web_server_idf/__init__.py index a84d9bb663b..73c51f8cb5e 100644 --- a/esphome/components/web_server_idf/__init__.py +++ b/esphome/components/web_server_idf/__init__.py @@ -1,5 +1,5 @@ -import esphome.config_validation as cv from esphome.components.esp32 import add_idf_sdkconfig_option +import esphome.config_validation as cv CODEOWNERS = ["@dentra"] diff --git a/esphome/components/weikai/__init__.py b/esphome/components/weikai/__init__.py index 4248c48e350..4c8f7e700d8 100644 --- a/esphome/components/weikai/__init__.py +++ b/esphome/components/weikai/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import uart +import esphome.config_validation as cv from esphome.const import ( CONF_BAUD_RATE, CONF_CHANNEL, diff --git a/esphome/components/whirlpool/climate.py b/esphome/components/whirlpool/climate.py index c5b953c46f3..40c60533494 100644 --- a/esphome/components/whirlpool/climate.py +++ b/esphome/components/whirlpool/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_MODEL AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/whynter/climate.py b/esphome/components/whynter/climate.py index 1d576344e62..ae21c64e9b8 100644 --- a/esphome/components/whynter/climate.py +++ b/esphome/components/whynter/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_USE_FAHRENHEIT AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/wireguard/binary_sensor.py b/esphome/components/wireguard/binary_sensor.py index 73445586590..02c4862e8d9 100644 --- a/esphome/components/wireguard/binary_sensor.py +++ b/esphome/components/wireguard/binary_sensor.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( CONF_STATUS, DEVICE_CLASS_CONNECTIVITY, diff --git a/esphome/components/wireguard/sensor.py b/esphome/components/wireguard/sensor.py index 85703d24b36..4c9d601eee2 100644 --- a/esphome/components/wireguard/sensor.py +++ b/esphome/components/wireguard/sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor -from esphome.const import ( - DEVICE_CLASS_TIMESTAMP, - ENTITY_CATEGORY_DIAGNOSTIC, -) +import esphome.config_validation as cv +from esphome.const import DEVICE_CLASS_TIMESTAMP, ENTITY_CATEGORY_DIAGNOSTIC from . import CONF_WIREGUARD_ID, Wireguard diff --git a/esphome/components/wireguard/text_sensor.py b/esphome/components/wireguard/text_sensor.py index 51614a1a288..e48678f5bf4 100644 --- a/esphome/components/wireguard/text_sensor.py +++ b/esphome/components/wireguard/text_sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor -from esphome.const import ( - CONF_ADDRESS, - ENTITY_CATEGORY_DIAGNOSTIC, -) +import esphome.config_validation as cv +from esphome.const import CONF_ADDRESS, ENTITY_CATEGORY_DIAGNOSTIC from . import CONF_WIREGUARD_ID, Wireguard diff --git a/esphome/components/wk2132_i2c/__init__.py b/esphome/components/wk2132_i2c/__init__.py index 912ab04236f..903fe8fe4fb 100644 --- a/esphome/components/wk2132_i2c/__init__.py +++ b/esphome/components/wk2132_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, weikai +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@DrCoolZic"] diff --git a/esphome/components/wk2132_spi/__init__.py b/esphome/components/wk2132_spi/__init__.py index 02c5fd96048..debc84f6d84 100644 --- a/esphome/components/wk2132_spi/__init__.py +++ b/esphome/components/wk2132_spi/__init__.py @@ -1,7 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi, weikai - +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@DrCoolZic"] diff --git a/esphome/components/wk2168_i2c/__init__.py b/esphome/components/wk2168_i2c/__init__.py index 93a8161e8e6..32fd4882dbd 100644 --- a/esphome/components/wk2168_i2c/__init__.py +++ b/esphome/components/wk2168_i2c/__init__.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, weikai -from esphome.const import ( - CONF_ID, - CONF_INVERTED, - CONF_MODE, - CONF_NUMBER, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INVERTED, CONF_MODE, CONF_NUMBER CODEOWNERS = ["@DrCoolZic"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/wk2168_spi/__init__.py b/esphome/components/wk2168_spi/__init__.py index 8861a6738c9..123ce0bb8b6 100644 --- a/esphome/components/wk2168_spi/__init__.py +++ b/esphome/components/wk2168_spi/__init__.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import spi, weikai -from esphome.const import ( - CONF_ID, - CONF_INVERTED, - CONF_MODE, - CONF_NUMBER, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INVERTED, CONF_MODE, CONF_NUMBER CODEOWNERS = ["@DrCoolZic"] DEPENDENCIES = ["spi"] diff --git a/esphome/components/wk2204_i2c/__init__.py b/esphome/components/wk2204_i2c/__init__.py index 98eca56c4d1..a52aa30cc96 100644 --- a/esphome/components/wk2204_i2c/__init__.py +++ b/esphome/components/wk2204_i2c/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, weikai +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@DrCoolZic"] diff --git a/esphome/components/wk2204_spi/__init__.py b/esphome/components/wk2204_spi/__init__.py index 447805375dc..616ba75c597 100644 --- a/esphome/components/wk2204_spi/__init__.py +++ b/esphome/components/wk2204_spi/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import spi, weikai +import esphome.config_validation as cv from esphome.const import CONF_ID CODEOWNERS = ["@DrCoolZic"] diff --git a/esphome/components/wk2212_i2c/__init__.py b/esphome/components/wk2212_i2c/__init__.py index fd4d717b31c..0ef32cbc960 100644 --- a/esphome/components/wk2212_i2c/__init__.py +++ b/esphome/components/wk2212_i2c/__init__.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import i2c, weikai -from esphome.const import ( - CONF_ID, - CONF_INVERTED, - CONF_MODE, - CONF_NUMBER, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INVERTED, CONF_MODE, CONF_NUMBER CODEOWNERS = ["@DrCoolZic"] DEPENDENCIES = ["i2c"] diff --git a/esphome/components/wk2212_spi/__init__.py b/esphome/components/wk2212_spi/__init__.py index bfeca87c222..8c9bea5416f 100644 --- a/esphome/components/wk2212_spi/__init__.py +++ b/esphome/components/wk2212_spi/__init__.py @@ -1,13 +1,8 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import spi, weikai -from esphome.const import ( - CONF_ID, - CONF_INVERTED, - CONF_MODE, - CONF_NUMBER, -) +import esphome.config_validation as cv +from esphome.const import CONF_ID, CONF_INVERTED, CONF_MODE, CONF_NUMBER CODEOWNERS = ["@DrCoolZic"] DEPENDENCIES = ["spi"] diff --git a/esphome/components/wl_134/text_sensor.py b/esphome/components/wl_134/text_sensor.py index 1373df77f44..d10627ab641 100644 --- a/esphome/components/wl_134/text_sensor.py +++ b/esphome/components/wl_134/text_sensor.py @@ -1,9 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import text_sensor, uart -from esphome.const import ( - ICON_FINGERPRINT, -) +import esphome.config_validation as cv +from esphome.const import ICON_FINGERPRINT CODEOWNERS = ["@hobbypunk90"] DEPENDENCIES = ["uart"] diff --git a/esphome/components/wled/__init__.py b/esphome/components/wled/__init__.py index 396d5891d82..fb20a030101 100644 --- a/esphome/components/wled/__init__.py +++ b/esphome/components/wled/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components.light.types import AddressableLightEffect from esphome.components.light.effects import register_addressable_effect +from esphome.components.light.types import AddressableLightEffect +import esphome.config_validation as cv from esphome.const import CONF_NAME, CONF_PORT wled_ns = cg.esphome_ns.namespace("wled") diff --git a/esphome/components/x9c/output.py b/esphome/components/x9c/output.py index 44979949827..0cc850b8565 100644 --- a/esphome/components/x9c/output.py +++ b/esphome/components/x9c/output.py @@ -1,14 +1,14 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import output +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_CS_PIN, + CONF_ID, CONF_INC_PIN, - CONF_UD_PIN, CONF_INITIAL_VALUE, CONF_STEP_DELAY, + CONF_UD_PIN, ) CODEOWNERS = ["@EtienneMD"] diff --git a/esphome/components/xgzp68xx/sensor.py b/esphome/components/xgzp68xx/sensor.py index 3e381aaa61a..74cef3bf7bd 100644 --- a/esphome/components/xgzp68xx/sensor.py +++ b/esphome/components/xgzp68xx/sensor.py @@ -1,15 +1,15 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( - DEVICE_CLASS_PRESSURE, CONF_ID, + CONF_PRESSURE, + CONF_TEMPERATURE, + DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, - UNIT_PASCAL, UNIT_CELSIUS, - CONF_TEMPERATURE, - CONF_PRESSURE, + UNIT_PASCAL, ) DEPENDENCIES = ["i2c"] diff --git a/esphome/components/xiaomi_ble/__init__.py b/esphome/components/xiaomi_ble/__init__.py index 046adc6248e..541a0e7894d 100644 --- a/esphome/components/xiaomi_ble/__init__.py +++ b/esphome/components/xiaomi_ble/__init__.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker +import esphome.config_validation as cv from esphome.const import CONF_ID DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_cgd1/sensor.py b/esphome/components/xiaomi_cgd1/sensor.py index 5b88121d7c7..e11ddac19d7 100644 --- a/esphome/components/xiaomi_cgd1/sensor.py +++ b/esphome/components/xiaomi_cgd1/sensor.py @@ -1,12 +1,13 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, - CONF_ID, DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, @@ -14,7 +15,6 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - CONF_BINDKEY, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_cgdk2/sensor.py b/esphome/components/xiaomi_cgdk2/sensor.py index ac487d87fc6..c7ec13f6e03 100644 --- a/esphome/components/xiaomi_cgdk2/sensor.py +++ b/esphome/components/xiaomi_cgdk2/sensor.py @@ -1,9 +1,11 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, DEVICE_CLASS_BATTERY, @@ -13,8 +15,6 @@ from esphome.const import ( STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - CONF_ID, - CONF_BINDKEY, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_cgg1/sensor.py b/esphome/components/xiaomi_cgg1/sensor.py index a4f9a39aff2..1a6ed2b7daa 100644 --- a/esphome/components/xiaomi_cgg1/sensor.py +++ b/esphome/components/xiaomi_cgg1/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, - CONF_ID, DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, diff --git a/esphome/components/xiaomi_cgpr1/binary_sensor.py b/esphome/components/xiaomi_cgpr1/binary_sensor.py index 1b878ca8008..2f71a11b28f 100644 --- a/esphome/components/xiaomi_cgpr1/binary_sensor.py +++ b/esphome/components/xiaomi_cgpr1/binary_sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg +from esphome.components import binary_sensor, esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, binary_sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_BINDKEY, + CONF_IDLE_TIME, + CONF_ILLUMINANCE, CONF_MAC_ADDRESS, DEVICE_CLASS_BATTERY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_MOTION, ENTITY_CATEGORY_DIAGNOSTIC, - UNIT_PERCENT, - CONF_IDLE_TIME, - CONF_ILLUMINANCE, - UNIT_MINUTE, - UNIT_LUX, ICON_TIMELAPSE, + UNIT_LUX, + UNIT_MINUTE, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_gcls002/sensor.py b/esphome/components/xiaomi_gcls002/sensor.py index 4154b64233b..6c9ad2e3611 100644 --- a/esphome/components/xiaomi_gcls002/sensor.py +++ b/esphome/components/xiaomi_gcls002/sensor.py @@ -1,22 +1,22 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( + CONF_CONDUCTIVITY, + CONF_ID, + CONF_ILLUMINANCE, CONF_MAC_ADDRESS, + CONF_MOISTURE, CONF_TEMPERATURE, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, + ICON_FLOWER, ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - UNIT_PERCENT, - CONF_ID, - CONF_MOISTURE, - CONF_ILLUMINANCE, UNIT_LUX, - CONF_CONDUCTIVITY, UNIT_MICROSIEMENS_PER_CENTIMETER, - ICON_FLOWER, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_hhccjcy01/sensor.py b/esphome/components/xiaomi_hhccjcy01/sensor.py index 535316e2468..90a87534124 100644 --- a/esphome/components/xiaomi_hhccjcy01/sensor.py +++ b/esphome/components/xiaomi_hhccjcy01/sensor.py @@ -1,25 +1,25 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( + CONF_BATTERY_LEVEL, + CONF_CONDUCTIVITY, + CONF_ID, + CONF_ILLUMINANCE, CONF_MAC_ADDRESS, + CONF_MOISTURE, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_FLOWER, ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - UNIT_PERCENT, - CONF_ID, - CONF_MOISTURE, - CONF_ILLUMINANCE, UNIT_LUX, - CONF_CONDUCTIVITY, UNIT_MICROSIEMENS_PER_CENTIMETER, - ICON_FLOWER, - DEVICE_CLASS_BATTERY, - CONF_BATTERY_LEVEL, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_hhccjcy10/sensor.py b/esphome/components/xiaomi_hhccjcy10/sensor.py index 4f77fa8103c..d6a4a4adb2d 100644 --- a/esphome/components/xiaomi_hhccjcy10/sensor.py +++ b/esphome/components/xiaomi_hhccjcy10/sensor.py @@ -1,25 +1,25 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( + CONF_BATTERY_LEVEL, + CONF_CONDUCTIVITY, + CONF_ID, + CONF_ILLUMINANCE, CONF_MAC_ADDRESS, + CONF_MOISTURE, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_FLOWER, ICON_WATER_PERCENT, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - UNIT_PERCENT, - CONF_ID, - CONF_MOISTURE, - CONF_ILLUMINANCE, UNIT_LUX, - CONF_CONDUCTIVITY, UNIT_MICROSIEMENS_PER_CENTIMETER, - ICON_FLOWER, - DEVICE_CLASS_BATTERY, - CONF_BATTERY_LEVEL, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_hhccpot002/sensor.py b/esphome/components/xiaomi_hhccpot002/sensor.py index 82ee12d8d1d..adc64f66505 100644 --- a/esphome/components/xiaomi_hhccpot002/sensor.py +++ b/esphome/components/xiaomi_hhccpot002/sensor.py @@ -1,16 +1,16 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( - CONF_MAC_ADDRESS, - STATE_CLASS_MEASUREMENT, - UNIT_PERCENT, - ICON_WATER_PERCENT, - CONF_ID, - CONF_MOISTURE, CONF_CONDUCTIVITY, - UNIT_MICROSIEMENS_PER_CENTIMETER, + CONF_ID, + CONF_MAC_ADDRESS, + CONF_MOISTURE, ICON_FLOWER, + ICON_WATER_PERCENT, + STATE_CLASS_MEASUREMENT, + UNIT_MICROSIEMENS_PER_CENTIMETER, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_jqjcy01ym/sensor.py b/esphome/components/xiaomi_jqjcy01ym/sensor.py index f4d2b342fdc..5890ed6b636 100644 --- a/esphome/components/xiaomi_jqjcy01ym/sensor.py +++ b/esphome/components/xiaomi_jqjcy01ym/sensor.py @@ -1,22 +1,22 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_FORMALDEHYDE, + CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, - CONF_ID, DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_FLASK_OUTLINE, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, - UNIT_PERCENT, - CONF_HUMIDITY, UNIT_MILLIGRAMS_PER_CUBIC_METER, - ICON_FLASK_OUTLINE, - CONF_FORMALDEHYDE, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_lywsd02/sensor.py b/esphome/components/xiaomi_lywsd02/sensor.py index 20629a0a9c4..ef6aebe6c03 100644 --- a/esphome/components/xiaomi_lywsd02/sensor.py +++ b/esphome/components/xiaomi_lywsd02/sensor.py @@ -1,19 +1,19 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_BATTERY, - CONF_ID, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_lywsd02mmc/sensor.py b/esphome/components/xiaomi_lywsd02mmc/sensor.py index 43784ef698d..813429a6c50 100644 --- a/esphome/components/xiaomi_lywsd02mmc/sensor.py +++ b/esphome/components/xiaomi_lywsd02mmc/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_BATTERY, - CONF_ID, - CONF_BINDKEY, ) AUTO_LOAD = ["xiaomi_ble"] diff --git a/esphome/components/xiaomi_lywsd03mmc/sensor.py b/esphome/components/xiaomi_lywsd03mmc/sensor.py index b2784e58fca..bf2de3756c3 100644 --- a/esphome/components/xiaomi_lywsd03mmc/sensor.py +++ b/esphome/components/xiaomi_lywsd03mmc/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, - CONF_ID, - CONF_BINDKEY, - DEVICE_CLASS_BATTERY, ) CODEOWNERS = ["@ahpohl"] diff --git a/esphome/components/xiaomi_lywsdcgq/sensor.py b/esphome/components/xiaomi_lywsdcgq/sensor.py index 80f24ac0efe..5d964ea22ad 100644 --- a/esphome/components/xiaomi_lywsdcgq/sensor.py +++ b/esphome/components/xiaomi_lywsdcgq/sensor.py @@ -1,19 +1,19 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_BATTERY, - CONF_ID, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_mhoc303/sensor.py b/esphome/components/xiaomi_mhoc303/sensor.py index 18f5ad77648..86c4d6699fb 100644 --- a/esphome/components/xiaomi_mhoc303/sensor.py +++ b/esphome/components/xiaomi_mhoc303/sensor.py @@ -1,19 +1,19 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_BATTERY, - CONF_ID, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_mhoc401/sensor.py b/esphome/components/xiaomi_mhoc401/sensor.py index 9e92e342307..7161e88da5c 100644 --- a/esphome/components/xiaomi_mhoc401/sensor.py +++ b/esphome/components/xiaomi_mhoc401/sensor.py @@ -1,20 +1,20 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_BINDKEY, CONF_HUMIDITY, + CONF_ID, CONF_MAC_ADDRESS, CONF_TEMPERATURE, + DEVICE_CLASS_BATTERY, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_CELSIUS, UNIT_PERCENT, - DEVICE_CLASS_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, - CONF_ID, - CONF_BINDKEY, - DEVICE_CLASS_BATTERY, ) CODEOWNERS = ["@vevsvevs"] diff --git a/esphome/components/xiaomi_miscale/sensor.py b/esphome/components/xiaomi_miscale/sensor.py index a2a2f3bdfca..4aa8d029f8d 100644 --- a/esphome/components/xiaomi_miscale/sensor.py +++ b/esphome/components/xiaomi_miscale/sensor.py @@ -1,17 +1,17 @@ import esphome.codegen as cg +from esphome.components import esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, esp32_ble_tracker from esphome.const import ( - CONF_MAC_ADDRESS, + CONF_CLEAR_IMPEDANCE, CONF_ID, + CONF_IMPEDANCE, + CONF_MAC_ADDRESS, CONF_WEIGHT, + ICON_OMEGA, + ICON_SCALE_BATHROOM, STATE_CLASS_MEASUREMENT, UNIT_KILOGRAM, - ICON_SCALE_BATHROOM, UNIT_OHM, - CONF_IMPEDANCE, - ICON_OMEGA, - CONF_CLEAR_IMPEDANCE, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_mjyd02yla/binary_sensor.py b/esphome/components/xiaomi_mjyd02yla/binary_sensor.py index 9a4b50df916..312f8b43b19 100644 --- a/esphome/components/xiaomi_mjyd02yla/binary_sensor.py +++ b/esphome/components/xiaomi_mjyd02yla/binary_sensor.py @@ -1,23 +1,23 @@ import esphome.codegen as cg +from esphome.components import binary_sensor, esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, binary_sensor, esp32_ble_tracker from esphome.const import ( - CONF_MAC_ADDRESS, - CONF_BINDKEY, - CONF_LIGHT, CONF_BATTERY_LEVEL, + CONF_BINDKEY, + CONF_IDLE_TIME, + CONF_ILLUMINANCE, + CONF_LIGHT, + CONF_MAC_ADDRESS, DEVICE_CLASS_BATTERY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_LIGHT, DEVICE_CLASS_MOTION, ENTITY_CATEGORY_DIAGNOSTIC, - STATE_CLASS_MEASUREMENT, - UNIT_PERCENT, - CONF_IDLE_TIME, - CONF_ILLUMINANCE, - UNIT_MINUTE, - UNIT_LUX, ICON_TIMELAPSE, + STATE_CLASS_MEASUREMENT, + UNIT_LUX, + UNIT_MINUTE, + UNIT_PERCENT, ) DEPENDENCIES = ["esp32_ble_tracker"] diff --git a/esphome/components/xiaomi_mue4094rt/binary_sensor.py b/esphome/components/xiaomi_mue4094rt/binary_sensor.py index 94d85213ffa..911d179d8b0 100644 --- a/esphome/components/xiaomi_mue4094rt/binary_sensor.py +++ b/esphome/components/xiaomi_mue4094rt/binary_sensor.py @@ -1,12 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor, esp32_ble_tracker -from esphome.const import ( - CONF_MAC_ADDRESS, - CONF_TIMEOUT, - DEVICE_CLASS_MOTION, -) - +import esphome.config_validation as cv +from esphome.const import CONF_MAC_ADDRESS, CONF_TIMEOUT, DEVICE_CLASS_MOTION DEPENDENCIES = ["esp32_ble_tracker"] AUTO_LOAD = ["xiaomi_ble"] diff --git a/esphome/components/xiaomi_rtcgq02lm/__init__.py b/esphome/components/xiaomi_rtcgq02lm/__init__.py index 0c8331db09c..df143bac225 100644 --- a/esphome/components/xiaomi_rtcgq02lm/__init__.py +++ b/esphome/components/xiaomi_rtcgq02lm/__init__.py @@ -1,8 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import esp32_ble_tracker -from esphome.const import CONF_MAC_ADDRESS, CONF_ID, CONF_BINDKEY - +import esphome.config_validation as cv +from esphome.const import CONF_BINDKEY, CONF_ID, CONF_MAC_ADDRESS AUTO_LOAD = ["xiaomi_ble"] CODEOWNERS = ["@jesserockz"] diff --git a/esphome/components/xiaomi_rtcgq02lm/binary_sensor.py b/esphome/components/xiaomi_rtcgq02lm/binary_sensor.py index ef8a472d663..8d0508b59b3 100644 --- a/esphome/components/xiaomi_rtcgq02lm/binary_sensor.py +++ b/esphome/components/xiaomi_rtcgq02lm/binary_sensor.py @@ -1,14 +1,14 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import binary_sensor +import esphome.config_validation as cv from esphome.const import ( + CONF_BUTTON, + CONF_ID, CONF_LIGHT, CONF_MOTION, CONF_TIMEOUT, DEVICE_CLASS_LIGHT, DEVICE_CLASS_MOTION, - CONF_ID, - CONF_BUTTON, ) from esphome.core import TimePeriod diff --git a/esphome/components/xiaomi_rtcgq02lm/sensor.py b/esphome/components/xiaomi_rtcgq02lm/sensor.py index 558e3623e5c..e49f1c960b0 100644 --- a/esphome/components/xiaomi_rtcgq02lm/sensor.py +++ b/esphome/components/xiaomi_rtcgq02lm/sensor.py @@ -1,13 +1,13 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( CONF_BATTERY_LEVEL, + CONF_ID, + DEVICE_CLASS_BATTERY, ENTITY_CATEGORY_DIAGNOSTIC, STATE_CLASS_MEASUREMENT, UNIT_PERCENT, - CONF_ID, - DEVICE_CLASS_BATTERY, ) from . import XiaomiRTCGQ02LM diff --git a/esphome/components/xiaomi_wx08zm/binary_sensor.py b/esphome/components/xiaomi_wx08zm/binary_sensor.py index 504dff9d664..69facf54edf 100644 --- a/esphome/components/xiaomi_wx08zm/binary_sensor.py +++ b/esphome/components/xiaomi_wx08zm/binary_sensor.py @@ -1,18 +1,17 @@ import esphome.codegen as cg +from esphome.components import binary_sensor, esp32_ble_tracker, sensor import esphome.config_validation as cv -from esphome.components import sensor, binary_sensor, esp32_ble_tracker from esphome.const import ( CONF_BATTERY_LEVEL, CONF_MAC_ADDRESS, CONF_TABLET, DEVICE_CLASS_BATTERY, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_BUG, STATE_CLASS_MEASUREMENT, UNIT_PERCENT, - ICON_BUG, ) - DEPENDENCIES = ["esp32_ble_tracker"] AUTO_LOAD = ["xiaomi_ble", "sensor"] diff --git a/esphome/components/xl9535/__init__.py b/esphome/components/xl9535/__init__.py index e6f8b28b46f..58ce4a30f8b 100644 --- a/esphome/components/xl9535/__init__.py +++ b/esphome/components/xl9535/__init__.py @@ -1,6 +1,7 @@ +from esphome import pins import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_INPUT, @@ -9,7 +10,6 @@ from esphome.const import ( CONF_NUMBER, CONF_OUTPUT, ) -from esphome import pins CONF_XL9535 = "xl9535" diff --git a/esphome/components/yashima/climate.py b/esphome/components/yashima/climate.py index 8cafd468ac2..eb68d3b6e7f 100644 --- a/esphome/components/yashima/climate.py +++ b/esphome/components/yashima/climate.py @@ -1,7 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate, remote_transmitter, sensor from esphome.components.remote_base import CONF_TRANSMITTER_ID +import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_SENSOR, CONF_SUPPORTS_COOL, CONF_SUPPORTS_HEAT AUTO_LOAD = ["sensor"] diff --git a/esphome/components/zhlt01/climate.py b/esphome/components/zhlt01/climate.py index 1451f8ec697..fc01107e1d6 100644 --- a/esphome/components/zhlt01/climate.py +++ b/esphome/components/zhlt01/climate.py @@ -1,6 +1,6 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import climate_ir +import esphome.config_validation as cv from esphome.const import CONF_ID AUTO_LOAD = ["climate_ir"] diff --git a/esphome/components/zio_ultrasonic/sensor.py b/esphome/components/zio_ultrasonic/sensor.py index c5eed14e649..533bc5cc574 100644 --- a/esphome/components/zio_ultrasonic/sensor.py +++ b/esphome/components/zio_ultrasonic/sensor.py @@ -1,10 +1,7 @@ import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor -from esphome.const import ( - DEVICE_CLASS_DISTANCE, - STATE_CLASS_MEASUREMENT, -) +import esphome.config_validation as cv +from esphome.const import DEVICE_CLASS_DISTANCE, STATE_CLASS_MEASUREMENT DEPENDENCIES = ["i2c"] CODEOWNERS = ["@kahrendt"] diff --git a/esphome/components/zyaura/sensor.py b/esphome/components/zyaura/sensor.py index 28a708b8668..58de5192839 100644 --- a/esphome/components/zyaura/sensor.py +++ b/esphome/components/zyaura/sensor.py @@ -1,22 +1,22 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins +import esphome.codegen as cg from esphome.components import sensor +import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_CLOCK_PIN, - CONF_DATA_PIN, CONF_CO2, - CONF_TEMPERATURE, + CONF_DATA_PIN, CONF_HUMIDITY, + CONF_ID, + CONF_TEMPERATURE, DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, - UNIT_CELSIUS, - UNIT_PERCENT, ICON_MOLECULE_CO2, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_PARTS_PER_MILLION, + UNIT_PERCENT, ) from esphome.cpp_helpers import gpio_pin_expression diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 858c6e197c2..e6927fd20ce 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -1499,30 +1499,9 @@ def dimensions(value): def directory(value): - import json - value = string(value) path = CORE.relative_config_path(value) - if CORE.vscode and ( - not CORE.ace or os.path.abspath(path) == os.path.abspath(CORE.config_path) - ): - print( - json.dumps( - { - "type": "check_directory_exists", - "path": path, - } - ) - ) - data = json.loads(input()) - assert data["type"] == "directory_exists_response" - if data["content"]: - return value - raise Invalid( - f"Could not find directory '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})." - ) - if not os.path.exists(path): raise Invalid( f"Could not find directory '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})." @@ -1535,30 +1514,9 @@ def directory(value): def file_(value): - import json - value = string(value) path = CORE.relative_config_path(value) - if CORE.vscode and ( - not CORE.ace or os.path.abspath(path) == os.path.abspath(CORE.config_path) - ): - print( - json.dumps( - { - "type": "check_file_exists", - "path": path, - } - ) - ) - data = json.loads(input()) - assert data["type"] == "file_exists_response" - if data["content"]: - return value - raise Invalid( - f"Could not find file '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})." - ) - if not os.path.exists(path): raise Invalid( f"Could not find file '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})." diff --git a/esphome/const.py b/esphome/const.py index dab9327a3a1..6fe79eb2c9c 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2025.3.3" +__version__ = "2025.4.0" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" VALID_SUBSTITUTIONS_CHARACTERS = ( @@ -196,8 +196,10 @@ CONF_DC_PIN = "dc_pin" CONF_DEASSERT_RTS_DTR = "deassert_rts_dtr" CONF_DEBOUNCE = "debounce" CONF_DEBUG = "debug" +CONF_DEBUG_SCHEDULER = "debug_scheduler" CONF_DECAY_MODE = "decay_mode" CONF_DECELERATION = "deceleration" +CONF_DEFAULT = "default" CONF_DEFAULT_MODE = "default_mode" CONF_DEFAULT_TARGET_TEMPERATURE_HIGH = "default_target_temperature_high" CONF_DEFAULT_TARGET_TEMPERATURE_LOW = "default_target_temperature_low" diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index 2a7b8b9d918..1a81a6d6cd3 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -475,7 +475,6 @@ class EsphomeCore: self.dashboard = False # True if command is run from vscode api self.vscode = False - self.ace = False # The name of the node self.name: Optional[str] = None # The friendly name of the node diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index a6224a17c00..b20964b8723 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -79,7 +79,7 @@ void Component::call_setup() { this->setup(); } void Component::call_dump_config() { this->dump_config(); if (this->is_failed()) { - ESP_LOGE(TAG, " Component %s is marked FAILED", this->get_component_source()); + ESP_LOGE(TAG, " Component %s is marked FAILED: %s", this->get_component_source(), this->error_message_.c_str()); } } @@ -162,6 +162,8 @@ void Component::status_set_error(const char *message) { this->component_state_ |= STATUS_LED_ERROR; App.app_state_ |= STATUS_LED_ERROR; ESP_LOGE(TAG, "Component %s set Error flag: %s", this->get_component_source(), message); + if (strcmp(message, "unspecified") != 0) + this->error_message_ = message; } void Component::status_clear_warning() { if ((this->component_state_ & STATUS_LED_WARNING) == 0) diff --git a/esphome/core/component.h b/esphome/core/component.h index a6bd8f81ac1..f5c56459b14 100644 --- a/esphome/core/component.h +++ b/esphome/core/component.h @@ -118,6 +118,11 @@ class Component { */ virtual void mark_failed(); + void mark_failed(const char *message) { + this->status_set_error(message); + this->mark_failed(); + } + bool is_failed() const; bool is_ready() const; @@ -165,10 +170,17 @@ class Component { * This will call f every interval ms. Can be cancelled via CancelInterval(). * Similar to javascript's setInterval(). * - * IMPORTANT: Do not rely on this having correct timing. This is only called from - * loop() and therefore can be significantly delay. If you need exact timing please + * IMPORTANT NOTE: + * The only guarantee offered by this call is that the callback will be called no *earlier* than + * the specified interval after the previous call. Any given interval may be longer due to + * other components blocking the loop() call. + * + * So do not rely on this having correct timing. If you need exact timing please * use hardware timers. * + * Note also that the first call to f will not happen immediately, but after a random delay. This is + * intended to prevent many interval functions from being called at the same time. + * * @param name The identifier for this interval function. * @param interval The interval in ms. * @param f The function (or lambda) that should be called @@ -272,6 +284,7 @@ class Component { uint32_t component_state_{0x0000}; ///< State of this component. float setup_priority_override_{NAN}; const char *component_source_{nullptr}; + std::string error_message_{}; }; /** This class simplifies creating components that periodically check a state. diff --git a/esphome/core/config.py b/esphome/core/config.py index f2b85851431..72e9f6a65c1 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_BUILD_PATH, CONF_COMMENT, CONF_COMPILE_PROCESS_LIMIT, + CONF_DEBUG_SCHEDULER, CONF_ESPHOME, CONF_FRIENDLY_NAME, CONF_INCLUDES, @@ -144,6 +145,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include), cv.Optional(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict), cv.Optional(CONF_NAME_ADD_MAC_SUFFIX, default=False): cv.boolean, + cv.Optional(CONF_DEBUG_SCHEDULER, default=False): cv.boolean, cv.Optional(CONF_PROJECT): cv.Schema( { cv.Required(CONF_NAME): cv.All( @@ -369,6 +371,8 @@ async def to_code(config): cg.add_build_flag("-Wno-unused-variable") cg.add_build_flag("-Wno-unused-but-set-variable") cg.add_build_flag("-Wno-sign-compare") + if config[CONF_DEBUG_SCHEDULER]: + cg.add_define("ESPHOME_DEBUG_SCHEDULER") if CORE.using_arduino and not CORE.is_bk72xx: CORE.add_job(add_arduino_global_workaround) diff --git a/esphome/core/defines.h b/esphome/core/defines.h index 7bc84a22dc7..64de41f23a9 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -13,6 +13,7 @@ #define ESPHOME_PROJECT_VERSION "v2" #define ESPHOME_PROJECT_VERSION_30 "v2" #define ESPHOME_VARIANT "ESP32" +#define ESPHOME_DEBUG_SCHEDULER // logger #define ESPHOME_LOG_LEVEL ESPHOME_LOG_LEVEL_VERY_VERBOSE @@ -47,16 +48,36 @@ #define USE_LOGGER #define USE_LVGL #define USE_LVGL_ANIMIMG +#define USE_LVGL_ARC #define USE_LVGL_BINARY_SENSOR +#define USE_LVGL_BUTTON #define USE_LVGL_BUTTONMATRIX +#define USE_LVGL_CANVAS +#define USE_LVGL_CHART +#define USE_LVGL_CHECKBOX #define USE_LVGL_DROPDOWN #define USE_LVGL_FONT #define USE_LVGL_IMAGE +#define USE_LVGL_IMAGEBUTTON #define USE_LVGL_KEY_LISTENER #define USE_LVGL_KEYBOARD +#define USE_LVGL_LABEL +#define USE_LVGL_LINE +#define USE_LVGL_LIST +#define USE_LVGL_MENU #define USE_LVGL_METER +#define USE_LVGL_MSGBOX #define USE_LVGL_ROLLER #define USE_LVGL_ROTARY_ENCODER +#define USE_LVGL_SLIDER +#define USE_LVGL_SPAN +#define USE_LVGL_SPINBOX +#define USE_LVGL_SPINNER +#define USE_LVGL_SWITCH +#define USE_LVGL_TABLE +#define USE_LVGL_TABVIEW +#define USE_LVGL_TEXTAREA +#define USE_LVGL_TILEVIEW #define USE_LVGL_TOUCHSCREEN #define USE_MD5 #define USE_MDNS diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 439bb2ccb06..36bc7f949b7 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -44,10 +44,7 @@ #include #endif #ifdef USE_ESP32 -#include "esp32/rom/crc.h" -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 2) -#include "esp_mac.h" -#endif +#include "rom/crc.h" #include "esp_efuse.h" #include "esp_efuse_table.h" #endif @@ -70,7 +67,9 @@ static const uint16_t CRC16_8408_LE_LUT_L[] = {0x0000, 0x1189, 0x2312, 0x329b, 0 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7}; static const uint16_t CRC16_8408_LE_LUT_H[] = {0x0000, 0x1081, 0x2102, 0x3183, 0x4204, 0x5285, 0x6306, 0x7387, 0x8408, 0x9489, 0xa50a, 0xb58b, 0xc60c, 0xd68d, 0xe70e, 0xf78f}; +#endif +#if !defined(USE_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) static const uint16_t CRC16_1021_BE_LUT_L[] = {0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef}; static const uint16_t CRC16_1021_BE_LUT_H[] = {0x0000, 0x1231, 0x2462, 0x3653, 0x48c4, 0x5af5, 0x6ca6, 0x7e97, @@ -151,7 +150,7 @@ uint16_t crc16(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t reverse } uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t poly, bool refin, bool refout) { -#ifdef USE_ESP32 +#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32S2) if (poly == 0x1021) { crc = crc16_be(refin ? crc : (crc ^ 0xffff), data, len); return refout ? crc : (crc ^ 0xffff); @@ -160,7 +159,7 @@ uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t poly, if (refin) { crc ^= 0xffff; } -#ifndef USE_ESP32 +#if !defined(USE_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) if (poly == 0x1021) { while (len--) { uint8_t combo = (crc >> 8) ^ *data++; @@ -178,7 +177,7 @@ uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t poly, } } } -#ifndef USE_ESP32 +#if !defined(USE_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) } #endif return refout ? (crc ^ 0xffff) : crc; diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 012c9af3c69..7e83b3b7056 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -1,4 +1,5 @@ #include "scheduler.h" +#include "esphome/core/defines.h" #include "esphome/core/log.h" #include "esphome/core/helpers.h" #include "esphome/core/hal.h" @@ -21,7 +22,7 @@ static const uint32_t MAX_LOGICALLY_DELETED_ITEMS = 10; void HOT Scheduler::set_timeout(Component *component, const std::string &name, uint32_t timeout, std::function func) { - const uint32_t now = this->millis_(); + const auto now = this->millis_(); if (!name.empty()) this->cancel_timeout(component, name); @@ -29,17 +30,16 @@ void HOT Scheduler::set_timeout(Component *component, const std::string &name, u if (timeout == SCHEDULER_DONT_RUN) return; - ESP_LOGVV(TAG, "set_timeout(name='%s', timeout=%" PRIu32 ")", name.c_str(), timeout); - auto item = make_unique(); item->component = component; item->name = name; item->type = SchedulerItem::TIMEOUT; - item->timeout = timeout; - item->last_execution = now; - item->last_execution_major = this->millis_major_; + item->next_execution_ = now + timeout; item->callback = std::move(func); item->remove = false; +#ifdef ESPHOME_DEBUG_SCHEDULER + ESP_LOGD(TAG, "set_timeout(name='%s/%s', timeout=%" PRIu32 ")", item->get_source(), name.c_str(), timeout); +#endif this->push_(std::move(item)); } bool HOT Scheduler::cancel_timeout(Component *component, const std::string &name) { @@ -47,7 +47,7 @@ bool HOT Scheduler::cancel_timeout(Component *component, const std::string &name } void HOT Scheduler::set_interval(Component *component, const std::string &name, uint32_t interval, std::function func) { - const uint32_t now = this->millis_(); + const auto now = this->millis_(); if (!name.empty()) this->cancel_interval(component, name); @@ -60,19 +60,18 @@ void HOT Scheduler::set_interval(Component *component, const std::string &name, if (interval != 0) offset = (random_uint32() % interval) / 2; - ESP_LOGVV(TAG, "set_interval(name='%s', interval=%" PRIu32 ", offset=%" PRIu32 ")", name.c_str(), interval, offset); - auto item = make_unique(); item->component = component; item->name = name; item->type = SchedulerItem::INTERVAL; item->interval = interval; - item->last_execution = now - offset - interval; - item->last_execution_major = this->millis_major_; - if (item->last_execution > now) - item->last_execution_major--; + item->next_execution_ = now + offset; item->callback = std::move(func); item->remove = false; +#ifdef ESPHOME_DEBUG_SCHEDULER + ESP_LOGD(TAG, "set_interval(name='%s/%s', interval=%" PRIu32 ", offset=%" PRIu32 ")", item->get_source(), + name.c_str(), interval, offset); +#endif this->push_(std::move(item)); } bool HOT Scheduler::cancel_interval(Component *component, const std::string &name) { @@ -138,36 +137,36 @@ optional HOT Scheduler::next_schedule_in() { if (this->empty_()) return {}; auto &item = this->items_[0]; - const uint32_t now = this->millis_(); - uint32_t next_time = item->last_execution + item->interval; - if (next_time < now) + const auto now = this->millis_(); + if (item->next_execution_ < now) return 0; - return next_time - now; + return item->next_execution_ - now; } void HOT Scheduler::call() { - const uint32_t now = this->millis_(); + const auto now = this->millis_(); this->process_to_add(); #ifdef ESPHOME_DEBUG_SCHEDULER - static uint32_t last_print = 0; + static uint64_t last_print = 0; if (now - last_print > 2000) { last_print = now; std::vector> old_items; - ESP_LOGVV(TAG, "Items: count=%u, now=%" PRIu32, this->items_.size(), now); + ESP_LOGD(TAG, "Items: count=%u, now=%" PRIu64 " (%u, %" PRIu32 ")", this->items_.size(), now, this->millis_major_, + this->last_millis_); while (!this->empty_()) { this->lock_.lock(); auto item = std::move(this->items_[0]); this->pop_raw_(); this->lock_.unlock(); - ESP_LOGVV(TAG, " %s '%s' interval=%" PRIu32 " last_execution=%" PRIu32 " (%u) next=%" PRIu32 " (%u)", - item->get_type_str(), item->name.c_str(), item->interval, item->last_execution, - item->last_execution_major, item->next_execution(), item->next_execution_major()); + ESP_LOGD(TAG, " %s '%s/%s' interval=%" PRIu32 " next_execution in %" PRIu64 "ms at %" PRIu64, + item->get_type_str(), item->get_source(), item->name.c_str(), item->interval, + item->next_execution_ - now, item->next_execution_); old_items.push_back(std::move(item)); } - ESP_LOGVV(TAG, "\n"); + ESP_LOGD(TAG, "\n"); { LockGuard guard{this->lock_}; @@ -206,14 +205,10 @@ void HOT Scheduler::call() { { // Don't copy-by value yet auto &item = this->items_[0]; - if ((now - item->last_execution) < item->interval) { + if (item->next_execution_ > now) { // Not reached timeout yet, done for this call break; } - uint8_t major = item->next_execution_major(); - if (this->millis_major_ - major > 1) - break; - // Don't run on failed components if (item->component != nullptr && item->component->is_failed()) { LockGuard guard{this->lock_}; @@ -221,9 +216,10 @@ void HOT Scheduler::call() { continue; } -#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE - ESP_LOGVV(TAG, "Running %s '%s' with interval=%" PRIu32 " last_execution=%" PRIu32 " (now=%" PRIu32 ")", - item->get_type_str(), item->name.c_str(), item->interval, item->last_execution, now); +#ifdef ESPHOME_DEBUG_SCHEDULER + ESP_LOGV(TAG, "Running %s '%s/%s' with interval=%" PRIu32 " next_execution=%" PRIu64 " (now=%" PRIu64 ")", + item->get_type_str(), item->get_source(), item->name.c_str(), item->interval, item->next_execution_, + now); #endif // Warning: During callback(), a lot of stuff can happen, including: @@ -254,13 +250,7 @@ void HOT Scheduler::call() { } if (item->type == SchedulerItem::INTERVAL) { - if (item->interval != 0) { - const uint32_t before = item->last_execution; - const uint32_t amount = (now - item->last_execution) / item->interval; - item->last_execution += amount * item->interval; - if (item->last_execution < before) - item->last_execution_major++; - } + item->next_execution_ = now + item->interval; this->push_(std::move(item)); } } @@ -322,43 +312,20 @@ bool HOT Scheduler::cancel_item_(Component *component, const std::string &name, return ret; } -uint32_t Scheduler::millis_() { +uint64_t Scheduler::millis_() { const uint32_t now = millis(); if (now < this->last_millis_) { - ESP_LOGD(TAG, "Incrementing scheduler major"); this->millis_major_++; + ESP_LOGD(TAG, "Incrementing scheduler major at %" PRIu64 "ms", + now + (static_cast(this->millis_major_) << 32)); } this->last_millis_ = now; - return now; + return now + (static_cast(this->millis_major_) << 32); } bool HOT Scheduler::SchedulerItem::cmp(const std::unique_ptr &a, const std::unique_ptr &b) { - // min-heap - // return true if *a* will happen after *b* - uint32_t a_next_exec = a->next_execution(); - uint8_t a_next_exec_major = a->next_execution_major(); - uint32_t b_next_exec = b->next_execution(); - uint8_t b_next_exec_major = b->next_execution_major(); - - if (a_next_exec_major != b_next_exec_major) { - // The "major" calculation is quite complicated. - // Basically, we need to check if the major value lies in the future or - // - - // Here are some cases to think about: - // Format: a_major,b_major -> expected result (a-b, b-a) - // a=255,b=0 -> false (255, 1) - // a=0,b=1 -> false (255, 1) - // a=1,b=0 -> true (1, 255) - // a=0,b=255 -> true (1, 255) - - uint8_t diff1 = a_next_exec_major - b_next_exec_major; - uint8_t diff2 = b_next_exec_major - a_next_exec_major; - return diff1 < diff2; - } - - return a_next_exec > b_next_exec; + return a->next_execution_ > b->next_execution_; } } // namespace esphome diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 44a58f37f5f..872a8bd6f6e 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -32,23 +32,10 @@ class Scheduler { Component *component; std::string name; enum Type { TIMEOUT, INTERVAL } type; - union { - uint32_t interval; - uint32_t timeout; - }; - uint32_t last_execution; + uint32_t interval; + uint64_t next_execution_; std::function callback; bool remove; - uint8_t last_execution_major; - - inline uint32_t next_execution() { return this->last_execution + this->timeout; } - inline uint8_t next_execution_major() { - uint32_t next_exec = this->next_execution(); - uint8_t next_exec_major = this->last_execution_major; - if (next_exec < this->last_execution) - next_exec_major++; - return next_exec_major; - } static bool cmp(const std::unique_ptr &a, const std::unique_ptr &b); const char *get_type_str() { @@ -61,9 +48,12 @@ class Scheduler { return ""; } } + const char *get_source() { + return this->component != nullptr ? this->component->get_component_source() : "unknown"; + } }; - uint32_t millis_(); + uint64_t millis_(); void cleanup_(); void pop_raw_(); void push_(std::unique_ptr item); @@ -77,7 +67,7 @@ class Scheduler { std::vector> items_; std::vector> to_add_; uint32_t last_millis_{0}; - uint8_t millis_major_{0}; + uint16_t millis_major_{0}; uint32_t to_remove_{0}; }; diff --git a/esphome/dashboard/status/mqtt.py b/esphome/dashboard/status/mqtt.py index 70eb0b58b55..c3e48838497 100644 --- a/esphome/dashboard/status/mqtt.py +++ b/esphome/dashboard/status/mqtt.py @@ -32,8 +32,6 @@ class MqttStatusThread(threading.Thread): topic = "esphome/discover/#" def on_message(client, userdata, msg): - nonlocal current_entries - payload = msg.payload.decode(errors="backslashreplace") if len(payload) > 0: data = json.loads(payload) diff --git a/esphome/vscode.py b/esphome/vscode.py index 907ed882163..fb62b60eac1 100644 --- a/esphome/vscode.py +++ b/esphome/vscode.py @@ -78,28 +78,47 @@ def _print_file_read_event(path: str) -> None: ) +def _request_and_get_stream_on_stdin(fname: str) -> StringIO: + _print_file_read_event(fname) + raw_yaml_stream = StringIO(_read_file_content_from_json_on_stdin()) + return raw_yaml_stream + + +def _vscode_loader(fname: str) -> dict[str, Any]: + raw_yaml_stream = _request_and_get_stream_on_stdin(fname) + # it is required to set the name on StringIO so document on start_mark + # is set properly. Otherwise it is initialized with "" + raw_yaml_stream.name = fname + return parse_yaml(fname, raw_yaml_stream, _vscode_loader) + + +def _ace_loader(fname: str) -> dict[str, Any]: + raw_yaml_stream = _request_and_get_stream_on_stdin(fname) + return parse_yaml(fname, raw_yaml_stream) + + def read_config(args): while True: CORE.reset() data = json.loads(input()) - assert data["type"] == "validate" + assert data["type"] == "validate" or data["type"] == "exit" + if data["type"] == "exit": + return CORE.vscode = True - CORE.ace = args.ace - f = data["file"] - if CORE.ace: - CORE.config_path = os.path.join(args.configuration, f) + if args.ace: # Running from ESPHome Compiler dashboard, not vscode + CORE.config_path = os.path.join(args.configuration, data["file"]) + loader = _ace_loader else: CORE.config_path = data["file"] + loader = _vscode_loader file_name = CORE.config_path - _print_file_read_event(file_name) - raw_yaml = _read_file_content_from_json_on_stdin() command_line_substitutions: dict[str, Any] = ( dict(args.substitution) if args.substitution else {} ) vs = VSCodeResult() try: - config = parse_yaml(file_name, StringIO(raw_yaml)) + config = loader(file_name) res = validate_config(config, command_line_substitutions) except Exception as err: # pylint: disable=broad-except vs.add_yaml_error(str(err)) diff --git a/esphome/yaml_util.py b/esphome/yaml_util.py index 431f397e38e..cbe3fef2723 100644 --- a/esphome/yaml_util.py +++ b/esphome/yaml_util.py @@ -3,12 +3,12 @@ from __future__ import annotations import fnmatch import functools import inspect -from io import TextIOWrapper +from io import BytesIO, TextIOBase, TextIOWrapper from ipaddress import _BaseAddress import logging import math import os -from typing import Any +from typing import Any, Callable import uuid import yaml @@ -69,7 +69,10 @@ class ESPForceValue: pass -def make_data_base(value, from_database: ESPHomeDataBase = None): +def make_data_base( + value, from_database: ESPHomeDataBase = None +) -> ESPHomeDataBase | Any: + """Wrap a value in a ESPHomeDataBase object.""" try: value = add_class_to_obj(value, ESPHomeDataBase) if from_database is not None: @@ -102,6 +105,11 @@ def _add_data_ref(fn): class ESPHomeLoaderMixin: """Loader class that keeps track of line numbers.""" + def __init__(self, name: str, yaml_loader: Callable[[str], dict[str, Any]]) -> None: + """Initialize the loader.""" + self.name = name + self.yaml_loader = yaml_loader + @_add_data_ref def construct_yaml_int(self, node): return super().construct_yaml_int(node) @@ -127,7 +135,7 @@ class ESPHomeLoaderMixin: return super().construct_yaml_seq(node) @_add_data_ref - def construct_yaml_map(self, node): + def construct_yaml_map(self, node: yaml.MappingNode) -> OrderedDict[str, Any]: """Traverses the given mapping node and returns a list of constructed key-value pairs.""" assert isinstance(node, yaml.MappingNode) # A list of key-value pairs we find in the current mapping @@ -231,7 +239,7 @@ class ESPHomeLoaderMixin: return OrderedDict(pairs) @_add_data_ref - def construct_env_var(self, node): + def construct_env_var(self, node: yaml.Node) -> str: args = node.value.split() # Check for a default value if len(args) > 1: @@ -243,23 +251,23 @@ class ESPHomeLoaderMixin: ) @property - def _directory(self): + def _directory(self) -> str: return os.path.dirname(self.name) - def _rel_path(self, *args): + def _rel_path(self, *args: str) -> str: return os.path.join(self._directory, *args) @_add_data_ref - def construct_secret(self, node): + def construct_secret(self, node: yaml.Node) -> str: try: - secrets = _load_yaml_internal(self._rel_path(SECRET_YAML)) + secrets = self.yaml_loader(self._rel_path(SECRET_YAML)) except EsphomeError as e: if self.name == CORE.config_path: raise e try: main_config_dir = os.path.dirname(CORE.config_path) main_secret_yml = os.path.join(main_config_dir, SECRET_YAML) - secrets = _load_yaml_internal(main_secret_yml) + secrets = self.yaml_loader(main_secret_yml) except EsphomeError as er: raise EsphomeError(f"{e}\n{er}") from er @@ -272,7 +280,9 @@ class ESPHomeLoaderMixin: return val @_add_data_ref - def construct_include(self, node): + def construct_include( + self, node: yaml.Node + ) -> dict[str, Any] | OrderedDict[str, Any]: from esphome.const import CONF_VARS def extract_file_vars(node): @@ -290,71 +300,93 @@ class ESPHomeLoaderMixin: else: file, vars = node.value, None - result = _load_yaml_internal(self._rel_path(file)) + result = self.yaml_loader(self._rel_path(file)) if not vars: vars = {} result = substitute_vars(result, vars) return result @_add_data_ref - def construct_include_dir_list(self, node): + def construct_include_dir_list(self, node: yaml.Node) -> list[dict[str, Any]]: files = filter_yaml_files(_find_files(self._rel_path(node.value), "*.yaml")) - return [_load_yaml_internal(f) for f in files] + return [self.yaml_loader(f) for f in files] @_add_data_ref - def construct_include_dir_merge_list(self, node): + def construct_include_dir_merge_list(self, node: yaml.Node) -> list[dict[str, Any]]: files = filter_yaml_files(_find_files(self._rel_path(node.value), "*.yaml")) merged_list = [] for fname in files: - loaded_yaml = _load_yaml_internal(fname) + loaded_yaml = self.yaml_loader(fname) if isinstance(loaded_yaml, list): merged_list.extend(loaded_yaml) return merged_list @_add_data_ref - def construct_include_dir_named(self, node): + def construct_include_dir_named( + self, node: yaml.Node + ) -> OrderedDict[str, dict[str, Any]]: files = filter_yaml_files(_find_files(self._rel_path(node.value), "*.yaml")) mapping = OrderedDict() for fname in files: filename = os.path.splitext(os.path.basename(fname))[0] - mapping[filename] = _load_yaml_internal(fname) + mapping[filename] = self.yaml_loader(fname) return mapping @_add_data_ref - def construct_include_dir_merge_named(self, node): + def construct_include_dir_merge_named( + self, node: yaml.Node + ) -> OrderedDict[str, dict[str, Any]]: files = filter_yaml_files(_find_files(self._rel_path(node.value), "*.yaml")) mapping = OrderedDict() for fname in files: - loaded_yaml = _load_yaml_internal(fname) + loaded_yaml = self.yaml_loader(fname) if isinstance(loaded_yaml, dict): mapping.update(loaded_yaml) return mapping @_add_data_ref - def construct_lambda(self, node): + def construct_lambda(self, node: yaml.Node) -> Lambda: return Lambda(str(node.value)) @_add_data_ref - def construct_force(self, node): + def construct_force(self, node: yaml.Node) -> ESPForceValue: obj = self.construct_scalar(node) return add_class_to_obj(obj, ESPForceValue) @_add_data_ref - def construct_extend(self, node): + def construct_extend(self, node: yaml.Node) -> Extend: return Extend(str(node.value)) @_add_data_ref - def construct_remove(self, node): + def construct_remove(self, node: yaml.Node) -> Remove: return Remove(str(node.value)) class ESPHomeLoader(ESPHomeLoaderMixin, FastestAvailableSafeLoader): """Loader class that keeps track of line numbers.""" + def __init__( + self, + stream: TextIOBase | BytesIO, + name: str, + yaml_loader: Callable[[str], dict[str, Any]], + ) -> None: + FastestAvailableSafeLoader.__init__(self, stream) + ESPHomeLoaderMixin.__init__(self, name, yaml_loader) + class ESPHomePurePythonLoader(ESPHomeLoaderMixin, PurePythonLoader): """Loader class that keeps track of line numbers.""" + def __init__( + self, + stream: TextIOBase | BytesIO, + name: str, + yaml_loader: Callable[[str], dict[str, Any]], + ) -> None: + PurePythonLoader.__init__(self, stream) + ESPHomeLoaderMixin.__init__(self, name, yaml_loader) + for _loader in (ESPHomeLoader, ESPHomePurePythonLoader): _loader.add_constructor("tag:yaml.org,2002:int", _loader.construct_yaml_int) @@ -388,17 +420,30 @@ def load_yaml(fname: str, clear_secrets: bool = True) -> Any: return _load_yaml_internal(fname) -def parse_yaml(file_name: str, file_handle: TextIOWrapper) -> Any: +def _load_yaml_internal(fname: str) -> Any: + """Load a YAML file.""" + try: + with open(fname, encoding="utf-8") as f_handle: + return parse_yaml(fname, f_handle) + except (UnicodeDecodeError, OSError) as err: + raise EsphomeError(f"Error reading file {fname}: {err}") from err + + +def parse_yaml( + file_name: str, file_handle: TextIOWrapper, yaml_loader=_load_yaml_internal +) -> Any: """Parse a YAML file.""" try: - return _load_yaml_internal_with_type(ESPHomeLoader, file_name, file_handle) + return _load_yaml_internal_with_type( + ESPHomeLoader, file_name, file_handle, yaml_loader + ) except EsphomeError: # Loading failed, so we now load with the Python loader which has more # readable exceptions # Rewind the stream so we can try again file_handle.seek(0, 0) return _load_yaml_internal_with_type( - ESPHomePurePythonLoader, file_name, file_handle + ESPHomePurePythonLoader, file_name, file_handle, yaml_loader ) @@ -435,23 +480,14 @@ def substitute_vars(config, vars): return result -def _load_yaml_internal(fname: str) -> Any: - """Load a YAML file.""" - try: - with open(fname, encoding="utf-8") as f_handle: - return parse_yaml(fname, f_handle) - except (UnicodeDecodeError, OSError) as err: - raise EsphomeError(f"Error reading file {fname}: {err}") from err - - def _load_yaml_internal_with_type( loader_type: type[ESPHomeLoader] | type[ESPHomePurePythonLoader], fname: str, content: TextIOWrapper, + yaml_loader: Any, ) -> Any: """Load a YAML file.""" - loader = loader_type(content) - loader.name = fname + loader = loader_type(content, fname, yaml_loader) try: return loader.get_single_data() or OrderedDict() except yaml.YAMLError as exc: @@ -470,7 +506,7 @@ def dump(dict_, show_secrets=False): ) -def _is_file_valid(name): +def _is_file_valid(name: str) -> bool: """Decide if a file is valid.""" return not name.startswith(".") diff --git a/pyproject.toml b/pyproject.toml index 69b36cd14a2..77dcaf1fabc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools==69.2.0", "wheel~=0.43.0"] +requires = ["setuptools==78.1.0", "wheel>=0.43,<0.46"] build-backend = "setuptools.build_meta" [project] @@ -8,7 +8,7 @@ license = {text = "MIT"} description = "ESPHome is a system to configure your microcontrollers by simple yet powerful configuration files and control them remotely through Home Automation systems." readme = "README.md" authors = [ - {name = "The ESPHome Authors", email = "esphome@nabucasa.com"} + {name = "The ESPHome Authors", email = "esphome@openhomefoundation.org"} ] keywords = ["home", "automation"] classifiers = [ @@ -86,6 +86,7 @@ disable = [ "too-many-branches", "too-many-statements", "too-many-arguments", + "too-many-positional-arguments", "too-many-return-statements", "too-many-instance-attributes", "duplicate-code", diff --git a/requirements.txt b/requirements.txt index 46746b08cf3..d40ce6c1451 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,23 @@ -async_timeout==4.0.3; python_version <= "3.10" +async_timeout==5.0.1; python_version <= "3.10" cryptography==44.0.2 -voluptuous==0.14.2 +voluptuous==0.15.2 PyYAML==6.0.2 paho-mqtt==1.6.1 colorama==0.4.6 icmplib==3.0.4 tornado==6.4.2 -tzlocal==5.2 # from time +tzlocal==5.3.1 # from time tzdata>=2021.1 # from time pyserial==3.5 -platformio==6.1.16 # When updating platformio, also update Dockerfile +platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==4.8.1 click==8.1.7 -esphome-dashboard==20250212.0 -aioesphomeapi==29.6.0 -zeroconf==0.146.1 -puremagic==1.27 -ruamel.yaml==0.18.6 # dashboard_import -esphome-glyphsets==0.1.0 +esphome-dashboard==20250415.0 +aioesphomeapi==29.10.0 +zeroconf==0.146.5 +puremagic==1.28 +ruamel.yaml==0.18.10 # dashboard_import +esphome-glyphsets==0.2.0 pillow==10.4.0 freetype-py==2.5.1 diff --git a/requirements_dev.txt b/requirements_dev.txt index 1a98a15ab26..d77ccaff693 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ # Useful stuff when working in a development environment clang-format==13.0.1 # also change in .pre-commit-config.yaml and Dockerfile when updating clang-tidy==18.1.8 # When updating clang-tidy, also update Dockerfile -yamllint==1.35.1 # also change in .pre-commit-config.yaml when updating +yamllint==1.37.0 # also change in .pre-commit-config.yaml when updating diff --git a/requirements_test.txt b/requirements_test.txt index d836efc148c..e43df6703fc 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,13 +1,13 @@ -pylint==3.2.7 -flake8==7.0.0 # also change in .pre-commit-config.yaml when updating -ruff==0.9.2 # also change in .pre-commit-config.yaml when updating -pyupgrade==3.15.2 # also change in .pre-commit-config.yaml when updating +pylint==3.3.6 +flake8==7.2.0 # also change in .pre-commit-config.yaml when updating +ruff==0.11.2 # also change in .pre-commit-config.yaml when updating +pyupgrade==3.19.1 # also change in .pre-commit-config.yaml when updating pre-commit # Unit tests -pytest==8.2.0 -pytest-cov==5.0.0 +pytest==8.3.5 +pytest-cov==6.0.0 pytest-mock==3.14.0 -pytest-asyncio==0.23.6 +pytest-asyncio==0.26.0 asyncmock==0.4.2 hypothesis==6.92.1 diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index a2bc3abf642..7771922697d 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -17,12 +17,12 @@ then run this script with python3 and the files will be generated, they still need to be formatted """ -import os -import re -import sys from abc import ABC, abstractmethod +import os from pathlib import Path +import re from subprocess import call +import sys from textwrap import dedent # Generate with @@ -528,7 +528,7 @@ class RepeatedTypeInfo(TypeInfo): @property def dump_content(self): - o = f'for (const auto {"" if self._ti_is_bool else "&"}it : this->{self.field_name}) {{\n' + o = f"for (const auto {'' if self._ti_is_bool else '&'}it : this->{self.field_name}) {{\n" o += f' out.append(" {self.name}: ");\n' o += indent(self._ti.dump("it")) + "\n" o += ' out.append("\\n");\n' diff --git a/script/build_language_schema.py b/script/build_language_schema.py index 07093e179aa..7152e23e8f3 100644 --- a/script/build_language_schema.py +++ b/script/build_language_schema.py @@ -85,8 +85,8 @@ def load_components(): # pylint: disable=wrong-import-position -from esphome.const import CONF_TYPE, KEY_CORE, KEY_TARGET_PLATFORM -from esphome.core import CORE +from esphome.const import CONF_TYPE, KEY_CORE, KEY_TARGET_PLATFORM # noqa: E402 +from esphome.core import CORE # noqa: E402 # pylint: enable=wrong-import-position @@ -95,13 +95,13 @@ load_components() # Import esphome after loading components (so schema is tracked) # pylint: disable=wrong-import-position -from esphome import automation, pins -from esphome.components import remote_base -import esphome.config_validation as cv -import esphome.core as esphome_core -from esphome.helpers import write_file_if_changed -from esphome.loader import CORE_COMPONENTS_PATH, get_platform -from esphome.util import Registry +from esphome import automation, pins # noqa: E402 +from esphome.components import remote_base # noqa: E402 +import esphome.config_validation as cv # noqa: E402 +import esphome.core as esphome_core # noqa: E402 +from esphome.helpers import write_file_if_changed # noqa: E402 +from esphome.loader import CORE_COMPONENTS_PATH, get_platform # noqa: E402 +from esphome.util import Registry # noqa: E402 # pylint: enable=wrong-import-position @@ -614,9 +614,9 @@ def build_schema(): if platform_manifest is not None: output[platform][S_COMPONENTS][domain] = {} if len(platform_manifest.dependencies) > 0: - output[platform][S_COMPONENTS][domain][ - "dependencies" - ] = platform_manifest.dependencies + output[platform][S_COMPONENTS][domain]["dependencies"] = ( + platform_manifest.dependencies + ) register_module_schemas( f"{domain}.{platform}", platform_manifest.module, platform_manifest ) diff --git a/script/clang-tidy b/script/clang-tidy index 51705f955bc..a857274b011 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -36,6 +36,7 @@ def clang_options(idedata): # clang doesn't support Xtensa (yet?), so compile in 32-bit mode and pretend we're the Xtensa compiler cmd.append("-m32") cmd.append("-D__XTENSA__") + cmd.append("-D_LIBC") else: cmd.append(f"--target={triplet}") @@ -79,6 +80,7 @@ def clang_options(idedata): "-fstrict-volatile-bitfields", "-mlongcalls", "-mtext-section-literals", + "-mdisable-hardware-atomics", "-mfix-esp32-psram-cache-issue", "-mfix-esp32-psram-cache-strategy=memw", "-fno-tree-switch-conversion", diff --git a/script/run-in-env.py b/script/run-in-env.py index 57121266be0..b03f5f19d3e 100644 --- a/script/run-in-env.py +++ b/script/run-in-env.py @@ -9,8 +9,8 @@ import sys def find_and_activate_virtualenv(): if ( ("VIRTUAL_ENV" in os.environ) - or os.environ.get("DEVCONTAINER", False) - or os.environ.get("ESPHOME_NO_VENV", False) + or os.environ.get("DEVCONTAINER") + or os.environ.get("ESPHOME_NO_VENV") ): return diff --git a/tests/component_tests/conftest.py b/tests/component_tests/conftest.py index aa564ed7b1c..7aa7dfe6982 100644 --- a/tests/component_tests/conftest.py +++ b/tests/component_tests/conftest.py @@ -1,18 +1,18 @@ """Fixtures for component tests.""" -import sys from pathlib import Path +import sys # Add package root to python path here = Path(__file__).parent package_root = here.parent.parent sys.path.insert(0, package_root.as_posix()) -import pytest +import pytest # noqa: E402 -from esphome.core import CORE -from esphome.config import read_config -from esphome.__main__ import generate_cpp_contents +from esphome.__main__ import generate_cpp_contents # noqa: E402 +from esphome.config import read_config # noqa: E402 +from esphome.core import CORE # noqa: E402 @pytest.fixture diff --git a/tests/components/bluetooth_proxy/common.yaml b/tests/components/bluetooth_proxy/common.yaml new file mode 100644 index 00000000000..5e84f4a6783 --- /dev/null +++ b/tests/components/bluetooth_proxy/common.yaml @@ -0,0 +1,8 @@ +wifi: + ssid: MySSID + password: password1 + +ota: + - platform: esphome + +api: diff --git a/tests/components/bluetooth_proxy/test.esp32-ard.yaml b/tests/components/bluetooth_proxy/test.esp32-ard.yaml new file mode 100644 index 00000000000..bf01b65b6f1 --- /dev/null +++ b/tests/components/bluetooth_proxy/test.esp32-ard.yaml @@ -0,0 +1,8 @@ +<<: !include common.yaml + +esp32_ble_tracker: + max_connections: 3 + +bluetooth_proxy: + active: true + connection_slots: 2 diff --git a/tests/components/bluetooth_proxy/test.esp32-c3-ard.yaml b/tests/components/bluetooth_proxy/test.esp32-c3-ard.yaml new file mode 100644 index 00000000000..bf01b65b6f1 --- /dev/null +++ b/tests/components/bluetooth_proxy/test.esp32-c3-ard.yaml @@ -0,0 +1,8 @@ +<<: !include common.yaml + +esp32_ble_tracker: + max_connections: 3 + +bluetooth_proxy: + active: true + connection_slots: 2 diff --git a/tests/components/bluetooth_proxy/test.esp32-c3-idf.yaml b/tests/components/bluetooth_proxy/test.esp32-c3-idf.yaml new file mode 100644 index 00000000000..6c27bd35d08 --- /dev/null +++ b/tests/components/bluetooth_proxy/test.esp32-c3-idf.yaml @@ -0,0 +1,8 @@ +<<: !include common.yaml + +esp32_ble_tracker: + max_connections: 9 + +bluetooth_proxy: + active: true + connection_slots: 9 diff --git a/tests/components/bluetooth_proxy/test.esp32-idf.yaml b/tests/components/bluetooth_proxy/test.esp32-idf.yaml new file mode 100644 index 00000000000..6c27bd35d08 --- /dev/null +++ b/tests/components/bluetooth_proxy/test.esp32-idf.yaml @@ -0,0 +1,8 @@ +<<: !include common.yaml + +esp32_ble_tracker: + max_connections: 9 + +bluetooth_proxy: + active: true + connection_slots: 9 diff --git a/tests/components/esp32_ble_tracker/test.esp32-ard.yaml b/tests/components/esp32_ble_tracker/test.esp32-ard.yaml index dade44d145b..070fffd68b7 100644 --- a/tests/components/esp32_ble_tracker/test.esp32-ard.yaml +++ b/tests/components/esp32_ble_tracker/test.esp32-ard.yaml @@ -1 +1,4 @@ <<: !include common.yaml + +esp32_ble_tracker: + max_connections: 3 diff --git a/tests/components/esp32_ble_tracker/test.esp32-c3-ard.yaml b/tests/components/esp32_ble_tracker/test.esp32-c3-ard.yaml index dade44d145b..070fffd68b7 100644 --- a/tests/components/esp32_ble_tracker/test.esp32-c3-ard.yaml +++ b/tests/components/esp32_ble_tracker/test.esp32-c3-ard.yaml @@ -1 +1,4 @@ <<: !include common.yaml + +esp32_ble_tracker: + max_connections: 3 diff --git a/tests/components/esp32_ble_tracker/test.esp32-c3-idf.yaml b/tests/components/esp32_ble_tracker/test.esp32-c3-idf.yaml index dade44d145b..5e09f5020e2 100644 --- a/tests/components/esp32_ble_tracker/test.esp32-c3-idf.yaml +++ b/tests/components/esp32_ble_tracker/test.esp32-c3-idf.yaml @@ -1 +1,4 @@ <<: !include common.yaml + +esp32_ble_tracker: + max_connections: 9 diff --git a/tests/components/esp32_ble_tracker/test.esp32-idf.yaml b/tests/components/esp32_ble_tracker/test.esp32-idf.yaml index dade44d145b..5e09f5020e2 100644 --- a/tests/components/esp32_ble_tracker/test.esp32-idf.yaml +++ b/tests/components/esp32_ble_tracker/test.esp32-idf.yaml @@ -1 +1,4 @@ <<: !include common.yaml + +esp32_ble_tracker: + max_connections: 9 diff --git a/tests/components/esphome/common.yaml b/tests/components/esphome/common.yaml new file mode 100644 index 00000000000..05954e37d7b --- /dev/null +++ b/tests/components/esphome/common.yaml @@ -0,0 +1,20 @@ +esphome: + debug_scheduler: true + platformio_options: + board_build.flash_mode: dio + area: testing + on_boot: + logger.log: on_boot + on_shutdown: + logger.log: on_shutdown + on_loop: + logger.log: on_loop + compile_process_limit: 1 + min_version: "2025.1" + name_add_mac_suffix: true + project: + name: esphome.test + version: "1.1" + on_update: + logger.log: on_update + diff --git a/tests/components/esphome/test.esp32-ard.yaml b/tests/components/esphome/test.esp32-ard.yaml new file mode 100644 index 00000000000..a991f7e15a8 --- /dev/null +++ b/tests/components/esphome/test.esp32-ard.yaml @@ -0,0 +1,2 @@ +<<: !include common.yaml + diff --git a/tests/components/esphome/test.esp32-c3-ard.yaml b/tests/components/esphome/test.esp32-c3-ard.yaml new file mode 100644 index 00000000000..a991f7e15a8 --- /dev/null +++ b/tests/components/esphome/test.esp32-c3-ard.yaml @@ -0,0 +1,2 @@ +<<: !include common.yaml + diff --git a/tests/components/psram/test.esp32-c3-idf.yaml b/tests/components/esphome/test.esp32-c3-idf.yaml similarity index 100% rename from tests/components/psram/test.esp32-c3-idf.yaml rename to tests/components/esphome/test.esp32-c3-idf.yaml diff --git a/tests/components/psram/test.esp32-c3-ard.yaml b/tests/components/esphome/test.esp32-idf.yaml similarity index 100% rename from tests/components/psram/test.esp32-c3-ard.yaml rename to tests/components/esphome/test.esp32-idf.yaml diff --git a/tests/components/esphome/test.esp8266-ard.yaml b/tests/components/esphome/test.esp8266-ard.yaml new file mode 100644 index 00000000000..dade44d145b --- /dev/null +++ b/tests/components/esphome/test.esp8266-ard.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/esphome/test.host.yaml b/tests/components/esphome/test.host.yaml new file mode 100644 index 00000000000..dade44d145b --- /dev/null +++ b/tests/components/esphome/test.host.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/esphome/test.rp2040-ard.yaml b/tests/components/esphome/test.rp2040-ard.yaml new file mode 100644 index 00000000000..dade44d145b --- /dev/null +++ b/tests/components/esphome/test.rp2040-ard.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/lvgl/common.yaml b/tests/components/lvgl/common.yaml index c7d635db1c0..174df56749f 100644 --- a/tests/components/lvgl/common.yaml +++ b/tests/components/lvgl/common.yaml @@ -38,6 +38,7 @@ number: widget: slider_id name: LVGL Slider update_on_release: true + restore_value: true - platform: lvgl widget: lv_arc id: lvgl_arc_number diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index c527f51b1ed..a0b7dd096f0 100644 --- a/tests/components/lvgl/lvgl-package.yaml +++ b/tests/components/lvgl/lvgl-package.yaml @@ -24,6 +24,8 @@ lvgl: logger.log: LVGL is Paused on_resume: logger.log: LVGL has resumed + on_boot: + logger.log: LVGL has started bg_color: light_blue disp_bg_color: color_id disp_bg_image: cat_image @@ -128,6 +130,10 @@ lvgl: on_click: then: - lvgl.widget.hide: message_box + - lvgl.style.update: + id: style_test + bg_color: blue + bg_opa: !lambda return 0.5; - id: simple_msgbox title: Simple @@ -210,6 +216,10 @@ lvgl: src: !lambda "return {dog_image, cat_image};" duration: 2s - label: + on_boot: + lvgl.label.update: + id: hello_label + text: Goodbye Cruel World id: hello_label text: Hello world text_color: 0xFF8000 @@ -504,6 +514,110 @@ lvgl: - id: page2 widgets: + - canvas: + id: canvas_id + align: center + width: 400 + height: 400 + transparent: true + on_boot: + - lvgl.canvas.fill: + color: blue + opa: 50% + - lvgl.canvas.draw_rectangle: + x: 20 + y: 20 + width: 150 + height: 150 + bg_color: green + bg_opa: cover + radius: 5 + border_color: black + border_width: 4 + border_opa: 80% + shadow_color: black + shadow_width: 10 + shadow_ofs_x: 5 + shadow_ofs_y: 5 + shadow_spread: 4 + shadow_opa: cover + outline_color: red + outline_width: 4 + outline_pad: 4 + outline_opa: cover + - lvgl.canvas.set_pixels: + color: red + points: + - x: 100 + y: 100 + - 100,101 + - 100,102 + - 100,103 + - 100,104 + - lvgl.canvas.set_pixels: + opa: 50% + color: !lambda return lv_color_make(255,255,255); + points: + - x: !lambda return random_uint32() % 200; + y: !lambda return random_uint32() % 200; + - 121,120 + - 122,120 + - 123,120 + - 124,120 + - 125,120 + + - lvgl.canvas.draw_text: + x: 100 + y: 100 + font: montserrat_18 + color: white + opa: cover + decor: underline + letter_space: 1 + line_space: 2 + text: Canvas Text + align: center + max_width: 150 + - lvgl.canvas.draw_image: + src: cat_image + x: 100 + y: 100 + angle: 90 + zoom: 2.0 + pivot_x: 25 + pivot_y: 25 + - lvgl.canvas.draw_line: + color: blue + width: 4 + round_end: true + round_start: false + points: + - 50,50 + - 50, 200 + - 200, 200 + - 200, 50 + - 50,50 + - lvgl.canvas.draw_polygon: + bg_color: teal + border_color: white + border_width: 2 + border_opa: cover + points: + - 150,150 + - 150, 300 + - 300, 300 + - 350, 250 + - lvgl.canvas.draw_arc: + x: 200 + y: 200 + radius: 40 + opa: 50% + color: purple + width: 6 + rounded: true + start_angle: 10 + end_angle: !lambda return 900; + - qrcode: id: lv_qr align: left_mid @@ -608,6 +722,8 @@ lvgl: align: center points: - 5, 5 + - x: !lambda return random_uint32() % 100; + y: !lambda return random_uint32() % 100; - 70, 70 - 120, 10 - 180, 60 @@ -616,6 +732,14 @@ lvgl: - lvgl.line.update: id: lv_line_id line_color: 0xFFFF + points: + - 5, 5 + - x: !lambda return random_uint32() % 100; + y: !lambda return random_uint32() % 100; + - 70, 70 + - 120, 10 + - 180, 60 + - 240, 10 - lvgl.page.next: - switch: align: right_mid @@ -866,3 +990,13 @@ color: green_int: 123 blue_int: 64 white_int: 255 + +select: + - platform: lvgl + id: lv_roller_select + widget: lv_roller + restore_value: true + - platform: lvgl + id: lv_dropdown_select + widget: lv_dropdown + restore_value: false diff --git a/tests/components/lvgl/test.esp32-idf.yaml b/tests/components/lvgl/test.esp32-idf.yaml index 05a1f243ed8..eacace1d4bc 100644 --- a/tests/components/lvgl/test.esp32-idf.yaml +++ b/tests/components/lvgl/test.esp32-idf.yaml @@ -71,5 +71,6 @@ lvgl: sensor: encoder enter_button: pushbutton group: general + initial_focus: lv_roller <<: !include common.yaml diff --git a/tests/components/mcp4461/common.yaml b/tests/components/mcp4461/common.yaml new file mode 100644 index 00000000000..ce1866fdb81 --- /dev/null +++ b/tests/components/mcp4461/common.yaml @@ -0,0 +1,28 @@ +i2c: + - id: i2c_mcp4461 + sda: ${sda_pin} + scl: ${scl_pin} + +mcp4461: + - id: mcp4461_digipot_01 + +output: + - platform: mcp4461 + id: digipot_wiper_1 + mcp4461_id: mcp4461_digipot_01 + channel: A + + - platform: mcp4461 + id: digipot_wiper_2 + mcp4461_id: mcp4461_digipot_01 + channel: B + + - platform: mcp4461 + id: digipot_wiper_3 + mcp4461_id: mcp4461_digipot_01 + channel: C + + - platform: mcp4461 + id: digipot_wiper_4 + mcp4461_id: mcp4461_digipot_01 + channel: D diff --git a/tests/components/mcp4461/test.esp32-ard.yaml b/tests/components/mcp4461/test.esp32-ard.yaml new file mode 100644 index 00000000000..c5deb7ca0a4 --- /dev/null +++ b/tests/components/mcp4461/test.esp32-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + sda_pin: GPIO16 + scl_pin: GPIO17 + +<<: !include common.yaml diff --git a/tests/components/mcp4461/test.esp32-c3-ard.yaml b/tests/components/mcp4461/test.esp32-c3-ard.yaml new file mode 100644 index 00000000000..a87353b78ba --- /dev/null +++ b/tests/components/mcp4461/test.esp32-c3-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + sda_pin: GPIO4 + scl_pin: GPIO5 + +<<: !include common.yaml diff --git a/tests/components/mcp4461/test.esp32-c3-idf.yaml b/tests/components/mcp4461/test.esp32-c3-idf.yaml new file mode 100644 index 00000000000..a87353b78ba --- /dev/null +++ b/tests/components/mcp4461/test.esp32-c3-idf.yaml @@ -0,0 +1,5 @@ +substitutions: + sda_pin: GPIO4 + scl_pin: GPIO5 + +<<: !include common.yaml diff --git a/tests/components/mcp4461/test.esp32-idf.yaml b/tests/components/mcp4461/test.esp32-idf.yaml new file mode 100644 index 00000000000..c5deb7ca0a4 --- /dev/null +++ b/tests/components/mcp4461/test.esp32-idf.yaml @@ -0,0 +1,5 @@ +substitutions: + sda_pin: GPIO16 + scl_pin: GPIO17 + +<<: !include common.yaml diff --git a/tests/components/mcp4461/test.esp8266-ard.yaml b/tests/components/mcp4461/test.esp8266-ard.yaml new file mode 100644 index 00000000000..a87353b78ba --- /dev/null +++ b/tests/components/mcp4461/test.esp8266-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + sda_pin: GPIO4 + scl_pin: GPIO5 + +<<: !include common.yaml diff --git a/tests/components/pipsolar/test.esp32-s2-idf.yaml b/tests/components/pipsolar/test.esp32-s2-idf.yaml new file mode 100644 index 00000000000..b516342f3bc --- /dev/null +++ b/tests/components/pipsolar/test.esp32-s2-idf.yaml @@ -0,0 +1,5 @@ +substitutions: + tx_pin: GPIO4 + rx_pin: GPIO5 + +<<: !include common.yaml diff --git a/tests/components/psram/common.yaml b/tests/components/psram/common.yaml index cfd39f77fed..9c6e3f2a60a 100644 --- a/tests/components/psram/common.yaml +++ b/tests/components/psram/common.yaml @@ -1,3 +1,2 @@ psram: - mode: octal speed: 80MHz diff --git a/tests/components/psram/test.esp32-s3-ard.yaml b/tests/components/psram/test.esp32-s3-ard.yaml index dade44d145b..cfd39f77fed 100644 --- a/tests/components/psram/test.esp32-s3-ard.yaml +++ b/tests/components/psram/test.esp32-s3-ard.yaml @@ -1 +1,3 @@ -<<: !include common.yaml +psram: + mode: octal + speed: 80MHz diff --git a/tests/components/psram/test.esp32-s3-idf.yaml b/tests/components/psram/test.esp32-s3-idf.yaml index dade44d145b..e0e7fb52f64 100644 --- a/tests/components/psram/test.esp32-s3-idf.yaml +++ b/tests/components/psram/test.esp32-s3-idf.yaml @@ -1 +1,10 @@ -<<: !include common.yaml +esp32: + framework: + type: esp-idf + advanced: + enable_idf_experimental_features: yes + +psram: + mode: octal + speed: 120MHz + enable_ecc: true diff --git a/tests/components/spi/test.esp32-s3-idf.yaml b/tests/components/spi/test.esp32-s3-idf.yaml index d394c5d7a42..061e3dd44a1 100644 --- a/tests/components/spi/test.esp32-s3-idf.yaml +++ b/tests/components/spi/test.esp32-s3-idf.yaml @@ -1,22 +1,36 @@ spi: - - id: spi_id_1 - type: single - clk_pin: - number: GPIO0 - ignore_strapping_warning: true - allow_other_uses: false - mosi_pin: GPIO6 - interface: hardware - id: quad_spi type: quad interface: spi3 - clk_pin: 47 + clk_pin: + number: 47 data_pins: - - number: 40 - allow_other_uses: false - - 41 - - 42 - - 43 + - allow_other_uses: true + number: 40 + - allow_other_uses: true + number: 41 + - allow_other_uses: true + number: 42 + - allow_other_uses: true + number: 43 + - id: octal_spi + type: octal + interface: hardware + clk_pin: + number: 0 + data_pins: + - 36 + - 37 + - 38 + - 39 + - allow_other_uses: true + number: 40 + - allow_other_uses: true + number: 41 + - allow_other_uses: true + number: 42 + - allow_other_uses: true + number: 43 - id: spi_id_3 interface: any clk_pin: 8 diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index d61c4a442ac..955869b799e 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -9,11 +9,10 @@ not be part of a unit test suite. """ -import sys -import pytest - from pathlib import Path +import sys +import pytest here = Path(__file__).parent diff --git a/tests/unit_tests/test_cpp_helpers.py b/tests/unit_tests/test_cpp_helpers.py index 497b3966fb8..2618803fecf 100644 --- a/tests/unit_tests/test_cpp_helpers.py +++ b/tests/unit_tests/test_cpp_helpers.py @@ -1,8 +1,8 @@ -import pytest from unittest.mock import Mock -from esphome import cpp_helpers as ch -from esphome import const +import pytest + +from esphome import const, cpp_helpers as ch @pytest.mark.asyncio diff --git a/tests/unit_tests/test_helpers.py b/tests/unit_tests/test_helpers.py index 26ebdcf6af0..862320b09e8 100644 --- a/tests/unit_tests/test_helpers.py +++ b/tests/unit_tests/test_helpers.py @@ -1,7 +1,6 @@ -import pytest - from hypothesis import given from hypothesis.strategies import ip_addresses +import pytest from esphome import helpers diff --git a/tests/unit_tests/test_vscode.py b/tests/unit_tests/test_vscode.py new file mode 100644 index 00000000000..f5ebd63f605 --- /dev/null +++ b/tests/unit_tests/test_vscode.py @@ -0,0 +1,125 @@ +import json +import os +from unittest.mock import Mock, patch + +from esphome import vscode + + +def _run_repl_test(input_data): + """Reusable test function for different input scenarios.""" + input_data.append(_exit()) + with ( + patch("builtins.input", side_effect=input_data), + patch("sys.stdout") as mock_stdout, + ): + args = Mock([]) + args.ace = False + args.substitution = None + vscode.read_config(args) + + # Capture printed output + full_output = "".join(call[0][0] for call in mock_stdout.write.call_args_list) + return full_output.strip().split("\n") + + +def _validate(file_path: str): + return json.dumps({"type": "validate", "file": file_path}) + + +def _file_response(data: str): + return json.dumps({"type": "file_response", "content": data}) + + +def _read_file(file_path: str): + return json.dumps({"type": "read_file", "path": file_path}) + + +def _exit(): + return json.dumps({"type": "exit"}) + + +RESULT_NO_ERROR = '{"type": "result", "yaml_errors": [], "validation_errors": []}' + + +def test_multi_file(): + source_path = os.path.join("dir_path", "x.yaml") + output_lines = _run_repl_test( + [ + _validate(source_path), + # read_file x.yaml + _file_response("""esphome: + name: test1 +esp8266: + board: !secret my_secret_board +"""), + # read_file secrets.yaml + _file_response("""my_secret_board: esp1f"""), + ] + ) + + expected_lines = [ + _read_file(source_path), + _read_file(os.path.join("dir_path", "secrets.yaml")), + RESULT_NO_ERROR, + ] + + assert output_lines == expected_lines + + +def test_shows_correct_range_error(): + source_path = os.path.join("dir_path", "x.yaml") + output_lines = _run_repl_test( + [ + _validate(source_path), + # read_file x.yaml + _file_response("""esphome: + name: test1 +esp8266: + broad: !secret my_secret_board # typo here +"""), + # read_file secrets.yaml + _file_response("""my_secret_board: esp1f"""), + ] + ) + + assert len(output_lines) == 3 + error = json.loads(output_lines[2]) + validation_error = error["validation_errors"][0] + assert validation_error["message"].startswith("[broad] is an invalid option for") + range = validation_error["range"] + assert range["document"] == source_path + assert range["start_line"] == 3 + assert range["start_col"] == 2 + assert range["end_line"] == 3 + assert range["end_col"] == 7 + + +def test_shows_correct_loaded_file_error(): + source_path = os.path.join("dir_path", "x.yaml") + output_lines = _run_repl_test( + [ + _validate(source_path), + # read_file x.yaml + _file_response("""esphome: + name: test1 + +packages: + board: !include .pkg.esp8266.yaml +"""), + # read_file .pkg.esp8266.yaml + _file_response("""esp8266: + broad: esp1f # typo here +"""), + ] + ) + + assert len(output_lines) == 3 + error = json.loads(output_lines[2]) + validation_error = error["validation_errors"][0] + assert validation_error["message"].startswith("[broad] is an invalid option for") + range = validation_error["range"] + assert range["document"] == os.path.join("dir_path", ".pkg.esp8266.yaml") + assert range["start_line"] == 1 + assert range["start_col"] == 2 + assert range["end_line"] == 1 + assert range["end_col"] == 7 diff --git a/tests/unit_tests/test_wizard.py b/tests/unit_tests/test_wizard.py index 9260629ec3d..6d360740f4a 100644 --- a/tests/unit_tests/test_wizard.py +++ b/tests/unit_tests/test_wizard.py @@ -1,16 +1,17 @@ """Tests for the wizard.py file.""" import os - -import esphome.wizard as wz -import pytest -from esphome.core import CORE -from esphome.components.esp8266.boards import ESP8266_BOARD_PINS -from esphome.components.esp32.boards import ESP32_BOARD_PINS -from esphome.components.bk72xx.boards import BK72XX_BOARD_PINS -from esphome.components.rtl87xx.boards import RTL87XX_BOARD_PINS from unittest.mock import MagicMock +import pytest + +from esphome.components.bk72xx.boards import BK72XX_BOARD_PINS +from esphome.components.esp32.boards import ESP32_BOARD_PINS +from esphome.components.esp8266.boards import ESP8266_BOARD_PINS +from esphome.components.rtl87xx.boards import RTL87XX_BOARD_PINS +from esphome.core import CORE +import esphome.wizard as wz + @pytest.fixture def default_config(): diff --git a/tests/unit_tests/test_yaml_util.py b/tests/unit_tests/test_yaml_util.py index 828b2bf14b4..f31e9554dc1 100644 --- a/tests/unit_tests/test_yaml_util.py +++ b/tests/unit_tests/test_yaml_util.py @@ -42,3 +42,23 @@ def test_loading_a_missing_file(fixture_path): yaml_util.load_yaml(yaml_file) except EsphomeError as err: assert "missing.yaml" in str(err) + + +def test_parsing_with_custom_loader(fixture_path): + """Test custom loader used for vscode connection + Default loader is tested in test_include_with_vars + """ + yaml_file = fixture_path / "yaml_util" / "includetest.yaml" + + loader_calls = [] + + def custom_loader(fname): + loader_calls.append(fname) + + with open(yaml_file, encoding="utf-8") as f_handle: + yaml_util.parse_yaml(yaml_file, f_handle, custom_loader) + + assert len(loader_calls) == 3 + assert loader_calls[0].endswith("includes/included.yaml") + assert loader_calls[1].endswith("includes/list.yaml") + assert loader_calls[2].endswith("includes/scalar.yaml")