mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 09:25:09 +08:00
@@ -57,14 +57,6 @@ runs:
|
|||||||
digest="${{ steps.build-ghcr.outputs.digest }}"
|
digest="${{ steps.build-ghcr.outputs.digest }}"
|
||||||
touch "/tmp/digests/${{ inputs.target }}/ghcr/${digest#sha256:}"
|
touch "/tmp/digests/${{ inputs.target }}/ghcr/${digest#sha256:}"
|
||||||
|
|
||||||
- name: Upload ghcr digest
|
|
||||||
uses: actions/upload-artifact@v3.1.3
|
|
||||||
with:
|
|
||||||
name: digests-${{ inputs.target }}-ghcr
|
|
||||||
path: /tmp/digests/${{ inputs.target }}/ghcr/*
|
|
||||||
if-no-files-found: error
|
|
||||||
retention-days: 1
|
|
||||||
|
|
||||||
- name: Build and push to dockerhub by digest
|
- name: Build and push to dockerhub by digest
|
||||||
id: build-dockerhub
|
id: build-dockerhub
|
||||||
uses: docker/build-push-action@v5.3.0
|
uses: docker/build-push-action@v5.3.0
|
||||||
@@ -87,11 +79,3 @@ runs:
|
|||||||
mkdir -p /tmp/digests/${{ inputs.target }}/dockerhub
|
mkdir -p /tmp/digests/${{ inputs.target }}/dockerhub
|
||||||
digest="${{ steps.build-dockerhub.outputs.digest }}"
|
digest="${{ steps.build-dockerhub.outputs.digest }}"
|
||||||
touch "/tmp/digests/${{ inputs.target }}/dockerhub/${digest#sha256:}"
|
touch "/tmp/digests/${{ inputs.target }}/dockerhub/${digest#sha256:}"
|
||||||
|
|
||||||
- name: Upload dockerhub digest
|
|
||||||
uses: actions/upload-artifact@v3.1.3
|
|
||||||
with:
|
|
||||||
name: digests-${{ inputs.target }}-dockerhub
|
|
||||||
path: /tmp/digests/${{ inputs.target }}/dockerhub/*
|
|
||||||
if-no-files-found: error
|
|
||||||
retention-days: 1
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.1.0
|
uses: actions/setup-python@v5.1.0
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
arch: [amd64, armv7, aarch64]
|
arch: [amd64, armv7, aarch64]
|
||||||
build_type: ["ha-addon", "docker", "lint"]
|
build_type: ["ha-addon", "docker", "lint"]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.1
|
- uses: actions/checkout@v4.1.5
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.1.0
|
uses: actions/setup-python@v5.1.0
|
||||||
with:
|
with:
|
||||||
|
|||||||
+95
-22
@@ -20,7 +20,6 @@ permissions:
|
|||||||
env:
|
env:
|
||||||
DEFAULT_PYTHON: "3.9"
|
DEFAULT_PYTHON: "3.9"
|
||||||
PYUPGRADE_TARGET: "--py39-plus"
|
PYUPGRADE_TARGET: "--py39-plus"
|
||||||
CLANG_FORMAT_VERSION: "13.0.1"
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
# yamllint disable-line rule:line-length
|
# yamllint disable-line rule:line-length
|
||||||
@@ -35,7 +34,7 @@ jobs:
|
|||||||
cache-key: ${{ steps.cache-key.outputs.key }}
|
cache-key: ${{ steps.cache-key.outputs.key }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Generate cache-key
|
- name: Generate cache-key
|
||||||
id: cache-key
|
id: cache-key
|
||||||
run: echo key="${{ hashFiles('requirements.txt', 'requirements_optional.txt', 'requirements_test.txt') }}" >> $GITHUB_OUTPUT
|
run: echo key="${{ hashFiles('requirements.txt', 'requirements_optional.txt', 'requirements_test.txt') }}" >> $GITHUB_OUTPUT
|
||||||
@@ -67,7 +66,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -88,7 +87,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -109,7 +108,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -130,7 +129,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -151,7 +150,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -200,7 +199,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -230,7 +229,7 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -239,7 +238,7 @@ jobs:
|
|||||||
- name: Install clang-format
|
- name: Install clang-format
|
||||||
run: |
|
run: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install clang-format==${{ env.CLANG_FORMAT_VERSION }}
|
pip install clang-format -c requirements_dev.txt
|
||||||
- name: Run clang-format
|
- name: Run clang-format
|
||||||
run: |
|
run: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
@@ -255,7 +254,7 @@ jobs:
|
|||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Find all YAML test files
|
- name: Find all YAML test files
|
||||||
id: set-matrix
|
id: set-matrix
|
||||||
run: echo "matrix=$(ls tests/test*.yaml | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
run: echo "matrix=$(ls tests/test*.yaml | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
||||||
@@ -272,7 +271,7 @@ jobs:
|
|||||||
file: ${{ fromJson(needs.compile-tests-list.outputs.matrix) }}
|
file: ${{ fromJson(needs.compile-tests-list.outputs.matrix) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -304,7 +303,7 @@ jobs:
|
|||||||
file: ${{ fromJson(needs.compile-tests-list.outputs.matrix) }}
|
file: ${{ fromJson(needs.compile-tests-list.outputs.matrix) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -359,7 +358,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -399,10 +398,11 @@ jobs:
|
|||||||
- common
|
- common
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
outputs:
|
outputs:
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
components: ${{ steps.list-components.outputs.components }}
|
||||||
|
count: ${{ steps.list-components.outputs.count }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
with:
|
with:
|
||||||
# Fetch enough history so `git merge-base refs/remotes/origin/dev HEAD` works.
|
# Fetch enough history so `git merge-base refs/remotes/origin/dev HEAD` works.
|
||||||
fetch-depth: 500
|
fetch-depth: 500
|
||||||
@@ -420,10 +420,18 @@ jobs:
|
|||||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||||
- name: Find changed components
|
- name: Find changed components
|
||||||
id: set-matrix
|
id: list-components
|
||||||
run: |
|
run: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
echo "matrix=$(script/list-components.py --changed --branch ${{ steps.target-branch.outputs.branch }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
components=$(script/list-components.py --changed --branch ${{ steps.target-branch.outputs.branch }})
|
||||||
|
output_components=$(echo "$components" | jq -R -s -c 'split("\n")[:-1] | map(select(length > 0))')
|
||||||
|
count=$(echo "$output_components" | jq length)
|
||||||
|
|
||||||
|
echo "components=$output_components" >> $GITHUB_OUTPUT
|
||||||
|
echo "count=$count" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
echo "$count Components:"
|
||||||
|
echo "$output_components" | jq
|
||||||
|
|
||||||
test-build-components:
|
test-build-components:
|
||||||
name: Component test ${{ matrix.file }}
|
name: Component test ${{ matrix.file }}
|
||||||
@@ -431,18 +439,18 @@ jobs:
|
|||||||
needs:
|
needs:
|
||||||
- common
|
- common
|
||||||
- list-components
|
- list-components
|
||||||
if: ${{ github.event_name == 'pull_request' && needs.list-components.outputs.matrix != '[]' && needs.list-components.outputs.matrix != '' }}
|
if: github.event_name == 'pull_request' && fromJSON(needs.list-components.outputs.count) > 0 && fromJSON(needs.list-components.outputs.count) < 100
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 2
|
max-parallel: 2
|
||||||
matrix:
|
matrix:
|
||||||
file: ${{ fromJson(needs.list-components.outputs.matrix) }}
|
file: ${{ fromJson(needs.list-components.outputs.components) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Install libsodium
|
- name: Install libsodium
|
||||||
run: sudo apt-get install libsodium-dev
|
run: sudo apt-get install libsodium-dev
|
||||||
|
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Restore Python
|
- name: Restore Python
|
||||||
uses: ./.github/actions/restore-python
|
uses: ./.github/actions/restore-python
|
||||||
with:
|
with:
|
||||||
@@ -457,6 +465,64 @@ jobs:
|
|||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
./script/test_build_components -e compile -c ${{ matrix.file }}
|
./script/test_build_components -e compile -c ${{ matrix.file }}
|
||||||
|
|
||||||
|
test-build-components-splitter:
|
||||||
|
name: Split components for testing into 20 groups maximum
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- common
|
||||||
|
- list-components
|
||||||
|
if: github.event_name == 'pull_request' && fromJSON(needs.list-components.outputs.count) >= 100
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.split.outputs.components }}
|
||||||
|
steps:
|
||||||
|
- name: Check out code from GitHub
|
||||||
|
uses: actions/checkout@v4.1.5
|
||||||
|
- name: Split components into 20 groups
|
||||||
|
id: split
|
||||||
|
run: |
|
||||||
|
components=$(echo '${{ needs.list-components.outputs.components }}' | jq -c '.[]' | shuf | jq -s -c '[_nwise(20) | join(" ")]')
|
||||||
|
echo "components=$components" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
test-build-components-split:
|
||||||
|
name: Test split components
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- common
|
||||||
|
- list-components
|
||||||
|
- test-build-components-splitter
|
||||||
|
if: github.event_name == 'pull_request' && fromJSON(needs.list-components.outputs.count) >= 100
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
max-parallel: 4
|
||||||
|
matrix:
|
||||||
|
components: ${{ fromJson(needs.test-build-components-splitter.outputs.matrix) }}
|
||||||
|
steps:
|
||||||
|
- name: List components
|
||||||
|
run: echo ${{ matrix.components }}
|
||||||
|
|
||||||
|
- name: Install libsodium
|
||||||
|
run: sudo apt-get install libsodium-dev
|
||||||
|
|
||||||
|
- name: Check out code from GitHub
|
||||||
|
uses: actions/checkout@v4.1.5
|
||||||
|
- name: Restore Python
|
||||||
|
uses: ./.github/actions/restore-python
|
||||||
|
with:
|
||||||
|
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||||
|
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||||
|
- name: Validate config
|
||||||
|
run: |
|
||||||
|
. venv/bin/activate
|
||||||
|
for component in ${{ matrix.components }}; do
|
||||||
|
./script/test_build_components -e config -c $component
|
||||||
|
done
|
||||||
|
- name: Compile config
|
||||||
|
run: |
|
||||||
|
. venv/bin/activate
|
||||||
|
for component in ${{ matrix.components }}; do
|
||||||
|
./script/test_build_components -e compile -c $component
|
||||||
|
done
|
||||||
|
|
||||||
ci-status:
|
ci-status:
|
||||||
name: CI Status
|
name: CI Status
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -471,7 +537,10 @@ jobs:
|
|||||||
- pyupgrade
|
- pyupgrade
|
||||||
- compile-tests
|
- compile-tests
|
||||||
- clang-tidy
|
- clang-tidy
|
||||||
|
- list-components
|
||||||
- test-build-components
|
- test-build-components
|
||||||
|
- test-build-components-splitter
|
||||||
|
- test-build-components-split
|
||||||
if: always()
|
if: always()
|
||||||
steps:
|
steps:
|
||||||
- name: Success
|
- name: Success
|
||||||
@@ -479,4 +548,8 @@ jobs:
|
|||||||
run: exit 0
|
run: exit 0
|
||||||
- name: Failure
|
- name: Failure
|
||||||
if: ${{ contains(needs.*.result, 'failure') }}
|
if: ${{ contains(needs.*.result, 'failure') }}
|
||||||
run: exit 1
|
env:
|
||||||
|
JSON_DOC: ${{ toJSON(needs) }}
|
||||||
|
run: |
|
||||||
|
echo $JSON_DOC | jq
|
||||||
|
exit 1
|
||||||
|
|||||||
@@ -17,14 +17,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
tag: ${{ steps.tag.outputs.tag }}
|
tag: ${{ steps.tag.outputs.tag }}
|
||||||
|
branch_build: ${{ steps.tag.outputs.branch_build }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.1
|
- uses: actions/checkout@v4.1.5
|
||||||
- name: Get tag
|
- name: Get tag
|
||||||
id: tag
|
id: tag
|
||||||
# yamllint disable rule:line-length
|
# yamllint disable rule:line-length
|
||||||
run: |
|
run: |
|
||||||
if [[ "$GITHUB_EVENT_NAME" = "release" ]]; then
|
if [[ "${{ github.event_name }}" = "release" ]]; then
|
||||||
TAG="${GITHUB_REF#refs/tags/}"
|
TAG="${{ github.event.release.tag_name}}"
|
||||||
|
BRANCH_BUILD="false"
|
||||||
else
|
else
|
||||||
TAG=$(cat esphome/const.py | sed -n -E "s/^__version__\s+=\s+\"(.+)\"$/\1/p")
|
TAG=$(cat esphome/const.py | sed -n -E "s/^__version__\s+=\s+\"(.+)\"$/\1/p")
|
||||||
today="$(date --utc '+%Y%m%d')"
|
today="$(date --utc '+%Y%m%d')"
|
||||||
@@ -32,17 +34,24 @@ jobs:
|
|||||||
BRANCH=${GITHUB_REF#refs/heads/}
|
BRANCH=${GITHUB_REF#refs/heads/}
|
||||||
if [[ "$BRANCH" != "dev" ]]; then
|
if [[ "$BRANCH" != "dev" ]]; then
|
||||||
TAG="${TAG}-${BRANCH}"
|
TAG="${TAG}-${BRANCH}"
|
||||||
|
BRANCH_BUILD="true"
|
||||||
|
else
|
||||||
|
BRANCH_BUILD="false"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
||||||
|
echo "branch_build=${BRANCH_BUILD}" >> $GITHUB_OUTPUT
|
||||||
# yamllint enable rule:line-length
|
# yamllint enable rule:line-length
|
||||||
|
|
||||||
deploy-pypi:
|
deploy-pypi:
|
||||||
name: Build and publish to PyPi
|
name: Build and publish to PyPi
|
||||||
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
|
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.1
|
- uses: actions/checkout@v4.1.5
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.1.0
|
uses: actions/setup-python@v5.1.0
|
||||||
with:
|
with:
|
||||||
@@ -50,16 +59,11 @@ jobs:
|
|||||||
- name: Set up python environment
|
- name: Set up python environment
|
||||||
env:
|
env:
|
||||||
ESPHOME_NO_VENV: 1
|
ESPHOME_NO_VENV: 1
|
||||||
run: |
|
run: script/setup
|
||||||
script/setup
|
|
||||||
pip install twine
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: python setup.py sdist bdist_wheel
|
run: python setup.py sdist bdist_wheel
|
||||||
- name: Upload
|
- name: Publish
|
||||||
env:
|
uses: pypa/gh-action-pypi-publish@v1.8.14
|
||||||
TWINE_USERNAME: __token__
|
|
||||||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
|
||||||
run: twine upload dist/*
|
|
||||||
|
|
||||||
deploy-docker:
|
deploy-docker:
|
||||||
name: Build ESPHome ${{ matrix.platform }}
|
name: Build ESPHome ${{ matrix.platform }}
|
||||||
@@ -77,7 +81,7 @@ jobs:
|
|||||||
- linux/arm/v7
|
- linux/arm/v7
|
||||||
- linux/arm64
|
- linux/arm64
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.1
|
- uses: actions/checkout@v4.1.5
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.1.0
|
uses: actions/setup-python@v5.1.0
|
||||||
with:
|
with:
|
||||||
@@ -128,6 +132,19 @@ jobs:
|
|||||||
suffix: lint
|
suffix: lint
|
||||||
version: ${{ needs.init.outputs.tag }}
|
version: ${{ needs.init.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Sanitize platform name
|
||||||
|
id: sanitize
|
||||||
|
run: |
|
||||||
|
echo "${{ matrix.platform }}" | sed 's|/|-|g' > /tmp/platform
|
||||||
|
echo name=$(cat /tmp/platform) >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Upload digests
|
||||||
|
uses: actions/upload-artifact@v4.3.3
|
||||||
|
with:
|
||||||
|
name: digests-${{ steps.sanitize.outputs.name }}
|
||||||
|
path: /tmp/digests
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
deploy-manifest:
|
deploy-manifest:
|
||||||
name: Publish ESPHome ${{ matrix.image.title }} to ${{ matrix.registry }}
|
name: Publish ESPHome ${{ matrix.image.title }} to ${{ matrix.registry }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -155,12 +172,15 @@ jobs:
|
|||||||
- ghcr
|
- ghcr
|
||||||
- dockerhub
|
- dockerhub
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.1
|
- uses: actions/checkout@v4.1.5
|
||||||
|
|
||||||
- name: Download digests
|
- name: Download digests
|
||||||
uses: actions/download-artifact@v3.0.2
|
uses: actions/download-artifact@v4.1.7
|
||||||
with:
|
with:
|
||||||
name: digests-${{ matrix.image.target }}-${{ matrix.registry }}
|
pattern: digests-*
|
||||||
path: /tmp/digests
|
path: /tmp/digests
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3.3.0
|
uses: docker/setup-buildx-action@v3.3.0
|
||||||
|
|
||||||
@@ -191,28 +211,34 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
- name: Create manifest list and push
|
- name: Create manifest list and push
|
||||||
working-directory: /tmp/digests
|
working-directory: /tmp/digests/${{ matrix.image.target }}/${{ matrix.registry }}
|
||||||
run: |
|
run: |
|
||||||
docker buildx imagetools create $(jq -Rcnr 'inputs | . / "," | map("-t " + .) | join(" ")' <<< "${{ steps.tags.outputs.tags}}") \
|
docker buildx imagetools create $(jq -Rcnr 'inputs | . / "," | map("-t " + .) | join(" ")' <<< "${{ steps.tags.outputs.tags}}") \
|
||||||
$(printf '${{ steps.tags.outputs.image }}@sha256:%s ' *)
|
$(printf '${{ steps.tags.outputs.image }}@sha256:%s ' *)
|
||||||
|
|
||||||
deploy-ha-addon-repo:
|
deploy-ha-addon-repo:
|
||||||
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
|
if: github.repository == 'esphome/esphome' && needs.init.outputs.branch_build == 'false'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [deploy-manifest]
|
needs:
|
||||||
|
- init
|
||||||
|
- deploy-manifest
|
||||||
steps:
|
steps:
|
||||||
- name: Trigger Workflow
|
- name: Trigger Workflow
|
||||||
uses: actions/github-script@v7.0.1
|
uses: actions/github-script@v7.0.1
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
|
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
let description = "ESPHome";
|
||||||
|
if (context.eventName == "release") {
|
||||||
|
description = ${{ toJSON(github.event.release.body) }};
|
||||||
|
}
|
||||||
github.rest.actions.createWorkflowDispatch({
|
github.rest.actions.createWorkflowDispatch({
|
||||||
owner: "esphome",
|
owner: "esphome",
|
||||||
repo: "home-assistant-addon",
|
repo: "home-assistant-addon",
|
||||||
workflow_id: "bump-version.yml",
|
workflow_id: "bump-version.yml",
|
||||||
ref: "main",
|
ref: "main",
|
||||||
inputs: {
|
inputs: {
|
||||||
version: "${{ github.event.release.tag_name }}",
|
version: "${{ needs.init.outputs.tag }}",
|
||||||
content: ${{ toJSON(github.event.release.body) }}
|
content: description
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ jobs:
|
|||||||
if: github.repository == 'esphome/esphome'
|
if: github.repository == 'esphome/esphome'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
|
|
||||||
- name: Checkout Home Assistant
|
- name: Checkout Home Assistant
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
with:
|
with:
|
||||||
repository: home-assistant/core
|
repository: home-assistant/core
|
||||||
path: lib/home-assistant
|
path: lib/home-assistant
|
||||||
@@ -24,7 +24,7 @@ jobs:
|
|||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v5.1.0
|
uses: actions/setup-python@v5.1.0
|
||||||
with:
|
with:
|
||||||
python-version: 3.11
|
python-version: 3.12
|
||||||
|
|
||||||
- name: Install Home Assistant
|
- name: Install Home Assistant
|
||||||
run: |
|
run: |
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
python ./script/sync-device_class.py
|
python ./script/sync-device_class.py
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
uses: peter-evans/create-pull-request@v6.0.2
|
uses: peter-evans/create-pull-request@v6.0.4
|
||||||
with:
|
with:
|
||||||
commit-message: "Synchronise Device Classes from Home Assistant"
|
commit-message: "Synchronise Device Classes from Home Assistant"
|
||||||
committer: esphomebot <esphome@nabucasa.com>
|
committer: esphomebot <esphome@nabucasa.com>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.5
|
||||||
- name: Run yamllint
|
- name: Run yamllint
|
||||||
uses: frenck/action-yamllint@v1.5.0
|
uses: frenck/action-yamllint@v1.5.0
|
||||||
with:
|
with:
|
||||||
|
|||||||
+10
-1
@@ -27,7 +27,16 @@ repos:
|
|||||||
- --branch=release
|
- --branch=release
|
||||||
- --branch=beta
|
- --branch=beta
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v3.15.1
|
rev: v3.15.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py39-plus]
|
args: [--py39-plus]
|
||||||
|
- repo: https://github.com/adrienverge/yamllint.git
|
||||||
|
rev: v1.35.1
|
||||||
|
hooks:
|
||||||
|
- id: yamllint
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||||
|
rev: v13.0.1
|
||||||
|
hooks:
|
||||||
|
- id: clang-format
|
||||||
|
types_or: [c, c++]
|
||||||
|
|||||||
+19
-2
@@ -63,7 +63,10 @@ esphome/components/bme280_base/* @esphome/core
|
|||||||
esphome/components/bme280_spi/* @apbodrov
|
esphome/components/bme280_spi/* @apbodrov
|
||||||
esphome/components/bme680_bsec/* @trvrnrth
|
esphome/components/bme680_bsec/* @trvrnrth
|
||||||
esphome/components/bmi160/* @flaviut
|
esphome/components/bmi160/* @flaviut
|
||||||
esphome/components/bmp3xx/* @martgras
|
esphome/components/bmp3xx/* @latonita
|
||||||
|
esphome/components/bmp3xx_base/* @latonita @martgras
|
||||||
|
esphome/components/bmp3xx_i2c/* @latonita
|
||||||
|
esphome/components/bmp3xx_spi/* @latonita
|
||||||
esphome/components/bmp581/* @kahrendt
|
esphome/components/bmp581/* @kahrendt
|
||||||
esphome/components/bp1658cj/* @Cossid
|
esphome/components/bp1658cj/* @Cossid
|
||||||
esphome/components/bp5758d/* @Cossid
|
esphome/components/bp5758d/* @Cossid
|
||||||
@@ -119,6 +122,7 @@ esphome/components/esp32_rmt/* @jesserockz
|
|||||||
esphome/components/esp32_rmt_led_strip/* @jesserockz
|
esphome/components/esp32_rmt_led_strip/* @jesserockz
|
||||||
esphome/components/esp8266/* @esphome/core
|
esphome/components/esp8266/* @esphome/core
|
||||||
esphome/components/ethernet_info/* @gtjadsonsantos
|
esphome/components/ethernet_info/* @gtjadsonsantos
|
||||||
|
esphome/components/event/* @nohat
|
||||||
esphome/components/exposure_notifications/* @OttoWinter
|
esphome/components/exposure_notifications/* @OttoWinter
|
||||||
esphome/components/ezo/* @ssieb
|
esphome/components/ezo/* @ssieb
|
||||||
esphome/components/ezo_pmp/* @carlos-sarmiento
|
esphome/components/ezo_pmp/* @carlos-sarmiento
|
||||||
@@ -241,7 +245,7 @@ esphome/components/mpl3115a2/* @kbickar
|
|||||||
esphome/components/mpu6886/* @fabaff
|
esphome/components/mpu6886/* @fabaff
|
||||||
esphome/components/ms8607/* @e28eta
|
esphome/components/ms8607/* @e28eta
|
||||||
esphome/components/network/* @esphome/core
|
esphome/components/network/* @esphome/core
|
||||||
esphome/components/nextion/* @senexcrenshaw
|
esphome/components/nextion/* @edwardtfn @senexcrenshaw
|
||||||
esphome/components/nextion/binary_sensor/* @senexcrenshaw
|
esphome/components/nextion/binary_sensor/* @senexcrenshaw
|
||||||
esphome/components/nextion/sensor/* @senexcrenshaw
|
esphome/components/nextion/sensor/* @senexcrenshaw
|
||||||
esphome/components/nextion/switch/* @senexcrenshaw
|
esphome/components/nextion/switch/* @senexcrenshaw
|
||||||
@@ -359,6 +363,7 @@ esphome/components/tee501/* @Stock-M
|
|||||||
esphome/components/teleinfo/* @0hax
|
esphome/components/teleinfo/* @0hax
|
||||||
esphome/components/template/alarm_control_panel/* @grahambrown11 @hwstar
|
esphome/components/template/alarm_control_panel/* @grahambrown11 @hwstar
|
||||||
esphome/components/template/datetime/* @rfdarter
|
esphome/components/template/datetime/* @rfdarter
|
||||||
|
esphome/components/template/event/* @nohat
|
||||||
esphome/components/template/fan/* @ssieb
|
esphome/components/template/fan/* @ssieb
|
||||||
esphome/components/text/* @mauritskorse
|
esphome/components/text/* @mauritskorse
|
||||||
esphome/components/thermostat/* @kbx81
|
esphome/components/thermostat/* @kbx81
|
||||||
@@ -390,6 +395,7 @@ esphome/components/ufire_ec/* @pvizeli
|
|||||||
esphome/components/ufire_ise/* @pvizeli
|
esphome/components/ufire_ise/* @pvizeli
|
||||||
esphome/components/ultrasonic/* @OttoWinter
|
esphome/components/ultrasonic/* @OttoWinter
|
||||||
esphome/components/uponor_smatrix/* @kroimon
|
esphome/components/uponor_smatrix/* @kroimon
|
||||||
|
esphome/components/valve/* @esphome/core
|
||||||
esphome/components/vbus/* @ssieb
|
esphome/components/vbus/* @ssieb
|
||||||
esphome/components/veml3235/* @kbx81
|
esphome/components/veml3235/* @kbx81
|
||||||
esphome/components/veml7700/* @latonita
|
esphome/components/veml7700/* @latonita
|
||||||
@@ -399,10 +405,21 @@ esphome/components/wake_on_lan/* @willwill2will54
|
|||||||
esphome/components/waveshare_epaper/* @clydebarrow
|
esphome/components/waveshare_epaper/* @clydebarrow
|
||||||
esphome/components/web_server_base/* @OttoWinter
|
esphome/components/web_server_base/* @OttoWinter
|
||||||
esphome/components/web_server_idf/* @dentra
|
esphome/components/web_server_idf/* @dentra
|
||||||
|
esphome/components/weikai/* @DrCoolZic
|
||||||
|
esphome/components/weikai_i2c/* @DrCoolZic
|
||||||
|
esphome/components/weikai_spi/* @DrCoolZic
|
||||||
esphome/components/whirlpool/* @glmnet
|
esphome/components/whirlpool/* @glmnet
|
||||||
esphome/components/whynter/* @aeonsablaze
|
esphome/components/whynter/* @aeonsablaze
|
||||||
esphome/components/wiegand/* @ssieb
|
esphome/components/wiegand/* @ssieb
|
||||||
esphome/components/wireguard/* @droscy @lhoracek @thomas0bernard
|
esphome/components/wireguard/* @droscy @lhoracek @thomas0bernard
|
||||||
|
esphome/components/wk2132_i2c/* @DrCoolZic
|
||||||
|
esphome/components/wk2132_spi/* @DrCoolZic
|
||||||
|
esphome/components/wk2168_i2c/* @DrCoolZic
|
||||||
|
esphome/components/wk2168_spi/* @DrCoolZic
|
||||||
|
esphome/components/wk2204_i2c/* @DrCoolZic
|
||||||
|
esphome/components/wk2204_spi/* @DrCoolZic
|
||||||
|
esphome/components/wk2212_i2c/* @DrCoolZic
|
||||||
|
esphome/components/wk2212_spi/* @DrCoolZic
|
||||||
esphome/components/wl_134/* @hobbypunk90
|
esphome/components/wl_134/* @hobbypunk90
|
||||||
esphome/components/x9c/* @EtienneMD
|
esphome/components/x9c/* @EtienneMD
|
||||||
esphome/components/xgzp68xx/* @gcormier
|
esphome/components/xgzp68xx/* @gcormier
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/with-contenv bashio
|
||||||
|
# ==============================================================================
|
||||||
|
# This file installs the user ESPHome fork if specified.
|
||||||
|
# The fork must be up to date with the latest ESPHome dev branch
|
||||||
|
# and have no conflicts.
|
||||||
|
# This config option only exists in the ESPHome Dev add-on.
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
declare esphome_fork
|
||||||
|
|
||||||
|
if bashio::config.has_value 'esphome_fork'; then
|
||||||
|
esphome_fork=$(bashio::config 'esphome_fork')
|
||||||
|
# format: [username][/repository]:ref
|
||||||
|
if [[ "$esphome_fork" =~ ^(([^/]+)(/([^:]+))?:)?([^:/]+)$ ]]; then
|
||||||
|
username="${BASH_REMATCH[2]:-esphome}"
|
||||||
|
repository="${BASH_REMATCH[4]:-esphome}"
|
||||||
|
ref="${BASH_REMATCH[5]}"
|
||||||
|
else
|
||||||
|
bashio::exit.nok "Invalid esphome_fork format: $esphome_fork"
|
||||||
|
fi
|
||||||
|
full_url="https://github.com/${username}/${repository}/archive/${ref}.tar.gz"
|
||||||
|
bashio::log.info "Checking forked ESPHome"
|
||||||
|
dev_version=$(python3 -c "from esphome.const import __version__; print(__version__)")
|
||||||
|
bashio::log.info "Downloading ESPHome from fork '${esphome_fork}' (${full_url})..."
|
||||||
|
curl -L -o /tmp/esphome.tar.gz "${full_url}" -qq ||
|
||||||
|
bashio::exit.nok "Failed downloading ESPHome fork."
|
||||||
|
bashio::log.info "Installing ESPHome from fork '${esphome_fork}' (${full_url})..."
|
||||||
|
rm -rf /esphome || bashio::exit.nok "Failed to remove ESPHome."
|
||||||
|
mkdir /esphome
|
||||||
|
tar -zxf /tmp/esphome.tar.gz -C /esphome --strip-components=1 ||
|
||||||
|
bashio::exit.nok "Failed installing ESPHome from fork."
|
||||||
|
pip install -U -e /esphome || bashio::exit.nok "Failed installing ESPHome from fork."
|
||||||
|
rm -f /tmp/esphome.tar.gz
|
||||||
|
fork_version=$(python3 -c "from esphome.const import __version__; print(__version__)")
|
||||||
|
|
||||||
|
if [[ "$fork_version" != "$dev_version" ]]; then
|
||||||
|
bashio::log.error "############################"
|
||||||
|
bashio::log.error "Uninstalled fork as version does not match"
|
||||||
|
bashio::log.error "Update (or ask the author to update) the branch"
|
||||||
|
bashio::log.error "This is important as the dev addon and the dev ESPHome"
|
||||||
|
bashio::log.error "branch can have changes that are not compatible with old forks"
|
||||||
|
bashio::log.error "and get reported as bugs which we cannot solve easily."
|
||||||
|
bashio::log.error "############################"
|
||||||
|
bashio::exit.nok
|
||||||
|
fi
|
||||||
|
bashio::log.info "Installed ESPHome from fork '${esphome_fork}' (${full_url})..."
|
||||||
|
fi
|
||||||
+6
-2
@@ -343,9 +343,10 @@ def upload_program(config, args, host):
|
|||||||
password = ota_conf.get(CONF_PASSWORD, "")
|
password = ota_conf.get(CONF_PASSWORD, "")
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not is_ip_address(CORE.address)
|
not is_ip_address(CORE.address) # pylint: disable=too-many-boolean-expressions
|
||||||
and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
and (get_port_type(host) == "MQTT" or config[CONF_MDNS][CONF_DISABLED])
|
||||||
and CONF_MQTT in config
|
and CONF_MQTT in config
|
||||||
|
and (not args.device or args.device == "MQTT")
|
||||||
):
|
):
|
||||||
from esphome import mqtt
|
from esphome import mqtt
|
||||||
|
|
||||||
@@ -768,7 +769,9 @@ def parse_args(argv):
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser_upload = subparsers.add_parser(
|
parser_upload = subparsers.add_parser(
|
||||||
"upload", help="Validate the configuration and upload the latest binary."
|
"upload",
|
||||||
|
help="Validate the configuration and upload the latest binary.",
|
||||||
|
parents=[mqtt_options],
|
||||||
)
|
)
|
||||||
parser_upload.add_argument(
|
parser_upload.add_argument(
|
||||||
"configuration", help="Your YAML configuration file(s).", nargs="+"
|
"configuration", help="Your YAML configuration file(s).", nargs="+"
|
||||||
@@ -785,6 +788,7 @@ def parse_args(argv):
|
|||||||
parser_logs = subparsers.add_parser(
|
parser_logs = subparsers.add_parser(
|
||||||
"logs",
|
"logs",
|
||||||
help="Validate the configuration and show all logs.",
|
help="Validate the configuration and show all logs.",
|
||||||
|
aliases=["log"],
|
||||||
parents=[mqtt_options],
|
parents=[mqtt_options],
|
||||||
)
|
)
|
||||||
parser_logs.add_argument(
|
parser_logs.add_argument(
|
||||||
|
|||||||
@@ -18,10 +18,20 @@ from esphome.util import Registry
|
|||||||
|
|
||||||
|
|
||||||
def maybe_simple_id(*validators):
|
def maybe_simple_id(*validators):
|
||||||
|
"""Allow a raw ID to be specified in place of a config block.
|
||||||
|
If the value that's being validated is a dictionary, it's passed as-is to the specified validators. Otherwise, it's
|
||||||
|
wrapped in a dict that looks like ``{"id": <value>}``, and that dict is then handed off to the specified validators.
|
||||||
|
"""
|
||||||
return maybe_conf(CONF_ID, *validators)
|
return maybe_conf(CONF_ID, *validators)
|
||||||
|
|
||||||
|
|
||||||
def maybe_conf(conf, *validators):
|
def maybe_conf(conf, *validators):
|
||||||
|
"""Allow a raw value to be specified in place of a config block.
|
||||||
|
If the value that's being validated is a dictionary, it's passed as-is to the specified validators. Otherwise, it's
|
||||||
|
wrapped in a dict that looks like ``{<conf>: <value>}``, and that dict is then handed off to the specified
|
||||||
|
validators.
|
||||||
|
(This is a general case of ``maybe_simple_id`` that allows the wrapping key to be something other than ``id``.)
|
||||||
|
"""
|
||||||
validator = cv.All(*validators)
|
validator = cv.All(*validators)
|
||||||
|
|
||||||
@schema_extractor("maybe")
|
@schema_extractor("maybe")
|
||||||
|
|||||||
@@ -18,11 +18,23 @@ from esphome.components.esp32.const import (
|
|||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
|
|
||||||
|
adc_ns = cg.esphome_ns.namespace("adc")
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
From the below patch versions (and 5.2+) ADC_ATTEN_DB_11 is deprecated and replaced with ADC_ATTEN_DB_12.
|
||||||
|
4.4.7
|
||||||
|
5.0.5
|
||||||
|
5.1.3
|
||||||
|
5.2+
|
||||||
|
"""
|
||||||
|
|
||||||
ATTENUATION_MODES = {
|
ATTENUATION_MODES = {
|
||||||
"0db": cg.global_ns.ADC_ATTEN_DB_0,
|
"0db": cg.global_ns.ADC_ATTEN_DB_0,
|
||||||
"2.5db": cg.global_ns.ADC_ATTEN_DB_2_5,
|
"2.5db": cg.global_ns.ADC_ATTEN_DB_2_5,
|
||||||
"6db": cg.global_ns.ADC_ATTEN_DB_6,
|
"6db": cg.global_ns.ADC_ATTEN_DB_6,
|
||||||
"11db": cg.global_ns.ADC_ATTEN_DB_11,
|
"11db": adc_ns.ADC_ATTEN_DB_12_COMPAT,
|
||||||
|
"12db": adc_ns.ADC_ATTEN_DB_12_COMPAT,
|
||||||
"auto": "auto",
|
"auto": "auto",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load characteristics for each attenuation
|
// load characteristics for each attenuation
|
||||||
for (int32_t i = 0; i <= ADC_ATTEN_DB_11; i++) {
|
for (int32_t i = 0; i <= ADC_ATTEN_DB_12_COMPAT; i++) {
|
||||||
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
||||||
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
||||||
1100, // default vref
|
1100, // default vref
|
||||||
@@ -118,8 +118,8 @@ void ADCSensor::dump_config() {
|
|||||||
case ADC_ATTEN_DB_6:
|
case ADC_ATTEN_DB_6:
|
||||||
ESP_LOGCONFIG(TAG, " Attenuation: 6db");
|
ESP_LOGCONFIG(TAG, " Attenuation: 6db");
|
||||||
break;
|
break;
|
||||||
case ADC_ATTEN_DB_11:
|
case ADC_ATTEN_DB_12_COMPAT:
|
||||||
ESP_LOGCONFIG(TAG, " Attenuation: 11db");
|
ESP_LOGCONFIG(TAG, " Attenuation: 12db");
|
||||||
break;
|
break;
|
||||||
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
||||||
break;
|
break;
|
||||||
@@ -183,12 +183,12 @@ float ADCSensor::sample() {
|
|||||||
return mv / 1000.0f;
|
return mv / 1000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
int raw12 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
||||||
|
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_12_COMPAT);
|
||||||
raw11 = adc1_get_raw(channel1_);
|
raw12 = adc1_get_raw(channel1_);
|
||||||
if (raw11 < ADC_MAX) {
|
if (raw12 < ADC_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_6);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_6);
|
||||||
raw6 = adc1_get_raw(channel1_);
|
raw6 = adc1_get_raw(channel1_);
|
||||||
if (raw6 < ADC_MAX) {
|
if (raw6 < ADC_MAX) {
|
||||||
@@ -201,9 +201,9 @@ float ADCSensor::sample() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
||||||
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_11);
|
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_12_COMPAT);
|
||||||
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw11);
|
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw12);
|
||||||
if (raw11 < ADC_MAX) {
|
if (raw12 < ADC_MAX) {
|
||||||
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_6);
|
adc2_config_channel_atten(channel2_, ADC_ATTEN_DB_6);
|
||||||
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw6);
|
adc2_get_raw(channel2_, ADC_WIDTH_MAX_SOC_BITS, &raw6);
|
||||||
if (raw6 < ADC_MAX) {
|
if (raw6 < ADC_MAX) {
|
||||||
@@ -217,25 +217,25 @@ float ADCSensor::sample() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw0 == -1 || raw2 == -1 || raw6 == -1 || raw11 == -1) {
|
if (raw0 == -1 || raw2 == -1 || raw6 == -1 || raw12 == -1) {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t mv11 = esp_adc_cal_raw_to_voltage(raw11, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_11]);
|
uint32_t mv12 = esp_adc_cal_raw_to_voltage(raw12, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_12_COMPAT]);
|
||||||
uint32_t mv6 = esp_adc_cal_raw_to_voltage(raw6, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_6]);
|
uint32_t mv6 = esp_adc_cal_raw_to_voltage(raw6, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_6]);
|
||||||
uint32_t mv2 = esp_adc_cal_raw_to_voltage(raw2, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_2_5]);
|
uint32_t mv2 = esp_adc_cal_raw_to_voltage(raw2, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_2_5]);
|
||||||
uint32_t mv0 = esp_adc_cal_raw_to_voltage(raw0, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_0]);
|
uint32_t mv0 = esp_adc_cal_raw_to_voltage(raw0, &cal_characteristics_[(int32_t) ADC_ATTEN_DB_0]);
|
||||||
|
|
||||||
// Contribution of each value, in range 0-2048 (12 bit ADC) or 0-4096 (13 bit ADC)
|
// Contribution of each value, in range 0-2048 (12 bit ADC) or 0-4096 (13 bit ADC)
|
||||||
uint32_t c11 = std::min(raw11, ADC_HALF);
|
uint32_t c12 = std::min(raw12, ADC_HALF);
|
||||||
uint32_t c6 = ADC_HALF - std::abs(raw6 - ADC_HALF);
|
uint32_t c6 = ADC_HALF - std::abs(raw6 - ADC_HALF);
|
||||||
uint32_t c2 = ADC_HALF - std::abs(raw2 - ADC_HALF);
|
uint32_t c2 = ADC_HALF - std::abs(raw2 - ADC_HALF);
|
||||||
uint32_t c0 = std::min(ADC_MAX - raw0, ADC_HALF);
|
uint32_t c0 = std::min(ADC_MAX - raw0, ADC_HALF);
|
||||||
// max theoretical csum value is 4096*4 = 16384
|
// max theoretical csum value is 4096*4 = 16384
|
||||||
uint32_t csum = c11 + c6 + c2 + c0;
|
uint32_t csum = c12 + c6 + c2 + c0;
|
||||||
|
|
||||||
// each mv is max 3900; so max value is 3900*4096*4, fits in unsigned32
|
// each mv is max 3900; so max value is 3900*4096*4, fits in unsigned32
|
||||||
uint32_t mv_scaled = (mv11 * c11) + (mv6 * c6) + (mv2 * c2) + (mv0 * c0);
|
uint32_t mv_scaled = (mv12 * c12) + (mv6 * c6) + (mv2 * c2) + (mv0 * c0);
|
||||||
return mv_scaled / (float) (csum * 1000U);
|
return mv_scaled / (float) (csum * 1000U);
|
||||||
}
|
}
|
||||||
#endif // USE_ESP32
|
#endif // USE_ESP32
|
||||||
|
|||||||
@@ -1,19 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
|
||||||
#include "esphome/core/hal.h"
|
|
||||||
#include "esphome/core/defines.h"
|
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#include "esphome/core/hal.h"
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
#include "driver/adc.h"
|
|
||||||
#include <esp_adc_cal.h>
|
#include <esp_adc_cal.h>
|
||||||
|
#include "driver/adc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace adc {
|
namespace adc {
|
||||||
|
|
||||||
|
#ifdef USE_ESP32
|
||||||
|
// clang-format off
|
||||||
|
#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 7)) || \
|
||||||
|
(ESP_IDF_VERSION_MAJOR == 5 && \
|
||||||
|
((ESP_IDF_VERSION_MINOR == 0 && ESP_IDF_VERSION_PATCH >= 5) || \
|
||||||
|
(ESP_IDF_VERSION_MINOR == 1 && ESP_IDF_VERSION_PATCH >= 3) || \
|
||||||
|
(ESP_IDF_VERSION_MINOR >= 2)) \
|
||||||
|
)
|
||||||
|
// clang-format on
|
||||||
|
static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_12;
|
||||||
|
#else
|
||||||
|
static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_11;
|
||||||
|
#endif
|
||||||
|
#endif // USE_ESP32
|
||||||
|
|
||||||
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
|
||||||
public:
|
public:
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.final_validate as fv
|
import esphome.final_validate as fv
|
||||||
@@ -19,16 +21,29 @@ from . import (
|
|||||||
ATTENUATION_MODES,
|
ATTENUATION_MODES,
|
||||||
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
|
ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
|
||||||
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
|
||||||
|
adc_ns,
|
||||||
validate_adc_pin,
|
validate_adc_pin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
AUTO_LOAD = ["voltage_sampler"]
|
AUTO_LOAD = ["voltage_sampler"]
|
||||||
|
|
||||||
|
|
||||||
|
_attenuation = cv.enum(ATTENUATION_MODES, lower=True)
|
||||||
|
|
||||||
|
|
||||||
def validate_config(config):
|
def validate_config(config):
|
||||||
if config[CONF_RAW] and config.get(CONF_ATTENUATION, None) == "auto":
|
if config[CONF_RAW] and config.get(CONF_ATTENUATION, None) == "auto":
|
||||||
raise cv.Invalid("Automatic attenuation cannot be used when raw output is set")
|
raise cv.Invalid("Automatic attenuation cannot be used when raw output is set")
|
||||||
|
|
||||||
|
if config.get(CONF_ATTENUATION) == "11db":
|
||||||
|
_LOGGER.warning(
|
||||||
|
"`attenuation: 11db` is deprecated, use `attenuation: 12db` instead"
|
||||||
|
)
|
||||||
|
# Alter value here so `config` command prints the recommended change
|
||||||
|
config[CONF_ATTENUATION] = _attenuation("12db")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +62,6 @@ def final_validate_config(config):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
adc_ns = cg.esphome_ns.namespace("adc")
|
|
||||||
ADCSensor = adc_ns.class_(
|
ADCSensor = adc_ns.class_(
|
||||||
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
|
||||||
)
|
)
|
||||||
@@ -65,7 +79,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Required(CONF_PIN): validate_adc_pin,
|
cv.Required(CONF_PIN): validate_adc_pin,
|
||||||
cv.Optional(CONF_RAW, default=False): cv.boolean,
|
cv.Optional(CONF_RAW, default=False): cv.boolean,
|
||||||
cv.SplitDefault(CONF_ATTENUATION, esp32="0db"): cv.All(
|
cv.SplitDefault(CONF_ATTENUATION, esp32="0db"): cv.All(
|
||||||
cv.only_on_esp32, cv.enum(ATTENUATION_MODES, lower=True)
|
cv.only_on_esp32, _attenuation
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from esphome.const import (
|
|||||||
CONF_RESET_PIN,
|
CONF_RESET_PIN,
|
||||||
CONF_REVERSE_ACTIVE_ENERGY,
|
CONF_REVERSE_ACTIVE_ENERGY,
|
||||||
CONF_VOLTAGE,
|
CONF_VOLTAGE,
|
||||||
|
CONF_VOLTAGE_GAIN,
|
||||||
DEVICE_CLASS_APPARENT_POWER,
|
DEVICE_CLASS_APPARENT_POWER,
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
@@ -47,7 +48,6 @@ CONF_CURRENT_GAIN = "current_gain"
|
|||||||
CONF_IRQ0_PIN = "irq0_pin"
|
CONF_IRQ0_PIN = "irq0_pin"
|
||||||
CONF_IRQ1_PIN = "irq1_pin"
|
CONF_IRQ1_PIN = "irq1_pin"
|
||||||
CONF_POWER_GAIN = "power_gain"
|
CONF_POWER_GAIN = "power_gain"
|
||||||
CONF_VOLTAGE_GAIN = "voltage_gain"
|
|
||||||
|
|
||||||
CONF_NEUTRAL = "neutral"
|
CONF_NEUTRAL = "neutral"
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from esphome.const import (
|
|||||||
CONF_IRQ_PIN,
|
CONF_IRQ_PIN,
|
||||||
CONF_VOLTAGE,
|
CONF_VOLTAGE,
|
||||||
CONF_FREQUENCY,
|
CONF_FREQUENCY,
|
||||||
|
CONF_VOLTAGE_GAIN,
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_APPARENT_POWER,
|
DEVICE_CLASS_APPARENT_POWER,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
@@ -36,7 +37,6 @@ CONF_POWER_FACTOR_B = "power_factor_b"
|
|||||||
CONF_VOLTAGE_PGA_GAIN = "voltage_pga_gain"
|
CONF_VOLTAGE_PGA_GAIN = "voltage_pga_gain"
|
||||||
CONF_CURRENT_PGA_GAIN_A = "current_pga_gain_a"
|
CONF_CURRENT_PGA_GAIN_A = "current_pga_gain_a"
|
||||||
CONF_CURRENT_PGA_GAIN_B = "current_pga_gain_b"
|
CONF_CURRENT_PGA_GAIN_B = "current_pga_gain_b"
|
||||||
CONF_VOLTAGE_GAIN = "voltage_gain"
|
|
||||||
CONF_CURRENT_GAIN_A = "current_gain_a"
|
CONF_CURRENT_GAIN_A = "current_gain_a"
|
||||||
CONF_CURRENT_GAIN_B = "current_gain_b"
|
CONF_CURRENT_GAIN_B = "current_gain_b"
|
||||||
CONF_ACTIVE_POWER_GAIN_A = "active_power_gain_a"
|
CONF_ACTIVE_POWER_GAIN_A = "active_power_gain_a"
|
||||||
|
|||||||
@@ -97,9 +97,11 @@ void Alpha3::handle_geni_response_(const uint8_t *response, uint16_t length) {
|
|||||||
void Alpha3::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) {
|
void Alpha3::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ESP_GATTC_OPEN_EVT: {
|
case ESP_GATTC_OPEN_EVT: {
|
||||||
this->response_offset_ = 0;
|
if (param->open.status == ESP_GATT_OK) {
|
||||||
this->response_length_ = 0;
|
this->response_offset_ = 0;
|
||||||
ESP_LOGI(TAG, "[%s] connection open", this->parent_->address_str().c_str());
|
this->response_length_ = 0;
|
||||||
|
ESP_LOGI(TAG, "[%s] connection open", this->parent_->address_str().c_str());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_CONNECT_EVT: {
|
case ESP_GATTC_CONNECT_EVT: {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ void Am43::setup() {
|
|||||||
void Am43::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) {
|
void Am43::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ESP_GATTC_OPEN_EVT: {
|
case ESP_GATTC_OPEN_EVT: {
|
||||||
this->logged_in_ = false;
|
if (param->open.status == ESP_GATT_OK) {
|
||||||
|
this->logged_in_ = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_DISCONNECT_EVT: {
|
case ESP_GATTC_DISCONNECT_EVT: {
|
||||||
|
|||||||
@@ -43,9 +43,11 @@ service APIConnection {
|
|||||||
rpc select_command (SelectCommandRequest) returns (void) {}
|
rpc select_command (SelectCommandRequest) returns (void) {}
|
||||||
rpc button_command (ButtonCommandRequest) returns (void) {}
|
rpc button_command (ButtonCommandRequest) returns (void) {}
|
||||||
rpc lock_command (LockCommandRequest) returns (void) {}
|
rpc lock_command (LockCommandRequest) returns (void) {}
|
||||||
|
rpc valve_command (ValveCommandRequest) returns (void) {}
|
||||||
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
||||||
rpc date_command (DateCommandRequest) returns (void) {}
|
rpc date_command (DateCommandRequest) returns (void) {}
|
||||||
rpc time_command (TimeCommandRequest) returns (void) {}
|
rpc time_command (TimeCommandRequest) returns (void) {}
|
||||||
|
rpc datetime_command (DateTimeCommandRequest) returns (void) {}
|
||||||
|
|
||||||
rpc subscribe_bluetooth_le_advertisements(SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
|
rpc subscribe_bluetooth_le_advertisements(SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
|
||||||
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
|
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
|
||||||
@@ -1145,6 +1147,9 @@ message MediaPlayerCommandRequest {
|
|||||||
|
|
||||||
bool has_media_url = 6;
|
bool has_media_url = 6;
|
||||||
string media_url = 7;
|
string media_url = 7;
|
||||||
|
|
||||||
|
bool has_announcement = 8;
|
||||||
|
bool announcement = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== BLUETOOTH ====================
|
// ==================== BLUETOOTH ====================
|
||||||
@@ -1700,3 +1705,116 @@ message TimeCommandRequest {
|
|||||||
uint32 minute = 3;
|
uint32 minute = 3;
|
||||||
uint32 second = 4;
|
uint32 second = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== EVENT ====================
|
||||||
|
message ListEntitiesEventResponse {
|
||||||
|
option (id) = 107;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_EVENT";
|
||||||
|
|
||||||
|
string object_id = 1;
|
||||||
|
fixed32 key = 2;
|
||||||
|
string name = 3;
|
||||||
|
string unique_id = 4;
|
||||||
|
|
||||||
|
string icon = 5;
|
||||||
|
bool disabled_by_default = 6;
|
||||||
|
EntityCategory entity_category = 7;
|
||||||
|
string device_class = 8;
|
||||||
|
|
||||||
|
repeated string event_types = 9;
|
||||||
|
}
|
||||||
|
message EventResponse {
|
||||||
|
option (id) = 108;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_EVENT";
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
string event_type = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== VALVE ====================
|
||||||
|
message ListEntitiesValveResponse {
|
||||||
|
option (id) = 109;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
|
||||||
|
string object_id = 1;
|
||||||
|
fixed32 key = 2;
|
||||||
|
string name = 3;
|
||||||
|
string unique_id = 4;
|
||||||
|
|
||||||
|
string icon = 5;
|
||||||
|
bool disabled_by_default = 6;
|
||||||
|
EntityCategory entity_category = 7;
|
||||||
|
string device_class = 8;
|
||||||
|
|
||||||
|
bool assumed_state = 9;
|
||||||
|
bool supports_position = 10;
|
||||||
|
bool supports_stop = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ValveOperation {
|
||||||
|
VALVE_OPERATION_IDLE = 0;
|
||||||
|
VALVE_OPERATION_IS_OPENING = 1;
|
||||||
|
VALVE_OPERATION_IS_CLOSING = 2;
|
||||||
|
}
|
||||||
|
message ValveStateResponse {
|
||||||
|
option (id) = 110;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
float position = 2;
|
||||||
|
ValveOperation current_operation = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ValveCommandRequest {
|
||||||
|
option (id) = 111;
|
||||||
|
option (source) = SOURCE_CLIENT;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
bool has_position = 2;
|
||||||
|
float position = 3;
|
||||||
|
bool stop = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== DATETIME DATETIME ====================
|
||||||
|
message ListEntitiesDateTimeResponse {
|
||||||
|
option (id) = 112;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_DATETIME_DATETIME";
|
||||||
|
|
||||||
|
string object_id = 1;
|
||||||
|
fixed32 key = 2;
|
||||||
|
string name = 3;
|
||||||
|
string unique_id = 4;
|
||||||
|
|
||||||
|
string icon = 5;
|
||||||
|
bool disabled_by_default = 6;
|
||||||
|
EntityCategory entity_category = 7;
|
||||||
|
}
|
||||||
|
message DateTimeStateResponse {
|
||||||
|
option (id) = 113;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_DATETIME_DATETIME";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
// If the datetime does not have a valid state yet.
|
||||||
|
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||||
|
bool missing_state = 2;
|
||||||
|
fixed32 epoch_seconds = 3;
|
||||||
|
}
|
||||||
|
message DateTimeCommandRequest {
|
||||||
|
option (id) = 114;
|
||||||
|
option (source) = SOURCE_CLIENT;
|
||||||
|
option (ifdef) = "USE_DATETIME_DATETIME";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
fixed32 epoch_seconds = 2;
|
||||||
|
}
|
||||||
|
|||||||
@@ -772,6 +772,44 @@ void APIConnection::time_command(const TimeCommandRequest &msg) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool APIConnection::send_datetime_state(datetime::DateTimeEntity *datetime) {
|
||||||
|
if (!this->state_subscription_)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DateTimeStateResponse resp{};
|
||||||
|
resp.key = datetime->get_object_id_hash();
|
||||||
|
resp.missing_state = !datetime->has_state();
|
||||||
|
if (datetime->has_state()) {
|
||||||
|
ESPTime state = datetime->state_as_esptime();
|
||||||
|
resp.epoch_seconds = state.timestamp;
|
||||||
|
}
|
||||||
|
return this->send_date_time_state_response(resp);
|
||||||
|
}
|
||||||
|
bool APIConnection::send_datetime_info(datetime::DateTimeEntity *datetime) {
|
||||||
|
ListEntitiesDateTimeResponse msg;
|
||||||
|
msg.key = datetime->get_object_id_hash();
|
||||||
|
msg.object_id = datetime->get_object_id();
|
||||||
|
if (datetime->has_own_name())
|
||||||
|
msg.name = datetime->get_name();
|
||||||
|
msg.unique_id = get_default_unique_id("datetime", datetime);
|
||||||
|
msg.icon = datetime->get_icon();
|
||||||
|
msg.disabled_by_default = datetime->is_disabled_by_default();
|
||||||
|
msg.entity_category = static_cast<enums::EntityCategory>(datetime->get_entity_category());
|
||||||
|
|
||||||
|
return this->send_list_entities_date_time_response(msg);
|
||||||
|
}
|
||||||
|
void APIConnection::datetime_command(const DateTimeCommandRequest &msg) {
|
||||||
|
datetime::DateTimeEntity *datetime = App.get_datetime_by_key(msg.key);
|
||||||
|
if (datetime == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto call = datetime->make_call();
|
||||||
|
call.set_datetime(msg.epoch_seconds);
|
||||||
|
call.perform();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool APIConnection::send_text_state(text::Text *text, std::string state) {
|
bool APIConnection::send_text_state(text::Text *text, std::string state) {
|
||||||
if (!this->state_subscription_)
|
if (!this->state_subscription_)
|
||||||
@@ -915,6 +953,48 @@ void APIConnection::lock_command(const LockCommandRequest &msg) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool APIConnection::send_valve_state(valve::Valve *valve) {
|
||||||
|
if (!this->state_subscription_)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ValveStateResponse resp{};
|
||||||
|
resp.key = valve->get_object_id_hash();
|
||||||
|
resp.position = valve->position;
|
||||||
|
resp.current_operation = static_cast<enums::ValveOperation>(valve->current_operation);
|
||||||
|
return this->send_valve_state_response(resp);
|
||||||
|
}
|
||||||
|
bool APIConnection::send_valve_info(valve::Valve *valve) {
|
||||||
|
auto traits = valve->get_traits();
|
||||||
|
ListEntitiesValveResponse msg;
|
||||||
|
msg.key = valve->get_object_id_hash();
|
||||||
|
msg.object_id = valve->get_object_id();
|
||||||
|
if (valve->has_own_name())
|
||||||
|
msg.name = valve->get_name();
|
||||||
|
msg.unique_id = get_default_unique_id("valve", valve);
|
||||||
|
msg.icon = valve->get_icon();
|
||||||
|
msg.disabled_by_default = valve->is_disabled_by_default();
|
||||||
|
msg.entity_category = static_cast<enums::EntityCategory>(valve->get_entity_category());
|
||||||
|
msg.device_class = valve->get_device_class();
|
||||||
|
msg.assumed_state = traits.get_is_assumed_state();
|
||||||
|
msg.supports_position = traits.get_supports_position();
|
||||||
|
msg.supports_stop = traits.get_supports_stop();
|
||||||
|
return this->send_list_entities_valve_response(msg);
|
||||||
|
}
|
||||||
|
void APIConnection::valve_command(const ValveCommandRequest &msg) {
|
||||||
|
valve::Valve *valve = App.get_valve_by_key(msg.key);
|
||||||
|
if (valve == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto call = valve->make_call();
|
||||||
|
if (msg.has_position)
|
||||||
|
call.set_position(msg.position);
|
||||||
|
if (msg.stop)
|
||||||
|
call.set_command_stop();
|
||||||
|
call.perform();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool APIConnection::send_media_player_state(media_player::MediaPlayer *media_player) {
|
bool APIConnection::send_media_player_state(media_player::MediaPlayer *media_player) {
|
||||||
if (!this->state_subscription_)
|
if (!this->state_subscription_)
|
||||||
@@ -922,7 +1002,11 @@ bool APIConnection::send_media_player_state(media_player::MediaPlayer *media_pla
|
|||||||
|
|
||||||
MediaPlayerStateResponse resp{};
|
MediaPlayerStateResponse resp{};
|
||||||
resp.key = media_player->get_object_id_hash();
|
resp.key = media_player->get_object_id_hash();
|
||||||
resp.state = static_cast<enums::MediaPlayerState>(media_player->state);
|
|
||||||
|
media_player::MediaPlayerState report_state = media_player->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
? media_player::MEDIA_PLAYER_STATE_PLAYING
|
||||||
|
: media_player->state;
|
||||||
|
resp.state = static_cast<enums::MediaPlayerState>(report_state);
|
||||||
resp.volume = media_player->volume;
|
resp.volume = media_player->volume;
|
||||||
resp.muted = media_player->is_muted();
|
resp.muted = media_player->is_muted();
|
||||||
return this->send_media_player_state_response(resp);
|
return this->send_media_player_state_response(resp);
|
||||||
@@ -958,6 +1042,9 @@ void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
|||||||
if (msg.has_media_url) {
|
if (msg.has_media_url) {
|
||||||
call.set_media_url(msg.media_url);
|
call.set_media_url(msg.media_url);
|
||||||
}
|
}
|
||||||
|
if (msg.has_announcement) {
|
||||||
|
call.set_announcement(msg.announcement);
|
||||||
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1167,6 +1254,30 @@ void APIConnection::alarm_control_panel_command(const AlarmControlPanelCommandRe
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool APIConnection::send_event(event::Event *event, std::string event_type) {
|
||||||
|
EventResponse resp{};
|
||||||
|
resp.key = event->get_object_id_hash();
|
||||||
|
resp.event_type = std::move(event_type);
|
||||||
|
return this->send_event_response(resp);
|
||||||
|
}
|
||||||
|
bool APIConnection::send_event_info(event::Event *event) {
|
||||||
|
ListEntitiesEventResponse msg;
|
||||||
|
msg.key = event->get_object_id_hash();
|
||||||
|
msg.object_id = event->get_object_id();
|
||||||
|
if (event->has_own_name())
|
||||||
|
msg.name = event->get_name();
|
||||||
|
msg.unique_id = get_default_unique_id("event", event);
|
||||||
|
msg.icon = event->get_icon();
|
||||||
|
msg.disabled_by_default = event->is_disabled_by_default();
|
||||||
|
msg.entity_category = static_cast<enums::EntityCategory>(event->get_entity_category());
|
||||||
|
msg.device_class = event->get_device_class();
|
||||||
|
for (const auto &event_type : event->get_event_types())
|
||||||
|
msg.event_types.push_back(event_type);
|
||||||
|
return this->send_list_entities_event_response(msg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool APIConnection::send_log_message(int level, const char *tag, const char *line) {
|
bool APIConnection::send_log_message(int level, const char *tag, const char *line) {
|
||||||
if (this->log_subscription_ < level)
|
if (this->log_subscription_ < level)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ class APIConnection : public APIServerConnection {
|
|||||||
bool send_time_info(datetime::TimeEntity *time);
|
bool send_time_info(datetime::TimeEntity *time);
|
||||||
void time_command(const TimeCommandRequest &msg) override;
|
void time_command(const TimeCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool send_datetime_state(datetime::DateTimeEntity *datetime);
|
||||||
|
bool send_datetime_info(datetime::DateTimeEntity *datetime);
|
||||||
|
void datetime_command(const DateTimeCommandRequest &msg) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool send_text_state(text::Text *text, std::string state);
|
bool send_text_state(text::Text *text, std::string state);
|
||||||
bool send_text_info(text::Text *text);
|
bool send_text_info(text::Text *text);
|
||||||
@@ -101,6 +106,11 @@ class APIConnection : public APIServerConnection {
|
|||||||
bool send_lock_info(lock::Lock *a_lock);
|
bool send_lock_info(lock::Lock *a_lock);
|
||||||
void lock_command(const LockCommandRequest &msg) override;
|
void lock_command(const LockCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool send_valve_state(valve::Valve *valve);
|
||||||
|
bool send_valve_info(valve::Valve *valve);
|
||||||
|
void valve_command(const ValveCommandRequest &msg) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool send_media_player_state(media_player::MediaPlayer *media_player);
|
bool send_media_player_state(media_player::MediaPlayer *media_player);
|
||||||
bool send_media_player_info(media_player::MediaPlayer *media_player);
|
bool send_media_player_info(media_player::MediaPlayer *media_player);
|
||||||
@@ -148,6 +158,11 @@ class APIConnection : public APIServerConnection {
|
|||||||
void alarm_control_panel_command(const AlarmControlPanelCommandRequest &msg) override;
|
void alarm_control_panel_command(const AlarmControlPanelCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool send_event(event::Event *event, std::string event_type);
|
||||||
|
bool send_event_info(event::Event *event);
|
||||||
|
#endif
|
||||||
|
|
||||||
void on_disconnect_response(const DisconnectResponse &value) override;
|
void on_disconnect_response(const DisconnectResponse &value) override;
|
||||||
void on_ping_response(const PingResponse &value) override {
|
void on_ping_response(const PingResponse &value) override {
|
||||||
// we initiated ping
|
// we initiated ping
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -216,6 +216,11 @@ enum TextMode : uint32_t {
|
|||||||
TEXT_MODE_TEXT = 0,
|
TEXT_MODE_TEXT = 0,
|
||||||
TEXT_MODE_PASSWORD = 1,
|
TEXT_MODE_PASSWORD = 1,
|
||||||
};
|
};
|
||||||
|
enum ValveOperation : uint32_t {
|
||||||
|
VALVE_OPERATION_IDLE = 0,
|
||||||
|
VALVE_OPERATION_IS_OPENING = 1,
|
||||||
|
VALVE_OPERATION_IS_CLOSING = 2,
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace enums
|
} // namespace enums
|
||||||
|
|
||||||
@@ -1293,6 +1298,8 @@ class MediaPlayerCommandRequest : public ProtoMessage {
|
|||||||
float volume{0.0f};
|
float volume{0.0f};
|
||||||
bool has_media_url{false};
|
bool has_media_url{false};
|
||||||
std::string media_url{};
|
std::string media_url{};
|
||||||
|
bool has_announcement{false};
|
||||||
|
bool announcement{false};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
@@ -1969,6 +1976,137 @@ class TimeCommandRequest : public ProtoMessage {
|
|||||||
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
};
|
};
|
||||||
|
class ListEntitiesEventResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
std::string object_id{};
|
||||||
|
uint32_t key{0};
|
||||||
|
std::string name{};
|
||||||
|
std::string unique_id{};
|
||||||
|
std::string icon{};
|
||||||
|
bool disabled_by_default{false};
|
||||||
|
enums::EntityCategory entity_category{};
|
||||||
|
std::string device_class{};
|
||||||
|
std::vector<std::string> event_types{};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class EventResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
uint32_t key{0};
|
||||||
|
std::string event_type{};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
|
};
|
||||||
|
class ListEntitiesValveResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
std::string object_id{};
|
||||||
|
uint32_t key{0};
|
||||||
|
std::string name{};
|
||||||
|
std::string unique_id{};
|
||||||
|
std::string icon{};
|
||||||
|
bool disabled_by_default{false};
|
||||||
|
enums::EntityCategory entity_category{};
|
||||||
|
std::string device_class{};
|
||||||
|
bool assumed_state{false};
|
||||||
|
bool supports_position{false};
|
||||||
|
bool supports_stop{false};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class ValveStateResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
uint32_t key{0};
|
||||||
|
float position{0.0f};
|
||||||
|
enums::ValveOperation current_operation{};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class ValveCommandRequest : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
uint32_t key{0};
|
||||||
|
bool has_position{false};
|
||||||
|
float position{0.0f};
|
||||||
|
bool stop{false};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class ListEntitiesDateTimeResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
std::string object_id{};
|
||||||
|
uint32_t key{0};
|
||||||
|
std::string name{};
|
||||||
|
std::string unique_id{};
|
||||||
|
std::string icon{};
|
||||||
|
bool disabled_by_default{false};
|
||||||
|
enums::EntityCategory entity_category{};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class DateTimeStateResponse : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
uint32_t key{0};
|
||||||
|
bool missing_state{false};
|
||||||
|
uint32_t epoch_seconds{0};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
|
class DateTimeCommandRequest : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
uint32_t key{0};
|
||||||
|
uint32_t epoch_seconds{0};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -557,6 +557,58 @@ bool APIServerConnectionBase::send_time_state_response(const TimeStateResponse &
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool APIServerConnectionBase::send_list_entities_event_response(const ListEntitiesEventResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_list_entities_event_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<ListEntitiesEventResponse>(msg, 107);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool APIServerConnectionBase::send_event_response(const EventResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_event_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<EventResponse>(msg, 108);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool APIServerConnectionBase::send_list_entities_valve_response(const ListEntitiesValveResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_list_entities_valve_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<ListEntitiesValveResponse>(msg, 109);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool APIServerConnectionBase::send_valve_state_response(const ValveStateResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_valve_state_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<ValveStateResponse>(msg, 110);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool APIServerConnectionBase::send_list_entities_date_time_response(const ListEntitiesDateTimeResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_list_entities_date_time_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<ListEntitiesDateTimeResponse>(msg, 112);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool APIServerConnectionBase::send_date_time_state_response(const DateTimeStateResponse &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_date_time_state_response: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<DateTimeStateResponse>(msg, 113);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
#endif
|
||||||
bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) {
|
bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) {
|
||||||
switch (msg_type) {
|
switch (msg_type) {
|
||||||
case 1: {
|
case 1: {
|
||||||
@@ -1019,6 +1071,28 @@ bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|||||||
ESP_LOGVV(TAG, "on_voice_assistant_audio: %s", msg.dump().c_str());
|
ESP_LOGVV(TAG, "on_voice_assistant_audio: %s", msg.dump().c_str());
|
||||||
#endif
|
#endif
|
||||||
this->on_voice_assistant_audio(msg);
|
this->on_voice_assistant_audio(msg);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 111: {
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
ValveCommandRequest msg;
|
||||||
|
msg.decode(msg_data, msg_size);
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "on_valve_command_request: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
this->on_valve_command_request(msg);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 114: {
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
DateTimeCommandRequest msg;
|
||||||
|
msg.decode(msg_data, msg_size);
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "on_date_time_command_request: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
this->on_date_time_command_request(msg);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1282,6 +1356,19 @@ void APIServerConnection::on_lock_command_request(const LockCommandRequest &msg)
|
|||||||
this->lock_command(msg);
|
this->lock_command(msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
void APIServerConnection::on_valve_command_request(const ValveCommandRequest &msg) {
|
||||||
|
if (!this->is_connection_setup()) {
|
||||||
|
this->on_no_setup_connection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this->is_authenticated()) {
|
||||||
|
this->on_unauthenticated_access();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->valve_command(msg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
void APIServerConnection::on_media_player_command_request(const MediaPlayerCommandRequest &msg) {
|
void APIServerConnection::on_media_player_command_request(const MediaPlayerCommandRequest &msg) {
|
||||||
if (!this->is_connection_setup()) {
|
if (!this->is_connection_setup()) {
|
||||||
@@ -1321,6 +1408,19 @@ void APIServerConnection::on_time_command_request(const TimeCommandRequest &msg)
|
|||||||
this->time_command(msg);
|
this->time_command(msg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
void APIServerConnection::on_date_time_command_request(const DateTimeCommandRequest &msg) {
|
||||||
|
if (!this->is_connection_setup()) {
|
||||||
|
this->on_no_setup_connection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this->is_authenticated()) {
|
||||||
|
this->on_unauthenticated_access();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->datetime_command(msg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef USE_BLUETOOTH_PROXY
|
#ifdef USE_BLUETOOTH_PROXY
|
||||||
void APIServerConnection::on_subscribe_bluetooth_le_advertisements_request(
|
void APIServerConnection::on_subscribe_bluetooth_le_advertisements_request(
|
||||||
const SubscribeBluetoothLEAdvertisementsRequest &msg) {
|
const SubscribeBluetoothLEAdvertisementsRequest &msg) {
|
||||||
|
|||||||
@@ -279,6 +279,30 @@ class APIServerConnectionBase : public ProtoService {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
virtual void on_time_command_request(const TimeCommandRequest &value){};
|
virtual void on_time_command_request(const TimeCommandRequest &value){};
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool send_list_entities_event_response(const ListEntitiesEventResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool send_event_response(const EventResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool send_list_entities_valve_response(const ListEntitiesValveResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool send_valve_state_response(const ValveStateResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
virtual void on_valve_command_request(const ValveCommandRequest &value){};
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool send_list_entities_date_time_response(const ListEntitiesDateTimeResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool send_date_time_state_response(const DateTimeStateResponse &msg);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
virtual void on_date_time_command_request(const DateTimeCommandRequest &value){};
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
bool read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) override;
|
bool read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) override;
|
||||||
@@ -331,6 +355,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
virtual void lock_command(const LockCommandRequest &msg) = 0;
|
virtual void lock_command(const LockCommandRequest &msg) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
virtual void valve_command(const ValveCommandRequest &msg) = 0;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
virtual void media_player_command(const MediaPlayerCommandRequest &msg) = 0;
|
virtual void media_player_command(const MediaPlayerCommandRequest &msg) = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -340,6 +367,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
virtual void time_command(const TimeCommandRequest &msg) = 0;
|
virtual void time_command(const TimeCommandRequest &msg) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
virtual void datetime_command(const DateTimeCommandRequest &msg) = 0;
|
||||||
|
#endif
|
||||||
#ifdef USE_BLUETOOTH_PROXY
|
#ifdef USE_BLUETOOTH_PROXY
|
||||||
virtual void subscribe_bluetooth_le_advertisements(const SubscribeBluetoothLEAdvertisementsRequest &msg) = 0;
|
virtual void subscribe_bluetooth_le_advertisements(const SubscribeBluetoothLEAdvertisementsRequest &msg) = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -423,6 +453,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
void on_lock_command_request(const LockCommandRequest &msg) override;
|
void on_lock_command_request(const LockCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
void on_valve_command_request(const ValveCommandRequest &msg) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
void on_media_player_command_request(const MediaPlayerCommandRequest &msg) override;
|
void on_media_player_command_request(const MediaPlayerCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
@@ -432,6 +465,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
void on_time_command_request(const TimeCommandRequest &msg) override;
|
void on_time_command_request(const TimeCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
void on_date_time_command_request(const DateTimeCommandRequest &msg) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_BLUETOOTH_PROXY
|
#ifdef USE_BLUETOOTH_PROXY
|
||||||
void on_subscribe_bluetooth_le_advertisements_request(const SubscribeBluetoothLEAdvertisementsRequest &msg) override;
|
void on_subscribe_bluetooth_le_advertisements_request(const SubscribeBluetoothLEAdvertisementsRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -273,6 +273,15 @@ void APIServer::on_time_update(datetime::TimeEntity *obj) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
void APIServer::on_datetime_update(datetime::DateTimeEntity *obj) {
|
||||||
|
if (obj->is_internal())
|
||||||
|
return;
|
||||||
|
for (auto &c : this->clients_)
|
||||||
|
c->send_datetime_state(obj);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
void APIServer::on_text_update(text::Text *obj, const std::string &state) {
|
void APIServer::on_text_update(text::Text *obj, const std::string &state) {
|
||||||
if (obj->is_internal())
|
if (obj->is_internal())
|
||||||
@@ -300,6 +309,15 @@ void APIServer::on_lock_update(lock::Lock *obj) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
void APIServer::on_valve_update(valve::Valve *obj) {
|
||||||
|
if (obj->is_internal())
|
||||||
|
return;
|
||||||
|
for (auto &c : this->clients_)
|
||||||
|
c->send_valve_state(obj);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
void APIServer::on_media_player_update(media_player::MediaPlayer *obj) {
|
void APIServer::on_media_player_update(media_player::MediaPlayer *obj) {
|
||||||
if (obj->is_internal())
|
if (obj->is_internal())
|
||||||
@@ -309,6 +327,13 @@ void APIServer::on_media_player_update(media_player::MediaPlayer *obj) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
void APIServer::on_event(event::Event *obj, const std::string &event_type) {
|
||||||
|
for (auto &c : this->clients_)
|
||||||
|
c->send_event(obj, event_type);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
float APIServer::get_setup_priority() const { return setup_priority::AFTER_WIFI; }
|
float APIServer::get_setup_priority() const { return setup_priority::AFTER_WIFI; }
|
||||||
void APIServer::set_port(uint16_t port) { this->port_ = port; }
|
void APIServer::set_port(uint16_t port) { this->port_ = port; }
|
||||||
APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ class APIServer : public Component, public Controller {
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
void on_time_update(datetime::TimeEntity *obj) override;
|
void on_time_update(datetime::TimeEntity *obj) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
void on_datetime_update(datetime::DateTimeEntity *obj) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
void on_text_update(text::Text *obj, const std::string &state) override;
|
void on_text_update(text::Text *obj, const std::string &state) override;
|
||||||
#endif
|
#endif
|
||||||
@@ -81,6 +84,9 @@ class APIServer : public Component, public Controller {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
void on_lock_update(lock::Lock *obj) override;
|
void on_lock_update(lock::Lock *obj) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
void on_valve_update(valve::Valve *obj) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
void on_media_player_update(media_player::MediaPlayer *obj) override;
|
void on_media_player_update(media_player::MediaPlayer *obj) override;
|
||||||
#endif
|
#endif
|
||||||
@@ -93,6 +99,9 @@ class APIServer : public Component, public Controller {
|
|||||||
#ifdef USE_ALARM_CONTROL_PANEL
|
#ifdef USE_ALARM_CONTROL_PANEL
|
||||||
void on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) override;
|
void on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
void on_event(event::Event *obj, const std::string &event_type) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool is_connected() const;
|
bool is_connected() const;
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ bool ListEntitiesIterator::on_text_sensor(text_sensor::TextSensor *text_sensor)
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
bool ListEntitiesIterator::on_lock(lock::Lock *a_lock) { return this->client_->send_lock_info(a_lock); }
|
bool ListEntitiesIterator::on_lock(lock::Lock *a_lock) { return this->client_->send_lock_info(a_lock); }
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool ListEntitiesIterator::on_valve(valve::Valve *valve) { return this->client_->send_valve_info(valve); }
|
||||||
|
#endif
|
||||||
|
|
||||||
bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done(); }
|
bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done(); }
|
||||||
ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {}
|
ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {}
|
||||||
@@ -68,6 +71,12 @@ bool ListEntitiesIterator::on_date(datetime::DateEntity *date) { return this->cl
|
|||||||
bool ListEntitiesIterator::on_time(datetime::TimeEntity *time) { return this->client_->send_time_info(time); }
|
bool ListEntitiesIterator::on_time(datetime::TimeEntity *time) { return this->client_->send_time_info(time); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool ListEntitiesIterator::on_datetime(datetime::DateTimeEntity *datetime) {
|
||||||
|
return this->client_->send_datetime_info(datetime);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool ListEntitiesIterator::on_text(text::Text *text) { return this->client_->send_text_info(text); }
|
bool ListEntitiesIterator::on_text(text::Text *text) { return this->client_->send_text_info(text); }
|
||||||
#endif
|
#endif
|
||||||
@@ -86,6 +95,9 @@ bool ListEntitiesIterator::on_alarm_control_panel(alarm_control_panel::AlarmCont
|
|||||||
return this->client_->send_alarm_control_panel_info(a_alarm_control_panel);
|
return this->client_->send_alarm_control_panel_info(a_alarm_control_panel);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool ListEntitiesIterator::on_event(event::Event *event) { return this->client_->send_event_info(event); }
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ class ListEntitiesIterator : public ComponentIterator {
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
bool on_time(datetime::TimeEntity *time) override;
|
bool on_time(datetime::TimeEntity *time) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool on_datetime(datetime::DateTimeEntity *datetime) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool on_text(text::Text *text) override;
|
bool on_text(text::Text *text) override;
|
||||||
#endif
|
#endif
|
||||||
@@ -61,11 +64,17 @@ class ListEntitiesIterator : public ComponentIterator {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
bool on_lock(lock::Lock *a_lock) override;
|
bool on_lock(lock::Lock *a_lock) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool on_valve(valve::Valve *valve) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool on_media_player(media_player::MediaPlayer *media_player) override;
|
bool on_media_player(media_player::MediaPlayer *media_player) override;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ALARM_CONTROL_PANEL
|
#ifdef USE_ALARM_CONTROL_PANEL
|
||||||
bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override;
|
bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override;
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool on_event(event::Event *event) override;
|
||||||
#endif
|
#endif
|
||||||
bool on_end() override;
|
bool on_end() override;
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ bool InitialStateIterator::on_date(datetime::DateEntity *date) { return this->cl
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
bool InitialStateIterator::on_time(datetime::TimeEntity *time) { return this->client_->send_time_state(time); }
|
bool InitialStateIterator::on_time(datetime::TimeEntity *time) { return this->client_->send_time_state(time); }
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool InitialStateIterator::on_datetime(datetime::DateTimeEntity *datetime) {
|
||||||
|
return this->client_->send_datetime_state(datetime);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool InitialStateIterator::on_text(text::Text *text) { return this->client_->send_text_state(text, text->state); }
|
bool InitialStateIterator::on_text(text::Text *text) { return this->client_->send_text_state(text, text->state); }
|
||||||
#endif
|
#endif
|
||||||
@@ -59,6 +64,9 @@ bool InitialStateIterator::on_select(select::Select *select) {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
bool InitialStateIterator::on_lock(lock::Lock *a_lock) { return this->client_->send_lock_state(a_lock, a_lock->state); }
|
bool InitialStateIterator::on_lock(lock::Lock *a_lock) { return this->client_->send_lock_state(a_lock, a_lock->state); }
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool InitialStateIterator::on_valve(valve::Valve *valve) { return this->client_->send_valve_state(valve); }
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool InitialStateIterator::on_media_player(media_player::MediaPlayer *media_player) {
|
bool InitialStateIterator::on_media_player(media_player::MediaPlayer *media_player) {
|
||||||
return this->client_->send_media_player_state(media_player);
|
return this->client_->send_media_player_state(media_player);
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ class InitialStateIterator : public ComponentIterator {
|
|||||||
#ifdef USE_DATETIME_TIME
|
#ifdef USE_DATETIME_TIME
|
||||||
bool on_time(datetime::TimeEntity *time) override;
|
bool on_time(datetime::TimeEntity *time) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_DATETIME_DATETIME
|
||||||
|
bool on_datetime(datetime::DateTimeEntity *datetime) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_TEXT
|
#ifdef USE_TEXT
|
||||||
bool on_text(text::Text *text) override;
|
bool on_text(text::Text *text) override;
|
||||||
#endif
|
#endif
|
||||||
@@ -58,11 +61,17 @@ class InitialStateIterator : public ComponentIterator {
|
|||||||
#ifdef USE_LOCK
|
#ifdef USE_LOCK
|
||||||
bool on_lock(lock::Lock *a_lock) override;
|
bool on_lock(lock::Lock *a_lock) override;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_VALVE
|
||||||
|
bool on_valve(valve::Valve *valve) override;
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool on_media_player(media_player::MediaPlayer *media_player) override;
|
bool on_media_player(media_player::MediaPlayer *media_player) override;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ALARM_CONTROL_PANEL
|
#ifdef USE_ALARM_CONTROL_PANEL
|
||||||
bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override;
|
bool on_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) override;
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EVENT
|
||||||
|
bool on_event(event::Event *event) override { return true; };
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
APIConnection *client_;
|
APIConnection *client_;
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ FAST_FILTER = {
|
|||||||
"LSB10": 7,
|
"LSB10": 7,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONF_ANGLE = "angle"
|
|
||||||
CONF_RAW_ANGLE = "raw_angle"
|
CONF_RAW_ANGLE = "raw_angle"
|
||||||
CONF_RAW_POSITION = "raw_position"
|
CONF_RAW_POSITION = "raw_position"
|
||||||
CONF_WATCHDOG = "watchdog"
|
CONF_WATCHDOG = "watchdog"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from esphome.const import (
|
|||||||
CONF_MAGNITUDE,
|
CONF_MAGNITUDE,
|
||||||
CONF_STATUS,
|
CONF_STATUS,
|
||||||
CONF_POSITION,
|
CONF_POSITION,
|
||||||
|
CONF_ANGLE,
|
||||||
)
|
)
|
||||||
from .. import as5600_ns, AS5600Component
|
from .. import as5600_ns, AS5600Component
|
||||||
|
|
||||||
@@ -19,7 +20,6 @@ DEPENDENCIES = ["as5600"]
|
|||||||
|
|
||||||
AS5600Sensor = as5600_ns.class_("AS5600Sensor", sensor.Sensor, cg.PollingComponent)
|
AS5600Sensor = as5600_ns.class_("AS5600Sensor", sensor.Sensor, cg.PollingComponent)
|
||||||
|
|
||||||
CONF_ANGLE = "angle"
|
|
||||||
CONF_RAW_ANGLE = "raw_angle"
|
CONF_RAW_ANGLE = "raw_angle"
|
||||||
CONF_RAW_POSITION = "raw_position"
|
CONF_RAW_POSITION = "raw_position"
|
||||||
CONF_WATCHDOG = "watchdog"
|
CONF_WATCHDOG = "watchdog"
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ CONF_AT581X_ID = "at581x_id"
|
|||||||
|
|
||||||
|
|
||||||
CONF_SENSING_DISTANCE = "sensing_distance"
|
CONF_SENSING_DISTANCE = "sensing_distance"
|
||||||
CONF_SENSITIVITY = "sensitivity"
|
|
||||||
CONF_POWERON_SELFCHECK_TIME = "poweron_selfcheck_time"
|
CONF_POWERON_SELFCHECK_TIME = "poweron_selfcheck_time"
|
||||||
CONF_PROTECT_TIME = "protect_time"
|
CONF_PROTECT_TIME = "protect_time"
|
||||||
CONF_TRIGGER_BASE = "trigger_base"
|
CONF_TRIGGER_BASE = "trigger_base"
|
||||||
|
|||||||
@@ -51,15 +51,15 @@ void binary_sensor::MultiClickTrigger::on_state_(bool state) {
|
|||||||
MultiClickTriggerEvent evt = this->timing_[*this->at_index_];
|
MultiClickTriggerEvent evt = this->timing_[*this->at_index_];
|
||||||
|
|
||||||
if (evt.max_length != 4294967294UL) {
|
if (evt.max_length != 4294967294UL) {
|
||||||
ESP_LOGV(TAG, "A i=%u min=%" PRIu32 " max=%" PRIu32, *this->at_index_, evt.min_length, evt.max_length); // NOLINT
|
ESP_LOGV(TAG, "A i=%zu min=%" PRIu32 " max=%" PRIu32, *this->at_index_, evt.min_length, evt.max_length); // NOLINT
|
||||||
this->schedule_is_valid_(evt.min_length);
|
this->schedule_is_valid_(evt.min_length);
|
||||||
this->schedule_is_not_valid_(evt.max_length);
|
this->schedule_is_not_valid_(evt.max_length);
|
||||||
} else if (*this->at_index_ + 1 != this->timing_.size()) {
|
} else if (*this->at_index_ + 1 != this->timing_.size()) {
|
||||||
ESP_LOGV(TAG, "B i=%u min=%" PRIu32, *this->at_index_, evt.min_length); // NOLINT
|
ESP_LOGV(TAG, "B i=%zu min=%" PRIu32, *this->at_index_, evt.min_length); // NOLINT
|
||||||
this->cancel_timeout("is_not_valid");
|
this->cancel_timeout("is_not_valid");
|
||||||
this->schedule_is_valid_(evt.min_length);
|
this->schedule_is_valid_(evt.min_length);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGV(TAG, "C i=%u min=%" PRIu32, *this->at_index_, evt.min_length); // NOLINT
|
ESP_LOGV(TAG, "C i=%zu min=%" PRIu32, *this->at_index_, evt.min_length); // NOLINT
|
||||||
this->is_valid_ = false;
|
this->is_valid_ = false;
|
||||||
this->cancel_timeout("is_not_valid");
|
this->cancel_timeout("is_not_valid");
|
||||||
this->set_timeout("trigger", evt.min_length, [this]() { this->trigger_(); });
|
this->set_timeout("trigger", evt.min_length, [this]() { this->trigger_(); });
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from esphome.const import (
|
|||||||
CONF_ENERGY,
|
CONF_ENERGY,
|
||||||
CONF_EXTERNAL_TEMPERATURE,
|
CONF_EXTERNAL_TEMPERATURE,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
|
CONF_INTERNAL_TEMPERATURE,
|
||||||
CONF_POWER,
|
CONF_POWER,
|
||||||
CONF_VOLTAGE,
|
CONF_VOLTAGE,
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
@@ -24,7 +25,6 @@ from esphome.const import (
|
|||||||
|
|
||||||
DEPENDENCIES = ["uart"]
|
DEPENDENCIES = ["uart"]
|
||||||
|
|
||||||
CONF_INTERNAL_TEMPERATURE = "internal_temperature"
|
|
||||||
|
|
||||||
bl0940_ns = cg.esphome_ns.namespace("bl0940")
|
bl0940_ns = cg.esphome_ns.namespace("bl0940")
|
||||||
BL0940 = bl0940_ns.class_("BL0940", cg.PollingComponent, uart.UARTDevice)
|
BL0940 = bl0940_ns.class_("BL0940", cg.PollingComponent, uart.UARTDevice)
|
||||||
|
|||||||
@@ -25,9 +25,13 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
|
|||||||
this->proxy_->send_connections_free();
|
this->proxy_->send_connections_free();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ESP_GATTC_CLOSE_EVT: {
|
||||||
|
this->proxy_->send_device_connection(this->address_, false, 0, param->close.reason);
|
||||||
|
this->set_address(0);
|
||||||
|
this->proxy_->send_connections_free();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ESP_GATTC_OPEN_EVT: {
|
case ESP_GATTC_OPEN_EVT: {
|
||||||
if (param->open.conn_id != this->conn_id_)
|
|
||||||
break;
|
|
||||||
if (param->open.status != ESP_GATT_OK && param->open.status != ESP_GATT_ALREADY_OPEN) {
|
if (param->open.status != ESP_GATT_OK && param->open.status != ESP_GATT_ALREADY_OPEN) {
|
||||||
this->proxy_->send_device_connection(this->address_, false, 0, param->open.status);
|
this->proxy_->send_device_connection(this->address_, false, 0, param->open.status);
|
||||||
this->set_address(0);
|
this->set_address(0);
|
||||||
@@ -39,9 +43,8 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
|
|||||||
this->seen_mtu_or_services_ = false;
|
this->seen_mtu_or_services_ = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_CFG_MTU_EVT: {
|
case ESP_GATTC_CFG_MTU_EVT:
|
||||||
if (param->cfg_mtu.conn_id != this->conn_id_)
|
case ESP_GATTC_SEARCH_CMPL_EVT: {
|
||||||
break;
|
|
||||||
if (!this->seen_mtu_or_services_) {
|
if (!this->seen_mtu_or_services_) {
|
||||||
// We don't know if we will get the MTU or the services first, so
|
// We don't know if we will get the MTU or the services first, so
|
||||||
// only send the device connection true if we have already received
|
// only send the device connection true if we have already received
|
||||||
@@ -53,24 +56,8 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
|
|||||||
this->proxy_->send_connections_free();
|
this->proxy_->send_connections_free();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_SEARCH_CMPL_EVT: {
|
|
||||||
if (param->search_cmpl.conn_id != this->conn_id_)
|
|
||||||
break;
|
|
||||||
if (!this->seen_mtu_or_services_) {
|
|
||||||
// We don't know if we will get the MTU or the services first, so
|
|
||||||
// only send the device connection true if we have already received
|
|
||||||
// the mtu.
|
|
||||||
this->seen_mtu_or_services_ = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this->proxy_->send_device_connection(this->address_, true, this->mtu_);
|
|
||||||
this->proxy_->send_connections_free();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ESP_GATTC_READ_DESCR_EVT:
|
case ESP_GATTC_READ_DESCR_EVT:
|
||||||
case ESP_GATTC_READ_CHAR_EVT: {
|
case ESP_GATTC_READ_CHAR_EVT: {
|
||||||
if (param->read.conn_id != this->conn_id_)
|
|
||||||
break;
|
|
||||||
if (param->read.status != ESP_GATT_OK) {
|
if (param->read.status != ESP_GATT_OK) {
|
||||||
ESP_LOGW(TAG, "[%d] [%s] Error reading char/descriptor at handle 0x%2X, status=%d", this->connection_index_,
|
ESP_LOGW(TAG, "[%d] [%s] Error reading char/descriptor at handle 0x%2X, status=%d", this->connection_index_,
|
||||||
this->address_str_.c_str(), param->read.handle, param->read.status);
|
this->address_str_.c_str(), param->read.handle, param->read.status);
|
||||||
@@ -89,8 +76,6 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
|
|||||||
}
|
}
|
||||||
case ESP_GATTC_WRITE_CHAR_EVT:
|
case ESP_GATTC_WRITE_CHAR_EVT:
|
||||||
case ESP_GATTC_WRITE_DESCR_EVT: {
|
case ESP_GATTC_WRITE_DESCR_EVT: {
|
||||||
if (param->write.conn_id != this->conn_id_)
|
|
||||||
break;
|
|
||||||
if (param->write.status != ESP_GATT_OK) {
|
if (param->write.status != ESP_GATT_OK) {
|
||||||
ESP_LOGW(TAG, "[%d] [%s] Error writing char/descriptor at handle 0x%2X, status=%d", this->connection_index_,
|
ESP_LOGW(TAG, "[%d] [%s] Error writing char/descriptor at handle 0x%2X, status=%d", this->connection_index_,
|
||||||
this->address_str_.c_str(), param->write.handle, param->write.status);
|
this->address_str_.c_str(), param->write.handle, param->write.status);
|
||||||
@@ -131,8 +116,6 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_NOTIFY_EVT: {
|
case ESP_GATTC_NOTIFY_EVT: {
|
||||||
if (param->notify.conn_id != this->conn_id_)
|
|
||||||
break;
|
|
||||||
ESP_LOGV(TAG, "[%d] [%s] ESP_GATTC_NOTIFY_EVT: handle=0x%2X", this->connection_index_, this->address_str_.c_str(),
|
ESP_LOGV(TAG, "[%d] [%s] ESP_GATTC_NOTIFY_EVT: handle=0x%2X", this->connection_index_, this->address_str_.c_str(),
|
||||||
param->notify.handle);
|
param->notify.handle);
|
||||||
api::BluetoothGATTNotifyDataResponse resp;
|
api::BluetoothGATTNotifyDataResponse resp;
|
||||||
|
|||||||
@@ -1 +1,108 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.components import sensor
|
||||||
|
from esphome.const import (
|
||||||
|
CONF_HUMIDITY,
|
||||||
|
CONF_ID,
|
||||||
|
CONF_IIR_FILTER,
|
||||||
|
CONF_OVERSAMPLING,
|
||||||
|
CONF_PRESSURE,
|
||||||
|
CONF_TEMPERATURE,
|
||||||
|
DEVICE_CLASS_HUMIDITY,
|
||||||
|
DEVICE_CLASS_PRESSURE,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
UNIT_CELSIUS,
|
||||||
|
UNIT_HECTOPASCAL,
|
||||||
|
UNIT_PERCENT,
|
||||||
|
)
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
|
|
||||||
|
bme280_ns = cg.esphome_ns.namespace("bme280_base")
|
||||||
|
BME280Oversampling = bme280_ns.enum("BME280Oversampling")
|
||||||
|
OVERSAMPLING_OPTIONS = {
|
||||||
|
"NONE": BME280Oversampling.BME280_OVERSAMPLING_NONE,
|
||||||
|
"1X": BME280Oversampling.BME280_OVERSAMPLING_1X,
|
||||||
|
"2X": BME280Oversampling.BME280_OVERSAMPLING_2X,
|
||||||
|
"4X": BME280Oversampling.BME280_OVERSAMPLING_4X,
|
||||||
|
"8X": BME280Oversampling.BME280_OVERSAMPLING_8X,
|
||||||
|
"16X": BME280Oversampling.BME280_OVERSAMPLING_16X,
|
||||||
|
}
|
||||||
|
|
||||||
|
BME280IIRFilter = bme280_ns.enum("BME280IIRFilter")
|
||||||
|
IIR_FILTER_OPTIONS = {
|
||||||
|
"OFF": BME280IIRFilter.BME280_IIR_FILTER_OFF,
|
||||||
|
"2X": BME280IIRFilter.BME280_IIR_FILTER_2X,
|
||||||
|
"4X": BME280IIRFilter.BME280_IIR_FILTER_4X,
|
||||||
|
"8X": BME280IIRFilter.BME280_IIR_FILTER_8X,
|
||||||
|
"16X": BME280IIRFilter.BME280_IIR_FILTER_16X,
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG_SCHEMA_BASE = cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_CELSIUS,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
).extend(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
||||||
|
OVERSAMPLING_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_HECTOPASCAL,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_PRESSURE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
).extend(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
||||||
|
OVERSAMPLING_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_PERCENT,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_HUMIDITY,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
).extend(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
||||||
|
OVERSAMPLING_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
||||||
|
IIR_FILTER_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
).extend(cv.polling_component_schema("60s"))
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code_base(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||||
|
sens = await sensor.new_sensor(temperature_config)
|
||||||
|
cg.add(var.set_temperature_sensor(sens))
|
||||||
|
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
||||||
|
|
||||||
|
if pressure_config := config.get(CONF_PRESSURE):
|
||||||
|
sens = await sensor.new_sensor(pressure_config)
|
||||||
|
cg.add(var.set_pressure_sensor(sens))
|
||||||
|
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
||||||
|
|
||||||
|
if humidity_config := config.get(CONF_HUMIDITY):
|
||||||
|
sens = await sensor.new_sensor(humidity_config)
|
||||||
|
cg.add(var.set_humidity_sensor(sens))
|
||||||
|
cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING]))
|
||||||
|
|
||||||
|
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
||||||
|
|
||||||
|
return var
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import sensor
|
|
||||||
from esphome.const import (
|
|
||||||
CONF_HUMIDITY,
|
|
||||||
CONF_ID,
|
|
||||||
CONF_IIR_FILTER,
|
|
||||||
CONF_OVERSAMPLING,
|
|
||||||
CONF_PRESSURE,
|
|
||||||
CONF_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_PRESSURE,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
STATE_CLASS_MEASUREMENT,
|
|
||||||
UNIT_CELSIUS,
|
|
||||||
UNIT_HECTOPASCAL,
|
|
||||||
UNIT_PERCENT,
|
|
||||||
)
|
|
||||||
|
|
||||||
bme280_ns = cg.esphome_ns.namespace("bme280_base")
|
|
||||||
BME280Oversampling = bme280_ns.enum("BME280Oversampling")
|
|
||||||
OVERSAMPLING_OPTIONS = {
|
|
||||||
"NONE": BME280Oversampling.BME280_OVERSAMPLING_NONE,
|
|
||||||
"1X": BME280Oversampling.BME280_OVERSAMPLING_1X,
|
|
||||||
"2X": BME280Oversampling.BME280_OVERSAMPLING_2X,
|
|
||||||
"4X": BME280Oversampling.BME280_OVERSAMPLING_4X,
|
|
||||||
"8X": BME280Oversampling.BME280_OVERSAMPLING_8X,
|
|
||||||
"16X": BME280Oversampling.BME280_OVERSAMPLING_16X,
|
|
||||||
}
|
|
||||||
|
|
||||||
BME280IIRFilter = bme280_ns.enum("BME280IIRFilter")
|
|
||||||
IIR_FILTER_OPTIONS = {
|
|
||||||
"OFF": BME280IIRFilter.BME280_IIR_FILTER_OFF,
|
|
||||||
"2X": BME280IIRFilter.BME280_IIR_FILTER_2X,
|
|
||||||
"4X": BME280IIRFilter.BME280_IIR_FILTER_4X,
|
|
||||||
"8X": BME280IIRFilter.BME280_IIR_FILTER_8X,
|
|
||||||
"16X": BME280IIRFilter.BME280_IIR_FILTER_16X,
|
|
||||||
}
|
|
||||||
|
|
||||||
CONFIG_SCHEMA_BASE = cv.Schema(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_CELSIUS,
|
|
||||||
accuracy_decimals=1,
|
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
).extend(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
|
||||||
OVERSAMPLING_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_HECTOPASCAL,
|
|
||||||
accuracy_decimals=1,
|
|
||||||
device_class=DEVICE_CLASS_PRESSURE,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
).extend(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
|
||||||
OVERSAMPLING_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_PERCENT,
|
|
||||||
accuracy_decimals=1,
|
|
||||||
device_class=DEVICE_CLASS_HUMIDITY,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
).extend(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
|
||||||
OVERSAMPLING_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
|
||||||
IIR_FILTER_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
).extend(cv.polling_component_schema("60s"))
|
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config, func=None):
|
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
|
||||||
await cg.register_component(var, config)
|
|
||||||
if func is not None:
|
|
||||||
await func(var, config)
|
|
||||||
|
|
||||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
|
||||||
sens = await sensor.new_sensor(temperature_config)
|
|
||||||
cg.add(var.set_temperature_sensor(sens))
|
|
||||||
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
|
||||||
|
|
||||||
if pressure_config := config.get(CONF_PRESSURE):
|
|
||||||
sens = await sensor.new_sensor(pressure_config)
|
|
||||||
cg.add(var.set_pressure_sensor(sens))
|
|
||||||
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
|
||||||
|
|
||||||
if humidity_config := config.get(CONF_HUMIDITY):
|
|
||||||
sens = await sensor.new_sensor(humidity_config)
|
|
||||||
cg.add(var.set_humidity_sensor(sens))
|
|
||||||
cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING]))
|
|
||||||
|
|
||||||
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.components import i2c
|
from esphome.components import i2c
|
||||||
from ..bme280_base.sensor import to_code as to_code_base, cv, CONFIG_SCHEMA_BASE
|
from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE
|
||||||
|
|
||||||
DEPENDENCIES = ["i2c"]
|
|
||||||
AUTO_LOAD = ["bme280_base"]
|
AUTO_LOAD = ["bme280_base"]
|
||||||
|
DEPENDENCIES = ["i2c"]
|
||||||
|
|
||||||
bme280_ns = cg.esphome_ns.namespace("bme280_i2c")
|
bme280_ns = cg.esphome_ns.namespace("bme280_i2c")
|
||||||
BME280I2CComponent = bme280_ns.class_(
|
BME280I2CComponent = bme280_ns.class_(
|
||||||
@@ -16,4 +17,5 @@ CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend(
|
|||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
await to_code_base(config, func=i2c.register_i2c_device)
|
var = await to_code_base(config)
|
||||||
|
await i2c.register_i2c_device(var, config)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
CODEOWNERS = ["@apbodrov"]
|
|
||||||
|
|||||||
@@ -4,19 +4,19 @@
|
|||||||
#include "bme280_spi.h"
|
#include "bme280_spi.h"
|
||||||
#include <esphome/components/bme280_base/bme280_base.h>
|
#include <esphome/components/bme280_base/bme280_base.h>
|
||||||
|
|
||||||
int set_bit(uint8_t num, int position) {
|
namespace esphome {
|
||||||
|
namespace bme280_spi {
|
||||||
|
|
||||||
|
uint8_t set_bit(uint8_t num, int position) {
|
||||||
int mask = 1 << position;
|
int mask = 1 << position;
|
||||||
return num | mask;
|
return num | mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
int clear_bit(uint8_t num, int position) {
|
uint8_t clear_bit(uint8_t num, int position) {
|
||||||
int mask = 1 << position;
|
int mask = 1 << position;
|
||||||
return num & ~mask;
|
return num & ~mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace esphome {
|
|
||||||
namespace bme280_spi {
|
|
||||||
|
|
||||||
void BME280SPIComponent::setup() {
|
void BME280SPIComponent::setup() {
|
||||||
this->spi_setup();
|
this->spi_setup();
|
||||||
BME280Component::setup();
|
BME280Component::setup();
|
||||||
@@ -30,34 +30,33 @@ void BME280SPIComponent::setup() {
|
|||||||
|
|
||||||
bool BME280SPIComponent::read_byte(uint8_t a_register, uint8_t *data) {
|
bool BME280SPIComponent::read_byte(uint8_t a_register, uint8_t *data) {
|
||||||
this->enable();
|
this->enable();
|
||||||
// cause: *data = this->delegate_->transfer(tmp) doesnt work
|
this->transfer_byte(set_bit(a_register, 7));
|
||||||
this->delegate_->transfer(set_bit(a_register, 7));
|
*data = this->transfer_byte(0);
|
||||||
*data = this->delegate_->transfer(0);
|
|
||||||
this->disable();
|
this->disable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BME280SPIComponent::write_byte(uint8_t a_register, uint8_t data) {
|
bool BME280SPIComponent::write_byte(uint8_t a_register, uint8_t data) {
|
||||||
this->enable();
|
this->enable();
|
||||||
this->delegate_->transfer(clear_bit(a_register, 7));
|
this->transfer_byte(clear_bit(a_register, 7));
|
||||||
this->delegate_->transfer(data);
|
this->transfer_byte(data);
|
||||||
this->disable();
|
this->disable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BME280SPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
|
bool BME280SPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
|
||||||
this->enable();
|
this->enable();
|
||||||
this->delegate_->transfer(set_bit(a_register, 7));
|
this->transfer_byte(set_bit(a_register, 7));
|
||||||
this->delegate_->read_array(data, len);
|
this->read_array(data, len);
|
||||||
this->disable();
|
this->disable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BME280SPIComponent::read_byte_16(uint8_t a_register, uint16_t *data) {
|
bool BME280SPIComponent::read_byte_16(uint8_t a_register, uint16_t *data) {
|
||||||
this->enable();
|
this->enable();
|
||||||
this->delegate_->transfer(set_bit(a_register, 7));
|
this->transfer_byte(set_bit(a_register, 7));
|
||||||
((uint8_t *) data)[1] = this->delegate_->transfer(0);
|
((uint8_t *) data)[1] = this->transfer_byte(0);
|
||||||
((uint8_t *) data)[0] = this->delegate_->transfer(0);
|
((uint8_t *) data)[0] = this->transfer_byte(0);
|
||||||
this->disable();
|
this->disable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.components import spi
|
from esphome.components import spi
|
||||||
from esphome.components.bme280_base.sensor import (
|
from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE
|
||||||
to_code as to_code_base,
|
|
||||||
cv,
|
|
||||||
CONFIG_SCHEMA_BASE,
|
|
||||||
)
|
|
||||||
|
|
||||||
DEPENDENCIES = ["spi"]
|
|
||||||
AUTO_LOAD = ["bme280_base"]
|
AUTO_LOAD = ["bme280_base"]
|
||||||
|
CODEOWNERS = ["@apbodrov"]
|
||||||
|
DEPENDENCIES = ["spi"]
|
||||||
|
|
||||||
|
|
||||||
bme280_spi_ns = cg.esphome_ns.namespace("bme280_spi")
|
bme280_spi_ns = cg.esphome_ns.namespace("bme280_spi")
|
||||||
@@ -21,4 +19,5 @@ CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend(spi.spi_device_schema()).extend(
|
|||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
await to_code_base(config, func=spi.register_spi_device)
|
var = await to_code_base(config)
|
||||||
|
await spi.register_spi_device(var, config)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import i2c, esp32
|
from esphome.components import i2c, esp32
|
||||||
from esphome.const import CONF_ID
|
from esphome.const import CONF_ID, CONF_TEMPERATURE_OFFSET
|
||||||
|
|
||||||
CODEOWNERS = ["@trvrnrth"]
|
CODEOWNERS = ["@trvrnrth"]
|
||||||
DEPENDENCIES = ["i2c"]
|
DEPENDENCIES = ["i2c"]
|
||||||
@@ -9,7 +9,6 @@ AUTO_LOAD = ["sensor", "text_sensor"]
|
|||||||
MULTI_CONF = True
|
MULTI_CONF = True
|
||||||
|
|
||||||
CONF_BME680_BSEC_ID = "bme680_bsec_id"
|
CONF_BME680_BSEC_ID = "bme680_bsec_id"
|
||||||
CONF_TEMPERATURE_OFFSET = "temperature_offset"
|
|
||||||
CONF_IAQ_MODE = "iaq_mode"
|
CONF_IAQ_MODE = "iaq_mode"
|
||||||
CONF_SUPPLY_VOLTAGE = "supply_voltage"
|
CONF_SUPPLY_VOLTAGE = "supply_voltage"
|
||||||
CONF_SAMPLE_RATE = "sample_rate"
|
CONF_SAMPLE_RATE = "sample_rate"
|
||||||
|
|||||||
@@ -1,102 +1,7 @@
|
|||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import i2c, sensor
|
|
||||||
from esphome.const import (
|
CODEOWNERS = ["@latonita"]
|
||||||
CONF_ID,
|
|
||||||
CONF_IIR_FILTER,
|
CONFIG_SCHEMA = CONFIG_SCHEMA = cv.invalid(
|
||||||
CONF_OVERSAMPLING,
|
"The bmp3xx sensor component has been renamed to bmp3xx_i2c."
|
||||||
CONF_PRESSURE,
|
|
||||||
CONF_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_PRESSURE,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
STATE_CLASS_MEASUREMENT,
|
|
||||||
UNIT_CELSIUS,
|
|
||||||
UNIT_HECTOPASCAL,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
CODEOWNERS = ["@martgras"]
|
|
||||||
DEPENDENCIES = ["i2c"]
|
|
||||||
|
|
||||||
bmp3xx_ns = cg.esphome_ns.namespace("bmp3xx")
|
|
||||||
Oversampling = bmp3xx_ns.enum("Oversampling")
|
|
||||||
OVERSAMPLING_OPTIONS = {
|
|
||||||
"NONE": Oversampling.OVERSAMPLING_NONE,
|
|
||||||
"2X": Oversampling.OVERSAMPLING_X2,
|
|
||||||
"4X": Oversampling.OVERSAMPLING_X4,
|
|
||||||
"8X": Oversampling.OVERSAMPLING_X8,
|
|
||||||
"16X": Oversampling.OVERSAMPLING_X16,
|
|
||||||
"32X": Oversampling.OVERSAMPLING_X32,
|
|
||||||
}
|
|
||||||
|
|
||||||
IIRFilter = bmp3xx_ns.enum("IIRFilter")
|
|
||||||
IIR_FILTER_OPTIONS = {
|
|
||||||
"OFF": IIRFilter.IIR_FILTER_OFF,
|
|
||||||
"2X": IIRFilter.IIR_FILTER_2,
|
|
||||||
"4X": IIRFilter.IIR_FILTER_4,
|
|
||||||
"8X": IIRFilter.IIR_FILTER_8,
|
|
||||||
"16X": IIRFilter.IIR_FILTER_16,
|
|
||||||
"32X": IIRFilter.IIR_FILTER_32,
|
|
||||||
"64X": IIRFilter.IIR_FILTER_64,
|
|
||||||
"128X": IIRFilter.IIR_FILTER_128,
|
|
||||||
}
|
|
||||||
|
|
||||||
BMP3XXComponent = bmp3xx_ns.class_(
|
|
||||||
"BMP3XXComponent", cg.PollingComponent, i2c.I2CDevice
|
|
||||||
)
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
|
||||||
cv.Schema(
|
|
||||||
{
|
|
||||||
cv.GenerateID(): cv.declare_id(BMP3XXComponent),
|
|
||||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_CELSIUS,
|
|
||||||
accuracy_decimals=1,
|
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
).extend(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_OVERSAMPLING, default="2X"): cv.enum(
|
|
||||||
OVERSAMPLING_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
|
||||||
unit_of_measurement=UNIT_HECTOPASCAL,
|
|
||||||
accuracy_decimals=1,
|
|
||||||
device_class=DEVICE_CLASS_PRESSURE,
|
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
|
||||||
).extend(
|
|
||||||
{
|
|
||||||
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
|
||||||
OVERSAMPLING_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
|
||||||
IIR_FILTER_OPTIONS, upper=True
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.extend(cv.polling_component_schema("60s"))
|
|
||||||
.extend(i2c.i2c_device_schema(0x77))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
|
||||||
await cg.register_component(var, config)
|
|
||||||
await i2c.register_i2c_device(var, config)
|
|
||||||
cg.add(var.set_iir_filter_config(config[CONF_IIR_FILTER]))
|
|
||||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
|
||||||
sens = await sensor.new_sensor(temperature_config)
|
|
||||||
cg.add(var.set_temperature_sensor(sens))
|
|
||||||
cg.add(
|
|
||||||
var.set_temperature_oversampling_config(
|
|
||||||
temperature_config[CONF_OVERSAMPLING]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if pressure_config := config.get(CONF_PRESSURE):
|
|
||||||
sens = await sensor.new_sensor(pressure_config)
|
|
||||||
cg.add(var.set_pressure_sensor(sens))
|
|
||||||
cg.add(var.set_pressure_oversampling_config(pressure_config[CONF_OVERSAMPLING]))
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.components import sensor
|
||||||
|
from esphome.const import (
|
||||||
|
CONF_ID,
|
||||||
|
CONF_IIR_FILTER,
|
||||||
|
CONF_OVERSAMPLING,
|
||||||
|
CONF_PRESSURE,
|
||||||
|
CONF_TEMPERATURE,
|
||||||
|
DEVICE_CLASS_PRESSURE,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
UNIT_CELSIUS,
|
||||||
|
UNIT_HECTOPASCAL,
|
||||||
|
)
|
||||||
|
|
||||||
|
CODEOWNERS = ["@martgras", "@latonita"]
|
||||||
|
|
||||||
|
bmp3xx_ns = cg.esphome_ns.namespace("bmp3xx_base")
|
||||||
|
Oversampling = bmp3xx_ns.enum("Oversampling")
|
||||||
|
OVERSAMPLING_OPTIONS = {
|
||||||
|
"NONE": Oversampling.OVERSAMPLING_NONE,
|
||||||
|
"2X": Oversampling.OVERSAMPLING_X2,
|
||||||
|
"4X": Oversampling.OVERSAMPLING_X4,
|
||||||
|
"8X": Oversampling.OVERSAMPLING_X8,
|
||||||
|
"16X": Oversampling.OVERSAMPLING_X16,
|
||||||
|
"32X": Oversampling.OVERSAMPLING_X32,
|
||||||
|
}
|
||||||
|
|
||||||
|
IIRFilter = bmp3xx_ns.enum("IIRFilter")
|
||||||
|
IIR_FILTER_OPTIONS = {
|
||||||
|
"OFF": IIRFilter.IIR_FILTER_OFF,
|
||||||
|
"2X": IIRFilter.IIR_FILTER_2,
|
||||||
|
"4X": IIRFilter.IIR_FILTER_4,
|
||||||
|
"8X": IIRFilter.IIR_FILTER_8,
|
||||||
|
"16X": IIRFilter.IIR_FILTER_16,
|
||||||
|
"32X": IIRFilter.IIR_FILTER_32,
|
||||||
|
"64X": IIRFilter.IIR_FILTER_64,
|
||||||
|
"128X": IIRFilter.IIR_FILTER_128,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_SCHEMA_BASE = cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_CELSIUS,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
).extend(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_OVERSAMPLING, default="2X"): cv.enum(
|
||||||
|
OVERSAMPLING_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
||||||
|
unit_of_measurement=UNIT_HECTOPASCAL,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_PRESSURE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
).extend(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
||||||
|
OVERSAMPLING_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
||||||
|
IIR_FILTER_OPTIONS, upper=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
).extend(cv.polling_component_schema("60s"))
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code_base(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
cg.add(var.set_iir_filter_config(config[CONF_IIR_FILTER]))
|
||||||
|
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||||
|
sens = await sensor.new_sensor(temperature_config)
|
||||||
|
cg.add(var.set_temperature_sensor(sens))
|
||||||
|
cg.add(
|
||||||
|
var.set_temperature_oversampling_config(
|
||||||
|
temperature_config[CONF_OVERSAMPLING]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if pressure_config := config.get(CONF_PRESSURE):
|
||||||
|
sens = await sensor.new_sensor(pressure_config)
|
||||||
|
cg.add(var.set_pressure_sensor(sens))
|
||||||
|
cg.add(var.set_pressure_oversampling_config(pressure_config[CONF_OVERSAMPLING]))
|
||||||
|
|
||||||
|
return var
|
||||||
+3
-4
@@ -5,13 +5,13 @@
|
|||||||
http://github.com/MartinL1/BMP388_DEV
|
http://github.com/MartinL1/BMP388_DEV
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bmp3xx.h"
|
#include "bmp3xx_base.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace bmp3xx {
|
namespace bmp3xx_base {
|
||||||
|
|
||||||
static const char *const TAG = "bmp3xx.sensor";
|
static const char *const TAG = "bmp3xx.sensor";
|
||||||
|
|
||||||
@@ -150,7 +150,6 @@ void BMP3XXComponent::setup() {
|
|||||||
void BMP3XXComponent::dump_config() {
|
void BMP3XXComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "BMP3XX:");
|
ESP_LOGCONFIG(TAG, "BMP3XX:");
|
||||||
ESP_LOGCONFIG(TAG, " Type: %s (0x%X)", LOG_STR_ARG(chip_type_to_str(this->chip_id_.reg)), this->chip_id_.reg);
|
ESP_LOGCONFIG(TAG, " Type: %s (0x%X)", LOG_STR_ARG(chip_type_to_str(this->chip_id_.reg)), this->chip_id_.reg);
|
||||||
LOG_I2C_DEVICE(this);
|
|
||||||
switch (this->error_code_) {
|
switch (this->error_code_) {
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
@@ -386,5 +385,5 @@ float BMP3XXComponent::bmp388_compensate_pressure_(float uncomp_press, float t_l
|
|||||||
return partial_out1 + partial_out2 + partial_data4;
|
return partial_out1 + partial_out2 + partial_data4;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace bmp3xx
|
} // namespace bmp3xx_base
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
@@ -9,10 +9,9 @@
|
|||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
#include "esphome/components/i2c/i2c.h"
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace bmp3xx {
|
namespace bmp3xx_base {
|
||||||
|
|
||||||
static const uint8_t BMP388_ID = 0x50; // The BMP388 device ID
|
static const uint8_t BMP388_ID = 0x50; // The BMP388 device ID
|
||||||
static const uint8_t BMP390_ID = 0x60; // The BMP390 device ID
|
static const uint8_t BMP390_ID = 0x60; // The BMP390 device ID
|
||||||
@@ -69,8 +68,8 @@ enum IIRFilter {
|
|||||||
IIR_FILTER_128 = 0x07
|
IIR_FILTER_128 = 0x07
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This class implements support for the BMP3XX Temperature+Pressure i2c sensor.
|
/// This class implements support for the BMP3XX Temperature+Pressure sensor.
|
||||||
class BMP3XXComponent : public PollingComponent, public i2c::I2CDevice {
|
class BMP3XXComponent : public PollingComponent {
|
||||||
public:
|
public:
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
@@ -231,7 +230,13 @@ class BMP3XXComponent : public PollingComponent, public i2c::I2CDevice {
|
|||||||
float bmp388_compensate_temperature_(float uncomp_temp);
|
float bmp388_compensate_temperature_(float uncomp_temp);
|
||||||
// Bosch pressure compensation function
|
// Bosch pressure compensation function
|
||||||
float bmp388_compensate_pressure_(float uncomp_press, float t_lin);
|
float bmp388_compensate_pressure_(float uncomp_press, float t_lin);
|
||||||
|
|
||||||
|
// interface specific functions
|
||||||
|
virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
|
||||||
|
virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
|
||||||
|
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
|
||||||
|
virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace bmp3xx
|
} // namespace bmp3xx_base
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user