diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index a8ca63d158..0000000000 --- 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 6eb557a514..3ac91f8ea2 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 d06d8a8eec..233fb64693 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 283b6edaeb..0a08e6ffad 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 6b7220d011..91c40d37c4 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 3cc668c113..7793c574fe 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 52adcefc32..0a0c834a71 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 667a8f2e8b..d11aa067bf 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 204d2b58bd..f6f7ac6f9c 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 b91a3b4f83..f32d9dafbf 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 ee375ba690..117ec17ae4 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 3fc787d485..31f98c4614 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 43b5504704..0d9662bfd6 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) @@ -397,7 +397,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 +842,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 +864,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 +893,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 b57daa0357..e5f4f7ef30 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 d491a51be9..f0bc59ae6c 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 744e9dc1cc..97f5a6fe0f 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 f2b075f4d9..62a2c8ab7c 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 c39fc382b6..5e24779510 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 919ffecbea..5e122676cd 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 c4e9d5831e..a5281aacc7 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 640a1b628e..a65ae9d537 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 327ec8296a..929d45121c 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 e075adb04c..3ef5e6bfff 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 af3f629ca8..42b6c8ba24 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 e52a44eced..4b55acdafa 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 5f9682c711..dce021daad 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 a463d8390d..6d52fc83fd 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 f346a71198..afb70d07c8 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 f8d51101a6..128e0d0701 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 4e89115447..33bfe97789 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 59aebd636b..8f0f372951 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 31b07c0e73..a5b1cf0ffb 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 ca94069703..eae400ab39 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 d9b97f1c8d..6a29683ced 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 0f4fd1a13a..f231be6670 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 d28c7e2abc..e0e90735f0 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 55a5d7c620..361e1d101f 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/sensor.py b/esphome/components/am2315c/sensor.py index f3201b05a2..ec12ab717e 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 ccd37d02c2..ed4a5fd922 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 103ac809e6..d60f9cd4e7 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 df068546cd..4b3e1716a4 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 7b964dfae6..775b3e6bbf 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 bdd77d6a33..052296294b 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 25b301444f..c3cba96fbf 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 06b3c85aee..99e37d3764 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 46b08d8d69..48e923ab2b 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 c9865f8687..468eb0995f 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 62f375508c..9e1b1521dd 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -893,8 +893,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 2ec7c50859..70015c53b9 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 3081d2115f..10004e69dc 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 ff78b8a050..79bc7af4a9 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 aa741b2ea6..09b588cb0c 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 849539f092..f4cf07a906 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 feeae107a7..1a437a68a2 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 30337ab61b..cfc38d796d 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 de60444aed..2832b7c3df 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 e636510a4b..117ada123d 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 c441b381a3..8e1b82b356 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 e86afa500d..5286d29d1b 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/b_parasite/sensor.py b/esphome/components/b_parasite/sensor.py index 86eef29b14..041303ad8b 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 82e9fead1e..416fa250cc 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 9dde0ae1ac..6511270f60 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 a4b8a50eab..d4bf813846 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 e454b0922b..7ba3e439b2 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 06e81ea979..fdf0636153 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 756b31de53..fa9ca7953e 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 2a1aa05c79..31572cd800 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 69778f49ce..7c7eecb88c 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 73d6b9339f..a504ef642c 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 49227ccadc..ebb22f4409 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 1181905f30..965e332e28 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 2a85b34567..bd4bdd93e5 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 5cb1472d76..f49e961f0a 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 bc7d517695..37f8ea32b3 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 960410a5cc..0975640ece 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 a6672e68f5..afa60f6c0c 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 5a4ba36666..04ac9116c7 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 6a5f7e1127..c37191bc07 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 f3007ebaac..1c37033613 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 33a12318a5..7f4fb5cf44 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 586b454697..5937ac6ad8 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 743ef6e85d..8ee463a59a 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 aa96998232..5107b0bfcd 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 6b46e501da..1fbb9e2aeb 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 baf185f95a..cc4037c1ee 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 83f5a0c821..6e51984e1f 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 c0f9af9dd7..d612920dd4 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 991bb827a3..3ff556d51a 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 511d45b24e..b3678ec01d 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 589d170907..c31db31761 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 ae59d29e89..6fed9fc9ee 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 3d1acd3c1b..22aab71977 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 1e0350075a..e2790f83b9 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 8388b16df9..dc80c67b44 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 3b89518621..023b6ecd1e 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 eeeab2a1bd..af78b38ef5 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 d0083fb33f..9adf13de55 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 76e77021ad..6867177795 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 73b86cba87..696cfff2b7 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 f22e6d6c9e..cde9dd46ae 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 7950774340..b7af53638a 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 a90ea14c4e..ea11e733ac 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 66d9274fe8..10565cb328 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 d57061b710..9b69576b43 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 3eee34b85e..dceaf6f371 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 c7c286d679..d8be61397e 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 c58e40f7f4..76d4c00baf 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 609d416a0b..c3381cfd70 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 3e7a0e73ae..045ab265cd 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 fad0277061..f5255fec03 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 2cfd1912e5..339e7de906 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 1b6836fae7..840200409f 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 626a5a8db1..8028d6a217 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 155e22883b..7db9034d02 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 22672c02d8..04872fb029 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 d19e4a5807..ddedea64c0 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 204518da39..3e2bbf2aae 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 6254ed03e1..d7ddc52c44 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 8e78cda7c7..57ca06aca7 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 beffbe7fbb..ee27e38c5f 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 7593789250..aa39225bc2 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 5b59f21319..7b38ff1a64 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 d8219e1df1..07b5ea1c63 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 c5ec3e5b71..7e8caf1ae1 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 b5b11a661e..6572a914aa 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 76975ffe78..62c2e3b20a 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 18ea5877d2..6ad7990e80 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 1fa4eaa03f..75f083ef14 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 c88a6b0054..50d84a582d 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 b6cd2b384e..842c84832e 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 f41e5c2422..cb7739242c 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 af60b17448..3946513191 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 51f253e9cb..967d080c24 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 7a5bd9b14d..aacac408ca 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 ab14a9afd5..3d35881722 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 669d40a68d..87f00ce507 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 724f19315b..95a2ae3b44 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 6d78946a02..560bcef64e 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 fcd5ee531b..9f4e2df85a 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 b1b22b816b..acaadab544 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 061c2750e4..0a23658907 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 24f938a0e2..96ef231850 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 fd7ef6fcce..63b359bd5b 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 614706defe..0d3bb76c98 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 05160bf8cb..349bd8e4cb 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 c37c9999aa..53ebda6bcc 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 39787ca66b..8c9438dccb 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 2fd0510476..193ef925a4 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 b1c35d27ac..f854d08398 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 be53df2625..d907495ba2 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 ae2173ef22..eb93cbae2c 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 742c873d9e..b2a98e5bab 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 ddc2939038..42b7184db9 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 9f56dc3465..017a11673f 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 f2398d1908..0696fccdf7 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 7c13fe7d58..3223d943be 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 3dcdf7a818..37c889cd85 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 556cd459a5..1907b3fcfe 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 cec0bdf4fa..301812e314 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 d06f9ca02f..0f8f44c8a2 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 c1fefb7f09..7d946fdcb9 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 8012d3e897..323195e99a 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 461ef73de1..586f0800a6 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 10ea3dfae6..b6a2c8a333 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 36585061e6..b925f4b61e 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 9f3cd395a5..286c876ff6 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 eb6d0880af..28e77e322b 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 96cbbaa7e9..cad4e81afc 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 552697fe1b..1bda05c7bb 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 3037156e01..289a559673 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 23b84f3d13..912a8bf94b 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 425ce54b9f..68be2cbbe9 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 2f1f9b90bb..e55c54f097 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 d8afea27b4..363218bbac 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 37bdfa3962..dfa98b2eff 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 5a45859b1f..a40f493075 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 b3086f9a48..416f037083 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 c80780986f..cf4f12c46d 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 0c94224ef8..e7953d4b3d 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 fc7bf200e4..224e301683 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 e9322b3080..75560d71b1 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 7feee79ff2..1404ef8ac3 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 ab760a9b6c..cd77ea6053 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 08f5fa6642..68a6e617fc 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 94eed886e5..2e67694bbd 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 9c28552267..ab7416a264 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 f4432a0362..a09217fd21 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 486ba0126e..cf240faec3 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 87cda41f89..c1f72bb05d 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 582eb7af25..a81b6c09f0 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 737985f4c5..a0473b292c 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 f8f133e316..afae1e5188 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 010691ac7f..61df5f297b 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 3cc19a35a3..17f4587e5d 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 62de036e62..1e70e14f10 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 dc456d4959..49a6d390be 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 b3ce1722ee..ac30721eb4 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 450eb967b1..b90374f6e8 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 23651bd049..115b89433b 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 8572919e36..5b8441ddfe 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 ed4e431dcc..d1655a6be1 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 0c50f52979..a168a36c31 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 4ceb50c709..e94791da4e 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 95fa371433..7615b3046f 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 427721f2db..6d2e46512e 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 5bcdc572ff..ec26447ccb 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 0d90257964..878f27bc44 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 2a3d6f07eb..a80487977f 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 f782264615..d04e0b8367 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 8defa4ac24..e4bce99b0b 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 7e1bd277a6..4ff8a38226 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 a7a2b46f58..96f1807688 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 7f17faa1b1..dc57833f4a 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 786c3f4b96..23f2781095 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 2166e92083..e2bb94dd66 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 2fa9f4dc78..786e04bac0 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 9da6870a46..604de6d809 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 d4cf79b49e..51288ccc30 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 1dae22a2b2..bdeeb86e00 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 0b83b71fe4..254294619e 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 7db0198a89..869c05387f 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 0db15ae53e..19f3adfd0e 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 18f5c49dbd..941b7bb847 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 3a4935b22d..2486b63155 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 745ad95fb6..28bb5045c3 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 23c1d6f008..e9025b560e 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 6076cb0bd5..acff0cf265 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 d28c5a8c0e..67f9fe1224 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 66b72f9e3e..532315a1d1 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 424e944290..4309a64359 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 fe5c3e9845..65dd3196df 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 39727f7159..e47a88545b 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 fd4c746016..a483d2a571 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 598071590b..612b0d6123 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 94b34eb955..0988d63995 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 33532230df..74f3c2fa14 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 2687edaca2..201ea4451f 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 27af0b5b6b..5eb1773518 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 f2decea150..96d0313008 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 0040988794..62cb96a25a 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 f5a6ad2398..93ae2b6056 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 ed8bff6e9b..25d03d31a6 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 c38a380127..2708e5d423 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 76a88d98a1..d9a2f1207c 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 a78ae574b1..d335d76dfa 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 8bd6160038..7eef641c4a 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 0ef1fc2348..a3f6d5840c 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 356afa1432..f1b282d891 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 bf0b9a23fb..a578670e37 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 fe53aa376e..638a8d77c5 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 88a0bb85b7..a5d11e9241 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 776be8a5d8..f899ce71ce 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 fb2099c85e..f81703c087 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 2ec2836461..22364ce854 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 e145ba56f8..531c363bd1 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 dfa69ecadd..2882729b1e 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 51c5b283b7..d3306fd0f8 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 020be9bc6e..621fd62e82 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 0accc58c00..2a7b3fc212 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 732d15d9ca..b98b4ce6cb 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 35b5baa83e..7c3d3c8899 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 57ddcef17a..1a470aa628 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 e7ae51d516..3ebe2cac73 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 9c42ecbb9d..acf7d7cdf0 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 cdd0b5ade5..b446c9f1e2 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 8fe7f7d41d..56d20508ec 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 d57f909662..3c04a338dd 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 809d7a40b9..9bfa3739c8 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 db3232c4b0..ac9219ff6a 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 682cf06570..214724aa3f 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 c9024e4a2b..fb37ac2c8d 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 fd142b3cd7..5750812f5c 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 082a055701..4f6cb7d091 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 96c874fa5c..96b6334730 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 693211c6fe..bf1072ce66 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 bfef402058..caa73194c9 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 b57a4a0f6c..3f3162e31e 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 5d9dd7adba..410c7f81b7 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 2b30b65f46..c58b9a4017 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 e00ab93be2..d2938754e9 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 34b18e8bdd..4cb50d707b 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 557b226dfe..1f9c50db1f 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 6c34a85ac6..686afdef14 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 83361db58a..38de1799cc 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 096cb5f67a..aecad606be 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 d64472a7d3..5a021d9163 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 c701423081..71a5fa13e4 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 43e22d0348..5ebc4a9f63 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 df774ad7bc..dfeb121c91 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 4ae08356fc..1558243cc2 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 554bd4147d..6ccc00b41c 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 6a67d1fc41..e39ca99ae1 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 b6d8c7c0e4..14d982e5fb 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 37f68a8f3e..442fdaa125 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 32c68f8d24..2133c4daf9 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 df10ee7229..fa33fb6c02 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 e74bc8f129..1eb4869da3 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 4e96dda663..802b341601 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 17f7262785..93687846e2 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 62c3edf8cb..579adb9051 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 153d1b3ad1..adaf669a72 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 e9a5264941..27263d0bff 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 22571c2550..30fa58c380 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 168fc03cb7..b0979b2848 100644 --- a/esphome/components/lvgl/automation.py +++ b/esphome/components/lvgl/automation.py @@ -17,6 +17,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 +33,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 ( diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 56a5a4b9e4..7dedb55418 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/lv_validation.py b/esphome/components/lvgl/lv_validation.py index f91ed893f2..a3b7cc8ed3 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 6b98cc4251..c8d744dfc8 100644 --- a/esphome/components/lvgl/lvcode.py +++ b/esphome/components/lvgl/lvcode.py @@ -206,11 +206,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 +290,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 69fa808d53..8ffdbf1eda 100644 --- a/esphome/components/lvgl/lvgl_esphome.h +++ b/esphome/components/lvgl/lvgl_esphome.h @@ -63,6 +63,11 @@ 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); } +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); +} + #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 +95,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 +336,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/schemas.py b/esphome/components/lvgl/schemas.py index ae50d5b2e1..c05dfae8c7 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 @@ -85,6 +87,31 @@ ENCODER_SCHEMA = cv.Schema( } ) +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 +130,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 +145,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 +175,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 +200,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 +219,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 +259,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 +360,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/styles.py b/esphome/components/lvgl/styles.py index 6332e0976f..b59ff513e2 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 b76f90fecd..283c9a5e56 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 e946a96000..ccad45bdc6 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/canvas.py b/esphome/components/lvgl/widgets/canvas.py new file mode 100644 index 0000000000..bc26558624 --- /dev/null +++ b/esphome/components/lvgl/widgets/canvas.py @@ -0,0 +1,403 @@ +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) + + +@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) + + +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) + + +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 0156fb1780..94fdfe2346 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/m5stack_8angle/__init__.py b/esphome/components/m5stack_8angle/__init__.py index 1aaa86a6fd..a1c197b381 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 a8b2690083..22ab73e901 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 07384ecd61..806ecaabf4 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 70744a59e6..2132eaa4c2 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 edebf7b772..8e63ed43ce 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 0cdedb5464..93e48beee0 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 704f945171..d4498b062f 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 498cccb77b..5aea7f0be2 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 23fc86d2c2..e42abb68d1 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 bb71dba8bf..0d2ff527c7 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 1caf8c8a44..352ba04a95 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 13807b0dbd..c9d10f3c45 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 779e385ab1..582d11bf4f 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 246d332a86..8405a3f75a 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 a534c9f87f..ed48eb06a6 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 55722e3ae0..e15c643349 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 42fc37dd1d..33b8a680cf 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 4d3998def8..c6152d58c0 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 9e199f79c4..9a763d09b0 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 1e41a8ddff..c0e44d72de 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 4353cd7bc6..d34a77248c 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 24a48664c1..41ccdd403a 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 8ae00ef29e..e85ce2955d 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 98129fc389..612297f934 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 6a81c6ec84..a4b177cbcf 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 0000000000..1764629ff3 --- /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 0000000000..5393241281 --- /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 0000000000..9b7f60f201 --- /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 0000000000..ba59f97643 --- /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 0000000000..2d85a5df61 --- /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 0000000000..4055cef30a --- /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 8f8b80d927..5ec6a9d686 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 a0702c415c..da3244be84 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 20b196ca2c..6f4a41510f 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 60235107e9..ebd597cfeb 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 2d7874fe20..ba6718ca56 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 3956727981..10428b1e4a 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 bd253f8ebd..31abc11abf 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 442f69c08b..813d24efef 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 7124bf50d0..b0eeaf8dd1 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 32e42f3888..ceb4a9ef77 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 9846d46cc6..43e5c9d844 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 dc27c4f32c..474c30e13b 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 d99500bbed..4e5471b117 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 b7fef5e1ab..1d3cac66ba 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 8fea6b192b..21fa5f4f56 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 5e865c636f..23f8ed21fa 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 3e90d19e45..6a34c4bdc0 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 cf16132470..3223225271 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 e3f4209cf9..aaff2946f2 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 ae0c818c28..2bd85c6121 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 2a08075831..61b60498d0 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 8f13f58f89..4ce0202d25 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 c89eae7933..c8648cbc63 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 95ade53013..4e84fb708c 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 ac745cf3d5..d4535d9671 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 68ed0e08a8..b2cd1fb535 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 1f8e804e88..b736a7e4f0 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 dfae92a9af..1252a65a84 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 f9b61dcadc..377958fbe7 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 535007d008..580fad7c23 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 6fe0c48ae0..56efb3f67e 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 5b5c0ae17f..9c5d3a81eb 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 5decb13436..168ca0c5c8 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 1113e14af2..7ed7c61750 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 58419450cd..e5a879a0f0 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 a3c16fd49a..b4fad82c5f 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 ea6c0258af..d7149e5697 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 3b0372aa89..17e426ccc6 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 4059d040d0..5a00fa2804 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 9bd9215936..affeb2de8f 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 a257587e13..7ef72c6491 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 1058c2a04b..9802762ff3 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 de1a061478..1974ff3b9e 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 793397b1f4..8fc0a8ceaf 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 2025cb5d9e..7f4e8e6488 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 bd5f4a1841..d47052cac6 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 42b476eb87..8cbee1eed2 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 7897747be1..c5814f74e2 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 bbf3e87586..00aa62483c 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 3a53c9d4f4..87307eb051 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 a58de8e2da..791ba215e0 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 94ec25e36c..ead086d24b 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 055cbfa827..2b80e59f7b 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 726d1ac084..78bfa045e1 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 c31865ccfb..1d14fa5755 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 3be2cb09aa..c9bdba0f75 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 f5325643a7..e896b183ca 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 8e45915cf3..58de1183ff 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 93be148169..da6c4623c9 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 da31dbd9d9..05713cccda 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 b22577bf9f..50f58cdfb9 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 b7681f9ba0..302c2f78c0 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 67ec230b5f..f3c0c3230f 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 2e6456a72d..e3b3b572aa 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 ebf112b85b..64bef86443 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 2c4ef688a5..aab7ee5c00 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 d1c65dfb39..4547f4d708 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 875de05713..1e4ea8492b 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 f4b34fd594..625c232ed5 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 b518d485e7..1eb7249119 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 3a6f94d6ac..0d00ba0083 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 80bcdad62e..11dbc91110 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 856352f8cb..90ce3a7e55 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 2df9edbf45..c693cfea19 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 ef620614a2..2a5b9eeac0 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 08ccd6096e..1556b3c983 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 81be327d14..d42338ab6f 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 cdcaf4267c..3f04e8e1cc 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 f7b8743967..7304f1b8ad 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 8a8ab1b175..67ebc88872 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 e3589ea449..131b56e30e 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 5f48a0f3cb..00a19ba03c 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 b102b38f98..899ecd595e 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 87c4719ca8..f8f8ebef98 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 ae1235655a..5498d0ac1b 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 01b541e4b5..851c136493 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 5b63710c6a..b899fe7642 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 796957c315..f268d5747f 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 d9a5bd101f..f592ada246 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 27364a34b3..b330758000 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 59ffa58c21..ca026eefa4 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 47d70166d3..120dc33b7b 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 70c568c1e3..0cf27b9f1c 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 aa4fc89727..da57c65341 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 197f7e7904..82b98654a2 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 a1477c627f..716cc1001a 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 d6ccc678f8..15741ea9d1 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 70dec82c3f..51b1ab2d80 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 ab7dd3e202..3af73b8695 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 097b1c1cfd..383a9dbb2c 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 341c0c3f8a..ade286cb9e 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 fdcfd4e66b..05eb7efa27 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 855db86335..1c5e0471b0 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 ab6dd66cf2..8c29991f37 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 380c93c400..fda6300d16 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 2c555f115e..f35f0e519c 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 360f8b506a..0a549ccb32 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 ffe434d19b..01910c81a8 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 a9667869b8..da04328218 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 1a1e641623..ce0d408c04 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 e42817352c..7c42a12429 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 77b0a99662..9ce94d7f31 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 f57eaaad6a..cbc54ad02b 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 cd808b92cc..7eb20b1302 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 3622799a07..1cb3c6020c 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 6aff8cb351..76757f7504 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 89805b4246..e9283c9e41 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 228e7d882b..5ccca823de 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 3d07855b8e..b6daaaaa3c 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 0565057316..dcd14310e3 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 f747580f61..84425c23c2 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 35f77b154b..882ab0cdbc 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 ae6b0ae3bf..645b4a81c5 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 af884d5ac2..4bd46731df 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 8dd2549ad4..4b6a80e78b 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 8f2972d4a0..ac1892fa29 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 10f1313408..0abd51a6f1 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 1e3fb4b003..13d49d3cfe 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 a46daf88ac..af262b2950 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 185c0e70b1..991747b089 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 5662db8f7e..0731ca50f5 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 7271358149..d656eee84a 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 cee8cc7b71..83fb9738ec 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 13027b6f88..f050c3ec34 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 16b1d4c54e..ee1f6a4ad0 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 18dc570f88..66709cc834 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 d6c0ed1c03..9f84f91c72 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 4f439ac506..24ae32c7bc 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 60608818a2..67f3f9561f 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 456d47ee91..ae1cc58a95 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 52b971e7e4..e80470bde1 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 003db9f4a3..26de1e4ac1 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 59372e4100..1e68d7e071 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 2055fc548c..4de3654e39 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 7da83627b9..14854f0795 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 d5eb09e265..7b20941aa4 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 bbf5391a57..741e7de3ca 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 aa50f577d4..fadd9c6dbc 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 ae9e1c23e6..99940ebf6d 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 916d4b4ba2..d7f667d862 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 1415dc27ca..8236248b8c 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 a6f9eeb920..2fea150cd2 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 e698255c25..069b61af5a 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 ee613dc440..e1c1d4e94b 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 fb1dc19278..52cecbfb69 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 d423793873..cd6d85c12b 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 b27f37099d..5d9424d1e7 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 7147828a07..2fee2840a5 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 428f6b874b..8e8a57e341 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 b7cec542bf..9317187df3 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 625784427f..bb2c3ceee8 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 1286489b29..7ad34972d4 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 e195bb9acc..871956f783 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 c8b56cfe30..bb83ee4482 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 79d0b23935..3423b40089 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 5de9f2d189..12cc477647 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 49ac9e685a..ca5b7a53e0 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 faa6cefe27..2ca9127d3f 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 f046d031ea..1cf0b4e1b8 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 156bd6a040..010e325df4 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 9cce35254b..73807ba377 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 8722bd35a9..81e7c04c0e 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 ec8ed722f3..e97bc440f4 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 e9b92f68f8..50f6ec759f 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 52128f1f24..28c92a42a7 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 5cd969c6a5..71c4af2253 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 ae6cb336ad..1b18a1d342 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 c4f63b451a..2a9698d645 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 6d6e0e311c..02a6d1f697 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 52b6321db1..ef7fec7307 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 0c3c54f200..60c9ccc40d 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 8bcfb69a45..936efd8561 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 a1fcc5e7ae..164a31f8a7 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/text_sensor/__init__.py b/esphome/components/sml/text_sensor/__init__.py index 81564bf65b..401db9c582 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 33eb78b841..ea42499379 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 0f2abd3678..f2ba5fedd1 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 2fd49f6824..db18b00cd1 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 19952aeece..77e8fe51f6 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 8ffe60224e..06cde45cd6 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/speed/fan/__init__.py b/esphome/components/speed/fan/__init__.py index 5fbf011669..fe43ac6a3a 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 3e6d680b89..5b28b3546b 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 64463747a2..378d95e7b9 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 55680f72d3..a78da2cd9a 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 e5bcf681f4..2c59309b1f 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 0f01bab514..d4f91b4188 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 c51ab5f93e..2ac0093ef1 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 471c874986..3569bbe957 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 e66cfbc684..12cbd883a0 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 7f2259cf32..d0ec2410e6 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 7b581cc92c..95de1c2979 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 80162979fc..144a95a29f 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 150d89afed..fc03083ad0 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 7ce50fd99f..6f93172a1a 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 fa92d652d7..bd62b3b382 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 1267e2ad63..de7b2247dd 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 3623338aec..39188c6b81 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 adc342ed4d..c1a4a52ce2 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 92869ee630..b299ae7ff7 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 d6a4a245e6..f8d03a3b4f 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 f2367fd62a..66fe88c6c4 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 a99503a2b8..7b04bd58bb 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 fa52200d46..41e49f70db 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 d00a00661a..5a2a39c427 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 10c0237327..a356d9cca8 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 80737bb9f2..fc733d3435 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 f4d46fade7..d073c16e4e 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 6d1be9c740..d8c59bf1de 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 d9d3e3ca66..f74f89b3b4 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 e4f79dc2bc..b1702b5ade 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 280b5ad90c..0ceca77a5d 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 7afea0fbf8..9e2db7bb10 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 71a099d635..6df40497a9 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 0f222b8fc7..cef779de2e 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 9facd6b8db..9cd193f5c7 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 d47e9a34c8..34b6c579b6 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 329fc724bd..db8e8d9268 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 e289e42c81..87c7b9e85c 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 ff2d81c95e..b436c70120 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 df8e4c21fc..79fabd10d0 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 5cd27433d0..508dc1bcd4 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 3555f2fafd..0f213857dc 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 43d0be99b4..5129e6b1af 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 746ab8a6f3..813d351fd9 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 2a948cfdfd..cf9c7f4c3d 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 348ebd281f..c885866d40 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 24709ff4f2..2dcb90e038 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 c6ed25adda..2f4c9cbffe 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 b42a4be166..2a37fccdbe 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 75dbd4f5c5..3282092d63 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 9ed7a83848..2c325427e9 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 a221cbaa60..e86657510f 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 f73b240197..b0fea38aaf 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 9bd603bbca..550b27356d 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 89d776dfdd..12e5174168 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 2b9a95c6bd..11e39e8f67 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 a17168ae6f..401798a568 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 a14a08ccad..c723345370 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 419fa397b7..b685423787 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 ac45909673..a2f4f16554 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 528d690fab..20e53893aa 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 1b5dff1854..a1290add81 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 0ff2a5d176..b09924c3d3 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 9fe7b18294..ae000ae0a9 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 a82b680f62..f521af2842 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 f14b9bd018..817231627a 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 dcbc64332a..141ee5a39f 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 4ef8842571..153cc690e7 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 2cb1a6d1f5..862d526ccf 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 25ec350b7a..bedeef8e3c 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 82d099cf12..e906fe0aee 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 21d6d48659..d3aeaa814f 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 f1cfe09a05..627ae6b63d 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 3f2c644c87..54582b78a9 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 45e9c03c1d..f026dc9530 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 fb2c00697b..cd4b88e740 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 5435ed4b62..0df3fa6687 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 d5423a01b2..f79eff0e01 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 510ca2df3a..9466dcdaa5 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 9c8208df83..fa1938723d 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 8a0c7fce48..178ad4f037 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 cba41a7938..412233a6bd 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 5fba0096de..07f00df4b4 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 0738f9b6a4..2cc60e225c 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 856b5eb323..767d1c636e 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 363e7c764b..371c599ef7 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 2dd66f814d..61029b6daa 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 4832fd8638..c732bdaf31 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 d806060018..1d2286e3c7 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 c00ea08d23..bd57c8be14 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 dc78b2c3db..a34e279746 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 69711204a8..861bbc656a 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 b4ec53ec59..e9987050cb 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 bc60369377..3bae109b93 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 f8a0b08d99..4f1582072e 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 0738a127e1..bee037774f 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 05909516a0..5b811de07d 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 8853a61ae3..b25e070461 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 8f4359d6af..e57a1155a4 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 88252ead73..b57d7ffb92 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 afbd1128c2..937d9a5261 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 35c4c4cecd..d4102d1026 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 0becec2624..5aeb521fb1 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 99a473a3dc..d916d7c064 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 70fbda2d1f..ae927656c0 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 2b89da6d32..fcff698ac0 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 79ba510e41..862fac302f 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 308f1c1c00..6ad2eb417f 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 c8774bb322..ba8c493d4b 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 7b485e3887..8055d5ff77 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 115f521d04..f50ee59b9c 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 a84d9bb663..73c51f8cb5 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 4248c48e35..4c8f7e700d 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 c5b953c46f..40c6053349 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 1d576344e6..ae21c64e9b 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 7344558659..02c4862e8d 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 85703d24b3..4c9d601eee 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 51614a1a28..e48678f5bf 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 912ab04236..903fe8fe4f 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 02c5fd9604..debc84f6d8 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 93a8161e8e..32fd4882db 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 8861a6738c..123ce0bb8b 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 98eca56c4d..a52aa30cc9 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 447805375d..616ba75c59 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 fd4d717b31..0ef32cbc96 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 bfeca87c22..8c9bea5416 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 1373df77f4..d10627ab64 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 396d5891d8..fb20a03010 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 4497994982..0cc850b856 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 3e381aaa61..74cef3bf7b 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 046adc6248..541a0e7894 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 5b88121d7c..e11ddac19d 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 ac487d87fc..c7ec13f6e0 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 a4f9a39aff..1a6ed2b7da 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 1b878ca800..2f71a11b28 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 4154b64233..6c9ad2e361 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 535316e246..90a8753412 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 4f77fa8103..d6a4a4adb2 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 82ee12d8d1..adc64f6650 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 f4d2b342fd..5890ed6b63 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 20629a0a9c..ef6aebe6c0 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 43784ef698..813429a6c5 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 b2784e58fc..bf2de3756c 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 80f24ac0ef..5d964ea22a 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 18f5ad7764..86c4d6699f 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 9e92e34230..7161e88da5 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 a2a2f3bdfc..4aa8d029f8 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 9a4b50df91..312f8b43b1 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 94d85213ff..911d179d8b 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 0c8331db09..df143bac22 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 ef8a472d66..8d0508b59b 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 558e3623e5..e49f1c960b 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 504dff9d66..69facf54ed 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 e6f8b28b46..58ce4a30f8 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 8cafd468ac..eb68d3b6e7 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 1451f8ec69..fc01107e1d 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 c5eed14e64..533bc5cc57 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 28a708b866..58de519283 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/const.py b/esphome/const.py index dab9327a3a..1d7f501c9e 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2025.3.3" +__version__ = "2025.4.0b1" 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/component.cpp b/esphome/core/component.cpp index a6224a17c0..b20964b872 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 a6bd8f81ac..f5c56459b1 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 f2b8585143..72e9f6a65c 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 7bc84a22dc..64de41f23a 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 439bb2ccb0..36bc7f949b 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 012c9af3c6..7e83b3b705 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 44a58f37f5..872a8bd6f6 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 70eb0b58b5..c3e4883849 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/pyproject.toml b/pyproject.toml index 69b36cd14a..77dcaf1fab 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 46746b08cf..0ee928569b 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 +aioesphomeapi==29.9.0 +zeroconf==0.146.3 +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 1a98a15ab2..d77ccaff69 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 d836efc148..e43df6703f 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 a2bc3abf64..7771922697 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 07093e179a..7152e23e8f 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 51705f955b..a857274b01 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 57121266be..b03f5f19d3 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 aa564ed7b1..7aa7dfe698 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 0000000000..5e84f4a678 --- /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 0000000000..bf01b65b6f --- /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 0000000000..bf01b65b6f --- /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 0000000000..6c27bd35d0 --- /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 0000000000..6c27bd35d0 --- /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 dade44d145..070fffd68b 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 dade44d145..070fffd68b 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 dade44d145..5e09f5020e 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 dade44d145..5e09f5020e 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 0000000000..05954e37d7 --- /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 0000000000..a991f7e15a --- /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 0000000000..a991f7e15a --- /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 0000000000..dade44d145 --- /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 0000000000..dade44d145 --- /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 0000000000..dade44d145 --- /dev/null +++ b/tests/components/esphome/test.rp2040-ard.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index c527f51b1e..78c261c01d 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 diff --git a/tests/components/mcp4461/common.yaml b/tests/components/mcp4461/common.yaml new file mode 100644 index 0000000000..ce1866fdb8 --- /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 0000000000..c5deb7ca0a --- /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 0000000000..a87353b78b --- /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 0000000000..a87353b78b --- /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 0000000000..c5deb7ca0a --- /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 0000000000..a87353b78b --- /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 0000000000..b516342f3b --- /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 cfd39f77fe..9c6e3f2a60 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 dade44d145..cfd39f77fe 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 dade44d145..e0e7fb52f6 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 d394c5d7a4..061e3dd44a 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 d61c4a442a..955869b799 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 497b3966fb..2618803fec 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 26ebdcf6af..862320b09e 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_wizard.py b/tests/unit_tests/test_wizard.py index 9260629ec3..6d360740f4 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():