mirror of
https://github.com/esphome/esphome.git
synced 2025-11-10 20:05:48 +00:00
Compare commits
182 Commits
2023.8.0b1
...
2023.9.0b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29249cdc1b | ||
|
|
e5bae8187f | ||
|
|
69adebfefa | ||
|
|
7dabbb65d0 | ||
|
|
b30bab8c1b | ||
|
|
0a1ed58454 | ||
|
|
5f5ee9c920 | ||
|
|
0aeebdd289 | ||
|
|
33e2aa341e | ||
|
|
a42788812e | ||
|
|
b07a038bc8 | ||
|
|
55e36ab982 | ||
|
|
90835ab917 | ||
|
|
5b46088ae4 | ||
|
|
d7e267eca5 | ||
|
|
807c47a076 | ||
|
|
7ebe6a5894 | ||
|
|
41c829fa32 | ||
|
|
8f1ce8c7f7 | ||
|
|
e55636ed52 | ||
|
|
e886262055 | ||
|
|
2fa7f8c511 | ||
|
|
4622ef770d | ||
|
|
d76f18b4f2 | ||
|
|
ec20778d83 | ||
|
|
b3ca71c6fb | ||
|
|
2d53dd05d8 | ||
|
|
68a2c45edf | ||
|
|
d2616cd6c6 | ||
|
|
736dbfac13 | ||
|
|
b8fa737bc9 | ||
|
|
bf5352b44e | ||
|
|
bff74af882 | ||
|
|
dadbc1aefa | ||
|
|
fc354eec0e | ||
|
|
47b1b45828 | ||
|
|
e6da2313e6 | ||
|
|
fe81bcc003 | ||
|
|
10eee47b6b | ||
|
|
c930c86cfa | ||
|
|
d3196e0e34 | ||
|
|
deb34c9473 | ||
|
|
892d2ce34f | ||
|
|
b107948c47 | ||
|
|
d2648657fb | ||
|
|
32b103eb1d | ||
|
|
e66047e072 | ||
|
|
0c84224ca2 | ||
|
|
7bb67ae94b | ||
|
|
ccc30116ba | ||
|
|
9cf115a752 | ||
|
|
d9523a0cbf | ||
|
|
2fd6942de4 | ||
|
|
b19a7e006e | ||
|
|
5c26f95a4b | ||
|
|
ce171f5c00 | ||
|
|
ab872b075a | ||
|
|
87395d259e | ||
|
|
72f29b1283 | ||
|
|
f2a6f18553 | ||
|
|
8cac5ca90c | ||
|
|
01ec414873 | ||
|
|
6b0fb3dd06 | ||
|
|
e89c6494a6 | ||
|
|
eff76d578b | ||
|
|
76ebbfefd2 | ||
|
|
150c9b5fa3 | ||
|
|
55df88d7ae | ||
|
|
619787e6d2 | ||
|
|
3f8bad3ed1 | ||
|
|
c146712b16 | ||
|
|
2cabe59c22 | ||
|
|
feba9ffdc4 | ||
|
|
74ab940aff | ||
|
|
82c1988a2d | ||
|
|
ac5c6ec288 | ||
|
|
47735d1dae | ||
|
|
35b5dadb99 | ||
|
|
e2d784a5b5 | ||
|
|
b7a16d5a59 | ||
|
|
97dcbe84da | ||
|
|
32b24726ed | ||
|
|
343278b291 | ||
|
|
b11824b058 | ||
|
|
562f7c8718 | ||
|
|
d382ca2401 | ||
|
|
a9630ac847 | ||
|
|
22c0b0abaa | ||
|
|
aabe0091cc | ||
|
|
3d9af2a67c | ||
|
|
4ae582c305 | ||
|
|
5fdafc00e6 | ||
|
|
2165960ba1 | ||
|
|
2bb5f53b98 | ||
|
|
211b3eddea | ||
|
|
bec53f97a2 | ||
|
|
c3332e4a39 | ||
|
|
f8a03be2f1 | ||
|
|
712634b301 | ||
|
|
19d53c6643 | ||
|
|
f14419bab5 | ||
|
|
3003485dc6 | ||
|
|
01f6791d1c | ||
|
|
cdb67fc90e | ||
|
|
78cb098691 | ||
|
|
45152ad55e | ||
|
|
45879e3100 | ||
|
|
c4adb30ab2 | ||
|
|
b20bae23cc | ||
|
|
11ed2d5f18 | ||
|
|
f814b6d47c | ||
|
|
a67b92a04c | ||
|
|
2a48b810a4 | ||
|
|
9fb8e9edef | ||
|
|
d2bccbe8ac | ||
|
|
e44a60e814 | ||
|
|
02a71cb6a7 | ||
|
|
e600784ebf | ||
|
|
5e19a3b892 | ||
|
|
0443310385 | ||
|
|
03ab23fec8 | ||
|
|
da8afd36b2 | ||
|
|
fe7893d1b3 | ||
|
|
d19bf5d6ee | ||
|
|
bfdcfa4766 | ||
|
|
c47c1a7867 | ||
|
|
f16a24ddf4 | ||
|
|
8bf112669f | ||
|
|
4278664208 | ||
|
|
0789657fd5 | ||
|
|
b566c78f00 | ||
|
|
c287e529a8 | ||
|
|
164d05fdce | ||
|
|
c11c4dad2f | ||
|
|
0af8d0b7ea | ||
|
|
2b4ed0c273 | ||
|
|
9fc50e8dbc | ||
|
|
a35122231c | ||
|
|
7e4ee32b54 | ||
|
|
7df80eadcf | ||
|
|
2aaba1d2b8 | ||
|
|
7c129a4018 | ||
|
|
cb66ce069e | ||
|
|
a27e72362a | ||
|
|
c5be5e6d12 | ||
|
|
63fc16d872 | ||
|
|
5f99ed943a | ||
|
|
f44e5d3142 | ||
|
|
532163738e | ||
|
|
63fa922547 | ||
|
|
48e4cb5ae2 | ||
|
|
ff8a73c2d1 | ||
|
|
afd26c6f1a | ||
|
|
67b06a88b2 | ||
|
|
5cb5594288 | ||
|
|
87629191b3 | ||
|
|
4a518e3e7a | ||
|
|
6089526975 | ||
|
|
b9e9223fdd | ||
|
|
e963eedb64 | ||
|
|
3b2c61e813 | ||
|
|
265e019381 | ||
|
|
560e36a65c | ||
|
|
b05a3fbb55 | ||
|
|
3a899e28dc | ||
|
|
f26238e824 | ||
|
|
3717e34bba | ||
|
|
be6f95d43e | ||
|
|
99a765dc06 | ||
|
|
351e7ea16b | ||
|
|
2fa79a2e2f | ||
|
|
44a917929d | ||
|
|
2dd4aa7bf6 | ||
|
|
4c1af007ca | ||
|
|
08013be6dd | ||
|
|
0daf4545a9 | ||
|
|
1269bf9791 | ||
|
|
5cb21324a1 | ||
|
|
3eef80506b | ||
|
|
283d9a0f5f | ||
|
|
a84365659b | ||
|
|
db9dc11022 |
4
.github/actions/restore-python/action.yml
vendored
4
.github/actions/restore-python/action.yml
vendored
@@ -17,12 +17,12 @@ runs:
|
||||
steps:
|
||||
- name: Set up Python ${{ inputs.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@v4.6.0
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: ${{ inputs.python-version }}
|
||||
- name: Restore Python virtual environment
|
||||
id: cache-venv
|
||||
uses: actions/cache/restore@v3.3.1
|
||||
uses: actions/cache/restore@v3.3.2
|
||||
with:
|
||||
path: venv
|
||||
# yamllint disable-line rule:line-length
|
||||
|
||||
12
.github/workflows/ci-docker.yml
vendored
12
.github/workflows/ci-docker.yml
vendored
@@ -8,7 +8,7 @@ on:
|
||||
branches: [dev, beta, release]
|
||||
paths:
|
||||
- "docker/**"
|
||||
- ".github/workflows/**"
|
||||
- ".github/workflows/ci-docker.yml"
|
||||
- "requirements*.txt"
|
||||
- "platformio.ini"
|
||||
- "script/platformio_install_deps.py"
|
||||
@@ -16,7 +16,7 @@ on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "docker/**"
|
||||
- ".github/workflows/**"
|
||||
- ".github/workflows/ci-docker.yml"
|
||||
- "requirements*.txt"
|
||||
- "platformio.ini"
|
||||
- "script/platformio_install_deps.py"
|
||||
@@ -40,15 +40,15 @@ jobs:
|
||||
arch: [amd64, armv7, aarch64]
|
||||
build_type: ["ha-addon", "docker", "lint"]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4.0.0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: "3.9"
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3.0.0
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v3.0.0
|
||||
|
||||
- name: Set TAG
|
||||
run: |
|
||||
|
||||
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@@ -7,6 +7,10 @@ on:
|
||||
branches: [dev, beta, release]
|
||||
|
||||
pull_request:
|
||||
paths:
|
||||
- "**"
|
||||
- "!.github/workflows/*.yml"
|
||||
- ".github/workflows/ci.yml"
|
||||
merge_group:
|
||||
|
||||
permissions:
|
||||
@@ -30,18 +34,18 @@ jobs:
|
||||
cache-key: ${{ steps.cache-key.outputs.key }}
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Generate cache-key
|
||||
id: cache-key
|
||||
run: echo key="${{ hashFiles('requirements.txt', 'requirements_optional.txt', 'requirements_test.txt') }}" >> $GITHUB_OUTPUT
|
||||
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
|
||||
id: python
|
||||
uses: actions/setup-python@v4.6.0
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||
- name: Restore Python virtual environment
|
||||
id: cache-venv
|
||||
uses: actions/cache@v3.3.1
|
||||
uses: actions/cache@v3.3.2
|
||||
with:
|
||||
path: venv
|
||||
# yamllint disable-line rule:line-length
|
||||
@@ -55,15 +59,6 @@ jobs:
|
||||
pip install -r requirements.txt -r requirements_optional.txt -r requirements_test.txt
|
||||
pip install -e .
|
||||
|
||||
yamllint:
|
||||
name: yamllint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
- name: Run yamllint
|
||||
uses: frenck/action-yamllint@v1.4.1
|
||||
|
||||
black:
|
||||
name: Check black
|
||||
runs-on: ubuntu-latest
|
||||
@@ -71,7 +66,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -92,7 +87,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -113,7 +108,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -134,7 +129,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -155,7 +150,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -176,7 +171,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -196,7 +191,7 @@ jobs:
|
||||
- common
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -227,15 +222,14 @@ jobs:
|
||||
- pylint
|
||||
- pytest
|
||||
- pyupgrade
|
||||
- yamllint
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 2
|
||||
matrix:
|
||||
file: [1, 2, 3, 3.1, 4, 5, 6, 7, 8]
|
||||
file: [1, 2, 3, 3.1, 4, 5, 6, 7, 8, 10, 11.5]
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
@@ -258,7 +252,6 @@ jobs:
|
||||
- pylint
|
||||
- pytest
|
||||
- pyupgrade
|
||||
- yamllint
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 2
|
||||
@@ -291,14 +284,14 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v3.5.2
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||
- name: Cache platformio
|
||||
uses: actions/cache@v3.3.1
|
||||
uses: actions/cache@v3.3.2
|
||||
with:
|
||||
path: ~/.platformio
|
||||
# yamllint disable-line rule:line-length
|
||||
@@ -337,7 +330,6 @@ jobs:
|
||||
- pylint
|
||||
- pytest
|
||||
- pyupgrade
|
||||
- yamllint
|
||||
- compile-tests
|
||||
- clang-tidy
|
||||
if: always()
|
||||
|
||||
2
.github/workflows/lock.yml
vendored
2
.github/workflows/lock.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v4
|
||||
- uses: dessant/lock-threads@v4.0.1
|
||||
with:
|
||||
pr-inactive-days: "1"
|
||||
pr-lock-reason: ""
|
||||
|
||||
22
.github/workflows/release.yml
vendored
22
.github/workflows/release.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
outputs:
|
||||
tag: ${{ steps.tag.outputs.tag }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4.0.0
|
||||
- name: Get tag
|
||||
id: tag
|
||||
# yamllint disable rule:line-length
|
||||
@@ -43,9 +43,9 @@ jobs:
|
||||
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4.0.0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: "3.x"
|
||||
- name: Set up python environment
|
||||
@@ -88,24 +88,24 @@ jobs:
|
||||
target: "lint"
|
||||
baseimg: "docker"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4.0.0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: "3.9"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
uses: docker/setup-buildx-action@v3.0.0
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
uses: docker/setup-qemu-action@v3.0.0
|
||||
|
||||
- name: Log in to docker hub
|
||||
uses: docker/login-action@v2
|
||||
uses: docker/login-action@v3.0.0
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- name: Log in to the GitHub container registry
|
||||
uses: docker/login-action@v2
|
||||
uses: docker/login-action@v3.0.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
@@ -119,7 +119,7 @@ jobs:
|
||||
--suffix "${{ matrix.image.suffix }}"
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
uses: docker/build-push-action@v5.0.0
|
||||
with:
|
||||
context: .
|
||||
file: ./docker/Dockerfile
|
||||
@@ -141,7 +141,7 @@ jobs:
|
||||
needs: [deploy-docker]
|
||||
steps:
|
||||
- name: Trigger Workflow
|
||||
uses: actions/github-script@v6
|
||||
uses: actions/github-script@v6.4.1
|
||||
with:
|
||||
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
|
||||
script: |
|
||||
|
||||
4
.github/workflows/stale.yml
vendored
4
.github/workflows/stale.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v8
|
||||
- uses: actions/stale@v8.0.0
|
||||
with:
|
||||
days-before-pr-stale: 90
|
||||
days-before-pr-close: 7
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
close-issues:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v8
|
||||
- uses: actions/stale@v8.0.0
|
||||
with:
|
||||
days-before-pr-stale: -1
|
||||
days-before-pr-close: -1
|
||||
|
||||
11
.github/workflows/sync-device-classes.yml
vendored
11
.github/workflows/sync-device-classes.yml
vendored
@@ -4,8 +4,7 @@ name: Synchronise Device Classes from Home Assistant
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '45 6 * * *'
|
||||
|
||||
- cron: "45 6 * * *"
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
@@ -14,16 +13,16 @@ jobs:
|
||||
if: github.repository == 'esphome/esphome'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4.0.0
|
||||
|
||||
- name: Checkout Home Assistant
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4.0.0
|
||||
with:
|
||||
repository: home-assistant/core
|
||||
path: lib/home-assistant
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
uses: actions/setup-python@v4.7.0
|
||||
with:
|
||||
python-version: 3.11
|
||||
|
||||
@@ -37,7 +36,7 @@ jobs:
|
||||
python ./script/sync-device_class.py
|
||||
|
||||
- name: Commit changes
|
||||
uses: peter-evans/create-pull-request@v5
|
||||
uses: peter-evans/create-pull-request@v5.0.2
|
||||
with:
|
||||
commit-message: "Synchronise Device Classes from Home Assistant"
|
||||
committer: esphomebot <esphome@nabucasa.com>
|
||||
|
||||
22
.github/workflows/yaml-lint.yml
vendored
Normal file
22
.github/workflows/yaml-lint.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: YAML lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [dev, beta, release]
|
||||
paths:
|
||||
- "**.yaml"
|
||||
- "**.yml"
|
||||
pull_request:
|
||||
paths:
|
||||
- "**.yaml"
|
||||
- "**.yml"
|
||||
|
||||
jobs:
|
||||
yamllint:
|
||||
name: yamllint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@v4.0.0
|
||||
- name: Run yamllint
|
||||
uses: frenck/action-yamllint@v1.4.1
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -13,6 +13,12 @@ __pycache__/
|
||||
# Intellij Idea
|
||||
.idea
|
||||
|
||||
# Eclipse
|
||||
.project
|
||||
.cproject
|
||||
.pydevproject
|
||||
.settings/
|
||||
|
||||
# Vim
|
||||
*.swp
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.7.0
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 23.9.1
|
||||
hooks:
|
||||
- id: black
|
||||
args:
|
||||
|
||||
23
CODEOWNERS
23
CODEOWNERS
@@ -42,19 +42,21 @@ esphome/components/bedjet/climate/* @jhansche
|
||||
esphome/components/bedjet/fan/* @jhansche
|
||||
esphome/components/bh1750/* @OttoWinter
|
||||
esphome/components/binary_sensor/* @esphome/core
|
||||
esphome/components/bk72xx/* @kuba2k2
|
||||
esphome/components/bl0939/* @ziceva
|
||||
esphome/components/bl0940/* @tobias-
|
||||
esphome/components/bl0942/* @dbuezas
|
||||
esphome/components/ble_client/* @buxtronix
|
||||
esphome/components/bluetooth_proxy/* @jesserockz
|
||||
esphome/components/bme680_bsec/* @trvrnrth
|
||||
esphome/components/bmi160/* @flaviut
|
||||
esphome/components/bmp3xx/* @martgras
|
||||
esphome/components/bmp581/* @kahrendt
|
||||
esphome/components/bp1658cj/* @Cossid
|
||||
esphome/components/bp5758d/* @Cossid
|
||||
esphome/components/button/* @esphome/core
|
||||
esphome/components/canbus/* @danielschramm @mvturnho
|
||||
esphome/components/cap1188/* @MrEditor97
|
||||
esphome/components/cap1188/* @mreditor97
|
||||
esphome/components/captive_portal/* @OttoWinter
|
||||
esphome/components/ccs811/* @habbie
|
||||
esphome/components/cd74hc4067/* @asoehlke
|
||||
@@ -87,7 +89,7 @@ esphome/components/ens210/* @itn3rd77
|
||||
esphome/components/esp32/* @esphome/core
|
||||
esphome/components/esp32_ble/* @jesserockz
|
||||
esphome/components/esp32_ble_client/* @jesserockz
|
||||
esphome/components/esp32_ble_server/* @jesserockz
|
||||
esphome/components/esp32_ble_server/* @clydebarrow @jesserockz
|
||||
esphome/components/esp32_camera_web_server/* @ayufan
|
||||
esphome/components/esp32_can/* @Sympatron
|
||||
esphome/components/esp32_improv/* @jesserockz
|
||||
@@ -129,10 +131,10 @@ esphome/components/i2s_audio/* @jesserockz
|
||||
esphome/components/i2s_audio/media_player/* @jesserockz
|
||||
esphome/components/i2s_audio/microphone/* @jesserockz
|
||||
esphome/components/i2s_audio/speaker/* @jesserockz
|
||||
esphome/components/ili9xxx/* @nielsnl68
|
||||
esphome/components/ili9xxx/* @clydebarrow @nielsnl68
|
||||
esphome/components/improv_base/* @esphome/core
|
||||
esphome/components/improv_serial/* @esphome/core
|
||||
esphome/components/ina260/* @MrEditor97
|
||||
esphome/components/ina260/* @mreditor97
|
||||
esphome/components/inkbird_ibsth1_mini/* @fkirill
|
||||
esphome/components/inkplate6/* @jesserockz
|
||||
esphome/components/integration/* @OttoWinter
|
||||
@@ -144,9 +146,12 @@ esphome/components/key_collector/* @ssieb
|
||||
esphome/components/key_provider/* @ssieb
|
||||
esphome/components/kuntze/* @ssieb
|
||||
esphome/components/lcd_menu/* @numo68
|
||||
esphome/components/ld2410/* @sebcaps
|
||||
esphome/components/ld2410/* @regevbr @sebcaps
|
||||
esphome/components/ledc/* @OttoWinter
|
||||
esphome/components/libretiny/* @kuba2k2
|
||||
esphome/components/libretiny_pwm/* @kuba2k2
|
||||
esphome/components/light/* @esphome/core
|
||||
esphome/components/lightwaverf/* @max246
|
||||
esphome/components/lilygo_t5_47/touchscreen/* @jesserockz
|
||||
esphome/components/lock/* @esphome/core
|
||||
esphome/components/logger/* @esphome/core
|
||||
@@ -168,7 +173,7 @@ esphome/components/mcp2515/* @danielschramm @mvturnho
|
||||
esphome/components/mcp3204/* @rsumner
|
||||
esphome/components/mcp4728/* @berfenger
|
||||
esphome/components/mcp47a1/* @jesserockz
|
||||
esphome/components/mcp9600/* @MrEditor97
|
||||
esphome/components/mcp9600/* @mreditor97
|
||||
esphome/components/mcp9808/* @k7hpn
|
||||
esphome/components/md5/* @esphome/core
|
||||
esphome/components/mdns/* @esphome/core
|
||||
@@ -212,6 +217,7 @@ esphome/components/pid/* @OttoWinter
|
||||
esphome/components/pipsolar/* @andreashergert1984
|
||||
esphome/components/pm1006/* @habbie
|
||||
esphome/components/pmsa003i/* @sjtrny
|
||||
esphome/components/pmwcs3/* @SeByDocKy
|
||||
esphome/components/pn532/* @OttoWinter @jesserockz
|
||||
esphome/components/pn532_i2c/* @OttoWinter @jesserockz
|
||||
esphome/components/pn532_spi/* @OttoWinter @jesserockz
|
||||
@@ -233,6 +239,7 @@ esphome/components/rgbct/* @jesserockz
|
||||
esphome/components/rp2040/* @jesserockz
|
||||
esphome/components/rp2040_pio_led_strip/* @Papa-DMan
|
||||
esphome/components/rp2040_pwm/* @jesserockz
|
||||
esphome/components/rtl87xx/* @kuba2k2
|
||||
esphome/components/rtttl/* @glmnet
|
||||
esphome/components/safe_mode/* @jsuanet @paulmonigatti
|
||||
esphome/components/scd4x/* @martgras @sjtrny
|
||||
@@ -241,6 +248,7 @@ esphome/components/sdm_meter/* @jesserockz @polyfaces
|
||||
esphome/components/sdp3x/* @Azimath
|
||||
esphome/components/selec_meter/* @sourabhjaiswal
|
||||
esphome/components/select/* @esphome/core
|
||||
esphome/components/sen0321/* @notjj
|
||||
esphome/components/sen21231/* @shreyaskarnik
|
||||
esphome/components/sen5x/* @martgras
|
||||
esphome/components/sensirion_common/* @martgras
|
||||
@@ -263,6 +271,8 @@ esphome/components/socket/* @esphome/core
|
||||
esphome/components/sonoff_d1/* @anatoly-savchenkov
|
||||
esphome/components/speaker/* @jesserockz
|
||||
esphome/components/spi/* @esphome/core
|
||||
esphome/components/spi_device/* @clydebarrow
|
||||
esphome/components/spi_led_strip/* @clydebarrow
|
||||
esphome/components/sprinkler/* @kbx81
|
||||
esphome/components/sps30/* @martgras
|
||||
esphome/components/ssd1322_base/* @kbx81
|
||||
@@ -323,6 +333,7 @@ esphome/components/web_server_idf/* @dentra
|
||||
esphome/components/whirlpool/* @glmnet
|
||||
esphome/components/whynter/* @aeonsablaze
|
||||
esphome/components/wiegand/* @ssieb
|
||||
esphome/components/wireguard/* @droscy @lhoracek @thomas0bernard
|
||||
esphome/components/wl_134/* @hobbypunk90
|
||||
esphome/components/x9c/* @EtienneMD
|
||||
esphome/components/xiaomi_lywsd03mmc/* @ahpohl
|
||||
|
||||
@@ -28,14 +28,16 @@ RUN \
|
||||
git=1:2.30.2-1+deb11u2 \
|
||||
curl=7.74.0-1.3+deb11u7 \
|
||||
openssh-client=1:8.4p1-5+deb11u1 \
|
||||
python3-cffi=1.14.5-1; \
|
||||
python3-cffi=1.14.5-1 \
|
||||
libcairo2=1.16.0-5 \
|
||||
patch=2.7.6-7; \
|
||||
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential=12.9 \
|
||||
python3-dev=3.9.2-3 \
|
||||
zlib1g-dev=1:1.2.11.dfsg-2+deb11u2 \
|
||||
libjpeg-dev=1:2.0.6-4 \
|
||||
libcairo2=1.16.0-5; \
|
||||
libfreetype-dev=2.10.4+dfsg-1+deb11u1; \
|
||||
fi; \
|
||||
rm -rf \
|
||||
/tmp/* \
|
||||
@@ -60,7 +62,7 @@ RUN \
|
||||
# Ubuntu python3-pip is missing wheel
|
||||
pip3 install --no-cache-dir \
|
||||
wheel==0.37.1 \
|
||||
platformio==6.1.7 \
|
||||
platformio==6.1.11 \
|
||||
# Change some platformio settings
|
||||
&& platformio settings set enable_telemetry No \
|
||||
&& platformio settings set check_platformio_interval 1000000 \
|
||||
|
||||
@@ -35,11 +35,16 @@ if bashio::config.has_value 'default_compile_process_limit'; then
|
||||
export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=$(bashio::config 'default_compile_process_limit')
|
||||
else
|
||||
if grep -q 'Raspberry Pi 3' /proc/cpuinfo; then
|
||||
export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=1;
|
||||
export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${pio_cache_base}"
|
||||
|
||||
if bashio::fs.directory_exists '/config/esphome/.esphome'; then
|
||||
bashio::log.info "Removing old .esphome directory..."
|
||||
rm -rf /config/esphome/.esphome
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting ESPHome dashboard..."
|
||||
exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --ha-addon
|
||||
|
||||
@@ -26,6 +26,8 @@ from esphome.const import (
|
||||
CONF_ESPHOME,
|
||||
CONF_PLATFORMIO_OPTIONS,
|
||||
CONF_SUBSTITUTIONS,
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_RTL87XX,
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
PLATFORM_RP2040,
|
||||
@@ -83,6 +85,8 @@ def choose_upload_log_host(
|
||||
options = []
|
||||
for port in get_serial_ports():
|
||||
options.append((f"{port.path} ({port.description})", port.path))
|
||||
if default == "SERIAL":
|
||||
return choose_prompt(options, purpose=purpose)
|
||||
if (show_ota and "ota" in CORE.config) or (show_api and "api" in CORE.config):
|
||||
options.append((f"Over The Air ({CORE.address})", CORE.address))
|
||||
if default == "OTA":
|
||||
@@ -216,14 +220,16 @@ def compile_program(args, config):
|
||||
return 0 if idedata is not None else 1
|
||||
|
||||
|
||||
def upload_using_esptool(config, port):
|
||||
def upload_using_esptool(config, port, file):
|
||||
from esphome import platformio_api
|
||||
|
||||
first_baudrate = config[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS].get(
|
||||
"upload_speed", 460800
|
||||
)
|
||||
|
||||
def run_esptool(baud_rate):
|
||||
if file is not None:
|
||||
flash_images = [platformio_api.FlashImage(path=file, offset="0x0")]
|
||||
else:
|
||||
idedata = platformio_api.get_idedata(config)
|
||||
|
||||
firmware_offset = "0x10000" if CORE.is_esp32 else "0x0"
|
||||
@@ -234,12 +240,13 @@ def upload_using_esptool(config, port):
|
||||
*idedata.extra_flash_images,
|
||||
]
|
||||
|
||||
mcu = "esp8266"
|
||||
if CORE.is_esp32:
|
||||
from esphome.components.esp32 import get_esp32_variant
|
||||
mcu = "esp8266"
|
||||
if CORE.is_esp32:
|
||||
from esphome.components.esp32 import get_esp32_variant
|
||||
|
||||
mcu = get_esp32_variant().lower()
|
||||
mcu = get_esp32_variant().lower()
|
||||
|
||||
def run_esptool(baud_rate):
|
||||
cmd = [
|
||||
"esptool.py",
|
||||
"--before",
|
||||
@@ -278,20 +285,26 @@ def upload_using_esptool(config, port):
|
||||
return run_esptool(115200)
|
||||
|
||||
|
||||
def upload_using_platformio(config, port):
|
||||
from esphome import platformio_api
|
||||
|
||||
upload_args = ["-t", "upload", "-t", "nobuild"]
|
||||
if port is not None:
|
||||
upload_args += ["--upload-port", port]
|
||||
return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args)
|
||||
|
||||
|
||||
def upload_program(config, args, host):
|
||||
if get_port_type(host) == "SERIAL":
|
||||
if CORE.target_platform in (PLATFORM_ESP32, PLATFORM_ESP8266):
|
||||
return upload_using_esptool(config, host)
|
||||
file = getattr(args, "file", None)
|
||||
return upload_using_esptool(config, host, file)
|
||||
|
||||
if CORE.target_platform in (PLATFORM_RP2040):
|
||||
from esphome import platformio_api
|
||||
return upload_using_platformio(config, args.device)
|
||||
|
||||
upload_args = ["-t", "upload"]
|
||||
if args.device is not None:
|
||||
upload_args += ["--upload-port", args.device]
|
||||
return platformio_api.run_platformio_cli_run(
|
||||
config, CORE.verbose, *upload_args
|
||||
)
|
||||
if CORE.target_platform in (PLATFORM_BK72XX, PLATFORM_RTL87XX):
|
||||
return upload_using_platformio(config, host)
|
||||
|
||||
return 1 # Unknown target platform
|
||||
|
||||
@@ -371,7 +384,7 @@ def command_config(args, config):
|
||||
# add the console decoration so the front-end can hide the secrets
|
||||
if not args.show_secrets:
|
||||
output = re.sub(
|
||||
r"(password|key|psk|ssid)\:\s(.*)", r"\1: \\033[5m\2\\033[6m", output
|
||||
r"(password|key|psk|ssid)\: (.+)", r"\1: \\033[5m\2\\033[6m", output
|
||||
)
|
||||
safe_print(output)
|
||||
_LOGGER.info("Configuration is valid!")
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.const import CONF_INPUT
|
||||
from esphome.const import CONF_ANALOG, CONF_INPUT
|
||||
|
||||
from esphome.core import CORE
|
||||
from esphome.components.esp32 import get_esp32_variant
|
||||
from esphome.const import PLATFORM_ESP8266
|
||||
from esphome.components.esp32.const import (
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32H2,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
@@ -70,6 +73,22 @@ ESP32_VARIANT_ADC1_PIN_TO_CHANNEL = {
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
},
|
||||
VARIANT_ESP32C2: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
},
|
||||
VARIANT_ESP32C6: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
2: adc1_channel_t.ADC1_CHANNEL_2,
|
||||
3: adc1_channel_t.ADC1_CHANNEL_3,
|
||||
4: adc1_channel_t.ADC1_CHANNEL_4,
|
||||
5: adc1_channel_t.ADC1_CHANNEL_5,
|
||||
6: adc1_channel_t.ADC1_CHANNEL_6,
|
||||
},
|
||||
VARIANT_ESP32H2: {
|
||||
0: adc1_channel_t.ADC1_CHANNEL_0,
|
||||
1: adc1_channel_t.ADC1_CHANNEL_1,
|
||||
@@ -125,7 +144,9 @@ ESP32_VARIANT_ADC2_PIN_TO_CHANNEL = {
|
||||
|
||||
def validate_adc_pin(value):
|
||||
if str(value).upper() == "VCC":
|
||||
return cv.only_on_esp8266("VCC")
|
||||
if CORE.is_rp2040:
|
||||
return pins.internal_gpio_input_pin_schema(29)
|
||||
return cv.only_on([PLATFORM_ESP8266])("VCC")
|
||||
|
||||
if str(value).upper() == "TEMPERATURE":
|
||||
return cv.only_on_rp2040("TEMPERATURE")
|
||||
@@ -148,8 +169,6 @@ def validate_adc_pin(value):
|
||||
return pins.internal_gpio_input_pin_schema(value)
|
||||
|
||||
if CORE.is_esp8266:
|
||||
from esphome.components.esp8266.gpio import CONF_ANALOG
|
||||
|
||||
value = pins.internal_gpio_pin_number({CONF_ANALOG: True, CONF_INPUT: True})(
|
||||
value
|
||||
)
|
||||
@@ -166,4 +185,9 @@ def validate_adc_pin(value):
|
||||
raise cv.Invalid("RP2040: Only pins 26, 27, 28 and 29 support ADC")
|
||||
return pins.internal_gpio_input_pin_schema(value)
|
||||
|
||||
if CORE.is_libretiny:
|
||||
return pins.gpio_pin_schema(
|
||||
{CONF_ANALOG: True, CONF_INPUT: True}, internal=True
|
||||
)(value)
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "adc_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
#ifdef USE_ADC_SENSOR_VCC
|
||||
@@ -12,6 +12,9 @@ ADC_MODE(ADC_VCC)
|
||||
#endif
|
||||
|
||||
#ifdef USE_RP2040
|
||||
#ifdef CYW43_USES_VSYS_PIN
|
||||
#include "pico/cyw43_arch.h"
|
||||
#endif
|
||||
#include <hardware/adc.h>
|
||||
#endif
|
||||
|
||||
@@ -92,13 +95,13 @@ extern "C"
|
||||
|
||||
void ADCSensor::dump_config() {
|
||||
LOG_SENSOR("", "ADC Sensor", this);
|
||||
#ifdef USE_ESP8266
|
||||
#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
|
||||
#ifdef USE_ADC_SENSOR_VCC
|
||||
ESP_LOGCONFIG(TAG, " Pin: VCC");
|
||||
#else
|
||||
LOG_PIN(" Pin: ", pin_);
|
||||
#endif
|
||||
#endif // USE_ESP8266
|
||||
#endif // USE_ESP8266 || USE_LIBRETINY
|
||||
|
||||
#ifdef USE_ESP32
|
||||
LOG_PIN(" Pin: ", pin_);
|
||||
@@ -123,13 +126,19 @@ void ADCSensor::dump_config() {
|
||||
}
|
||||
}
|
||||
#endif // USE_ESP32
|
||||
|
||||
#ifdef USE_RP2040
|
||||
if (this->is_temperature_) {
|
||||
ESP_LOGCONFIG(TAG, " Pin: Temperature");
|
||||
} else {
|
||||
#ifdef USE_ADC_SENSOR_VCC
|
||||
ESP_LOGCONFIG(TAG, " Pin: VCC");
|
||||
#else
|
||||
LOG_PIN(" Pin: ", pin_);
|
||||
#endif // USE_ADC_SENSOR_VCC
|
||||
}
|
||||
#endif
|
||||
#endif // USE_RP2040
|
||||
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
@@ -237,23 +246,54 @@ float ADCSensor::sample() {
|
||||
adc_set_temp_sensor_enabled(true);
|
||||
delay(1);
|
||||
adc_select_input(4);
|
||||
|
||||
int32_t raw = adc_read();
|
||||
adc_set_temp_sensor_enabled(false);
|
||||
if (this->output_raw_) {
|
||||
return raw;
|
||||
}
|
||||
return raw * 3.3f / 4096.0f;
|
||||
} else {
|
||||
uint8_t pin = this->pin_->get_pin();
|
||||
#ifdef CYW43_USES_VSYS_PIN
|
||||
if (pin == PICO_VSYS_PIN) {
|
||||
// Measuring VSYS on Raspberry Pico W needs to be wrapped with
|
||||
// `cyw43_thread_enter()`/`cyw43_thread_exit()` as discussed in
|
||||
// https://github.com/raspberrypi/pico-sdk/issues/1222, since Wifi chip and
|
||||
// VSYS ADC both share GPIO29
|
||||
cyw43_thread_enter();
|
||||
}
|
||||
#endif // CYW43_USES_VSYS_PIN
|
||||
|
||||
adc_gpio_init(pin);
|
||||
adc_select_input(pin - 26);
|
||||
}
|
||||
|
||||
int32_t raw = adc_read();
|
||||
if (this->is_temperature_) {
|
||||
adc_set_temp_sensor_enabled(false);
|
||||
int32_t raw = adc_read();
|
||||
|
||||
#ifdef CYW43_USES_VSYS_PIN
|
||||
if (pin == PICO_VSYS_PIN) {
|
||||
cyw43_thread_exit();
|
||||
}
|
||||
#endif // CYW43_USES_VSYS_PIN
|
||||
|
||||
if (output_raw_) {
|
||||
return raw;
|
||||
}
|
||||
float coeff = pin == PICO_VSYS_PIN ? 3.0 : 1.0;
|
||||
return raw * 3.3f / 4096.0f * coeff;
|
||||
}
|
||||
if (output_raw_) {
|
||||
return raw;
|
||||
}
|
||||
return raw * 3.3f / 4096.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIBRETINY
|
||||
float ADCSensor::sample() {
|
||||
if (output_raw_) {
|
||||
return analogRead(this->pin_->get_pin()); // NOLINT
|
||||
}
|
||||
return analogReadVoltage(this->pin_->get_pin()) / 1000.0f; // NOLINT
|
||||
}
|
||||
#endif // USE_LIBRETINY
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
|
||||
#endif
|
||||
|
||||
@@ -62,8 +62,12 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
||||
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
||||
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
||||
bool autorange_{false};
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
esp_adc_cal_characteristics_t cal_characteristics_[SOC_ADC_ATTEN_NUM] = {};
|
||||
#else
|
||||
esp_adc_cal_characteristics_t cal_characteristics_[ADC_ATTEN_MAX] = {};
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace adc
|
||||
|
||||
@@ -1051,6 +1051,10 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
resp.manufacturer = "Espressif";
|
||||
#elif defined(USE_RP2040)
|
||||
resp.manufacturer = "Raspberry Pi";
|
||||
#elif defined(USE_BK72XX)
|
||||
resp.manufacturer = "Beken";
|
||||
#elif defined(USE_RTL87XX)
|
||||
resp.manufacturer = "Realtek";
|
||||
#elif defined(USE_HOST)
|
||||
resp.manufacturer = "Host";
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "api_pb2.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
namespace esphome {
|
||||
namespace api {
|
||||
|
||||
@@ -522,12 +524,12 @@ void HelloRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" api_version_major: ");
|
||||
sprintf(buffer, "%u", this->api_version_major);
|
||||
sprintf(buffer, "%" PRIu32, this->api_version_major);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" api_version_minor: ");
|
||||
sprintf(buffer, "%u", this->api_version_minor);
|
||||
sprintf(buffer, "%" PRIu32, this->api_version_minor);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -572,12 +574,12 @@ void HelloResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("HelloResponse {\n");
|
||||
out.append(" api_version_major: ");
|
||||
sprintf(buffer, "%u", this->api_version_major);
|
||||
sprintf(buffer, "%" PRIu32, this->api_version_major);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" api_version_minor: ");
|
||||
sprintf(buffer, "%u", this->api_version_minor);
|
||||
sprintf(buffer, "%" PRIu32, this->api_version_minor);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -783,17 +785,17 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" webserver_port: ");
|
||||
sprintf(buffer, "%u", this->webserver_port);
|
||||
sprintf(buffer, "%" PRIu32, this->webserver_port);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" legacy_bluetooth_proxy_version: ");
|
||||
sprintf(buffer, "%u", this->legacy_bluetooth_proxy_version);
|
||||
sprintf(buffer, "%" PRIu32, this->legacy_bluetooth_proxy_version);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" bluetooth_proxy_feature_flags: ");
|
||||
sprintf(buffer, "%u", this->bluetooth_proxy_feature_flags);
|
||||
sprintf(buffer, "%" PRIu32, this->bluetooth_proxy_feature_flags);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -806,7 +808,7 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" voice_assistant_version: ");
|
||||
sprintf(buffer, "%u", this->voice_assistant_version);
|
||||
sprintf(buffer, "%" PRIu32, this->voice_assistant_version);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -898,7 +900,7 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -966,7 +968,7 @@ void BinarySensorStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("BinarySensorStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1069,7 +1071,7 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1159,7 +1161,7 @@ void CoverStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("CoverStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1242,7 +1244,7 @@ void CoverCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("CoverCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1362,7 +1364,7 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1387,7 +1389,7 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supported_speed_count: ");
|
||||
sprintf(buffer, "%d", this->supported_speed_count);
|
||||
sprintf(buffer, "%" PRId32, this->supported_speed_count);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1454,7 +1456,7 @@ void FanStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("FanStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1475,7 +1477,7 @@ void FanStateResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" speed_level: ");
|
||||
sprintf(buffer, "%d", this->speed_level);
|
||||
sprintf(buffer, "%" PRId32, this->speed_level);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -1555,7 +1557,7 @@ void FanCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("FanCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1596,7 +1598,7 @@ void FanCommandRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" speed_level: ");
|
||||
sprintf(buffer, "%d", this->speed_level);
|
||||
sprintf(buffer, "%" PRId32, this->speed_level);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -1710,7 +1712,7 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -1864,7 +1866,7 @@ void LightStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("LightStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2087,7 +2089,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("LightCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2185,7 +2187,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" transition_length: ");
|
||||
sprintf(buffer, "%u", this->transition_length);
|
||||
sprintf(buffer, "%" PRIu32, this->transition_length);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2194,7 +2196,7 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" flash_length: ");
|
||||
sprintf(buffer, "%u", this->flash_length);
|
||||
sprintf(buffer, "%" PRIu32, this->flash_length);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2302,7 +2304,7 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2323,7 +2325,7 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" accuracy_decimals: ");
|
||||
sprintf(buffer, "%d", this->accuracy_decimals);
|
||||
sprintf(buffer, "%" PRId32, this->accuracy_decimals);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2387,7 +2389,7 @@ void SensorStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SensorStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2476,7 +2478,7 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2539,7 +2541,7 @@ void SwitchStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SwitchStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2578,7 +2580,7 @@ void SwitchCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SwitchCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2652,7 +2654,7 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -2718,7 +2720,7 @@ void TextSensorStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("TextSensorStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3025,7 +3027,7 @@ void GetTimeResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("GetTimeResponse {\n");
|
||||
out.append(" epoch_seconds: ");
|
||||
sprintf(buffer, "%u", this->epoch_seconds);
|
||||
sprintf(buffer, "%" PRIu32, this->epoch_seconds);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -3109,7 +3111,7 @@ void ListEntitiesServicesResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3203,7 +3205,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" legacy_int: ");
|
||||
sprintf(buffer, "%d", this->legacy_int);
|
||||
sprintf(buffer, "%" PRId32, this->legacy_int);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3217,7 +3219,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" int_: ");
|
||||
sprintf(buffer, "%d", this->int_);
|
||||
sprintf(buffer, "%" PRId32, this->int_);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3229,7 +3231,7 @@ void ExecuteServiceArgument::dump_to(std::string &out) const {
|
||||
|
||||
for (const auto &it : this->int_array) {
|
||||
out.append(" int_array: ");
|
||||
sprintf(buffer, "%d", it);
|
||||
sprintf(buffer, "%" PRId32, it);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
}
|
||||
@@ -3280,7 +3282,7 @@ void ExecuteServiceRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("ExecuteServiceRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3356,7 +3358,7 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3422,7 +3424,7 @@ void CameraImageResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("CameraImageResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3614,7 +3616,7 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3802,7 +3804,7 @@ void ClimateStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("ClimateStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -3990,7 +3992,7 @@ void ClimateCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("ClimateCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4173,7 +4175,7 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4260,7 +4262,7 @@ void NumberStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("NumberStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4298,7 +4300,7 @@ void NumberCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("NumberCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4380,7 +4382,7 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4452,7 +4454,7 @@ void SelectStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SelectStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4495,7 +4497,7 @@ void SelectCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SelectCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4589,7 +4591,7 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4660,7 +4662,7 @@ void LockStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("LockStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4715,7 +4717,7 @@ void LockCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("LockCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4802,7 +4804,7 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4848,7 +4850,7 @@ void ButtonCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("ButtonCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -4923,7 +4925,7 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -4992,7 +4994,7 @@ void MediaPlayerStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("MediaPlayerStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5071,7 +5073,7 @@ void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("MediaPlayerCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5120,7 +5122,7 @@ void SubscribeBluetoothLEAdvertisementsRequest::dump_to(std::string &out) const
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("SubscribeBluetoothLEAdvertisementsRequest {\n");
|
||||
out.append(" flags: ");
|
||||
sprintf(buffer, "%u", this->flags);
|
||||
sprintf(buffer, "%" PRIu32, this->flags);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5167,7 +5169,7 @@ void BluetoothServiceData::dump_to(std::string &out) const {
|
||||
|
||||
for (const auto &it : this->legacy_data) {
|
||||
out.append(" legacy_data: ");
|
||||
sprintf(buffer, "%u", it);
|
||||
sprintf(buffer, "%" PRIu32, it);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
}
|
||||
@@ -5247,7 +5249,7 @@ void BluetoothLEAdvertisementResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" rssi: ");
|
||||
sprintf(buffer, "%d", this->rssi);
|
||||
sprintf(buffer, "%" PRId32, this->rssi);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5270,7 +5272,7 @@ void BluetoothLEAdvertisementResponse::dump_to(std::string &out) const {
|
||||
}
|
||||
|
||||
out.append(" address_type: ");
|
||||
sprintf(buffer, "%u", this->address_type);
|
||||
sprintf(buffer, "%" PRIu32, this->address_type);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5320,12 +5322,12 @@ void BluetoothLERawAdvertisement::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" rssi: ");
|
||||
sprintf(buffer, "%d", this->rssi);
|
||||
sprintf(buffer, "%" PRId32, this->rssi);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" address_type: ");
|
||||
sprintf(buffer, "%u", this->address_type);
|
||||
sprintf(buffer, "%" PRIu32, this->address_type);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5408,7 +5410,7 @@ void BluetoothDeviceRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" address_type: ");
|
||||
sprintf(buffer, "%u", this->address_type);
|
||||
sprintf(buffer, "%" PRIu32, this->address_type);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5456,12 +5458,12 @@ void BluetoothDeviceConnectionResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" mtu: ");
|
||||
sprintf(buffer, "%u", this->mtu);
|
||||
sprintf(buffer, "%" PRIu32, this->mtu);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
sprintf(buffer, "%" PRId32, this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5521,7 +5523,7 @@ void BluetoothGATTDescriptor::dump_to(std::string &out) const {
|
||||
}
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5577,12 +5579,12 @@ void BluetoothGATTCharacteristic::dump_to(std::string &out) const {
|
||||
}
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" properties: ");
|
||||
sprintf(buffer, "%u", this->properties);
|
||||
sprintf(buffer, "%" PRIu32, this->properties);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5639,7 +5641,7 @@ void BluetoothGATTService::dump_to(std::string &out) const {
|
||||
}
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5746,7 +5748,7 @@ void BluetoothGATTReadRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5791,7 +5793,7 @@ void BluetoothGATTReadResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5845,7 +5847,7 @@ void BluetoothGATTWriteRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5887,7 +5889,7 @@ void BluetoothGATTReadDescriptorRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -5932,7 +5934,7 @@ void BluetoothGATTWriteDescriptorRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -5975,7 +5977,7 @@ void BluetoothGATTNotifyRequest::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6024,7 +6026,7 @@ void BluetoothGATTNotifyDataResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6063,12 +6065,12 @@ void BluetoothConnectionsFreeResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("BluetoothConnectionsFreeResponse {\n");
|
||||
out.append(" free: ");
|
||||
sprintf(buffer, "%u", this->free);
|
||||
sprintf(buffer, "%" PRIu32, this->free);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" limit: ");
|
||||
sprintf(buffer, "%u", this->limit);
|
||||
sprintf(buffer, "%" PRIu32, this->limit);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6107,12 +6109,12 @@ void BluetoothGATTErrorResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
sprintf(buffer, "%" PRId32, this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6146,7 +6148,7 @@ void BluetoothGATTWriteResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6180,7 +6182,7 @@ void BluetoothGATTNotifyResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" handle: ");
|
||||
sprintf(buffer, "%u", this->handle);
|
||||
sprintf(buffer, "%" PRIu32, this->handle);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6223,7 +6225,7 @@ void BluetoothDevicePairingResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
sprintf(buffer, "%" PRId32, this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6266,7 +6268,7 @@ void BluetoothDeviceUnpairingResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
sprintf(buffer, "%" PRId32, this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6315,7 +6317,7 @@ void BluetoothDeviceClearCacheResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
sprintf(buffer, "%" PRId32, this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
@@ -6412,7 +6414,7 @@ void VoiceAssistantResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("VoiceAssistantResponse {\n");
|
||||
out.append(" port: ");
|
||||
sprintf(buffer, "%u", this->port);
|
||||
sprintf(buffer, "%" PRIu32, this->port);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6575,7 +6577,7 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6600,7 +6602,7 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const {
|
||||
out.append("\n");
|
||||
|
||||
out.append(" supported_features: ");
|
||||
sprintf(buffer, "%u", this->supported_features);
|
||||
sprintf(buffer, "%" PRIu32, this->supported_features);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6643,7 +6645,7 @@ void AlarmControlPanelStateResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("AlarmControlPanelStateResponse {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
@@ -6693,7 +6695,7 @@ void AlarmControlPanelCommandRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("AlarmControlPanelCommandRequest {\n");
|
||||
out.append(" key: ");
|
||||
sprintf(buffer, "%u", this->key);
|
||||
sprintf(buffer, "%" PRIu32, this->key);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
|
||||
@@ -8,15 +8,15 @@ CODEOWNERS = ["@OttoWinter"]
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema({}),
|
||||
cv.only_with_arduino,
|
||||
cv.only_on(["esp32", "esp8266"]),
|
||||
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
|
||||
)
|
||||
|
||||
|
||||
@coroutine_with_priority(200.0)
|
||||
async def to_code(config):
|
||||
if CORE.is_esp32:
|
||||
if CORE.is_esp32 or CORE.is_libretiny:
|
||||
# https://github.com/esphome/AsyncTCP/blob/master/library.json
|
||||
cg.add_library("esphome/AsyncTCP-esphome", "1.2.2")
|
||||
cg.add_library("esphome/AsyncTCP-esphome", "2.0.1")
|
||||
elif CORE.is_esp8266:
|
||||
# https://github.com/esphome/ESPAsyncTCP
|
||||
cg.add_library("esphome/ESPAsyncTCP-esphome", "1.2.3")
|
||||
cg.add_library("esphome/ESPAsyncTCP-esphome", "2.0.0")
|
||||
|
||||
@@ -6,6 +6,9 @@ from esphome.const import (
|
||||
CONF_REACTIVE_POWER,
|
||||
CONF_VOLTAGE,
|
||||
CONF_CURRENT,
|
||||
CONF_PHASE_A,
|
||||
CONF_PHASE_B,
|
||||
CONF_PHASE_C,
|
||||
CONF_POWER,
|
||||
CONF_POWER_FACTOR,
|
||||
CONF_FREQUENCY,
|
||||
@@ -31,10 +34,6 @@ from esphome.const import (
|
||||
UNIT_WATT_HOURS,
|
||||
)
|
||||
|
||||
CONF_PHASE_A = "phase_a"
|
||||
CONF_PHASE_B = "phase_b"
|
||||
CONF_PHASE_C = "phase_c"
|
||||
|
||||
CONF_LINE_FREQUENCY = "line_frequency"
|
||||
CONF_CHIP_TEMPERATURE = "chip_temperature"
|
||||
CONF_GAIN_PGA = "gain_pga"
|
||||
|
||||
51
esphome/components/bk72xx/__init__.py
Normal file
51
esphome/components/bk72xx/__init__.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# This file was auto-generated by libretiny/generate_components.py
|
||||
# Do not modify its contents.
|
||||
# For custom pin validators, put validate_pin() or validate_usage()
|
||||
# in gpio.py file in this directory.
|
||||
# For changing schema/pin schema, put COMPONENT_SCHEMA or COMPONENT_PIN_SCHEMA
|
||||
# in schema.py file in this directory.
|
||||
|
||||
from esphome import pins
|
||||
from esphome.components import libretiny
|
||||
from esphome.components.libretiny.const import (
|
||||
COMPONENT_BK72XX,
|
||||
KEY_COMPONENT_DATA,
|
||||
KEY_LIBRETINY,
|
||||
LibreTinyComponent,
|
||||
)
|
||||
from esphome.core import CORE
|
||||
|
||||
from .boards import BK72XX_BOARDS, BK72XX_BOARD_PINS
|
||||
|
||||
CODEOWNERS = ["@kuba2k2"]
|
||||
AUTO_LOAD = ["libretiny"]
|
||||
|
||||
COMPONENT_DATA = LibreTinyComponent(
|
||||
name=COMPONENT_BK72XX,
|
||||
boards=BK72XX_BOARDS,
|
||||
board_pins=BK72XX_BOARD_PINS,
|
||||
pin_validation=None,
|
||||
usage_validation=None,
|
||||
)
|
||||
|
||||
|
||||
def _set_core_data(config):
|
||||
CORE.data[KEY_LIBRETINY] = {}
|
||||
CORE.data[KEY_LIBRETINY][KEY_COMPONENT_DATA] = COMPONENT_DATA
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = libretiny.BASE_SCHEMA
|
||||
|
||||
PIN_SCHEMA = libretiny.gpio.BASE_PIN_SCHEMA
|
||||
|
||||
CONFIG_SCHEMA.prepend_extra(_set_core_data)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
return await libretiny.component_to_code(config)
|
||||
|
||||
|
||||
@pins.PIN_SCHEMA_REGISTRY.register("bk72xx", PIN_SCHEMA)
|
||||
async def pin_to_code(config):
|
||||
return await libretiny.gpio.component_pin_to_code(config)
|
||||
1264
esphome/components/bk72xx/boards.py
Normal file
1264
esphome/components/bk72xx/boards.py
Normal file
File diff suppressed because it is too large
Load Diff
1
esphome/components/bmi160/__init__.py
Normal file
1
esphome/components/bmi160/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
CODEOWNERS = ["@flaviut"]
|
||||
270
esphome/components/bmi160/bmi160.cpp
Normal file
270
esphome/components/bmi160/bmi160.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
#include "bmi160.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace bmi160 {
|
||||
|
||||
static const char *const TAG = "bmi160";
|
||||
|
||||
const uint8_t BMI160_REGISTER_CHIPID = 0x00;
|
||||
|
||||
const uint8_t BMI160_REGISTER_CMD = 0x7E;
|
||||
enum class Cmd : uint8_t {
|
||||
START_FOC = 0x03,
|
||||
ACCL_SET_PMU_MODE = 0b00010000, // last 2 bits are mode
|
||||
GYRO_SET_PMU_MODE = 0b00010100, // last 2 bits are mode
|
||||
MAG_SET_PMU_MODE = 0b00011000, // last 2 bits are mode
|
||||
PROG_NVM = 0xA0,
|
||||
FIFO_FLUSH = 0xB0,
|
||||
INT_RESET = 0xB1,
|
||||
SOFT_RESET = 0xB6,
|
||||
STEP_CNT_CLR = 0xB2,
|
||||
};
|
||||
enum class GyroPmuMode : uint8_t {
|
||||
SUSPEND = 0b00,
|
||||
NORMAL = 0b01,
|
||||
LOW_POWER = 0b10,
|
||||
};
|
||||
enum class AcclPmuMode : uint8_t {
|
||||
SUSPEND = 0b00,
|
||||
NORMAL = 0b01,
|
||||
FAST_STARTUP = 0b11,
|
||||
};
|
||||
enum class MagPmuMode : uint8_t {
|
||||
SUSPEND = 0b00,
|
||||
NORMAL = 0b01,
|
||||
LOW_POWER = 0b10,
|
||||
};
|
||||
|
||||
const uint8_t BMI160_REGISTER_ACCEL_CONFIG = 0x40;
|
||||
enum class AcclFilterMode : uint8_t {
|
||||
POWER_SAVING = 0b00000000,
|
||||
PERF = 0b10000000,
|
||||
};
|
||||
enum class AcclBandwidth : uint8_t {
|
||||
OSR4_AVG1 = 0b00000000,
|
||||
OSR2_AVG2 = 0b00010000,
|
||||
NORMAL_AVG4 = 0b00100000,
|
||||
RES_AVG8 = 0b00110000,
|
||||
RES_AVG16 = 0b01000000,
|
||||
RES_AVG32 = 0b01010000,
|
||||
RES_AVG64 = 0b01100000,
|
||||
RES_AVG128 = 0b01110000,
|
||||
};
|
||||
enum class AccelOutputDataRate : uint8_t {
|
||||
HZ_25_32 = 0b0001, // 25/32 Hz
|
||||
HZ_25_16 = 0b0010, // 25/16 Hz
|
||||
HZ_25_8 = 0b0011, // 25/8 Hz
|
||||
HZ_25_4 = 0b0100, // 25/4 Hz
|
||||
HZ_25_2 = 0b0101, // 25/2 Hz
|
||||
HZ_25 = 0b0110, // 25 Hz
|
||||
HZ_50 = 0b0111, // 50 Hz
|
||||
HZ_100 = 0b1000, // 100 Hz
|
||||
HZ_200 = 0b1001, // 200 Hz
|
||||
HZ_400 = 0b1010, // 400 Hz
|
||||
HZ_800 = 0b1011, // 800 Hz
|
||||
HZ_1600 = 0b1100, // 1600 Hz
|
||||
};
|
||||
const uint8_t BMI160_REGISTER_ACCEL_RANGE = 0x41;
|
||||
enum class AccelRange : uint8_t {
|
||||
RANGE_2G = 0b0011,
|
||||
RANGE_4G = 0b0101,
|
||||
RANGE_8G = 0b1000,
|
||||
RANGE_16G = 0b1100,
|
||||
};
|
||||
|
||||
const uint8_t BMI160_REGISTER_GYRO_CONFIG = 0x42;
|
||||
enum class GyroBandwidth : uint8_t {
|
||||
OSR4 = 0x00,
|
||||
OSR2 = 0x10,
|
||||
NORMAL = 0x20,
|
||||
};
|
||||
enum class GyroOuputDataRate : uint8_t {
|
||||
HZ_25 = 0x06,
|
||||
HZ_50 = 0x07,
|
||||
HZ_100 = 0x08,
|
||||
HZ_200 = 0x09,
|
||||
HZ_400 = 0x0A,
|
||||
HZ_800 = 0x0B,
|
||||
HZ_1600 = 0x0C,
|
||||
HZ_3200 = 0x0D,
|
||||
};
|
||||
const uint8_t BMI160_REGISTER_GYRO_RANGE = 0x43;
|
||||
enum class GyroRange : uint8_t {
|
||||
RANGE_2000_DPS = 0x0, // ±2000 °/s
|
||||
RANGE_1000_DPS = 0x1,
|
||||
RANGE_500_DPS = 0x2,
|
||||
RANGE_250_DPS = 0x3,
|
||||
RANGE_125_DPS = 0x4,
|
||||
};
|
||||
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_X_LSB = 0x0C;
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_X_MSB = 0x0D;
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_Y_LSB = 0x0E;
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_Y_MSB = 0x0F;
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_Z_LSB = 0x10;
|
||||
const uint8_t BMI160_REGISTER_DATA_GYRO_Z_MSB = 0x11;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_X_LSB = 0x12;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_X_MSB = 0x13;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_Y_LSB = 0x14;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_Y_MSB = 0x15;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_Z_LSB = 0x16;
|
||||
const uint8_t BMI160_REGISTER_DATA_ACCEL_Z_MSB = 0x17;
|
||||
const uint8_t BMI160_REGISTER_DATA_TEMP_LSB = 0x20;
|
||||
const uint8_t BMI160_REGISTER_DATA_TEMP_MSB = 0x21;
|
||||
|
||||
const float GRAVITY_EARTH = 9.80665f;
|
||||
|
||||
void BMI160Component::internal_setup_(int stage) {
|
||||
switch (stage) {
|
||||
case 0:
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMI160...");
|
||||
uint8_t chipid;
|
||||
if (!this->read_byte(BMI160_REGISTER_CHIPID, &chipid) || (chipid != 0b11010001)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Bringing accelerometer out of sleep...");
|
||||
if (!this->write_byte(BMI160_REGISTER_CMD, (uint8_t) Cmd::ACCL_SET_PMU_MODE | (uint8_t) AcclPmuMode::NORMAL)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Waiting for accelerometer to wake up...");
|
||||
// need to wait (max delay in datasheet) because we can't send commands while another is in progress
|
||||
// min 5ms, 10ms
|
||||
this->set_timeout(10, [this]() { this->internal_setup_(1); });
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ESP_LOGV(TAG, " Bringing gyroscope out of sleep...");
|
||||
if (!this->write_byte(BMI160_REGISTER_CMD, (uint8_t) Cmd::GYRO_SET_PMU_MODE | (uint8_t) GyroPmuMode::NORMAL)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Waiting for gyroscope to wake up...");
|
||||
// wait between 51 & 81ms, doing 100 to be safe
|
||||
this->set_timeout(10, [this]() { this->internal_setup_(2); });
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ESP_LOGV(TAG, " Setting up Gyro Config...");
|
||||
uint8_t gyro_config = (uint8_t) GyroBandwidth::OSR4 | (uint8_t) GyroOuputDataRate::HZ_25;
|
||||
ESP_LOGV(TAG, " Output gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
if (!this->write_byte(BMI160_REGISTER_GYRO_CONFIG, gyro_config)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Setting up Gyro Range...");
|
||||
uint8_t gyro_range = (uint8_t) GyroRange::RANGE_2000_DPS;
|
||||
ESP_LOGV(TAG, " Output gyro_range: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_range));
|
||||
if (!this->write_byte(BMI160_REGISTER_GYRO_RANGE, gyro_range)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Accel Config...");
|
||||
uint8_t accel_config =
|
||||
(uint8_t) AcclFilterMode::PERF | (uint8_t) AcclBandwidth::RES_AVG16 | (uint8_t) AccelOutputDataRate::HZ_25;
|
||||
ESP_LOGV(TAG, " Output accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
if (!this->write_byte(BMI160_REGISTER_ACCEL_CONFIG, accel_config)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Setting up Accel Range...");
|
||||
uint8_t accel_range = (uint8_t) AccelRange::RANGE_16G;
|
||||
ESP_LOGV(TAG, " Output accel_range: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_range));
|
||||
if (!this->write_byte(BMI160_REGISTER_ACCEL_RANGE, accel_range)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
this->setup_complete_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BMI160Component::setup() { this->internal_setup_(0); }
|
||||
void BMI160Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BMI160:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with BMI160 failed!");
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_);
|
||||
LOG_SENSOR(" ", "Acceleration Y", this->accel_y_sensor_);
|
||||
LOG_SENSOR(" ", "Acceleration Z", this->accel_z_sensor_);
|
||||
LOG_SENSOR(" ", "Gyro X", this->gyro_x_sensor_);
|
||||
LOG_SENSOR(" ", "Gyro Y", this->gyro_y_sensor_);
|
||||
LOG_SENSOR(" ", "Gyro Z", this->gyro_z_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
}
|
||||
|
||||
i2c::ErrorCode BMI160Component::read_le_int16_(uint8_t reg, int16_t *value, uint8_t len) {
|
||||
uint8_t raw_data[len * 2];
|
||||
// read using read_register because we have little-endian data, and read_bytes_16 will swap it
|
||||
i2c::ErrorCode err = this->read_register(reg, raw_data, len * 2, true);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
value[i] = (int16_t) ((uint16_t) raw_data[i * 2] | ((uint16_t) raw_data[i * 2 + 1] << 8));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void BMI160Component::update() {
|
||||
if (!this->setup_complete_) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Updating BMI160...");
|
||||
int16_t data[6];
|
||||
if (this->read_le_int16_(BMI160_REGISTER_DATA_GYRO_X_LSB, data, 6) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
float gyro_x = (float) data[0] / (float) INT16_MAX * 2000.f;
|
||||
float gyro_y = (float) data[1] / (float) INT16_MAX * 2000.f;
|
||||
float gyro_z = (float) data[2] / (float) INT16_MAX * 2000.f;
|
||||
float accel_x = (float) data[3] / (float) INT16_MAX * 16 * GRAVITY_EARTH;
|
||||
float accel_y = (float) data[4] / (float) INT16_MAX * 16 * GRAVITY_EARTH;
|
||||
float accel_z = (float) data[5] / (float) INT16_MAX * 16 * GRAVITY_EARTH;
|
||||
|
||||
int16_t raw_temperature;
|
||||
if (this->read_le_int16_(BMI160_REGISTER_DATA_TEMP_LSB, &raw_temperature, 1) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
float temperature = (float) raw_temperature / (float) INT16_MAX * 64.5f + 23.f;
|
||||
|
||||
ESP_LOGD(TAG,
|
||||
"Got accel={x=%.3f m/s², y=%.3f m/s², z=%.3f m/s²}, "
|
||||
"gyro={x=%.3f °/s, y=%.3f °/s, z=%.3f °/s}, temp=%.3f°C",
|
||||
accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z, temperature);
|
||||
|
||||
if (this->accel_x_sensor_ != nullptr)
|
||||
this->accel_x_sensor_->publish_state(accel_x);
|
||||
if (this->accel_y_sensor_ != nullptr)
|
||||
this->accel_y_sensor_->publish_state(accel_y);
|
||||
if (this->accel_z_sensor_ != nullptr)
|
||||
this->accel_z_sensor_->publish_state(accel_z);
|
||||
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(temperature);
|
||||
|
||||
if (this->gyro_x_sensor_ != nullptr)
|
||||
this->gyro_x_sensor_->publish_state(gyro_x);
|
||||
if (this->gyro_y_sensor_ != nullptr)
|
||||
this->gyro_y_sensor_->publish_state(gyro_y);
|
||||
if (this->gyro_z_sensor_ != nullptr)
|
||||
this->gyro_z_sensor_->publish_state(gyro_z);
|
||||
|
||||
this->status_clear_warning();
|
||||
}
|
||||
float BMI160Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
} // namespace bmi160
|
||||
} // namespace esphome
|
||||
44
esphome/components/bmi160/bmi160.h
Normal file
44
esphome/components/bmi160/bmi160.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace bmi160 {
|
||||
|
||||
class BMI160Component : public PollingComponent, public i2c::I2CDevice {
|
||||
public:
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
void update() override;
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
void set_accel_x_sensor(sensor::Sensor *accel_x_sensor) { accel_x_sensor_ = accel_x_sensor; }
|
||||
void set_accel_y_sensor(sensor::Sensor *accel_y_sensor) { accel_y_sensor_ = accel_y_sensor; }
|
||||
void set_accel_z_sensor(sensor::Sensor *accel_z_sensor) { accel_z_sensor_ = accel_z_sensor; }
|
||||
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
|
||||
void set_gyro_x_sensor(sensor::Sensor *gyro_x_sensor) { gyro_x_sensor_ = gyro_x_sensor; }
|
||||
void set_gyro_y_sensor(sensor::Sensor *gyro_y_sensor) { gyro_y_sensor_ = gyro_y_sensor; }
|
||||
void set_gyro_z_sensor(sensor::Sensor *gyro_z_sensor) { gyro_z_sensor_ = gyro_z_sensor; }
|
||||
|
||||
protected:
|
||||
sensor::Sensor *accel_x_sensor_{nullptr};
|
||||
sensor::Sensor *accel_y_sensor_{nullptr};
|
||||
sensor::Sensor *accel_z_sensor_{nullptr};
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *gyro_x_sensor_{nullptr};
|
||||
sensor::Sensor *gyro_y_sensor_{nullptr};
|
||||
sensor::Sensor *gyro_z_sensor_{nullptr};
|
||||
|
||||
void internal_setup_(int stage);
|
||||
bool setup_complete_{false};
|
||||
|
||||
/** reads `len` 16-bit little-endian integers from the given i2c register */
|
||||
i2c::ErrorCode read_le_int16_(uint8_t reg, int16_t *value, uint8_t len);
|
||||
};
|
||||
|
||||
} // namespace bmi160
|
||||
} // namespace esphome
|
||||
102
esphome/components/bmi160/sensor.py
Normal file
102
esphome/components/bmi160/sensor.py
Normal file
@@ -0,0 +1,102 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_TEMPERATURE,
|
||||
CONF_ACCELERATION_X,
|
||||
CONF_ACCELERATION_Y,
|
||||
CONF_ACCELERATION_Z,
|
||||
CONF_GYROSCOPE_X,
|
||||
CONF_GYROSCOPE_Y,
|
||||
CONF_GYROSCOPE_Z,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_METER_PER_SECOND_SQUARED,
|
||||
ICON_ACCELERATION_X,
|
||||
ICON_ACCELERATION_Y,
|
||||
ICON_ACCELERATION_Z,
|
||||
ICON_GYROSCOPE_X,
|
||||
ICON_GYROSCOPE_Y,
|
||||
ICON_GYROSCOPE_Z,
|
||||
UNIT_DEGREE_PER_SECOND,
|
||||
UNIT_CELSIUS,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
bmi160_ns = cg.esphome_ns.namespace("bmi160")
|
||||
BMI160Component = bmi160_ns.class_(
|
||||
"BMI160Component", cg.PollingComponent, i2c.I2CDevice
|
||||
)
|
||||
|
||||
accel_schema = {
|
||||
"unit_of_measurement": UNIT_METER_PER_SECOND_SQUARED,
|
||||
"accuracy_decimals": 2,
|
||||
"state_class": STATE_CLASS_MEASUREMENT,
|
||||
}
|
||||
gyro_schema = {
|
||||
"unit_of_measurement": UNIT_DEGREE_PER_SECOND,
|
||||
"accuracy_decimals": 2,
|
||||
"state_class": STATE_CLASS_MEASUREMENT,
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(BMI160Component),
|
||||
cv.Optional(CONF_ACCELERATION_X): sensor.sensor_schema(
|
||||
icon=ICON_ACCELERATION_X,
|
||||
**accel_schema,
|
||||
),
|
||||
cv.Optional(CONF_ACCELERATION_Y): sensor.sensor_schema(
|
||||
icon=ICON_ACCELERATION_Y,
|
||||
**accel_schema,
|
||||
),
|
||||
cv.Optional(CONF_ACCELERATION_Z): sensor.sensor_schema(
|
||||
icon=ICON_ACCELERATION_Z,
|
||||
**accel_schema,
|
||||
),
|
||||
cv.Optional(CONF_GYROSCOPE_X): sensor.sensor_schema(
|
||||
icon=ICON_GYROSCOPE_X,
|
||||
**gyro_schema,
|
||||
),
|
||||
cv.Optional(CONF_GYROSCOPE_Y): sensor.sensor_schema(
|
||||
icon=ICON_GYROSCOPE_Y,
|
||||
**gyro_schema,
|
||||
),
|
||||
cv.Optional(CONF_GYROSCOPE_Z): sensor.sensor_schema(
|
||||
icon=ICON_GYROSCOPE_Z,
|
||||
**gyro_schema,
|
||||
),
|
||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
accuracy_decimals=0,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(0x68))
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
for d in ["x", "y", "z"]:
|
||||
accel_key = f"acceleration_{d}"
|
||||
if accel_key in config:
|
||||
sens = await sensor.new_sensor(config[accel_key])
|
||||
cg.add(getattr(var, f"set_accel_{d}_sensor")(sens))
|
||||
accel_key = f"gyroscope_{d}"
|
||||
if accel_key in config:
|
||||
sens = await sensor.new_sensor(config[accel_key])
|
||||
cg.add(getattr(var, f"set_gyro_{d}_sensor")(sens))
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
@@ -45,9 +45,13 @@ CanbusTrigger = canbus_ns.class_(
|
||||
CanSpeed = canbus_ns.enum("CAN_SPEED")
|
||||
|
||||
CAN_SPEEDS = {
|
||||
"1KBPS": CanSpeed.CAN_1KBPS,
|
||||
"5KBPS": CanSpeed.CAN_5KBPS,
|
||||
"10KBPS": CanSpeed.CAN_10KBPS,
|
||||
"12K5BPS": CanSpeed.CAN_12K5BPS,
|
||||
"16KBPS": CanSpeed.CAN_16KBPS,
|
||||
"20KBPS": CanSpeed.CAN_20KBPS,
|
||||
"25KBPS": CanSpeed.CAN_25KBPS,
|
||||
"31K25BPS": CanSpeed.CAN_31K25BPS,
|
||||
"33KBPS": CanSpeed.CAN_33KBPS,
|
||||
"40KBPS": CanSpeed.CAN_40KBPS,
|
||||
@@ -60,9 +64,9 @@ CAN_SPEEDS = {
|
||||
"200KBPS": CanSpeed.CAN_200KBPS,
|
||||
"250KBPS": CanSpeed.CAN_250KBPS,
|
||||
"500KBPS": CanSpeed.CAN_500KBPS,
|
||||
"800KBPS": CanSpeed.CAN_800KBPS,
|
||||
"1000KBPS": CanSpeed.CAN_1000KBPS,
|
||||
}
|
||||
|
||||
CANBUS_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CanbusComponent),
|
||||
|
||||
@@ -19,9 +19,13 @@ enum Error : uint8_t {
|
||||
};
|
||||
|
||||
enum CanSpeed : uint8_t {
|
||||
CAN_1KBPS,
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_12K5BPS,
|
||||
CAN_16KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_25KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS,
|
||||
CAN_40KBPS,
|
||||
@@ -34,6 +38,7 @@ enum CanSpeed : uint8_t {
|
||||
CAN_200KBPS,
|
||||
CAN_250KBPS,
|
||||
CAN_500KBPS,
|
||||
CAN_800KBPS,
|
||||
CAN_1000KBPS
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ CONF_ALLOW_MULTIPLE_TOUCHES = "allow_multiple_touches"
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
AUTO_LOAD = ["binary_sensor", "output"]
|
||||
CODEOWNERS = ["@MrEditor97"]
|
||||
CODEOWNERS = ["@mreditor97"]
|
||||
|
||||
cap1188_ns = cg.esphome_ns.namespace("cap1188")
|
||||
CONF_CAP1188_ID = "cap1188_id"
|
||||
|
||||
@@ -21,7 +21,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
cv.only_on(["esp32", "esp8266"]),
|
||||
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
|
||||
)
|
||||
|
||||
|
||||
@@ -39,3 +39,5 @@ async def to_code(config):
|
||||
cg.add_library("WiFi", None)
|
||||
if CORE.is_esp8266:
|
||||
cg.add_library("DNSServer", None)
|
||||
if CORE.is_libretiny:
|
||||
cg.add_library("DNSServer", None)
|
||||
|
||||
@@ -38,7 +38,7 @@ void CurrentBasedCover::control(const CoverCall &call) {
|
||||
}
|
||||
if (call.get_position().has_value()) {
|
||||
auto pos = *call.get_position();
|
||||
if (pos == this->position) {
|
||||
if (fabsf(this->position - pos) < 0.01) {
|
||||
// already at target
|
||||
} else {
|
||||
auto op = pos < this->position ? COVER_OPERATION_CLOSING : COVER_OPERATION_OPENING;
|
||||
|
||||
@@ -24,7 +24,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
).extend(
|
||||
{
|
||||
cv.GenerateID(CONF_DALLAS_ID): cv.use_id(DallasComponent),
|
||||
cv.Optional(CONF_ADDRESS): cv.hex_int,
|
||||
cv.Optional(CONF_ADDRESS): cv.hex_uint64_t,
|
||||
cv.Optional(CONF_INDEX): cv.positive_int,
|
||||
cv.Optional(CONF_RESOLUTION, default=12): cv.int_range(min=9, max=12),
|
||||
}
|
||||
|
||||
@@ -12,11 +12,17 @@
|
||||
#include <esp_heap_caps.h>
|
||||
#include <esp_system.h>
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include <esp32/rom/rtc.h>
|
||||
#include <esp_chip_info.h>
|
||||
#else
|
||||
#include <rom/rtc.h>
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
#include <esp32/rom/rtc.h>
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
#include <esp32c3/rom/rtc.h>
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C6)
|
||||
#include <esp32c6/rom/rtc.h>
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
#include <esp32s2/rom/rtc.h>
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
#include <esp32s3/rom/rtc.h>
|
||||
#endif
|
||||
|
||||
#endif // USE_ESP32
|
||||
@@ -24,7 +30,7 @@
|
||||
#ifdef USE_ARDUINO
|
||||
#ifdef USE_RP2040
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#elif defined(USE_ESP32) || defined(USE_ESP8266)
|
||||
#include <Esp.h>
|
||||
#endif
|
||||
#endif
|
||||
@@ -41,6 +47,8 @@ static uint32_t get_free_heap() {
|
||||
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
||||
#elif defined(USE_RP2040)
|
||||
return rp2040.getFreeHeap();
|
||||
#elif defined(USE_LIBRETINY)
|
||||
return lt_heap_get_free();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ void DebugComponent::dump_config() {
|
||||
this->free_heap_ = get_free_heap();
|
||||
ESP_LOGD(TAG, "Free Heap Size: %" PRIu32 " bytes", this->free_heap_);
|
||||
|
||||
#if defined(USE_ARDUINO) && !defined(USE_RP2040)
|
||||
#if defined(USE_ARDUINO) && (defined(USE_ESP32) || defined(USE_ESP8266))
|
||||
const char *flash_mode;
|
||||
switch (ESP.getFlashChipMode()) { // NOLINT(readability-static-accessed-through-instance)
|
||||
case FM_QIO:
|
||||
@@ -103,19 +111,27 @@ void DebugComponent::dump_config() {
|
||||
device_info += "|Flash: " + to_string(ESP.getFlashChipSize() / 1024) + // NOLINT
|
||||
"kB Speed:" + to_string(ESP.getFlashChipSpeed() / 1000000) + "MHz Mode:"; // NOLINT
|
||||
device_info += flash_mode;
|
||||
#endif // USE_ARDUINO
|
||||
#endif // USE_ARDUINO && (USE_ESP32 || USE_ESP8266)
|
||||
|
||||
#ifdef USE_ESP32
|
||||
esp_chip_info_t info;
|
||||
esp_chip_info(&info);
|
||||
const char *model;
|
||||
switch (info.model) {
|
||||
case CHIP_ESP32:
|
||||
model = "ESP32";
|
||||
break;
|
||||
default:
|
||||
model = "UNKNOWN";
|
||||
}
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
model = "ESP32";
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C3)
|
||||
model = "ESP32-C3";
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C6)
|
||||
model = "ESP32-C6";
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32S2)
|
||||
model = "ESP32-S2";
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
model = "ESP32-S3";
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32H2)
|
||||
model = "ESP32-H2";
|
||||
#else
|
||||
model = "UNKNOWN";
|
||||
#endif
|
||||
std::string features;
|
||||
if (info.features & CHIP_FEATURE_EMB_FLASH) {
|
||||
features += "EMB_FLASH,";
|
||||
@@ -133,6 +149,10 @@ void DebugComponent::dump_config() {
|
||||
features += "BT,";
|
||||
info.features &= ~CHIP_FEATURE_BT;
|
||||
}
|
||||
if (info.features & CHIP_FEATURE_EMB_PSRAM) {
|
||||
features += "EMB_PSRAM,";
|
||||
info.features &= ~CHIP_FEATURE_EMB_PSRAM;
|
||||
}
|
||||
if (info.features)
|
||||
features += "Other:" + format_hex(info.features);
|
||||
ESP_LOGD(TAG, "Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
|
||||
@@ -157,18 +177,26 @@ void DebugComponent::dump_config() {
|
||||
case POWERON_RESET:
|
||||
reset_reason = "Power On Reset";
|
||||
break;
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case SW_RESET:
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case RTC_SW_SYS_RESET:
|
||||
#endif
|
||||
reset_reason = "Software Reset Digital Core";
|
||||
break;
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case OWDT_RESET:
|
||||
reset_reason = "Watch Dog Reset Digital Core";
|
||||
break;
|
||||
#endif
|
||||
case DEEPSLEEP_RESET:
|
||||
reset_reason = "Deep Sleep Reset Digital Core";
|
||||
break;
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case SDIO_RESET:
|
||||
reset_reason = "SLC Module Reset Digital Core";
|
||||
break;
|
||||
#endif
|
||||
case TG0WDT_SYS_RESET:
|
||||
reset_reason = "Timer Group 0 Watch Dog Reset Digital Core";
|
||||
break;
|
||||
@@ -178,27 +206,66 @@ void DebugComponent::dump_config() {
|
||||
case RTCWDT_SYS_RESET:
|
||||
reset_reason = "RTC Watch Dog Reset Digital Core";
|
||||
break;
|
||||
#if !defined(USE_ESP32_VARIANT_ESP32C6)
|
||||
case INTRUSION_RESET:
|
||||
reset_reason = "Intrusion Reset CPU";
|
||||
break;
|
||||
#endif
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case TGWDT_CPU_RESET:
|
||||
reset_reason = "Timer Group Reset CPU";
|
||||
break;
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case TG0WDT_CPU_RESET:
|
||||
reset_reason = "Timer Group 0 Reset CPU";
|
||||
break;
|
||||
#endif
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case SW_CPU_RESET:
|
||||
#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case RTC_SW_CPU_RESET:
|
||||
#endif
|
||||
reset_reason = "Software Reset CPU";
|
||||
break;
|
||||
case RTCWDT_CPU_RESET:
|
||||
reset_reason = "RTC Watch Dog Reset CPU";
|
||||
break;
|
||||
#if defined(USE_ESP32_VARIANT_ESP32)
|
||||
case EXT_CPU_RESET:
|
||||
reset_reason = "External CPU Reset";
|
||||
break;
|
||||
#endif
|
||||
case RTCWDT_BROWN_OUT_RESET:
|
||||
reset_reason = "Voltage Unstable Reset";
|
||||
break;
|
||||
case RTCWDT_RTC_RESET:
|
||||
reset_reason = "RTC Watch Dog Reset Digital Core And RTC Module";
|
||||
break;
|
||||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case TG1WDT_CPU_RESET:
|
||||
reset_reason = "Timer Group 1 Reset CPU";
|
||||
break;
|
||||
case SUPER_WDT_RESET:
|
||||
reset_reason = "Super Watchdog Reset Digital Core And RTC Module";
|
||||
break;
|
||||
case GLITCH_RTC_RESET:
|
||||
reset_reason = "Glitch Reset Digital Core And RTC Module";
|
||||
break;
|
||||
case EFUSE_RESET:
|
||||
reset_reason = "eFuse Reset Digital Core";
|
||||
break;
|
||||
#endif
|
||||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case USB_UART_CHIP_RESET:
|
||||
reset_reason = "USB UART Reset Digital Core";
|
||||
break;
|
||||
case USB_JTAG_CHIP_RESET:
|
||||
reset_reason = "USB JTAG Reset Digital Core";
|
||||
break;
|
||||
case POWER_GLITCH_RESET:
|
||||
reset_reason = "Power Glitch Reset Digital Core And RTC Module";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
reset_reason = "Unknown Reset Reason";
|
||||
}
|
||||
@@ -285,6 +352,27 @@ void DebugComponent::dump_config() {
|
||||
device_info += "CPU Frequency: " + to_string(rp2040.f_cpu());
|
||||
#endif // USE_RP2040
|
||||
|
||||
#ifdef USE_LIBRETINY
|
||||
ESP_LOGD(TAG, "LibreTiny Version: %s", lt_get_version());
|
||||
ESP_LOGD(TAG, "Chip: %s (%04x) @ %u MHz", lt_cpu_get_model_name(), lt_cpu_get_model(), lt_cpu_get_freq_mhz());
|
||||
ESP_LOGD(TAG, "Chip ID: 0x%06X", lt_cpu_get_mac_id());
|
||||
ESP_LOGD(TAG, "Board: %s", lt_get_board_code());
|
||||
ESP_LOGD(TAG, "Flash: %u KiB / RAM: %u KiB", lt_flash_get_size() / 1024, lt_ram_get_size() / 1024);
|
||||
ESP_LOGD(TAG, "Reset Reason: %s", lt_get_reboot_reason_name(lt_get_reboot_reason()));
|
||||
|
||||
device_info += "|Version: ";
|
||||
device_info += LT_BANNER_STR + 10;
|
||||
device_info += "|Reset Reason: ";
|
||||
device_info += lt_get_reboot_reason_name(lt_get_reboot_reason());
|
||||
device_info += "|Chip Name: ";
|
||||
device_info += lt_cpu_get_model_name();
|
||||
device_info += "|Chip ID: 0x" + format_hex(lt_cpu_get_mac_id());
|
||||
device_info += "|Flash: " + to_string(lt_flash_get_size() / 1024) + " KiB";
|
||||
device_info += "|RAM: " + to_string(lt_ram_get_size() / 1024) + " KiB";
|
||||
|
||||
reset_reason = lt_get_reboot_reason_name(lt_get_reboot_reason());
|
||||
#endif // USE_LIBRETINY
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
if (this->device_info_ != nullptr) {
|
||||
if (device_info.length() > 255)
|
||||
@@ -329,6 +417,8 @@ void DebugComponent::update() {
|
||||
this->block_sensor_->publish_state(ESP.getMaxFreeBlockSize());
|
||||
#elif defined(USE_ESP32)
|
||||
this->block_sensor_->publish_state(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL));
|
||||
#elif defined(USE_LIBRETINY)
|
||||
this->block_sensor_->publish_state(lt_heap_get_max_alloc());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -343,6 +433,12 @@ void DebugComponent::update() {
|
||||
this->loop_time_sensor_->publish_state(this->max_loop_time_);
|
||||
this->max_loop_time_ = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_ESP32
|
||||
if (this->psram_sensor_ != nullptr) {
|
||||
this->psram_sensor_->publish_state(heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
#endif // USE_ESP32
|
||||
#endif // USE_SENSOR
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ class DebugComponent : public PollingComponent {
|
||||
void set_fragmentation_sensor(sensor::Sensor *fragmentation_sensor) { fragmentation_sensor_ = fragmentation_sensor; }
|
||||
#endif
|
||||
void set_loop_time_sensor(sensor::Sensor *loop_time_sensor) { loop_time_sensor_ = loop_time_sensor; }
|
||||
#ifdef USE_ESP32
|
||||
void set_psram_sensor(sensor::Sensor *psram_sensor) { this->psram_sensor_ = psram_sensor; }
|
||||
#endif // USE_ESP32
|
||||
#endif // USE_SENSOR
|
||||
protected:
|
||||
uint32_t free_heap_{};
|
||||
@@ -47,6 +50,9 @@ class DebugComponent : public PollingComponent {
|
||||
sensor::Sensor *fragmentation_sensor_{nullptr};
|
||||
#endif
|
||||
sensor::Sensor *loop_time_sensor_{nullptr};
|
||||
#ifdef USE_ESP32
|
||||
sensor::Sensor *psram_sensor_{nullptr};
|
||||
#endif // USE_ESP32
|
||||
#endif // USE_SENSOR
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
|
||||
@@ -17,6 +17,8 @@ from . import CONF_DEBUG_ID, DebugComponent
|
||||
|
||||
DEPENDENCIES = ["debug"]
|
||||
|
||||
CONF_PSRAM = "psram"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_DEBUG_ID): cv.use_id(DebugComponent),
|
||||
cv.Optional(CONF_FREE): sensor.sensor_schema(
|
||||
@@ -47,24 +49,38 @@ CONFIG_SCHEMA = {
|
||||
accuracy_decimals=0,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional(CONF_PSRAM): cv.All(
|
||||
cv.only_on_esp32,
|
||||
cv.requires_component("psram"),
|
||||
sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_BYTES,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
debug_component = await cg.get_variable(config[CONF_DEBUG_ID])
|
||||
|
||||
if CONF_FREE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FREE])
|
||||
if free_conf := config.get(CONF_FREE):
|
||||
sens = await sensor.new_sensor(free_conf)
|
||||
cg.add(debug_component.set_free_sensor(sens))
|
||||
|
||||
if CONF_BLOCK in config:
|
||||
sens = await sensor.new_sensor(config[CONF_BLOCK])
|
||||
if block_conf := config.get(CONF_BLOCK):
|
||||
sens = await sensor.new_sensor(block_conf)
|
||||
cg.add(debug_component.set_block_sensor(sens))
|
||||
|
||||
if CONF_FRAGMENTATION in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FRAGMENTATION])
|
||||
if fragmentation_conf := config.get(CONF_FRAGMENTATION):
|
||||
sens = await sensor.new_sensor(fragmentation_conf)
|
||||
cg.add(debug_component.set_fragmentation_sensor(sens))
|
||||
|
||||
if CONF_LOOP_TIME in config:
|
||||
sens = await sensor.new_sensor(config[CONF_LOOP_TIME])
|
||||
if loop_time_conf := config.get(CONF_LOOP_TIME):
|
||||
sens = await sensor.new_sensor(loop_time_conf)
|
||||
cg.add(debug_component.set_loop_time_sensor(sens))
|
||||
|
||||
if psram_conf := config.get(CONF_PSRAM):
|
||||
sens = await sensor.new_sensor(psram_conf)
|
||||
cg.add(debug_component.set_psram_sensor(sens))
|
||||
|
||||
@@ -22,6 +22,8 @@ from esphome.components.esp32.const import (
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C6,
|
||||
)
|
||||
|
||||
WAKEUP_PINS = {
|
||||
@@ -94,6 +96,8 @@ WAKEUP_PINS = {
|
||||
20,
|
||||
21,
|
||||
],
|
||||
VARIANT_ESP32C2: [0, 1, 2, 3, 4, 5],
|
||||
VARIANT_ESP32C6: [0, 1, 2, 3, 4, 5, 6, 7],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,6 +101,11 @@ void DFPlayer::loop() {
|
||||
ESP_LOGV(TAG, "Nack");
|
||||
this->ack_set_is_playing_ = false;
|
||||
this->ack_reset_is_playing_ = false;
|
||||
if (argument == 6) {
|
||||
ESP_LOGV(TAG, "File not found");
|
||||
this->is_playing_ = false;
|
||||
}
|
||||
break;
|
||||
case 0x41:
|
||||
ESP_LOGV(TAG, "Ack ok");
|
||||
this->is_playing_ |= this->ack_set_is_playing_;
|
||||
|
||||
@@ -22,6 +22,7 @@ from esphome.const import (
|
||||
CONF_IGNORE_EFUSE_MAC_CRC,
|
||||
KEY_CORE,
|
||||
KEY_FRAMEWORK_VERSION,
|
||||
KEY_NAME,
|
||||
KEY_TARGET_FRAMEWORK,
|
||||
KEY_TARGET_PLATFORM,
|
||||
TYPE_GIT,
|
||||
@@ -37,6 +38,7 @@ from .const import ( # noqa
|
||||
KEY_BOARD,
|
||||
KEY_COMPONENTS,
|
||||
KEY_ESP32,
|
||||
KEY_EXTRA_BUILD_FILES,
|
||||
KEY_PATH,
|
||||
KEY_REF,
|
||||
KEY_REFRESH,
|
||||
@@ -44,7 +46,6 @@ from .const import ( # noqa
|
||||
KEY_SDKCONFIG_OPTIONS,
|
||||
KEY_SUBMODULES,
|
||||
KEY_VARIANT,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_FRIENDLY,
|
||||
VARIANTS,
|
||||
)
|
||||
@@ -74,6 +75,8 @@ def set_core_data(config):
|
||||
)
|
||||
CORE.data[KEY_ESP32][KEY_BOARD] = config[CONF_BOARD]
|
||||
CORE.data[KEY_ESP32][KEY_VARIANT] = config[CONF_VARIANT]
|
||||
CORE.data[KEY_ESP32][KEY_EXTRA_BUILD_FILES] = {}
|
||||
|
||||
return config
|
||||
|
||||
|
||||
@@ -85,6 +88,23 @@ def get_board(core_obj=None):
|
||||
return (core_obj or CORE).data[KEY_ESP32][KEY_BOARD]
|
||||
|
||||
|
||||
def get_download_types(storage_json):
|
||||
return [
|
||||
{
|
||||
"title": "Modern format",
|
||||
"description": "For use with ESPHome Web and other tools.",
|
||||
"file": "firmware-factory.bin",
|
||||
"download": f"{storage_json.name}-factory.bin",
|
||||
},
|
||||
{
|
||||
"title": "Legacy format",
|
||||
"description": "For use with ESPHome Flasher.",
|
||||
"file": "firmware.bin",
|
||||
"download": f"{storage_json.name}.bin",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def only_on_variant(*, supported=None, unsupported=None):
|
||||
"""Config validator for features only available on some ESP32 variants."""
|
||||
if supported is not None and not isinstance(supported, list):
|
||||
@@ -150,6 +170,24 @@ def add_idf_component(
|
||||
}
|
||||
|
||||
|
||||
def add_extra_script(stage: str, filename: str, path: str):
|
||||
"""Add an extra script to the project."""
|
||||
key = f"{stage}:{filename}"
|
||||
if add_extra_build_file(filename, path):
|
||||
cg.add_platformio_option("extra_scripts", [key])
|
||||
|
||||
|
||||
def add_extra_build_file(filename: str, path: str) -> bool:
|
||||
"""Add an extra build file to the project."""
|
||||
if filename not in CORE.data[KEY_ESP32][KEY_EXTRA_BUILD_FILES]:
|
||||
CORE.data[KEY_ESP32][KEY_EXTRA_BUILD_FILES][filename] = {
|
||||
KEY_NAME: filename,
|
||||
KEY_PATH: path,
|
||||
}
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _format_framework_arduino_version(ver: cv.Version) -> str:
|
||||
# format the given arduino (https://github.com/espressif/arduino-esp32/releases) version to
|
||||
# a PIO platformio/framework-arduinoespressif32 value
|
||||
@@ -374,7 +412,11 @@ async def to_code(config):
|
||||
conf = config[CONF_FRAMEWORK]
|
||||
cg.add_platformio_option("platform", conf[CONF_PLATFORM_VERSION])
|
||||
|
||||
cg.add_platformio_option("extra_scripts", ["post:post_build.py"])
|
||||
add_extra_script(
|
||||
"post",
|
||||
"post_build2.py",
|
||||
os.path.join(os.path.dirname(__file__), "post_build.py.script"),
|
||||
)
|
||||
|
||||
if conf[CONF_TYPE] == FRAMEWORK_ESP_IDF:
|
||||
cg.add_platformio_option("framework", "espidf")
|
||||
@@ -588,9 +630,15 @@ def copy_files():
|
||||
ignore_dangling_symlinks=True,
|
||||
)
|
||||
|
||||
dir = os.path.dirname(__file__)
|
||||
post_build_file = os.path.join(dir, "post_build.py.script")
|
||||
copy_file_if_changed(
|
||||
post_build_file,
|
||||
CORE.relative_build_path("post_build.py"),
|
||||
)
|
||||
for _, file in CORE.data[KEY_ESP32][KEY_EXTRA_BUILD_FILES].items():
|
||||
if file[KEY_PATH].startswith("http"):
|
||||
import requests
|
||||
|
||||
mkdir_p(CORE.relative_build_path(os.path.dirname(file[KEY_NAME])))
|
||||
with open(CORE.relative_build_path(file[KEY_NAME]), "wb") as f:
|
||||
f.write(requests.get(file[KEY_PATH], timeout=30).content)
|
||||
else:
|
||||
copy_file_if_changed(
|
||||
file[KEY_PATH],
|
||||
CORE.relative_build_path(file[KEY_NAME]),
|
||||
)
|
||||
|
||||
@@ -10,17 +10,22 @@ KEY_REF = "ref"
|
||||
KEY_REFRESH = "refresh"
|
||||
KEY_PATH = "path"
|
||||
KEY_SUBMODULES = "submodules"
|
||||
KEY_EXTRA_BUILD_FILES = "extra_build_files"
|
||||
|
||||
VARIANT_ESP32 = "ESP32"
|
||||
VARIANT_ESP32S2 = "ESP32S2"
|
||||
VARIANT_ESP32S3 = "ESP32S3"
|
||||
VARIANT_ESP32C2 = "ESP32C2"
|
||||
VARIANT_ESP32C3 = "ESP32C3"
|
||||
VARIANT_ESP32C6 = "ESP32C6"
|
||||
VARIANT_ESP32H2 = "ESP32H2"
|
||||
VARIANTS = [
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32H2,
|
||||
]
|
||||
|
||||
@@ -28,7 +33,9 @@ VARIANT_FRIENDLY = {
|
||||
VARIANT_ESP32: "ESP32",
|
||||
VARIANT_ESP32S2: "ESP32-S2",
|
||||
VARIANT_ESP32S3: "ESP32-S3",
|
||||
VARIANT_ESP32C2: "ESP32-C2",
|
||||
VARIANT_ESP32C3: "ESP32-C3",
|
||||
VARIANT_ESP32C6: "ESP32-C6",
|
||||
VARIANT_ESP32H2: "ESP32-H2",
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
#include <esp_timer.h>
|
||||
#include <soc/rtc.h>
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include <hal/cpu_hal.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
#include <esp32-hal.h>
|
||||
@@ -55,15 +53,11 @@ void arch_init() {
|
||||
void IRAM_ATTR HOT arch_feed_wdt() { esp_task_wdt_reset(); }
|
||||
|
||||
uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
|
||||
uint32_t arch_get_cpu_cycle_count() {
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
return cpu_hal_get_cycle_count();
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
uint32_t arch_get_cpu_cycle_count() { return esp_cpu_get_cycle_count(); }
|
||||
#else
|
||||
uint32_t ccount;
|
||||
__asm__ __volatile__("esync; rsr %0,ccount" : "=a"(ccount));
|
||||
return ccount;
|
||||
uint32_t arch_get_cpu_cycle_count() { return cpu_hal_get_cycle_count(); }
|
||||
#endif
|
||||
}
|
||||
uint32_t arch_get_cpu_freq_hz() { return rtc_clk_apb_freq_get(); }
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
@@ -26,6 +26,8 @@ from .const import (
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32C2,
|
||||
VARIANT_ESP32C6,
|
||||
VARIANT_ESP32H2,
|
||||
esp32_ns,
|
||||
)
|
||||
@@ -35,6 +37,8 @@ from .gpio_esp32 import esp32_validate_gpio_pin, esp32_validate_supports
|
||||
from .gpio_esp32_s2 import esp32_s2_validate_gpio_pin, esp32_s2_validate_supports
|
||||
from .gpio_esp32_c3 import esp32_c3_validate_gpio_pin, esp32_c3_validate_supports
|
||||
from .gpio_esp32_s3 import esp32_s3_validate_gpio_pin, esp32_s3_validate_supports
|
||||
from .gpio_esp32_c2 import esp32_c2_validate_gpio_pin, esp32_c2_validate_supports
|
||||
from .gpio_esp32_c6 import esp32_c6_validate_gpio_pin, esp32_c6_validate_supports
|
||||
from .gpio_esp32_h2 import esp32_h2_validate_gpio_pin, esp32_h2_validate_supports
|
||||
|
||||
|
||||
@@ -95,6 +99,14 @@ _esp32_validations = {
|
||||
pin_validation=esp32_s3_validate_gpio_pin,
|
||||
usage_validation=esp32_s3_validate_supports,
|
||||
),
|
||||
VARIANT_ESP32C2: ESP32ValidationFunctions(
|
||||
pin_validation=esp32_c2_validate_gpio_pin,
|
||||
usage_validation=esp32_c2_validate_supports,
|
||||
),
|
||||
VARIANT_ESP32C6: ESP32ValidationFunctions(
|
||||
pin_validation=esp32_c6_validate_gpio_pin,
|
||||
usage_validation=esp32_c6_validate_supports,
|
||||
),
|
||||
VARIANT_ESP32H2: ESP32ValidationFunctions(
|
||||
pin_validation=esp32_h2_validate_gpio_pin,
|
||||
usage_validation=esp32_h2_validate_supports,
|
||||
|
||||
37
esphome/components/esp32/gpio_esp32_c2.py
Normal file
37
esphome/components/esp32/gpio_esp32_c2.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import logging
|
||||
|
||||
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
||||
|
||||
import esphome.config_validation as cv
|
||||
|
||||
_ESP32C2_STRAPPING_PINS = {8, 9}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def esp32_c2_validate_gpio_pin(value):
|
||||
if value < 0 or value > 20:
|
||||
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-20)")
|
||||
if value in _ESP32C2_STRAPPING_PINS:
|
||||
_LOGGER.warning(
|
||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
||||
value,
|
||||
)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def esp32_c2_validate_supports(value):
|
||||
num = value[CONF_NUMBER]
|
||||
mode = value[CONF_MODE]
|
||||
is_input = mode[CONF_INPUT]
|
||||
|
||||
if num < 0 or num > 20:
|
||||
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-20)")
|
||||
|
||||
if is_input:
|
||||
# All ESP32 pins support input mode
|
||||
pass
|
||||
return value
|
||||
50
esphome/components/esp32/gpio_esp32_c6.py
Normal file
50
esphome/components/esp32/gpio_esp32_c6.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import logging
|
||||
|
||||
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
|
||||
|
||||
import esphome.config_validation as cv
|
||||
|
||||
_ESP32C6_SPI_PSRAM_PINS = {
|
||||
24: "SPICS0",
|
||||
25: "SPIQ",
|
||||
26: "SPIWP",
|
||||
27: "VDD_SPI",
|
||||
28: "SPIHD",
|
||||
29: "SPICLK",
|
||||
30: "SPID",
|
||||
}
|
||||
|
||||
_ESP32C6_STRAPPING_PINS = {8, 9, 15}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def esp32_c6_validate_gpio_pin(value):
|
||||
if value < 0 or value > 23:
|
||||
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-23)")
|
||||
if value in _ESP32C6_SPI_PSRAM_PINS:
|
||||
raise cv.Invalid(
|
||||
f"This pin cannot be used on ESP32-C6s and is already used by the SPI/PSRAM interface (function: {_ESP32C6_SPI_PSRAM_PINS[value]})"
|
||||
)
|
||||
if value in _ESP32C6_STRAPPING_PINS:
|
||||
_LOGGER.warning(
|
||||
"GPIO%d is a Strapping PIN and should be avoided.\n"
|
||||
"Attaching external pullup/down resistors to strapping pins can cause unexpected failures.\n"
|
||||
"See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins",
|
||||
value,
|
||||
)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def esp32_c6_validate_supports(value):
|
||||
num = value[CONF_NUMBER]
|
||||
mode = value[CONF_MODE]
|
||||
is_input = mode[CONF_INPUT]
|
||||
|
||||
if num < 0 or num > 23:
|
||||
raise cv.Invalid(f"Invalid pin number: {value} (must be 0-23)")
|
||||
if is_input:
|
||||
# All ESP32 pins support input mode
|
||||
pass
|
||||
return value
|
||||
@@ -42,9 +42,15 @@ void BLEAdvertising::remove_service_uuid(ESPBTUUID uuid) {
|
||||
this->advertising_uuids_.end());
|
||||
}
|
||||
|
||||
void BLEAdvertising::set_manufacturer_data(uint8_t *data, uint16_t size) {
|
||||
this->advertising_data_.p_manufacturer_data = data;
|
||||
this->advertising_data_.manufacturer_len = size;
|
||||
void BLEAdvertising::set_manufacturer_data(const std::vector<uint8_t> &data) {
|
||||
delete[] this->advertising_data_.p_manufacturer_data;
|
||||
this->advertising_data_.p_manufacturer_data = nullptr;
|
||||
this->advertising_data_.manufacturer_len = data.size();
|
||||
if (!data.empty()) {
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
|
||||
this->advertising_data_.p_manufacturer_data = new uint8_t[data.size()];
|
||||
memcpy(this->advertising_data_.p_manufacturer_data, data.data(), data.size());
|
||||
}
|
||||
}
|
||||
|
||||
void BLEAdvertising::start() {
|
||||
@@ -74,16 +80,21 @@ void BLEAdvertising::start() {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&this->scan_response_data_, &this->advertising_data_, sizeof(esp_ble_adv_data_t));
|
||||
this->scan_response_data_.set_scan_rsp = true;
|
||||
this->scan_response_data_.include_name = true;
|
||||
this->scan_response_data_.include_txpower = true;
|
||||
this->scan_response_data_.appearance = 0;
|
||||
this->scan_response_data_.flag = 0;
|
||||
err = esp_ble_gap_config_adv_data(&this->scan_response_data_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_ble_gap_config_adv_data failed (Scan response): %d", err);
|
||||
return;
|
||||
if (this->scan_response_) {
|
||||
memcpy(&this->scan_response_data_, &this->advertising_data_, sizeof(esp_ble_adv_data_t));
|
||||
this->scan_response_data_.set_scan_rsp = true;
|
||||
this->scan_response_data_.include_name = true;
|
||||
this->scan_response_data_.include_txpower = true;
|
||||
this->scan_response_data_.min_interval = 0;
|
||||
this->scan_response_data_.max_interval = 0;
|
||||
this->scan_response_data_.manufacturer_len = 0;
|
||||
this->scan_response_data_.appearance = 0;
|
||||
this->scan_response_data_.flag = 0;
|
||||
err = esp_ble_gap_config_adv_data(&this->scan_response_data_);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_ble_gap_config_adv_data failed (Scan response): %d", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->advertising_data_.service_uuid_len > 0) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class BLEAdvertising {
|
||||
void remove_service_uuid(ESPBTUUID uuid);
|
||||
void set_scan_response(bool scan_response) { this->scan_response_ = scan_response; }
|
||||
void set_min_preferred_interval(uint16_t interval) { this->advertising_data_.min_interval = interval; }
|
||||
void set_manufacturer_data(uint8_t *data, uint16_t size);
|
||||
void set_manufacturer_data(const std::vector<uint8_t> &data);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
@@ -6,11 +6,12 @@ from esphome.core import CORE
|
||||
from esphome.components.esp32 import add_idf_sdkconfig_option
|
||||
|
||||
AUTO_LOAD = ["esp32_ble"]
|
||||
CODEOWNERS = ["@jesserockz"]
|
||||
CODEOWNERS = ["@jesserockz", "@clydebarrow"]
|
||||
CONFLICTS_WITH = ["esp32_ble_beacon"]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
|
||||
CONF_MANUFACTURER = "manufacturer"
|
||||
CONF_MANUFACTURER_DATA = "manufacturer_data"
|
||||
|
||||
esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server")
|
||||
BLEServer = esp32_ble_server_ns.class_(
|
||||
@@ -27,6 +28,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.GenerateID(): cv.declare_id(BLEServer),
|
||||
cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE),
|
||||
cv.Optional(CONF_MANUFACTURER, default="ESPHome"): cv.string,
|
||||
cv.Optional(CONF_MANUFACTURER_DATA): cv.Schema([cv.hex_uint8_t]),
|
||||
cv.Optional(CONF_MODEL): cv.string,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
@@ -42,6 +44,8 @@ async def to_code(config):
|
||||
cg.add(var.set_parent(parent))
|
||||
|
||||
cg.add(var.set_manufacturer(config[CONF_MANUFACTURER]))
|
||||
if CONF_MANUFACTURER_DATA in config:
|
||||
cg.add(var.set_manufacturer_data(config[CONF_MANUFACTURER_DATA]))
|
||||
if CONF_MODEL in config:
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
cg.add_define("USE_ESP32_BLE_SERVER")
|
||||
|
||||
@@ -68,6 +68,7 @@ void BLEServer::loop() {
|
||||
if (this->device_information_service_->is_running()) {
|
||||
this->state_ = RUNNING;
|
||||
this->can_proceed_ = true;
|
||||
this->restart_advertising_();
|
||||
ESP_LOGD(TAG, "BLE server setup successfully");
|
||||
} else if (!this->device_information_service_->is_starting()) {
|
||||
this->device_information_service_->start();
|
||||
@@ -77,6 +78,13 @@ void BLEServer::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
void BLEServer::restart_advertising_() {
|
||||
if (this->state_ == RUNNING) {
|
||||
esp32_ble::global_ble->get_advertising()->set_manufacturer_data(this->manufacturer_data_);
|
||||
esp32_ble::global_ble->get_advertising()->start();
|
||||
}
|
||||
}
|
||||
|
||||
bool BLEServer::create_device_characteristics_() {
|
||||
if (this->model_.has_value()) {
|
||||
BLECharacteristic *model =
|
||||
|
||||
@@ -45,6 +45,10 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES
|
||||
|
||||
void set_manufacturer(const std::string &manufacturer) { this->manufacturer_ = manufacturer; }
|
||||
void set_model(const std::string &model) { this->model_ = model; }
|
||||
void set_manufacturer_data(const std::vector<uint8_t> &data) {
|
||||
this->manufacturer_data_ = data;
|
||||
this->restart_advertising_();
|
||||
}
|
||||
|
||||
std::shared_ptr<BLEService> create_service(const uint8_t *uuid, bool advertise = false);
|
||||
std::shared_ptr<BLEService> create_service(uint16_t uuid, bool advertise = false);
|
||||
@@ -63,6 +67,7 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES
|
||||
|
||||
protected:
|
||||
bool create_device_characteristics_();
|
||||
void restart_advertising_();
|
||||
|
||||
void add_client_(uint16_t conn_id, void *client) {
|
||||
this->clients_.insert(std::pair<uint16_t, void *>(conn_id, client));
|
||||
@@ -73,6 +78,7 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES
|
||||
|
||||
std::string manufacturer_;
|
||||
optional<std::string> model_;
|
||||
std::vector<uint8_t> manufacturer_data_;
|
||||
esp_gatt_if_t gatts_if_{0};
|
||||
bool registered_{false};
|
||||
|
||||
|
||||
@@ -5,6 +5,15 @@ from esphome.components import canbus
|
||||
from esphome.const import CONF_ID, CONF_RX_PIN, CONF_TX_PIN
|
||||
from esphome.components.canbus import CanbusComponent, CanSpeed, CONF_BIT_RATE
|
||||
|
||||
from esphome.components.esp32 import get_esp32_variant
|
||||
from esphome.components.esp32.const import (
|
||||
VARIANT_ESP32,
|
||||
VARIANT_ESP32S2,
|
||||
VARIANT_ESP32S3,
|
||||
VARIANT_ESP32C3,
|
||||
VARIANT_ESP32H2,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@Sympatron"]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
|
||||
@@ -12,19 +21,57 @@ esp32_can_ns = cg.esphome_ns.namespace("esp32_can")
|
||||
esp32_can = esp32_can_ns.class_("ESP32Can", CanbusComponent)
|
||||
|
||||
# Currently the driver only supports a subset of the bit rates defined in canbus
|
||||
CAN_SPEEDS = {
|
||||
# The supported bit rates differ between ESP32 variants.
|
||||
# See ESP-IDF Programming Guide --> API Reference --> Two-Wire Automotive Interface (TWAI)
|
||||
|
||||
CAN_SPEEDS_ESP32 = {
|
||||
"25KBPS": CanSpeed.CAN_25KBPS,
|
||||
"50KBPS": CanSpeed.CAN_50KBPS,
|
||||
"100KBPS": CanSpeed.CAN_100KBPS,
|
||||
"125KBPS": CanSpeed.CAN_125KBPS,
|
||||
"250KBPS": CanSpeed.CAN_250KBPS,
|
||||
"500KBPS": CanSpeed.CAN_500KBPS,
|
||||
"800KBPS": CanSpeed.CAN_800KBPS,
|
||||
"1000KBPS": CanSpeed.CAN_1000KBPS,
|
||||
}
|
||||
|
||||
CAN_SPEEDS_ESP32_S2 = {
|
||||
"1KBPS": CanSpeed.CAN_1KBPS,
|
||||
"5KBPS": CanSpeed.CAN_5KBPS,
|
||||
"10KBPS": CanSpeed.CAN_10KBPS,
|
||||
"12K5BPS": CanSpeed.CAN_12K5BPS,
|
||||
"16KBPS": CanSpeed.CAN_16KBPS,
|
||||
"20KBPS": CanSpeed.CAN_20KBPS,
|
||||
**CAN_SPEEDS_ESP32,
|
||||
}
|
||||
|
||||
CAN_SPEEDS_ESP32_S3 = {**CAN_SPEEDS_ESP32_S2}
|
||||
CAN_SPEEDS_ESP32_C3 = {**CAN_SPEEDS_ESP32_S2}
|
||||
CAN_SPEEDS_ESP32_H2 = {**CAN_SPEEDS_ESP32_S2}
|
||||
|
||||
CAN_SPEEDS = {
|
||||
VARIANT_ESP32: CAN_SPEEDS_ESP32,
|
||||
VARIANT_ESP32S2: CAN_SPEEDS_ESP32_S2,
|
||||
VARIANT_ESP32S3: CAN_SPEEDS_ESP32_S3,
|
||||
VARIANT_ESP32C3: CAN_SPEEDS_ESP32_C3,
|
||||
VARIANT_ESP32H2: CAN_SPEEDS_ESP32_H2,
|
||||
}
|
||||
|
||||
|
||||
def validate_bit_rate(value):
|
||||
variant = get_esp32_variant()
|
||||
if variant not in CAN_SPEEDS:
|
||||
raise cv.Invalid(f"{variant} is not supported by component {esp32_can_ns}")
|
||||
value = value.upper()
|
||||
if value not in CAN_SPEEDS[variant]:
|
||||
raise cv.Invalid(f"Bit rate {value} is not supported on {variant}")
|
||||
return cv.enum(CAN_SPEEDS[variant])(value)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = canbus.CANBUS_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(esp32_can),
|
||||
cv.Optional(CONF_BIT_RATE, default="125KBPS"): cv.enum(CAN_SPEEDS, upper=True),
|
||||
cv.Optional(CONF_BIT_RATE, default="125KBPS"): validate_bit_rate,
|
||||
cv.Required(CONF_RX_PIN): pins.internal_gpio_input_pin_number,
|
||||
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_number,
|
||||
}
|
||||
|
||||
@@ -16,6 +16,30 @@ static const char *const TAG = "esp32_can";
|
||||
|
||||
static bool get_bitrate(canbus::CanSpeed bitrate, twai_timing_config_t *t_config) {
|
||||
switch (bitrate) {
|
||||
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C3) || \
|
||||
defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H6)
|
||||
case canbus::CAN_1KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_1KBITS();
|
||||
return true;
|
||||
case canbus::CAN_5KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_5KBITS();
|
||||
return true;
|
||||
case canbus::CAN_10KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_10KBITS();
|
||||
return true;
|
||||
case canbus::CAN_12K5BPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_12_5KBITS();
|
||||
return true;
|
||||
case canbus::CAN_16KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_16KBITS();
|
||||
return true;
|
||||
case canbus::CAN_20KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_20KBITS();
|
||||
return true;
|
||||
#endif
|
||||
case canbus::CAN_25KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_25KBITS();
|
||||
return true;
|
||||
case canbus::CAN_50KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_50KBITS();
|
||||
return true;
|
||||
@@ -31,6 +55,9 @@ static bool get_bitrate(canbus::CanSpeed bitrate, twai_timing_config_t *t_config
|
||||
case canbus::CAN_500KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_500KBITS();
|
||||
return true;
|
||||
case canbus::CAN_800KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_800KBITS();
|
||||
return true;
|
||||
case canbus::CAN_1000KBPS:
|
||||
*t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_1MBITS();
|
||||
return true;
|
||||
|
||||
@@ -63,6 +63,7 @@ RMT_CHANNELS = {
|
||||
esp32.const.VARIANT_ESP32S2: [0, 1, 2, 3],
|
||||
esp32.const.VARIANT_ESP32S3: [0, 1, 2, 3],
|
||||
esp32.const.VARIANT_ESP32C3: [0, 1],
|
||||
esp32.const.VARIANT_ESP32C6: [0, 1],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,11 +8,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include <driver/touch_sensor.h>
|
||||
#else
|
||||
#include <driver/touch_pad.h>
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace esp32_touch {
|
||||
|
||||
@@ -50,6 +50,17 @@ def set_core_data(config):
|
||||
return config
|
||||
|
||||
|
||||
def get_download_types(storage_json):
|
||||
return [
|
||||
{
|
||||
"title": "Standard format",
|
||||
"description": "For flashing ESP8266.",
|
||||
"file": "firmware.bin",
|
||||
"download": f"{storage_json.name}.bin",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _format_framework_arduino_version(ver: cv.Version) -> str:
|
||||
# format the given arduino (https://github.com/esp8266/Arduino/releases) version to
|
||||
# a PIO platformio/framework-arduinoespressif8266 value
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from esphome.const import (
|
||||
CONF_ANALOG,
|
||||
CONF_ID,
|
||||
CONF_INPUT,
|
||||
CONF_INVERTED,
|
||||
@@ -140,7 +141,6 @@ def validate_supports(value):
|
||||
return value
|
||||
|
||||
|
||||
CONF_ANALOG = "analog"
|
||||
ESP8266_PIN_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ESP8266GPIOPin),
|
||||
|
||||
@@ -118,10 +118,10 @@ void EthernetComponent::setup() {
|
||||
ESPHL_ERROR_CHECK(err, "ETH event handler register error");
|
||||
err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetComponent::got_ip_event_handler, nullptr);
|
||||
ESPHL_ERROR_CHECK(err, "GOT IP event handler register error");
|
||||
#if LWIP_IPV6
|
||||
#if ENABLE_IPV6
|
||||
err = esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EthernetComponent::got_ip6_event_handler, nullptr);
|
||||
ESPHL_ERROR_CHECK(err, "GOT IP6 event handler register error");
|
||||
#endif /* LWIP_IPV6 */
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
/* start Ethernet driver state machine */
|
||||
err = esp_eth_start(this->eth_handle_);
|
||||
@@ -164,7 +164,7 @@ void EthernetComponent::loop() {
|
||||
this->state_ = EthernetComponentState::CONNECTING;
|
||||
this->start_connect_();
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
#if ENABLE_IPV6
|
||||
else if (this->got_ipv6_) {
|
||||
esp_ip6_addr_t ip6_addr;
|
||||
if (esp_netif_get_ip6_global(this->eth_netif_, &ip6_addr) == 0 &&
|
||||
@@ -177,7 +177,7 @@ void EthernetComponent::loop() {
|
||||
|
||||
this->got_ipv6_ = false;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
#endif /* ENABLE_IPV6 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -272,14 +272,14 @@ void EthernetComponent::got_ip_event_handler(void *arg, esp_event_base_t event_b
|
||||
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP (num=%" PRId32 ")", event_id);
|
||||
}
|
||||
|
||||
#if LWIP_IPV6
|
||||
#if ENABLE_IPV6
|
||||
void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
|
||||
void *event_data) {
|
||||
ESP_LOGV(TAG, "[Ethernet event] ETH Got IP6 (num=%d)", event_id);
|
||||
global_eth_component->got_ipv6_ = true;
|
||||
global_eth_component->ipv6_count_ += 1;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
void EthernetComponent::start_connect_() {
|
||||
this->connect_begin_ = millis();
|
||||
@@ -343,12 +343,12 @@ void EthernetComponent::start_connect_() {
|
||||
if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
|
||||
ESPHL_ERROR_CHECK(err, "DHCPC start error");
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
#if ENABLE_IPV6
|
||||
err = esp_netif_create_ip6_linklocal(this->eth_netif_);
|
||||
if (err != ESP_OK) {
|
||||
ESPHL_ERROR_CHECK(err, "IPv6 local failed");
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
#endif /* ENABLE_IPV6 */
|
||||
}
|
||||
|
||||
this->connect_begin_ = millis();
|
||||
@@ -376,7 +376,7 @@ void EthernetComponent::dump_connect_params_() {
|
||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->addr).str().c_str());
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV6
|
||||
#if ENABLE_IPV6
|
||||
if (this->ipv6_count_ > 0) {
|
||||
esp_ip6_addr_t ip6_addr;
|
||||
esp_netif_get_ip6_linklocal(this->eth_netif_, &ip6_addr);
|
||||
@@ -387,7 +387,7 @@ void EthernetComponent::dump_connect_params_() {
|
||||
ESP_LOGCONFIG(TAG, "IPv6 Addr (Global): " IPV6STR, IPV62STR(ip6_addr));
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
esp_err_t err;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/components/network/ip_address.h"
|
||||
|
||||
|
||||
@@ -98,10 +98,9 @@ def validate_truetype_file(value):
|
||||
|
||||
|
||||
def _compute_local_font_dir(name) -> Path:
|
||||
base_dir = Path(CORE.config_dir) / ".esphome" / DOMAIN
|
||||
h = hashlib.new("sha256")
|
||||
h.update(name.encode())
|
||||
return base_dir / h.hexdigest()[:8]
|
||||
return Path(CORE.data_dir) / DOMAIN / h.hexdigest()[:8]
|
||||
|
||||
|
||||
def _compute_gfonts_local_path(value) -> Path:
|
||||
|
||||
@@ -15,8 +15,14 @@ CODEOWNERS = ["@esphome/core"]
|
||||
globals_ns = cg.esphome_ns.namespace("globals")
|
||||
GlobalsComponent = globals_ns.class_("GlobalsComponent", cg.Component)
|
||||
RestoringGlobalsComponent = globals_ns.class_("RestoringGlobalsComponent", cg.Component)
|
||||
RestoringGlobalStringComponent = globals_ns.class_(
|
||||
"RestoringGlobalStringComponent", cg.Component
|
||||
)
|
||||
GlobalVarSetAction = globals_ns.class_("GlobalVarSetAction", automation.Action)
|
||||
|
||||
CONF_MAX_RESTORE_DATA_LENGTH = "max_restore_data_length"
|
||||
|
||||
|
||||
MULTI_CONF = True
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
@@ -24,6 +30,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.Required(CONF_TYPE): cv.string_strict,
|
||||
cv.Optional(CONF_INITIAL_VALUE): cv.string_strict,
|
||||
cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean,
|
||||
cv.Optional(CONF_MAX_RESTORE_DATA_LENGTH): cv.int_range(0, 254),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
@@ -32,12 +39,19 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
@coroutine_with_priority(-100.0)
|
||||
async def to_code(config):
|
||||
type_ = cg.RawExpression(config[CONF_TYPE])
|
||||
template_args = cg.TemplateArguments(type_)
|
||||
restore = config[CONF_RESTORE_VALUE]
|
||||
|
||||
type = RestoringGlobalsComponent if restore else GlobalsComponent
|
||||
res_type = type.template(template_args)
|
||||
# Special casing the strings to their own class with a different save/restore mechanism
|
||||
if str(type_) == "std::string" and restore:
|
||||
template_args = cg.TemplateArguments(
|
||||
type_, config.get(CONF_MAX_RESTORE_DATA_LENGTH, 63) + 1
|
||||
)
|
||||
type = RestoringGlobalStringComponent
|
||||
else:
|
||||
template_args = cg.TemplateArguments(type_)
|
||||
type = RestoringGlobalsComponent if restore else GlobalsComponent
|
||||
|
||||
res_type = type.template(template_args)
|
||||
initial_value = None
|
||||
if CONF_INITIAL_VALUE in config:
|
||||
initial_value = cg.RawExpression(config[CONF_INITIAL_VALUE])
|
||||
|
||||
@@ -65,6 +65,64 @@ template<typename T> class RestoringGlobalsComponent : public Component {
|
||||
ESPPreferenceObject rtc_;
|
||||
};
|
||||
|
||||
// Use with string or subclasses of strings
|
||||
template<typename T, uint8_t SZ> class RestoringGlobalStringComponent : public Component {
|
||||
public:
|
||||
using value_type = T;
|
||||
explicit RestoringGlobalStringComponent() = default;
|
||||
explicit RestoringGlobalStringComponent(T initial_value) { this->value_ = initial_value; }
|
||||
explicit RestoringGlobalStringComponent(
|
||||
std::array<typename std::remove_extent<T>::type, std::extent<T>::value> initial_value) {
|
||||
memcpy(this->value_, initial_value.data(), sizeof(T));
|
||||
}
|
||||
|
||||
T &value() { return this->value_; }
|
||||
|
||||
void setup() override {
|
||||
char temp[SZ];
|
||||
this->rtc_ = global_preferences->make_preference<uint8_t[SZ]>(1944399030U ^ this->name_hash_);
|
||||
bool hasdata = this->rtc_.load(&temp);
|
||||
if (hasdata) {
|
||||
this->value_.assign(temp + 1, temp[0]);
|
||||
}
|
||||
this->prev_value_.assign(this->value_);
|
||||
}
|
||||
|
||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||
|
||||
void loop() override { store_value_(); }
|
||||
|
||||
void on_shutdown() override { store_value_(); }
|
||||
|
||||
void set_name_hash(uint32_t name_hash) { this->name_hash_ = name_hash; }
|
||||
|
||||
protected:
|
||||
void store_value_() {
|
||||
int diff = this->value_.compare(this->prev_value_);
|
||||
if (diff != 0) {
|
||||
// Make it into a length prefixed thing
|
||||
unsigned char temp[SZ];
|
||||
|
||||
// If string is bigger than the allocation, do not save it.
|
||||
// We don't need to waste ram setting prev_value either.
|
||||
int size = this->value_.size();
|
||||
// Less than, not less than or equal, SZ includes the length byte.
|
||||
if (size < SZ) {
|
||||
memcpy(temp + 1, this->value_.c_str(), size);
|
||||
// SZ should be pre checked at the schema level, it can't go past the char range.
|
||||
temp[0] = ((unsigned char) size);
|
||||
this->rtc_.save(&temp);
|
||||
this->prev_value_.assign(this->value_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T value_{};
|
||||
T prev_value_{};
|
||||
uint32_t name_hash_{};
|
||||
ESPPreferenceObject rtc_;
|
||||
};
|
||||
|
||||
template<class C, typename... Ts> class GlobalVarSetAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit GlobalVarSetAction(C *parent) : parent_(parent) {}
|
||||
@@ -81,6 +139,7 @@ template<class C, typename... Ts> class GlobalVarSetAction : public Action<Ts...
|
||||
|
||||
template<typename T> T &id(GlobalsComponent<T> *value) { return value->value(); }
|
||||
template<typename T> T &id(RestoringGlobalsComponent<T> *value) { return value->value(); }
|
||||
template<typename T, uint8_t SZ> T &id(RestoringGlobalStringComponent<T, SZ> *value) { return value->value(); }
|
||||
|
||||
} // namespace globals
|
||||
} // namespace esphome
|
||||
|
||||
@@ -6,6 +6,9 @@ from esphome.const import (
|
||||
CONF_CURRENT,
|
||||
CONF_FREQUENCY,
|
||||
CONF_ID,
|
||||
CONF_PHASE_A,
|
||||
CONF_PHASE_B,
|
||||
CONF_PHASE_C,
|
||||
CONF_VOLTAGE,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
@@ -21,10 +24,6 @@ from esphome.const import (
|
||||
UNIT_WATT,
|
||||
)
|
||||
|
||||
CONF_PHASE_A = "phase_a"
|
||||
CONF_PHASE_B = "phase_b"
|
||||
CONF_PHASE_C = "phase_c"
|
||||
|
||||
CONF_ENERGY_PRODUCTION_DAY = "energy_production_day"
|
||||
CONF_TOTAL_ENERGY_PRODUCTION = "total_energy_production"
|
||||
CONF_TOTAL_GENERATION_TIME = "total_generation_time"
|
||||
|
||||
@@ -14,7 +14,10 @@ from esphome.const import (
|
||||
CONF_MIN_TEMPERATURE,
|
||||
CONF_PROTOCOL,
|
||||
CONF_SUPPORTED_MODES,
|
||||
CONF_SUPPORTED_PRESETS,
|
||||
CONF_SUPPORTED_SWING_MODES,
|
||||
CONF_TARGET_TEMPERATURE,
|
||||
CONF_TEMPERATURE_STEP,
|
||||
CONF_VISUAL,
|
||||
CONF_WIFI,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
@@ -23,25 +26,29 @@ from esphome.const import (
|
||||
UNIT_CELSIUS,
|
||||
)
|
||||
from esphome.components.climate import (
|
||||
ClimateSwingMode,
|
||||
ClimateMode,
|
||||
ClimatePreset,
|
||||
ClimateSwingMode,
|
||||
CONF_CURRENT_TEMPERATURE,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PROTOCOL_MIN_TEMPERATURE = 16.0
|
||||
PROTOCOL_MAX_TEMPERATURE = 30.0
|
||||
PROTOCOL_TEMPERATURE_STEP = 1.0
|
||||
PROTOCOL_TARGET_TEMPERATURE_STEP = 1.0
|
||||
PROTOCOL_CURRENT_TEMPERATURE_STEP = 0.5
|
||||
|
||||
CODEOWNERS = ["@paveldn"]
|
||||
AUTO_LOAD = ["sensor"]
|
||||
DEPENDENCIES = ["climate", "uart"]
|
||||
CONF_WIFI_SIGNAL = "wifi_signal"
|
||||
CONF_ANSWER_TIMEOUT = "answer_timeout"
|
||||
CONF_DISPLAY = "display"
|
||||
CONF_OUTDOOR_TEMPERATURE = "outdoor_temperature"
|
||||
CONF_VERTICAL_AIRFLOW = "vertical_airflow"
|
||||
CONF_HORIZONTAL_AIRFLOW = "horizontal_airflow"
|
||||
|
||||
|
||||
PROTOCOL_HON = "HON"
|
||||
PROTOCOL_SMARTAIR2 = "SMARTAIR2"
|
||||
PROTOCOLS_SUPPORTED = [PROTOCOL_HON, PROTOCOL_SMARTAIR2]
|
||||
@@ -82,13 +89,24 @@ SUPPORTED_SWING_MODES_OPTIONS = {
|
||||
|
||||
SUPPORTED_CLIMATE_MODES_OPTIONS = {
|
||||
"OFF": ClimateMode.CLIMATE_MODE_OFF, # always available
|
||||
"AUTO": ClimateMode.CLIMATE_MODE_AUTO, # always available
|
||||
"HEAT_COOL": ClimateMode.CLIMATE_MODE_HEAT_COOL, # always available
|
||||
"COOL": ClimateMode.CLIMATE_MODE_COOL,
|
||||
"HEAT": ClimateMode.CLIMATE_MODE_HEAT,
|
||||
"DRY": ClimateMode.CLIMATE_MODE_DRY,
|
||||
"FAN_ONLY": ClimateMode.CLIMATE_MODE_FAN_ONLY,
|
||||
}
|
||||
|
||||
SUPPORTED_CLIMATE_PRESETS_SMARTAIR2_OPTIONS = {
|
||||
"BOOST": ClimatePreset.CLIMATE_PRESET_BOOST,
|
||||
"COMFORT": ClimatePreset.CLIMATE_PRESET_COMFORT,
|
||||
}
|
||||
|
||||
SUPPORTED_CLIMATE_PRESETS_HON_OPTIONS = {
|
||||
"ECO": ClimatePreset.CLIMATE_PRESET_ECO,
|
||||
"BOOST": ClimatePreset.CLIMATE_PRESET_BOOST,
|
||||
"SLEEP": ClimatePreset.CLIMATE_PRESET_SLEEP,
|
||||
}
|
||||
|
||||
|
||||
def validate_visual(config):
|
||||
if CONF_VISUAL in config:
|
||||
@@ -109,10 +127,27 @@ def validate_visual(config):
|
||||
)
|
||||
else:
|
||||
config[CONF_VISUAL][CONF_MAX_TEMPERATURE] = PROTOCOL_MAX_TEMPERATURE
|
||||
if CONF_TEMPERATURE_STEP in visual_config:
|
||||
temp_step = config[CONF_VISUAL][CONF_TEMPERATURE_STEP][
|
||||
CONF_TARGET_TEMPERATURE
|
||||
]
|
||||
if ((int)(temp_step * 2)) / 2 != temp_step:
|
||||
raise cv.Invalid(
|
||||
f"Configured visual temperature step {temp_step} is wrong, it should be a multiple of 0.5"
|
||||
)
|
||||
else:
|
||||
config[CONF_VISUAL][CONF_TEMPERATURE_STEP] = {
|
||||
CONF_TARGET_TEMPERATURE: PROTOCOL_TARGET_TEMPERATURE_STEP,
|
||||
CONF_CURRENT_TEMPERATURE: PROTOCOL_CURRENT_TEMPERATURE_STEP,
|
||||
}
|
||||
else:
|
||||
config[CONF_VISUAL] = {
|
||||
CONF_MIN_TEMPERATURE: PROTOCOL_MIN_TEMPERATURE,
|
||||
CONF_MAX_TEMPERATURE: PROTOCOL_MAX_TEMPERATURE,
|
||||
CONF_TEMPERATURE_STEP: {
|
||||
CONF_TARGET_TEMPERATURE: PROTOCOL_TARGET_TEMPERATURE_STEP,
|
||||
CONF_CURRENT_TEMPERATURE: PROTOCOL_CURRENT_TEMPERATURE_STEP,
|
||||
},
|
||||
}
|
||||
return config
|
||||
|
||||
@@ -132,6 +167,11 @@ BASE_CONFIG_SCHEMA = (
|
||||
"BOTH",
|
||||
],
|
||||
): cv.ensure_list(cv.enum(SUPPORTED_SWING_MODES_OPTIONS, upper=True)),
|
||||
cv.Optional(CONF_WIFI_SIGNAL, default=False): cv.boolean,
|
||||
cv.Optional(CONF_DISPLAY): cv.boolean,
|
||||
cv.Optional(
|
||||
CONF_ANSWER_TIMEOUT,
|
||||
): cv.positive_time_period_milliseconds,
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
@@ -144,13 +184,26 @@ CONFIG_SCHEMA = cv.All(
|
||||
PROTOCOL_SMARTAIR2: BASE_CONFIG_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(Smartair2Climate),
|
||||
cv.Optional(
|
||||
CONF_SUPPORTED_PRESETS,
|
||||
default=list(
|
||||
SUPPORTED_CLIMATE_PRESETS_SMARTAIR2_OPTIONS.keys()
|
||||
),
|
||||
): cv.ensure_list(
|
||||
cv.enum(SUPPORTED_CLIMATE_PRESETS_SMARTAIR2_OPTIONS, upper=True)
|
||||
),
|
||||
}
|
||||
),
|
||||
PROTOCOL_HON: BASE_CONFIG_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(HonClimate),
|
||||
cv.Optional(CONF_WIFI_SIGNAL, default=True): cv.boolean,
|
||||
cv.Optional(CONF_BEEPER, default=True): cv.boolean,
|
||||
cv.Optional(
|
||||
CONF_SUPPORTED_PRESETS,
|
||||
default=list(SUPPORTED_CLIMATE_PRESETS_HON_OPTIONS.keys()),
|
||||
): cv.ensure_list(
|
||||
cv.enum(SUPPORTED_CLIMATE_PRESETS_HON_OPTIONS, upper=True)
|
||||
),
|
||||
cv.Optional(CONF_OUTDOOR_TEMPERATURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
icon=ICON_THERMOMETER,
|
||||
@@ -354,10 +407,11 @@ async def to_code(config):
|
||||
await uart.register_uart_device(var, config)
|
||||
await climate.register_climate(var, config)
|
||||
|
||||
if (CONF_WIFI_SIGNAL in config) and (config[CONF_WIFI_SIGNAL]):
|
||||
cg.add(var.set_send_wifi(config[CONF_WIFI_SIGNAL]))
|
||||
cg.add(var.set_send_wifi(config[CONF_WIFI_SIGNAL]))
|
||||
if CONF_BEEPER in config:
|
||||
cg.add(var.set_beeper_state(config[CONF_BEEPER]))
|
||||
if CONF_DISPLAY in config:
|
||||
cg.add(var.set_display_state(config[CONF_DISPLAY]))
|
||||
if CONF_OUTDOOR_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_OUTDOOR_TEMPERATURE])
|
||||
cg.add(var.set_outdoor_temperature_sensor(sens))
|
||||
@@ -365,5 +419,9 @@ async def to_code(config):
|
||||
cg.add(var.set_supported_modes(config[CONF_SUPPORTED_MODES]))
|
||||
if CONF_SUPPORTED_SWING_MODES in config:
|
||||
cg.add(var.set_supported_swing_modes(config[CONF_SUPPORTED_SWING_MODES]))
|
||||
if CONF_SUPPORTED_PRESETS in config:
|
||||
cg.add(var.set_supported_presets(config[CONF_SUPPORTED_PRESETS]))
|
||||
if CONF_ANSWER_TIMEOUT in config:
|
||||
cg.add(var.set_answer_timeout(config[CONF_ANSWER_TIMEOUT]))
|
||||
# https://github.com/paveldn/HaierProtocol
|
||||
cg.add_library("pavlodn/HaierProtocol", "0.9.18")
|
||||
cg.add_library("pavlodn/HaierProtocol", "0.9.20")
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#include <string>
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#ifdef USE_WIFI
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
#endif
|
||||
#include "haier_base.h"
|
||||
|
||||
using namespace esphome::climate;
|
||||
@@ -24,14 +27,15 @@ constexpr size_t NO_COMMAND = 0xFF; // Indicate that there is no command suppli
|
||||
const char *HaierClimateBase::phase_to_string_(ProtocolPhases phase) {
|
||||
static const char *phase_names[] = {
|
||||
"SENDING_INIT_1",
|
||||
"WAITING_ANSWER_INIT_1",
|
||||
"WAITING_INIT_1_ANSWER",
|
||||
"SENDING_INIT_2",
|
||||
"WAITING_ANSWER_INIT_2",
|
||||
"WAITING_INIT_2_ANSWER",
|
||||
"SENDING_FIRST_STATUS_REQUEST",
|
||||
"WAITING_FIRST_STATUS_ANSWER",
|
||||
"SENDING_ALARM_STATUS_REQUEST",
|
||||
"WAITING_ALARM_STATUS_ANSWER",
|
||||
"IDLE",
|
||||
"UNKNOWN",
|
||||
"SENDING_STATUS_REQUEST",
|
||||
"WAITING_STATUS_ANSWER",
|
||||
"SENDING_UPDATE_SIGNAL_REQUEST",
|
||||
@@ -63,11 +67,12 @@ HaierClimateBase::HaierClimateBase()
|
||||
forced_publish_(false),
|
||||
forced_request_status_(false),
|
||||
first_control_attempt_(false),
|
||||
reset_protocol_request_(false) {
|
||||
reset_protocol_request_(false),
|
||||
send_wifi_signal_(true) {
|
||||
this->traits_ = climate::ClimateTraits();
|
||||
this->traits_.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL, climate::CLIMATE_MODE_HEAT,
|
||||
climate::CLIMATE_MODE_FAN_ONLY, climate::CLIMATE_MODE_DRY,
|
||||
climate::CLIMATE_MODE_AUTO});
|
||||
climate::CLIMATE_MODE_HEAT_COOL});
|
||||
this->traits_.set_supported_fan_modes(
|
||||
{climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH});
|
||||
this->traits_.set_supported_swing_modes({climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH,
|
||||
@@ -77,7 +82,7 @@ HaierClimateBase::HaierClimateBase()
|
||||
|
||||
HaierClimateBase::~HaierClimateBase() {}
|
||||
|
||||
void HaierClimateBase::set_phase_(ProtocolPhases phase) {
|
||||
void HaierClimateBase::set_phase(ProtocolPhases phase) {
|
||||
if (this->protocol_phase_ != phase) {
|
||||
#if (HAIER_LOG_LEVEL > 4)
|
||||
ESP_LOGV(TAG, "Phase transition: %s => %s", phase_to_string_(this->protocol_phase_), phase_to_string_(phase));
|
||||
@@ -109,10 +114,27 @@ bool HaierClimateBase::is_control_message_interval_exceeded_(std::chrono::steady
|
||||
return this->check_timeout_(now, this->last_request_timestamp_, CONTROL_MESSAGES_INTERVAL_MS);
|
||||
}
|
||||
|
||||
bool HaierClimateBase::is_protocol_initialisation_interval_exceded_(std::chrono::steady_clock::time_point now) {
|
||||
bool HaierClimateBase::is_protocol_initialisation_interval_exceeded_(std::chrono::steady_clock::time_point now) {
|
||||
return this->check_timeout_(now, this->last_request_timestamp_, PROTOCOL_INITIALIZATION_INTERVAL);
|
||||
}
|
||||
|
||||
#ifdef USE_WIFI
|
||||
haier_protocol::HaierMessage HaierClimateBase::get_wifi_signal_message_(uint8_t message_type) {
|
||||
static uint8_t wifi_status_data[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (wifi::global_wifi_component->is_connected()) {
|
||||
wifi_status_data[1] = 0;
|
||||
int8_t rssi = wifi::global_wifi_component->wifi_rssi();
|
||||
wifi_status_data[3] = uint8_t((128 + rssi) / 1.28f);
|
||||
ESP_LOGD(TAG, "WiFi signal is: %ddBm => %d%%", rssi, wifi_status_data[3]);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "WiFi is not connected");
|
||||
wifi_status_data[1] = 1;
|
||||
wifi_status_data[3] = 0;
|
||||
}
|
||||
return haier_protocol::HaierMessage(message_type, wifi_status_data, sizeof(wifi_status_data));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool HaierClimateBase::get_display_state() const { return this->display_status_; }
|
||||
|
||||
void HaierClimateBase::set_display_state(bool state) {
|
||||
@@ -136,18 +158,31 @@ void HaierClimateBase::send_power_on_command() { this->action_request_ = ActionR
|
||||
void HaierClimateBase::send_power_off_command() { this->action_request_ = ActionRequest::TURN_POWER_OFF; }
|
||||
|
||||
void HaierClimateBase::toggle_power() { this->action_request_ = ActionRequest::TOGGLE_POWER; }
|
||||
|
||||
void HaierClimateBase::set_supported_swing_modes(const std::set<climate::ClimateSwingMode> &modes) {
|
||||
this->traits_.set_supported_swing_modes(modes);
|
||||
this->traits_.add_supported_swing_mode(climate::CLIMATE_SWING_OFF); // Always available
|
||||
this->traits_.add_supported_swing_mode(climate::CLIMATE_SWING_VERTICAL); // Always available
|
||||
if (!modes.empty())
|
||||
this->traits_.add_supported_swing_mode(climate::CLIMATE_SWING_OFF);
|
||||
}
|
||||
|
||||
void HaierClimateBase::set_answer_timeout(uint32_t timeout) {
|
||||
this->answer_timeout_ = std::chrono::milliseconds(timeout);
|
||||
}
|
||||
|
||||
void HaierClimateBase::set_supported_modes(const std::set<climate::ClimateMode> &modes) {
|
||||
this->traits_.set_supported_modes(modes);
|
||||
this->traits_.add_supported_mode(climate::CLIMATE_MODE_OFF); // Always available
|
||||
this->traits_.add_supported_mode(climate::CLIMATE_MODE_AUTO); // Always available
|
||||
this->traits_.add_supported_mode(climate::CLIMATE_MODE_OFF); // Always available
|
||||
this->traits_.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL); // Always available
|
||||
}
|
||||
|
||||
void HaierClimateBase::set_supported_presets(const std::set<climate::ClimatePreset> &presets) {
|
||||
this->traits_.set_supported_presets(presets);
|
||||
if (!presets.empty())
|
||||
this->traits_.add_supported_preset(climate::CLIMATE_PRESET_NONE);
|
||||
}
|
||||
|
||||
void HaierClimateBase::set_send_wifi(bool send_wifi) { this->send_wifi_signal_ = send_wifi; }
|
||||
|
||||
haier_protocol::HandlerError HaierClimateBase::answer_preprocess_(uint8_t request_message_type,
|
||||
uint8_t expected_request_message_type,
|
||||
uint8_t answer_message_type,
|
||||
@@ -155,9 +190,9 @@ haier_protocol::HandlerError HaierClimateBase::answer_preprocess_(uint8_t reques
|
||||
ProtocolPhases expected_phase) {
|
||||
haier_protocol::HandlerError result = haier_protocol::HandlerError::HANDLER_OK;
|
||||
if ((expected_request_message_type != NO_COMMAND) && (request_message_type != expected_request_message_type))
|
||||
result = haier_protocol::HandlerError::UNSUPORTED_MESSAGE;
|
||||
result = haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
|
||||
if ((expected_answer_message_type != NO_COMMAND) && (answer_message_type != expected_answer_message_type))
|
||||
result = haier_protocol::HandlerError::UNSUPORTED_MESSAGE;
|
||||
result = haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
|
||||
if ((expected_phase != ProtocolPhases::UNKNOWN) && (expected_phase != this->protocol_phase_))
|
||||
result = haier_protocol::HandlerError::UNEXPECTED_MESSAGE;
|
||||
if (is_message_invalid(answer_message_type))
|
||||
@@ -172,9 +207,9 @@ haier_protocol::HandlerError HaierClimateBase::timeout_default_handler_(uint8_t
|
||||
ESP_LOGW(TAG, "Answer timeout for command %02X, phase %d", request_type, (int) this->protocol_phase_);
|
||||
#endif
|
||||
if (this->protocol_phase_ > ProtocolPhases::IDLE) {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else {
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
}
|
||||
return haier_protocol::HandlerError::HANDLER_OK;
|
||||
}
|
||||
@@ -183,8 +218,8 @@ void HaierClimateBase::setup() {
|
||||
ESP_LOGI(TAG, "Haier initialization...");
|
||||
// Set timestamp here to give AC time to boot
|
||||
this->last_request_timestamp_ = std::chrono::steady_clock::now();
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_answers_handlers();
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_handlers();
|
||||
this->haier_protocol_.set_default_timeout_handler(
|
||||
std::bind(&esphome::haier::HaierClimateBase::timeout_default_handler_, this, std::placeholders::_1));
|
||||
}
|
||||
@@ -212,7 +247,7 @@ void HaierClimateBase::loop() {
|
||||
this->set_force_send_control_(false);
|
||||
if (this->hvac_settings_.valid)
|
||||
this->hvac_settings_.reset();
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
return;
|
||||
} else {
|
||||
// No need to reset protocol if we didn't pass initialization phase
|
||||
@@ -229,7 +264,7 @@ void HaierClimateBase::loop() {
|
||||
this->process_pending_action();
|
||||
} else if (this->hvac_settings_.valid || this->force_send_control_) {
|
||||
ESP_LOGV(TAG, "Control packet is pending...");
|
||||
this->set_phase_(ProtocolPhases::SENDING_CONTROL);
|
||||
this->set_phase(ProtocolPhases::SENDING_CONTROL);
|
||||
}
|
||||
}
|
||||
this->process_phase(now);
|
||||
@@ -243,10 +278,10 @@ void HaierClimateBase::process_pending_action() {
|
||||
}
|
||||
switch (request) {
|
||||
case ActionRequest::TURN_POWER_ON:
|
||||
this->set_phase_(ProtocolPhases::SENDING_POWER_ON_COMMAND);
|
||||
this->set_phase(ProtocolPhases::SENDING_POWER_ON_COMMAND);
|
||||
break;
|
||||
case ActionRequest::TURN_POWER_OFF:
|
||||
this->set_phase_(ProtocolPhases::SENDING_POWER_OFF_COMMAND);
|
||||
this->set_phase(ProtocolPhases::SENDING_POWER_OFF_COMMAND);
|
||||
break;
|
||||
case ActionRequest::TOGGLE_POWER:
|
||||
case ActionRequest::NO_ACTION:
|
||||
@@ -303,7 +338,11 @@ void HaierClimateBase::set_force_send_control_(bool status) {
|
||||
}
|
||||
|
||||
void HaierClimateBase::send_message_(const haier_protocol::HaierMessage &command, bool use_crc) {
|
||||
this->haier_protocol_.send_message(command, use_crc);
|
||||
if (this->answer_timeout_.has_value()) {
|
||||
this->haier_protocol_.send_message(command, use_crc, this->answer_timeout_.value());
|
||||
} else {
|
||||
this->haier_protocol_.send_message(command, use_crc);
|
||||
}
|
||||
this->last_request_timestamp_ = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ class HaierClimateBase : public esphome::Component,
|
||||
void reset_protocol() { this->reset_protocol_request_ = true; };
|
||||
void set_supported_modes(const std::set<esphome::climate::ClimateMode> &modes);
|
||||
void set_supported_swing_modes(const std::set<esphome::climate::ClimateSwingMode> &modes);
|
||||
void set_supported_presets(const std::set<esphome::climate::ClimatePreset> &presets);
|
||||
size_t available() noexcept override { return esphome::uart::UARTDevice::available(); };
|
||||
size_t read_array(uint8_t *data, size_t len) noexcept override {
|
||||
return esphome::uart::UARTDevice::read_array(data, len) ? len : 0;
|
||||
@@ -52,39 +53,41 @@ class HaierClimateBase : public esphome::Component,
|
||||
esphome::uart::UARTDevice::write_array(data, len);
|
||||
};
|
||||
bool can_send_message() const { return haier_protocol_.get_outgoing_queue_size() == 0; };
|
||||
void set_answer_timeout(uint32_t timeout);
|
||||
void set_send_wifi(bool send_wifi);
|
||||
|
||||
protected:
|
||||
enum class ProtocolPhases {
|
||||
UNKNOWN = -1,
|
||||
// INITIALIZATION
|
||||
SENDING_INIT_1 = 0,
|
||||
WAITING_ANSWER_INIT_1 = 1,
|
||||
WAITING_INIT_1_ANSWER = 1,
|
||||
SENDING_INIT_2 = 2,
|
||||
WAITING_ANSWER_INIT_2 = 3,
|
||||
WAITING_INIT_2_ANSWER = 3,
|
||||
SENDING_FIRST_STATUS_REQUEST = 4,
|
||||
WAITING_FIRST_STATUS_ANSWER = 5,
|
||||
SENDING_ALARM_STATUS_REQUEST = 6,
|
||||
WAITING_ALARM_STATUS_ANSWER = 7,
|
||||
// FUNCTIONAL STATE
|
||||
IDLE = 8,
|
||||
SENDING_STATUS_REQUEST = 9,
|
||||
WAITING_STATUS_ANSWER = 10,
|
||||
SENDING_UPDATE_SIGNAL_REQUEST = 11,
|
||||
WAITING_UPDATE_SIGNAL_ANSWER = 12,
|
||||
SENDING_SIGNAL_LEVEL = 13,
|
||||
WAITING_SIGNAL_LEVEL_ANSWER = 14,
|
||||
SENDING_CONTROL = 15,
|
||||
WAITING_CONTROL_ANSWER = 16,
|
||||
SENDING_POWER_ON_COMMAND = 17,
|
||||
WAITING_POWER_ON_ANSWER = 18,
|
||||
SENDING_POWER_OFF_COMMAND = 19,
|
||||
WAITING_POWER_OFF_ANSWER = 20,
|
||||
SENDING_STATUS_REQUEST = 10,
|
||||
WAITING_STATUS_ANSWER = 11,
|
||||
SENDING_UPDATE_SIGNAL_REQUEST = 12,
|
||||
WAITING_UPDATE_SIGNAL_ANSWER = 13,
|
||||
SENDING_SIGNAL_LEVEL = 14,
|
||||
WAITING_SIGNAL_LEVEL_ANSWER = 15,
|
||||
SENDING_CONTROL = 16,
|
||||
WAITING_CONTROL_ANSWER = 17,
|
||||
SENDING_POWER_ON_COMMAND = 18,
|
||||
WAITING_POWER_ON_ANSWER = 19,
|
||||
SENDING_POWER_OFF_COMMAND = 20,
|
||||
WAITING_POWER_OFF_ANSWER = 21,
|
||||
NUM_PROTOCOL_PHASES
|
||||
};
|
||||
#if (HAIER_LOG_LEVEL > 4)
|
||||
const char *phase_to_string_(ProtocolPhases phase);
|
||||
#endif
|
||||
virtual void set_answers_handlers() = 0;
|
||||
virtual void set_handlers() = 0;
|
||||
virtual void process_phase(std::chrono::steady_clock::time_point now) = 0;
|
||||
virtual haier_protocol::HaierMessage get_control_message() = 0;
|
||||
virtual bool is_message_invalid(uint8_t message_type) = 0;
|
||||
@@ -99,14 +102,17 @@ class HaierClimateBase : public esphome::Component,
|
||||
// Helper functions
|
||||
void set_force_send_control_(bool status);
|
||||
void send_message_(const haier_protocol::HaierMessage &command, bool use_crc);
|
||||
void set_phase_(ProtocolPhases phase);
|
||||
virtual void set_phase(ProtocolPhases phase);
|
||||
bool check_timeout_(std::chrono::steady_clock::time_point now, std::chrono::steady_clock::time_point tpoint,
|
||||
size_t timeout);
|
||||
bool is_message_interval_exceeded_(std::chrono::steady_clock::time_point now);
|
||||
bool is_status_request_interval_exceeded_(std::chrono::steady_clock::time_point now);
|
||||
bool is_control_message_timeout_exceeded_(std::chrono::steady_clock::time_point now);
|
||||
bool is_control_message_interval_exceeded_(std::chrono::steady_clock::time_point now);
|
||||
bool is_protocol_initialisation_interval_exceded_(std::chrono::steady_clock::time_point now);
|
||||
bool is_protocol_initialisation_interval_exceeded_(std::chrono::steady_clock::time_point now);
|
||||
#ifdef USE_WIFI
|
||||
haier_protocol::HaierMessage get_wifi_signal_message_(uint8_t message_type);
|
||||
#endif
|
||||
|
||||
struct HvacSettings {
|
||||
esphome::optional<esphome::climate::ClimateMode> mode;
|
||||
@@ -136,6 +142,9 @@ class HaierClimateBase : public esphome::Component,
|
||||
std::chrono::steady_clock::time_point last_valid_status_timestamp_; // For protocol timeout
|
||||
std::chrono::steady_clock::time_point last_status_request_; // To request AC status
|
||||
std::chrono::steady_clock::time_point control_request_timestamp_; // To send control message
|
||||
optional<std::chrono::milliseconds> answer_timeout_; // Message answer timeout
|
||||
bool send_wifi_signal_;
|
||||
std::chrono::steady_clock::time_point last_signal_request_; // To send WiFI signal level
|
||||
};
|
||||
|
||||
} // namespace haier
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
#include <string>
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#ifdef USE_WIFI
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
#endif
|
||||
#include "hon_climate.h"
|
||||
#include "hon_packet.h"
|
||||
|
||||
@@ -58,14 +55,7 @@ HonClimate::HonClimate()
|
||||
hvac_functions_{false, false, false, false, false},
|
||||
use_crc_(hvac_functions_[2]),
|
||||
active_alarms_{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
outdoor_sensor_(nullptr),
|
||||
send_wifi_signal_(true) {
|
||||
this->traits_.set_supported_presets({
|
||||
climate::CLIMATE_PRESET_NONE,
|
||||
climate::CLIMATE_PRESET_ECO,
|
||||
climate::CLIMATE_PRESET_BOOST,
|
||||
climate::CLIMATE_PRESET_SLEEP,
|
||||
});
|
||||
outdoor_sensor_(nullptr) {
|
||||
this->fan_mode_speed_ = (uint8_t) hon_protocol::FanMode::FAN_MID;
|
||||
this->other_modes_fan_speed_ = (uint8_t) hon_protocol::FanMode::FAN_AUTO;
|
||||
}
|
||||
@@ -121,17 +111,22 @@ void HonClimate::start_steri_cleaning() {
|
||||
}
|
||||
}
|
||||
|
||||
void HonClimate::set_send_wifi(bool send_wifi) { this->send_wifi_signal_ = send_wifi; }
|
||||
|
||||
haier_protocol::HandlerError HonClimate::get_device_version_answer_handler_(uint8_t request_type, uint8_t message_type,
|
||||
const uint8_t *data, size_t data_size) {
|
||||
// Should check this before preprocess
|
||||
if (message_type == (uint8_t) hon_protocol::FrameType::INVALID) {
|
||||
ESP_LOGW(TAG, "It looks like your ESPHome Haier climate configuration is wrong. You should use the smartAir2 "
|
||||
"protocol instead of hOn");
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
return haier_protocol::HandlerError::INVALID_ANSWER;
|
||||
}
|
||||
haier_protocol::HandlerError result = this->answer_preprocess_(
|
||||
request_type, (uint8_t) hon_protocol::FrameType::GET_DEVICE_VERSION, message_type,
|
||||
(uint8_t) hon_protocol::FrameType::GET_DEVICE_VERSION_RESPONSE, ProtocolPhases::WAITING_ANSWER_INIT_1);
|
||||
(uint8_t) hon_protocol::FrameType::GET_DEVICE_VERSION_RESPONSE, ProtocolPhases::WAITING_INIT_1_ANSWER);
|
||||
if (result == haier_protocol::HandlerError::HANDLER_OK) {
|
||||
if (data_size < sizeof(hon_protocol::DeviceVersionAnswer)) {
|
||||
// Wrong structure
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
return haier_protocol::HandlerError::WRONG_MESSAGE_STRUCTURE;
|
||||
}
|
||||
// All OK
|
||||
@@ -152,11 +147,11 @@ haier_protocol::HandlerError HonClimate::get_device_version_answer_handler_(uint
|
||||
this->hvac_functions_[3] = (answr->functions[1] & 0x08) != 0; // multiple AC support
|
||||
this->hvac_functions_[4] = (answr->functions[1] & 0x20) != 0; // roles support
|
||||
this->hvac_hardware_info_available_ = true;
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_2);
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_2);
|
||||
return result;
|
||||
} else {
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -165,13 +160,13 @@ haier_protocol::HandlerError HonClimate::get_device_id_answer_handler_(uint8_t r
|
||||
const uint8_t *data, size_t data_size) {
|
||||
haier_protocol::HandlerError result = this->answer_preprocess_(
|
||||
request_type, (uint8_t) hon_protocol::FrameType::GET_DEVICE_ID, message_type,
|
||||
(uint8_t) hon_protocol::FrameType::GET_DEVICE_ID_RESPONSE, ProtocolPhases::WAITING_ANSWER_INIT_2);
|
||||
(uint8_t) hon_protocol::FrameType::GET_DEVICE_ID_RESPONSE, ProtocolPhases::WAITING_INIT_2_ANSWER);
|
||||
if (result == haier_protocol::HandlerError::HANDLER_OK) {
|
||||
this->set_phase_(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
this->set_phase(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
return result;
|
||||
} else {
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -185,8 +180,8 @@ haier_protocol::HandlerError HonClimate::status_handler_(uint8_t request_type, u
|
||||
result = this->process_status_message_(data, data_size);
|
||||
if (result != haier_protocol::HandlerError::HANDLER_OK) {
|
||||
ESP_LOGW(TAG, "Error %d while parsing Status packet", (int) result);
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
} else {
|
||||
if (data_size >= sizeof(hon_protocol::HaierPacketControl) + 2) {
|
||||
memcpy(this->last_status_message_.get(), data + 2, sizeof(hon_protocol::HaierPacketControl));
|
||||
@@ -196,13 +191,13 @@ haier_protocol::HandlerError HonClimate::status_handler_(uint8_t request_type, u
|
||||
}
|
||||
if (this->protocol_phase_ == ProtocolPhases::WAITING_FIRST_STATUS_ANSWER) {
|
||||
ESP_LOGI(TAG, "First HVAC status received");
|
||||
this->set_phase_(ProtocolPhases::SENDING_ALARM_STATUS_REQUEST);
|
||||
this->set_phase(ProtocolPhases::SENDING_ALARM_STATUS_REQUEST);
|
||||
} else if ((this->protocol_phase_ == ProtocolPhases::WAITING_STATUS_ANSWER) ||
|
||||
(this->protocol_phase_ == ProtocolPhases::WAITING_POWER_ON_ANSWER) ||
|
||||
(this->protocol_phase_ == ProtocolPhases::WAITING_POWER_OFF_ANSWER)) {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else if (this->protocol_phase_ == ProtocolPhases::WAITING_CONTROL_ANSWER) {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
this->set_force_send_control_(false);
|
||||
if (this->hvac_settings_.valid)
|
||||
this->hvac_settings_.reset();
|
||||
@@ -210,8 +205,8 @@ haier_protocol::HandlerError HonClimate::status_handler_(uint8_t request_type, u
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_INIT_1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -225,10 +220,10 @@ haier_protocol::HandlerError HonClimate::get_management_information_answer_handl
|
||||
message_type, (uint8_t) hon_protocol::FrameType::GET_MANAGEMENT_INFORMATION_RESPONSE,
|
||||
ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER);
|
||||
if (result == haier_protocol::HandlerError::HANDLER_OK) {
|
||||
this->set_phase_(ProtocolPhases::SENDING_SIGNAL_LEVEL);
|
||||
this->set_phase(ProtocolPhases::SENDING_SIGNAL_LEVEL);
|
||||
return result;
|
||||
} else {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +234,7 @@ haier_protocol::HandlerError HonClimate::report_network_status_answer_handler_(u
|
||||
haier_protocol::HandlerError result =
|
||||
this->answer_preprocess_(request_type, (uint8_t) hon_protocol::FrameType::REPORT_NETWORK_STATUS, message_type,
|
||||
(uint8_t) hon_protocol::FrameType::CONFIRM, ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER);
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -248,24 +243,24 @@ haier_protocol::HandlerError HonClimate::get_alarm_status_answer_handler_(uint8_
|
||||
if (request_type == (uint8_t) hon_protocol::FrameType::GET_ALARM_STATUS) {
|
||||
if (message_type != (uint8_t) hon_protocol::FrameType::GET_ALARM_STATUS_RESPONSE) {
|
||||
// Unexpected answer to request
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::UNSUPORTED_MESSAGE;
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
|
||||
}
|
||||
if (this->protocol_phase_ != ProtocolPhases::WAITING_ALARM_STATUS_ANSWER) {
|
||||
// Don't expect this answer now
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::UNEXPECTED_MESSAGE;
|
||||
}
|
||||
memcpy(this->active_alarms_, data + 2, 8);
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::HANDLER_OK;
|
||||
} else {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::UNSUPORTED_MESSAGE;
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
void HonClimate::set_answers_handlers() {
|
||||
void HonClimate::set_handlers() {
|
||||
// Set handlers
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
(uint8_t) (hon_protocol::FrameType::GET_DEVICE_VERSION),
|
||||
@@ -311,7 +306,7 @@ void HonClimate::dump_config() {
|
||||
void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
switch (this->protocol_phase_) {
|
||||
case ProtocolPhases::SENDING_INIT_1:
|
||||
if (this->can_send_message() && this->is_protocol_initialisation_interval_exceded_(now)) {
|
||||
if (this->can_send_message() && this->is_protocol_initialisation_interval_exceeded_(now)) {
|
||||
this->hvac_hardware_info_available_ = false;
|
||||
// Indicate device capabilities:
|
||||
// bit 0 - if 1 module support interactive mode
|
||||
@@ -323,24 +318,24 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
static const haier_protocol::HaierMessage DEVICE_VERSION_REQUEST(
|
||||
(uint8_t) hon_protocol::FrameType::GET_DEVICE_VERSION, module_capabilities, sizeof(module_capabilities));
|
||||
this->send_message_(DEVICE_VERSION_REQUEST, this->use_crc_);
|
||||
this->set_phase_(ProtocolPhases::WAITING_ANSWER_INIT_1);
|
||||
this->set_phase(ProtocolPhases::WAITING_INIT_1_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_INIT_2:
|
||||
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
|
||||
static const haier_protocol::HaierMessage DEVICEID_REQUEST((uint8_t) hon_protocol::FrameType::GET_DEVICE_ID);
|
||||
this->send_message_(DEVICEID_REQUEST, this->use_crc_);
|
||||
this->set_phase_(ProtocolPhases::WAITING_ANSWER_INIT_2);
|
||||
this->set_phase(ProtocolPhases::WAITING_INIT_2_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_FIRST_STATUS_REQUEST:
|
||||
case ProtocolPhases::SENDING_STATUS_REQUEST:
|
||||
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
|
||||
static const haier_protocol::HaierMessage STATUS_REQUEST(
|
||||
(uint8_t) hon_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcomandsControl::GET_USER_DATA);
|
||||
(uint8_t) hon_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcommandsControl::GET_USER_DATA);
|
||||
this->send_message_(STATUS_REQUEST, this->use_crc_);
|
||||
this->last_status_request_ = now;
|
||||
this->set_phase_((ProtocolPhases) ((uint8_t) this->protocol_phase_ + 1));
|
||||
this->set_phase((ProtocolPhases) ((uint8_t) this->protocol_phase_ + 1));
|
||||
}
|
||||
break;
|
||||
#ifdef USE_WIFI
|
||||
@@ -350,26 +345,14 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
(uint8_t) hon_protocol::FrameType::GET_MANAGEMENT_INFORMATION);
|
||||
this->send_message_(UPDATE_SIGNAL_REQUEST, this->use_crc_);
|
||||
this->last_signal_request_ = now;
|
||||
this->set_phase_(ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER);
|
||||
this->set_phase(ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_SIGNAL_LEVEL:
|
||||
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
|
||||
static uint8_t wifi_status_data[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (wifi::global_wifi_component->is_connected()) {
|
||||
wifi_status_data[1] = 0;
|
||||
int8_t rssi = wifi::global_wifi_component->wifi_rssi();
|
||||
wifi_status_data[3] = uint8_t((128 + rssi) / 1.28f);
|
||||
ESP_LOGD(TAG, "WiFi signal is: %ddBm => %d%%", rssi, wifi_status_data[3]);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "WiFi is not connected");
|
||||
wifi_status_data[1] = 1;
|
||||
wifi_status_data[3] = 0;
|
||||
}
|
||||
haier_protocol::HaierMessage wifi_status_request((uint8_t) hon_protocol::FrameType::REPORT_NETWORK_STATUS,
|
||||
wifi_status_data, sizeof(wifi_status_data));
|
||||
this->send_message_(wifi_status_request, this->use_crc_);
|
||||
this->set_phase_(ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER);
|
||||
this->send_message_(this->get_wifi_signal_message_((uint8_t) hon_protocol::FrameType::REPORT_NETWORK_STATUS),
|
||||
this->use_crc_);
|
||||
this->set_phase(ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER:
|
||||
@@ -380,7 +363,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
case ProtocolPhases::SENDING_SIGNAL_LEVEL:
|
||||
case ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER:
|
||||
case ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER:
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
break;
|
||||
#endif
|
||||
case ProtocolPhases::SENDING_ALARM_STATUS_REQUEST:
|
||||
@@ -388,7 +371,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
static const haier_protocol::HaierMessage ALARM_STATUS_REQUEST(
|
||||
(uint8_t) hon_protocol::FrameType::GET_ALARM_STATUS);
|
||||
this->send_message_(ALARM_STATUS_REQUEST, this->use_crc_);
|
||||
this->set_phase_(ProtocolPhases::WAITING_ALARM_STATUS_ANSWER);
|
||||
this->set_phase(ProtocolPhases::WAITING_ALARM_STATUS_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_CONTROL:
|
||||
@@ -403,12 +386,12 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
this->hvac_settings_.reset();
|
||||
this->forced_request_status_ = true;
|
||||
this->forced_publish_ = true;
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else if (this->can_send_message() && this->is_control_message_interval_exceeded_(now)) {
|
||||
haier_protocol::HaierMessage control_message = get_control_message();
|
||||
this->send_message_(control_message, this->use_crc_);
|
||||
ESP_LOGI(TAG, "Control packet sent");
|
||||
this->set_phase_(ProtocolPhases::WAITING_CONTROL_ANSWER);
|
||||
this->set_phase(ProtocolPhases::WAITING_CONTROL_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_POWER_ON_COMMAND:
|
||||
@@ -418,17 +401,17 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
if (this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND)
|
||||
pwr_cmd_buf[1] = 0x01;
|
||||
haier_protocol::HaierMessage power_cmd((uint8_t) hon_protocol::FrameType::CONTROL,
|
||||
((uint16_t) hon_protocol::SubcomandsControl::SET_SINGLE_PARAMETER) + 1,
|
||||
((uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER) + 1,
|
||||
pwr_cmd_buf, sizeof(pwr_cmd_buf));
|
||||
this->send_message_(power_cmd, this->use_crc_);
|
||||
this->set_phase_(this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND
|
||||
? ProtocolPhases::WAITING_POWER_ON_ANSWER
|
||||
: ProtocolPhases::WAITING_POWER_OFF_ANSWER);
|
||||
this->set_phase(this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND
|
||||
? ProtocolPhases::WAITING_POWER_ON_ANSWER
|
||||
: ProtocolPhases::WAITING_POWER_OFF_ANSWER);
|
||||
}
|
||||
break;
|
||||
|
||||
case ProtocolPhases::WAITING_ANSWER_INIT_1:
|
||||
case ProtocolPhases::WAITING_ANSWER_INIT_2:
|
||||
case ProtocolPhases::WAITING_INIT_1_ANSWER:
|
||||
case ProtocolPhases::WAITING_INIT_2_ANSWER:
|
||||
case ProtocolPhases::WAITING_FIRST_STATUS_ANSWER:
|
||||
case ProtocolPhases::WAITING_ALARM_STATUS_ANSWER:
|
||||
case ProtocolPhases::WAITING_STATUS_ANSWER:
|
||||
@@ -438,14 +421,14 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
break;
|
||||
case ProtocolPhases::IDLE: {
|
||||
if (this->forced_request_status_ || this->is_status_request_interval_exceeded_(now)) {
|
||||
this->set_phase_(ProtocolPhases::SENDING_STATUS_REQUEST);
|
||||
this->set_phase(ProtocolPhases::SENDING_STATUS_REQUEST);
|
||||
this->forced_request_status_ = false;
|
||||
}
|
||||
#ifdef USE_WIFI
|
||||
else if (this->send_wifi_signal_ &&
|
||||
(std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_signal_request_).count() >
|
||||
SIGNAL_LEVEL_UPDATE_INTERVAL_MS))
|
||||
this->set_phase_(ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST);
|
||||
this->set_phase(ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST);
|
||||
#endif
|
||||
} break;
|
||||
default:
|
||||
@@ -456,7 +439,7 @@ void HonClimate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
#else
|
||||
ESP_LOGE(TAG, "Wrong protocol handler state: %d, resetting communication", (int) this->protocol_phase_);
|
||||
#endif
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -475,7 +458,7 @@ haier_protocol::HaierMessage HonClimate::get_control_message() {
|
||||
case CLIMATE_MODE_OFF:
|
||||
out_data->ac_power = 0;
|
||||
break;
|
||||
case CLIMATE_MODE_AUTO:
|
||||
case CLIMATE_MODE_HEAT_COOL:
|
||||
out_data->ac_power = 1;
|
||||
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::AUTO;
|
||||
out_data->fan_mode = this->other_modes_fan_speed_;
|
||||
@@ -551,11 +534,12 @@ haier_protocol::HaierMessage HonClimate::get_control_message() {
|
||||
}
|
||||
}
|
||||
if (climate_control.target_temperature.has_value()) {
|
||||
out_data->set_point =
|
||||
climate_control.target_temperature.value() - 16; // set the temperature at our offset, subtract 16.
|
||||
float target_temp = climate_control.target_temperature.value();
|
||||
out_data->set_point = ((int) target_temp) - 16; // set the temperature at our offset, subtract 16.
|
||||
out_data->half_degree = (target_temp - ((int) target_temp) >= 0.49) ? 1 : 0;
|
||||
}
|
||||
if (out_data->ac_power == 0) {
|
||||
// If AC is off - no presets alowed
|
||||
// If AC is off - no presets allowed
|
||||
out_data->quiet_mode = 0;
|
||||
out_data->fast_mode = 0;
|
||||
out_data->sleep_mode = 0;
|
||||
@@ -631,7 +615,7 @@ haier_protocol::HaierMessage HonClimate::get_control_message() {
|
||||
break;
|
||||
}
|
||||
return haier_protocol::HaierMessage((uint8_t) hon_protocol::FrameType::CONTROL,
|
||||
(uint16_t) hon_protocol::SubcomandsControl::SET_GROUP_PARAMETERS,
|
||||
(uint16_t) hon_protocol::SubcommandsControl::SET_GROUP_PARAMETERS,
|
||||
control_out_buffer, sizeof(hon_protocol::HaierPacketControl));
|
||||
}
|
||||
|
||||
@@ -669,7 +653,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
||||
{
|
||||
// Target temperature
|
||||
float old_target_temperature = this->target_temperature;
|
||||
this->target_temperature = packet.control.set_point + 16.0f;
|
||||
this->target_temperature = packet.control.set_point + 16.0f + ((packet.control.half_degree == 1) ? 0.5f : 0.0f);
|
||||
should_publish = should_publish || (old_target_temperature != this->target_temperature);
|
||||
}
|
||||
{
|
||||
@@ -747,7 +731,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
||||
if (new_cleaning != this->cleaning_status_) {
|
||||
ESP_LOGD(TAG, "Cleaning status change: %d => %d", (uint8_t) this->cleaning_status_, (uint8_t) new_cleaning);
|
||||
if (new_cleaning == CleaningState::NO_CLEANING) {
|
||||
// Turnuin AC off after cleaning
|
||||
// Turning AC off after cleaning
|
||||
this->action_request_ = ActionRequest::TURN_POWER_OFF;
|
||||
}
|
||||
this->cleaning_status_ = new_cleaning;
|
||||
@@ -774,7 +758,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
||||
this->mode = CLIMATE_MODE_FAN_ONLY;
|
||||
break;
|
||||
case (uint8_t) hon_protocol::ConditioningMode::AUTO:
|
||||
this->mode = CLIMATE_MODE_AUTO;
|
||||
this->mode = CLIMATE_MODE_HEAT_COOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -837,7 +821,7 @@ void HonClimate::process_pending_action() {
|
||||
case ActionRequest::START_SELF_CLEAN:
|
||||
case ActionRequest::START_STERI_CLEAN:
|
||||
// Will reset action with control message sending
|
||||
this->set_phase_(ProtocolPhases::SENDING_CONTROL);
|
||||
this->set_phase(ProtocolPhases::SENDING_CONTROL);
|
||||
break;
|
||||
default:
|
||||
HaierClimateBase::process_pending_action();
|
||||
|
||||
@@ -48,10 +48,9 @@ class HonClimate : public HaierClimateBase {
|
||||
CleaningState get_cleaning_status() const;
|
||||
void start_self_cleaning();
|
||||
void start_steri_cleaning();
|
||||
void set_send_wifi(bool send_wifi);
|
||||
|
||||
protected:
|
||||
void set_answers_handlers() override;
|
||||
void set_handlers() override;
|
||||
void process_phase(std::chrono::steady_clock::time_point now) override;
|
||||
haier_protocol::HaierMessage get_control_message() override;
|
||||
bool is_message_invalid(uint8_t message_type) override;
|
||||
@@ -87,8 +86,6 @@ class HonClimate : public HaierClimateBase {
|
||||
bool &use_crc_;
|
||||
uint8_t active_alarms_[8];
|
||||
esphome::sensor::Sensor *outdoor_sensor_;
|
||||
bool send_wifi_signal_;
|
||||
std::chrono::steady_clock::time_point last_signal_request_; // To send WiFI signal level
|
||||
};
|
||||
|
||||
} // namespace haier
|
||||
|
||||
@@ -53,12 +53,12 @@ struct HaierPacketControl {
|
||||
// 13
|
||||
uint8_t : 8;
|
||||
// 14
|
||||
uint8_t ten_degree : 1; // 10 degree status
|
||||
uint8_t display_status : 1; // If 0 disables AC's display
|
||||
uint8_t half_degree : 1; // Use half degree
|
||||
uint8_t intelegence_status : 1; // Intelligence status
|
||||
uint8_t pmv_status : 1; // Comfort/PMV status
|
||||
uint8_t use_fahrenheit : 1; // Use Fahrenheit instead of Celsius
|
||||
uint8_t ten_degree : 1; // 10 degree status
|
||||
uint8_t display_status : 1; // If 0 disables AC's display
|
||||
uint8_t half_degree : 1; // Use half degree
|
||||
uint8_t intelligence_status : 1; // Intelligence status
|
||||
uint8_t pmv_status : 1; // Comfort/PMV status
|
||||
uint8_t use_fahrenheit : 1; // Use Fahrenheit instead of Celsius
|
||||
uint8_t : 1;
|
||||
uint8_t steri_clean : 1;
|
||||
// 15
|
||||
@@ -153,7 +153,7 @@ enum class FrameType : uint8_t {
|
||||
// <-> device, required)
|
||||
REPORT = 0x06, // Report frame (module <-> device, interactive, required)
|
||||
STOP_FAULT_ALARM = 0x09, // Stop fault alarm frame (module -> device, interactive, required)
|
||||
SYSTEM_DOWNLIK = 0x11, // System downlink frame (module -> device, optional)
|
||||
SYSTEM_DOWNLINK = 0x11, // System downlink frame (module -> device, optional)
|
||||
DEVICE_UPLINK = 0x12, // Device uplink frame (module <- device , interactive, optional)
|
||||
SYSTEM_QUERY = 0x13, // System query frame (module -> device, optional)
|
||||
SYSTEM_QUERY_RESPONSE = 0x14, // System query response frame (module <- device , optional)
|
||||
@@ -210,7 +210,7 @@ enum class FrameType : uint8_t {
|
||||
WAKE_UP = 0xFE, // Request to wake up (module <-> device, optional)
|
||||
};
|
||||
|
||||
enum class SubcomandsControl : uint16_t {
|
||||
enum class SubcommandsControl : uint16_t {
|
||||
GET_PARAMETERS = 0x4C01, // Request specific parameters (packet content: parameter ID1 + parameter ID2 + ...)
|
||||
GET_USER_DATA = 0x4D01, // Request all user data from device (packet content: None)
|
||||
GET_BIG_DATA = 0x4DFE, // Request big data information from device (packet content: None)
|
||||
|
||||
@@ -11,15 +11,10 @@ namespace esphome {
|
||||
namespace haier {
|
||||
|
||||
static const char *const TAG = "haier.climate";
|
||||
constexpr size_t SIGNAL_LEVEL_UPDATE_INTERVAL_MS = 10000;
|
||||
|
||||
Smartair2Climate::Smartair2Climate()
|
||||
: last_status_message_(new uint8_t[sizeof(smartair2_protocol::HaierPacketControl)]) {
|
||||
this->traits_.set_supported_presets({
|
||||
climate::CLIMATE_PRESET_NONE,
|
||||
climate::CLIMATE_PRESET_BOOST,
|
||||
climate::CLIMATE_PRESET_COMFORT,
|
||||
});
|
||||
}
|
||||
: last_status_message_(new uint8_t[sizeof(smartair2_protocol::HaierPacketControl)]), timeouts_counter_(0) {}
|
||||
|
||||
haier_protocol::HandlerError Smartair2Climate::status_handler_(uint8_t request_type, uint8_t message_type,
|
||||
const uint8_t *data, size_t data_size) {
|
||||
@@ -30,8 +25,8 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(uint8_t request_t
|
||||
result = this->process_status_message_(data, data_size);
|
||||
if (result != haier_protocol::HandlerError::HANDLER_OK) {
|
||||
ESP_LOGW(TAG, "Error %d while parsing Status packet", (int) result);
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
} else {
|
||||
if (data_size >= sizeof(smartair2_protocol::HaierPacketControl) + 2) {
|
||||
memcpy(this->last_status_message_.get(), data + 2, sizeof(smartair2_protocol::HaierPacketControl));
|
||||
@@ -41,11 +36,11 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(uint8_t request_t
|
||||
}
|
||||
if (this->protocol_phase_ == ProtocolPhases::WAITING_FIRST_STATUS_ANSWER) {
|
||||
ESP_LOGI(TAG, "First HVAC status received");
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else if (this->protocol_phase_ == ProtocolPhases::WAITING_STATUS_ANSWER) {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else if (this->protocol_phase_ == ProtocolPhases::WAITING_CONTROL_ANSWER) {
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
this->set_force_send_control_(false);
|
||||
if (this->hvac_settings_.valid)
|
||||
this->hvac_settings_.reset();
|
||||
@@ -53,17 +48,82 @@ haier_protocol::HandlerError Smartair2Climate::status_handler_(uint8_t request_t
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
this->set_phase_((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
this->set_phase((this->protocol_phase_ >= ProtocolPhases::IDLE) ? ProtocolPhases::IDLE
|
||||
: ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void Smartair2Climate::set_answers_handlers() {
|
||||
haier_protocol::HandlerError Smartair2Climate::get_device_version_answer_handler_(uint8_t request_type,
|
||||
uint8_t message_type,
|
||||
const uint8_t *data,
|
||||
size_t data_size) {
|
||||
if (request_type != (uint8_t) smartair2_protocol::FrameType::GET_DEVICE_VERSION)
|
||||
return haier_protocol::HandlerError::UNSUPPORTED_MESSAGE;
|
||||
if (ProtocolPhases::WAITING_INIT_1_ANSWER != this->protocol_phase_)
|
||||
return haier_protocol::HandlerError::UNEXPECTED_MESSAGE;
|
||||
// Invalid packet is expected answer
|
||||
if ((message_type == (uint8_t) smartair2_protocol::FrameType::GET_DEVICE_VERSION_RESPONSE) && (data_size >= 39) &&
|
||||
((data[37] & 0x04) != 0)) {
|
||||
ESP_LOGW(TAG, "It looks like your ESPHome Haier climate configuration is wrong. You should use the hOn protocol "
|
||||
"instead of smartAir2");
|
||||
}
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_2);
|
||||
return haier_protocol::HandlerError::HANDLER_OK;
|
||||
}
|
||||
|
||||
haier_protocol::HandlerError Smartair2Climate::report_network_status_answer_handler_(uint8_t request_type,
|
||||
uint8_t message_type,
|
||||
const uint8_t *data,
|
||||
size_t data_size) {
|
||||
haier_protocol::HandlerError result = this->answer_preprocess_(
|
||||
request_type, (uint8_t) smartair2_protocol::FrameType::REPORT_NETWORK_STATUS, message_type,
|
||||
(uint8_t) smartair2_protocol::FrameType::CONFIRM, ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
return result;
|
||||
}
|
||||
|
||||
haier_protocol::HandlerError Smartair2Climate::initial_messages_timeout_handler_(uint8_t message_type) {
|
||||
if (this->protocol_phase_ >= ProtocolPhases::IDLE)
|
||||
return HaierClimateBase::timeout_default_handler_(message_type);
|
||||
this->timeouts_counter_++;
|
||||
ESP_LOGI(TAG, "Answer timeout for command %02X, phase %d, timeout counter %d", message_type,
|
||||
(int) this->protocol_phase_, this->timeouts_counter_);
|
||||
if (this->timeouts_counter_ >= 3) {
|
||||
ProtocolPhases new_phase = (ProtocolPhases) ((int) this->protocol_phase_ + 1);
|
||||
if (new_phase >= ProtocolPhases::SENDING_ALARM_STATUS_REQUEST)
|
||||
new_phase = ProtocolPhases::SENDING_INIT_1;
|
||||
this->set_phase(new_phase);
|
||||
} else {
|
||||
// Returning to the previous state to try again
|
||||
this->set_phase((ProtocolPhases) ((int) this->protocol_phase_ - 1));
|
||||
}
|
||||
return haier_protocol::HandlerError::HANDLER_OK;
|
||||
}
|
||||
|
||||
void Smartair2Climate::set_handlers() {
|
||||
// Set handlers
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::GET_DEVICE_VERSION),
|
||||
std::bind(&Smartair2Climate::get_device_version_answer_handler_, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::CONTROL),
|
||||
std::bind(&Smartair2Climate::status_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::REPORT_NETWORK_STATUS),
|
||||
std::bind(&Smartair2Climate::report_network_status_answer_handler_, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
this->haier_protocol_.set_timeout_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::GET_DEVICE_ID),
|
||||
std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1));
|
||||
this->haier_protocol_.set_timeout_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::GET_DEVICE_VERSION),
|
||||
std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1));
|
||||
this->haier_protocol_.set_timeout_handler(
|
||||
(uint8_t) (smartair2_protocol::FrameType::CONTROL),
|
||||
std::bind(&Smartair2Climate::initial_messages_timeout_handler_, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void Smartair2Climate::dump_config() {
|
||||
@@ -74,39 +134,62 @@ void Smartair2Climate::dump_config() {
|
||||
void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now) {
|
||||
switch (this->protocol_phase_) {
|
||||
case ProtocolPhases::SENDING_INIT_1:
|
||||
this->set_phase_(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
break;
|
||||
case ProtocolPhases::WAITING_ANSWER_INIT_1:
|
||||
case ProtocolPhases::SENDING_INIT_2:
|
||||
case ProtocolPhases::WAITING_ANSWER_INIT_2:
|
||||
case ProtocolPhases::SENDING_ALARM_STATUS_REQUEST:
|
||||
case ProtocolPhases::WAITING_ALARM_STATUS_ANSWER:
|
||||
this->set_phase_(ProtocolPhases::SENDING_INIT_1);
|
||||
break;
|
||||
case ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST:
|
||||
case ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER:
|
||||
case ProtocolPhases::SENDING_SIGNAL_LEVEL:
|
||||
case ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER:
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
break;
|
||||
case ProtocolPhases::SENDING_FIRST_STATUS_REQUEST:
|
||||
if (this->can_send_message() && this->is_protocol_initialisation_interval_exceded_(now)) {
|
||||
static const haier_protocol::HaierMessage STATUS_REQUEST((uint8_t) smartair2_protocol::FrameType::CONTROL,
|
||||
0x4D01);
|
||||
this->send_message_(STATUS_REQUEST, false);
|
||||
this->last_status_request_ = now;
|
||||
this->set_phase_(ProtocolPhases::WAITING_FIRST_STATUS_ANSWER);
|
||||
if (this->can_send_message() &&
|
||||
(((this->timeouts_counter_ == 0) && (this->is_protocol_initialisation_interval_exceeded_(now))) ||
|
||||
((this->timeouts_counter_ > 0) && (this->is_message_interval_exceeded_(now))))) {
|
||||
// Indicate device capabilities:
|
||||
// bit 0 - if 1 module support interactive mode
|
||||
// bit 1 - if 1 module support controller-device mode
|
||||
// bit 2 - if 1 module support crc
|
||||
// bit 3 - if 1 module support multiple devices
|
||||
// bit 4..bit 15 - not used
|
||||
uint8_t module_capabilities[2] = {0b00000000, 0b00000111};
|
||||
static const haier_protocol::HaierMessage DEVICE_VERSION_REQUEST(
|
||||
(uint8_t) smartair2_protocol::FrameType::GET_DEVICE_VERSION, module_capabilities,
|
||||
sizeof(module_capabilities));
|
||||
this->send_message_(DEVICE_VERSION_REQUEST, false);
|
||||
this->set_phase(ProtocolPhases::WAITING_INIT_1_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_INIT_2:
|
||||
case ProtocolPhases::WAITING_INIT_2_ANSWER:
|
||||
this->set_phase(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
break;
|
||||
case ProtocolPhases::SENDING_FIRST_STATUS_REQUEST:
|
||||
case ProtocolPhases::SENDING_STATUS_REQUEST:
|
||||
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
|
||||
static const haier_protocol::HaierMessage STATUS_REQUEST((uint8_t) smartair2_protocol::FrameType::CONTROL,
|
||||
0x4D01);
|
||||
this->send_message_(STATUS_REQUEST, false);
|
||||
this->last_status_request_ = now;
|
||||
this->set_phase_(ProtocolPhases::WAITING_STATUS_ANSWER);
|
||||
this->set_phase((ProtocolPhases) ((uint8_t) this->protocol_phase_ + 1));
|
||||
}
|
||||
break;
|
||||
#ifdef USE_WIFI
|
||||
case ProtocolPhases::SENDING_SIGNAL_LEVEL:
|
||||
if (this->can_send_message() && this->is_message_interval_exceeded_(now)) {
|
||||
this->send_message_(
|
||||
this->get_wifi_signal_message_((uint8_t) smartair2_protocol::FrameType::REPORT_NETWORK_STATUS), false);
|
||||
this->last_signal_request_ = now;
|
||||
this->set_phase(ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER:
|
||||
break;
|
||||
#else
|
||||
case ProtocolPhases::SENDING_SIGNAL_LEVEL:
|
||||
case ProtocolPhases::WAITING_SIGNAL_LEVEL_ANSWER:
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
break;
|
||||
#endif
|
||||
case ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST:
|
||||
case ProtocolPhases::WAITING_UPDATE_SIGNAL_ANSWER:
|
||||
this->set_phase(ProtocolPhases::SENDING_SIGNAL_LEVEL);
|
||||
break;
|
||||
case ProtocolPhases::SENDING_ALARM_STATUS_REQUEST:
|
||||
case ProtocolPhases::WAITING_ALARM_STATUS_ANSWER:
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
break;
|
||||
case ProtocolPhases::SENDING_CONTROL:
|
||||
if (this->first_control_attempt_) {
|
||||
this->control_request_timestamp_ = now;
|
||||
@@ -119,14 +202,14 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now)
|
||||
this->hvac_settings_.reset();
|
||||
this->forced_request_status_ = true;
|
||||
this->forced_publish_ = true;
|
||||
this->set_phase_(ProtocolPhases::IDLE);
|
||||
this->set_phase(ProtocolPhases::IDLE);
|
||||
} else if (this->can_send_message() && this->is_control_message_interval_exceeded_(
|
||||
now)) // Using CONTROL_MESSAGES_INTERVAL_MS to speedup requests
|
||||
{
|
||||
haier_protocol::HaierMessage control_message = get_control_message();
|
||||
this->send_message_(control_message, false);
|
||||
ESP_LOGI(TAG, "Control packet sent");
|
||||
this->set_phase_(ProtocolPhases::WAITING_CONTROL_ANSWER);
|
||||
this->set_phase(ProtocolPhases::WAITING_CONTROL_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::SENDING_POWER_ON_COMMAND:
|
||||
@@ -136,11 +219,12 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now)
|
||||
(uint8_t) smartair2_protocol::FrameType::CONTROL,
|
||||
this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND ? 0x4D02 : 0x4D03);
|
||||
this->send_message_(power_cmd, false);
|
||||
this->set_phase_(this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND
|
||||
? ProtocolPhases::WAITING_POWER_ON_ANSWER
|
||||
: ProtocolPhases::WAITING_POWER_OFF_ANSWER);
|
||||
this->set_phase(this->protocol_phase_ == ProtocolPhases::SENDING_POWER_ON_COMMAND
|
||||
? ProtocolPhases::WAITING_POWER_ON_ANSWER
|
||||
: ProtocolPhases::WAITING_POWER_OFF_ANSWER);
|
||||
}
|
||||
break;
|
||||
case ProtocolPhases::WAITING_INIT_1_ANSWER:
|
||||
case ProtocolPhases::WAITING_FIRST_STATUS_ANSWER:
|
||||
case ProtocolPhases::WAITING_STATUS_ANSWER:
|
||||
case ProtocolPhases::WAITING_CONTROL_ANSWER:
|
||||
@@ -149,14 +233,25 @@ void Smartair2Climate::process_phase(std::chrono::steady_clock::time_point now)
|
||||
break;
|
||||
case ProtocolPhases::IDLE: {
|
||||
if (this->forced_request_status_ || this->is_status_request_interval_exceeded_(now)) {
|
||||
this->set_phase_(ProtocolPhases::SENDING_STATUS_REQUEST);
|
||||
this->set_phase(ProtocolPhases::SENDING_STATUS_REQUEST);
|
||||
this->forced_request_status_ = false;
|
||||
}
|
||||
#ifdef USE_WIFI
|
||||
else if (this->send_wifi_signal_ &&
|
||||
(std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_signal_request_).count() >
|
||||
SIGNAL_LEVEL_UPDATE_INTERVAL_MS))
|
||||
this->set_phase(ProtocolPhases::SENDING_UPDATE_SIGNAL_REQUEST);
|
||||
#endif
|
||||
} break;
|
||||
default:
|
||||
// Shouldn't get here
|
||||
#if (HAIER_LOG_LEVEL > 4)
|
||||
ESP_LOGE(TAG, "Wrong protocol handler state: %s (%d), resetting communication",
|
||||
phase_to_string_(this->protocol_phase_), (int) this->protocol_phase_);
|
||||
#else
|
||||
ESP_LOGE(TAG, "Wrong protocol handler state: %d, resetting communication", (int) this->protocol_phase_);
|
||||
this->set_phase_(ProtocolPhases::SENDING_FIRST_STATUS_REQUEST);
|
||||
#endif
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +270,7 @@ haier_protocol::HaierMessage Smartair2Climate::get_control_message() {
|
||||
out_data->ac_power = 0;
|
||||
break;
|
||||
|
||||
case CLIMATE_MODE_AUTO:
|
||||
case CLIMATE_MODE_HEAT_COOL:
|
||||
out_data->ac_power = 1;
|
||||
out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::AUTO;
|
||||
out_data->fan_mode = this->other_modes_fan_speed_;
|
||||
@@ -256,11 +351,12 @@ haier_protocol::HaierMessage Smartair2Climate::get_control_message() {
|
||||
}
|
||||
}
|
||||
if (climate_control.target_temperature.has_value()) {
|
||||
out_data->set_point =
|
||||
climate_control.target_temperature.value() - 16; // set the temperature at our offset, subtract 16.
|
||||
float target_temp = climate_control.target_temperature.value();
|
||||
out_data->set_point = target_temp - 16; // set the temperature with offset 16
|
||||
out_data->half_degree = (target_temp - ((int) target_temp) >= 0.49) ? 1 : 0;
|
||||
}
|
||||
if (out_data->ac_power == 0) {
|
||||
// If AC is off - no presets alowed
|
||||
// If AC is off - no presets allowed
|
||||
out_data->turbo_mode = 0;
|
||||
out_data->quiet_mode = 0;
|
||||
} else if (climate_control.preset.has_value()) {
|
||||
@@ -312,7 +408,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
||||
{
|
||||
// Target temperature
|
||||
float old_target_temperature = this->target_temperature;
|
||||
this->target_temperature = packet.control.set_point + 16.0f;
|
||||
this->target_temperature = packet.control.set_point + 16.0f + ((packet.control.half_degree == 1) ? 0.5f : 0.0f);
|
||||
should_publish = should_publish || (old_target_temperature != this->target_temperature);
|
||||
}
|
||||
{
|
||||
@@ -333,7 +429,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
||||
}
|
||||
switch (packet.control.fan_mode) {
|
||||
case (uint8_t) smartair2_protocol::FanMode::FAN_AUTO:
|
||||
// Somtimes AC reports in fan only mode that fan speed is auto
|
||||
// Sometimes AC reports in fan only mode that fan speed is auto
|
||||
// but never accept this value back
|
||||
if (packet.control.ac_mode != (uint8_t) smartair2_protocol::ConditioningMode::FAN) {
|
||||
this->fan_mode = CLIMATE_FAN_AUTO;
|
||||
@@ -391,7 +487,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
||||
this->mode = CLIMATE_MODE_FAN_ONLY;
|
||||
break;
|
||||
case (uint8_t) smartair2_protocol::ConditioningMode::AUTO:
|
||||
this->mode = CLIMATE_MODE_AUTO;
|
||||
this->mode = CLIMATE_MODE_HEAT_COOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -453,5 +549,15 @@ bool Smartair2Climate::is_message_invalid(uint8_t message_type) {
|
||||
return message_type == (uint8_t) smartair2_protocol::FrameType::INVALID;
|
||||
}
|
||||
|
||||
void Smartair2Climate::set_phase(HaierClimateBase::ProtocolPhases phase) {
|
||||
int old_phase = (int) this->protocol_phase_;
|
||||
int new_phase = (int) phase;
|
||||
int min_p = std::min(old_phase, new_phase);
|
||||
int max_p = std::max(old_phase, new_phase);
|
||||
if ((min_p % 2 != 0) || (max_p - min_p > 1))
|
||||
this->timeouts_counter_ = 0;
|
||||
HaierClimateBase::set_phase(phase);
|
||||
}
|
||||
|
||||
} // namespace haier
|
||||
} // namespace esphome
|
||||
|
||||
@@ -15,16 +15,25 @@ class Smartair2Climate : public HaierClimateBase {
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
void set_answers_handlers() override;
|
||||
void set_handlers() override;
|
||||
void process_phase(std::chrono::steady_clock::time_point now) override;
|
||||
haier_protocol::HaierMessage get_control_message() override;
|
||||
bool is_message_invalid(uint8_t message_type) override;
|
||||
// Answers handlers
|
||||
void set_phase(HaierClimateBase::ProtocolPhases phase) override;
|
||||
// Answer and timeout handlers
|
||||
haier_protocol::HandlerError status_handler_(uint8_t request_type, uint8_t message_type, const uint8_t *data,
|
||||
size_t data_size);
|
||||
haier_protocol::HandlerError get_device_version_answer_handler_(uint8_t request_type, uint8_t message_type,
|
||||
const uint8_t *data, size_t data_size);
|
||||
haier_protocol::HandlerError get_device_id_answer_handler_(uint8_t request_type, uint8_t message_type,
|
||||
const uint8_t *data, size_t data_size);
|
||||
haier_protocol::HandlerError report_network_status_answer_handler_(uint8_t request_type, uint8_t message_type,
|
||||
const uint8_t *data, size_t data_size);
|
||||
haier_protocol::HandlerError initial_messages_timeout_handler_(uint8_t message_type);
|
||||
// Helper functions
|
||||
haier_protocol::HandlerError process_status_message_(const uint8_t *packet, uint8_t size);
|
||||
std::unique_ptr<uint8_t[]> last_status_message_;
|
||||
unsigned int timeouts_counter_;
|
||||
};
|
||||
|
||||
} // namespace haier
|
||||
|
||||
@@ -53,8 +53,8 @@ struct HaierPacketControl {
|
||||
uint8_t : 2;
|
||||
uint8_t health_mode : 1; // Health mode on or off
|
||||
uint8_t compressor : 1; // Compressor on or off ???
|
||||
uint8_t : 1;
|
||||
uint8_t ten_degree : 1; // 10 degree status (only work in heat mode)
|
||||
uint8_t half_degree : 1; // Use half degree
|
||||
uint8_t ten_degree : 1; // 10 degree status (only work in heat mode)
|
||||
uint8_t : 0;
|
||||
// 28
|
||||
uint8_t : 8;
|
||||
@@ -88,6 +88,9 @@ enum class FrameType : uint8_t {
|
||||
INVALID = 0x03,
|
||||
CONFIRM = 0x05,
|
||||
GET_DEVICE_VERSION = 0x61,
|
||||
GET_DEVICE_VERSION_RESPONSE = 0x62,
|
||||
GET_DEVICE_ID = 0x70,
|
||||
GET_DEVICE_ID_RESPONSE = 0x71,
|
||||
REPORT_NETWORK_STATUS = 0xF7,
|
||||
NO_COMMAND = 0xFF,
|
||||
};
|
||||
|
||||
@@ -6,6 +6,9 @@ from esphome.const import (
|
||||
CONF_CURRENT,
|
||||
CONF_FREQUENCY,
|
||||
CONF_ID,
|
||||
CONF_PHASE_A,
|
||||
CONF_PHASE_B,
|
||||
CONF_PHASE_C,
|
||||
CONF_REACTIVE_POWER,
|
||||
CONF_VOLTAGE,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
@@ -24,9 +27,6 @@ from esphome.const import (
|
||||
UNIT_WATT,
|
||||
)
|
||||
|
||||
CONF_PHASE_A = "phase_a"
|
||||
CONF_PHASE_B = "phase_b"
|
||||
CONF_PHASE_C = "phase_c"
|
||||
CONF_ENERGY_PRODUCTION_DAY = "energy_production_day"
|
||||
CONF_TOTAL_ENERGY_PRODUCTION = "total_energy_production"
|
||||
CONF_TOTAL_GENERATION_TIME = "total_generation_time"
|
||||
|
||||
@@ -33,6 +33,7 @@ PROTOCOLS = {
|
||||
"greeya": Protocol.PROTOCOL_GREEYAA,
|
||||
"greeyan": Protocol.PROTOCOL_GREEYAN,
|
||||
"greeyac": Protocol.PROTOCOL_GREEYAC,
|
||||
"greeyt": Protocol.PROTOCOL_GREEYT,
|
||||
"hisense_aud": Protocol.PROTOCOL_HISENSE_AUD,
|
||||
"hitachi": Protocol.PROTOCOL_HITACHI,
|
||||
"hyundai": Protocol.PROTOCOL_HYUNDAI,
|
||||
@@ -115,7 +116,7 @@ def to_code(config):
|
||||
cg.add(var.set_max_temperature(config[CONF_MAX_TEMPERATURE]))
|
||||
cg.add(var.set_min_temperature(config[CONF_MIN_TEMPERATURE]))
|
||||
|
||||
cg.add_library("tonia/HeatpumpIR", "1.0.20")
|
||||
cg.add_library("tonia/HeatpumpIR", "1.0.23")
|
||||
|
||||
if CORE.is_esp8266 or CORE.is_esp32:
|
||||
cg.add_library("crankyoldgit/IRremoteESP8266", "2.7.12")
|
||||
|
||||
@@ -27,6 +27,7 @@ const std::map<Protocol, std::function<HeatpumpIR *()>> PROTOCOL_CONSTRUCTOR_MAP
|
||||
{PROTOCOL_GREEYAA, []() { return new GreeYAAHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_GREEYAN, []() { return new GreeYANHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_GREEYAC, []() { return new GreeYACHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_GREEYT, []() { return new GreeYTHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_HISENSE_AUD, []() { return new HisenseHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_HITACHI, []() { return new HitachiHeatpumpIR(); }}, // NOLINT
|
||||
{PROTOCOL_HYUNDAI, []() { return new HyundaiHeatpumpIR(); }}, // NOLINT
|
||||
|
||||
@@ -27,6 +27,7 @@ enum Protocol {
|
||||
PROTOCOL_GREEYAA,
|
||||
PROTOCOL_GREEYAN,
|
||||
PROTOCOL_GREEYAC,
|
||||
PROTOCOL_GREEYT,
|
||||
PROTOCOL_HISENSE_AUD,
|
||||
PROTOCOL_HITACHI,
|
||||
PROTOCOL_HYUNDAI,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Official Datasheet:
|
||||
// https://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf
|
||||
// HRXL: https://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf
|
||||
// XL: https://www.maxbotix.com/documents/XL-MaxSonar-WR_Datasheet.pdf
|
||||
//
|
||||
// This implementation is designed to work with the TTL Versions of the
|
||||
// MaxBotix HRXL MaxSonar WR sensor series. The sensor's TTL Pin (5) should be
|
||||
// wired to one of the ESP's input pins and configured as uart rx_pin.
|
||||
// MaxBotix HRXL and XL MaxSonar WR sensor series. The sensor's TTL Pin (5)
|
||||
// should be wired to one of the ESP's input pins and configured as uart rx_pin.
|
||||
|
||||
#include "hrxl_maxsonar_wr.h"
|
||||
#include "esphome/core/log.h"
|
||||
@@ -17,8 +18,10 @@ static const uint8_t ASCII_NBSP = 0xFF;
|
||||
static const int MAX_DATA_LENGTH_BYTES = 6;
|
||||
|
||||
/**
|
||||
* The sensor outputs something like "R1234\r" at a fixed rate of 6 Hz. Where
|
||||
* 1234 means a distance of 1,234 m.
|
||||
* HRXL sensors output the format "R1234\r" at 6Hz
|
||||
* The 1234 means 1234mm
|
||||
* XL sensors output the format "R123\r" at 5 to 10Hz
|
||||
* The 123 means 123cm
|
||||
*/
|
||||
void HrxlMaxsonarWrComponent::loop() {
|
||||
uint8_t data;
|
||||
@@ -42,9 +45,17 @@ void HrxlMaxsonarWrComponent::check_buffer_() {
|
||||
if (this->buffer_.back() == static_cast<char>(ASCII_CR) || this->buffer_.length() >= MAX_DATA_LENGTH_BYTES) {
|
||||
ESP_LOGV(TAG, "Read from serial: %s", this->buffer_.c_str());
|
||||
|
||||
if (this->buffer_.length() == MAX_DATA_LENGTH_BYTES && this->buffer_[0] == 'R' &&
|
||||
this->buffer_.back() == static_cast<char>(ASCII_CR)) {
|
||||
int millimeters = parse_number<int>(this->buffer_.substr(1, MAX_DATA_LENGTH_BYTES - 2)).value_or(0);
|
||||
size_t rpos = this->buffer_.find(static_cast<char>(ASCII_CR));
|
||||
|
||||
if (this->buffer_.length() <= MAX_DATA_LENGTH_BYTES && this->buffer_[0] == 'R' && rpos != std::string::npos) {
|
||||
std::string distance = this->buffer_.substr(1, rpos - 1);
|
||||
int millimeters = parse_number<int>(distance).value_or(0);
|
||||
|
||||
// XL reports in cm instead of mm and reports 3 digits instead of 4
|
||||
if (distance.length() == 3) {
|
||||
millimeters = millimeters * 10;
|
||||
}
|
||||
|
||||
float meters = float(millimeters) / 1000.0;
|
||||
ESP_LOGV(TAG, "Distance from sensor: %d mm, %f m", millimeters, meters);
|
||||
this->publish_state(meters);
|
||||
|
||||
@@ -80,8 +80,6 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||
TEMPLATABLE_VALUE(std::string, url)
|
||||
TEMPLATABLE_VALUE(const char *, method)
|
||||
TEMPLATABLE_VALUE(std::string, body)
|
||||
TEMPLATABLE_VALUE(const char *, useragent)
|
||||
TEMPLATABLE_VALUE(uint16_t, timeout)
|
||||
|
||||
void add_header(const char *key, TemplatableValue<const char *, Ts...> value) { this->headers_.insert({key, value}); }
|
||||
|
||||
@@ -105,25 +103,18 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||
auto f = std::bind(&HttpRequestSendAction<Ts...>::encode_json_func_, this, x..., std::placeholders::_1);
|
||||
this->parent_->set_body(json::build_json(f));
|
||||
}
|
||||
if (this->useragent_.has_value()) {
|
||||
this->parent_->set_useragent(this->useragent_.value(x...));
|
||||
}
|
||||
if (this->timeout_.has_value()) {
|
||||
this->parent_->set_timeout(this->timeout_.value(x...));
|
||||
}
|
||||
if (!this->headers_.empty()) {
|
||||
std::list<Header> headers;
|
||||
for (const auto &item : this->headers_) {
|
||||
auto val = item.second;
|
||||
Header header;
|
||||
header.name = item.first;
|
||||
header.value = val.value(x...);
|
||||
headers.push_back(header);
|
||||
}
|
||||
this->parent_->set_headers(headers);
|
||||
std::list<Header> headers;
|
||||
for (const auto &item : this->headers_) {
|
||||
auto val = item.second;
|
||||
Header header;
|
||||
header.name = item.first;
|
||||
header.value = val.value(x...);
|
||||
headers.push_back(header);
|
||||
}
|
||||
this->parent_->set_headers(headers);
|
||||
this->parent_->send(this->response_triggers_);
|
||||
this->parent_->close();
|
||||
this->parent_->set_body("");
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -11,7 +11,11 @@ static const uint8_t HTU21D_ADDRESS = 0x40;
|
||||
static const uint8_t HTU21D_REGISTER_RESET = 0xFE;
|
||||
static const uint8_t HTU21D_REGISTER_TEMPERATURE = 0xF3;
|
||||
static const uint8_t HTU21D_REGISTER_HUMIDITY = 0xF5;
|
||||
static const uint8_t HTU21D_WRITERHT_REG_CMD = 0xE6; /**< Write RH/T User Register 1 */
|
||||
static const uint8_t HTU21D_REGISTER_STATUS = 0xE7;
|
||||
static const uint8_t HTU21D_WRITEHEATER_REG_CMD = 0x51; /**< Write Heater Control Register */
|
||||
static const uint8_t HTU21D_READHEATER_REG_CMD = 0x11; /**< Read Heater Control Register */
|
||||
static const uint8_t HTU21D_REG_HTRE_BIT = 0x02; /**< Control Register Heater Bit */
|
||||
|
||||
void HTU21DComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up HTU21D...");
|
||||
@@ -62,14 +66,66 @@ void HTU21DComponent::update() {
|
||||
raw_humidity = i2c::i2ctohs(raw_humidity);
|
||||
|
||||
float humidity = (float(raw_humidity & 0xFFFC)) * 125.0f / 65536.0f - 6.0f;
|
||||
ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%%", temperature, humidity);
|
||||
|
||||
int8_t heater_level = this->get_heater_level();
|
||||
|
||||
ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%% Heater Level=%d", temperature, humidity, heater_level);
|
||||
|
||||
if (this->temperature_ != nullptr)
|
||||
this->temperature_->publish_state(temperature);
|
||||
if (this->humidity_ != nullptr)
|
||||
this->humidity_->publish_state(humidity);
|
||||
if (this->heater_ != nullptr)
|
||||
this->heater_->publish_state(humidity);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
bool HTU21DComponent::is_heater_enabled() {
|
||||
uint8_t raw_heater;
|
||||
if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return false;
|
||||
}
|
||||
raw_heater = i2c::i2ctohs(raw_heater);
|
||||
return (bool) (((raw_heater) >> (HTU21D_REG_HTRE_BIT)) & 0x01);
|
||||
}
|
||||
|
||||
void HTU21DComponent::set_heater(bool status) {
|
||||
uint8_t raw_heater;
|
||||
if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
raw_heater = i2c::i2ctohs(raw_heater);
|
||||
if (status) {
|
||||
raw_heater |= (1 << (HTU21D_REG_HTRE_BIT));
|
||||
} else {
|
||||
raw_heater &= ~(1 << (HTU21D_REG_HTRE_BIT));
|
||||
}
|
||||
|
||||
if (this->write_register(HTU21D_WRITERHT_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void HTU21DComponent::set_heater_level(uint8_t level) {
|
||||
if (this->write_register(HTU21D_WRITEHEATER_REG_CMD, &level, 1) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int8_t HTU21DComponent::get_heater_level() {
|
||||
int8_t raw_heater;
|
||||
if (this->read_register(HTU21D_READHEATER_REG_CMD, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
return 0;
|
||||
}
|
||||
raw_heater = i2c::i2ctohs(raw_heater);
|
||||
return raw_heater;
|
||||
}
|
||||
|
||||
float HTU21DComponent::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
} // namespace htu21d
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/core/automation.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace htu21d {
|
||||
@@ -11,6 +12,7 @@ class HTU21DComponent : public PollingComponent, public i2c::I2CDevice {
|
||||
public:
|
||||
void set_temperature(sensor::Sensor *temperature) { temperature_ = temperature; }
|
||||
void set_humidity(sensor::Sensor *humidity) { humidity_ = humidity; }
|
||||
void set_heater(sensor::Sensor *heater) { heater_ = heater; }
|
||||
|
||||
/// Setup (reset) the sensor and check connection.
|
||||
void setup() override;
|
||||
@@ -18,11 +20,39 @@ class HTU21DComponent : public PollingComponent, public i2c::I2CDevice {
|
||||
/// Update the sensor values (temperature+humidity).
|
||||
void update() override;
|
||||
|
||||
bool is_heater_enabled();
|
||||
void set_heater(bool status);
|
||||
void set_heater_level(uint8_t level);
|
||||
int8_t get_heater_level();
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
protected:
|
||||
sensor::Sensor *temperature_{nullptr};
|
||||
sensor::Sensor *humidity_{nullptr};
|
||||
sensor::Sensor *heater_{nullptr};
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetHeaterLevelAction : public Action<Ts...>, public Parented<HTU21DComponent> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(uint8_t, level)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto level = this->level_.value(x...);
|
||||
|
||||
this->parent_->set_heater_level(level);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetHeaterAction : public Action<Ts...>, public Parented<HTU21DComponent> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(bool, status)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto status = this->status_.value(x...);
|
||||
|
||||
this->parent_->set_heater(status);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace htu21d
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
from esphome import automation
|
||||
from esphome.const import (
|
||||
CONF_HUMIDITY,
|
||||
CONF_ID,
|
||||
@@ -10,6 +11,10 @@ from esphome.const import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_PERCENT,
|
||||
CONF_HEATER,
|
||||
UNIT_EMPTY,
|
||||
CONF_LEVEL,
|
||||
CONF_STATUS,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
@@ -19,22 +24,31 @@ HTU21DComponent = htu21d_ns.class_(
|
||||
"HTU21DComponent", cg.PollingComponent, i2c.I2CDevice
|
||||
)
|
||||
|
||||
SetHeaterLevelAction = htu21d_ns.class_("SetHeaterLevelAction", automation.Action)
|
||||
SetHeaterAction = htu21d_ns.class_("SetHeaterAction", automation.Action)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(HTU21DComponent),
|
||||
cv.Required(CONF_TEMPERATURE): sensor.sensor_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,
|
||||
),
|
||||
cv.Required(CONF_HUMIDITY): sensor.sensor_schema(
|
||||
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,
|
||||
),
|
||||
cv.Optional(CONF_HEATER): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_EMPTY,
|
||||
accuracy_decimals=1,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
@@ -54,3 +68,45 @@ async def to_code(config):
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
|
||||
cg.add(var.set_humidity(sens))
|
||||
|
||||
if CONF_HEATER in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HEATER])
|
||||
cg.add(var.set_heater(sens))
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"htu21d.set_heater_level",
|
||||
SetHeaterLevelAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(HTU21DComponent),
|
||||
cv.Required(CONF_LEVEL): cv.templatable(cv.int_),
|
||||
},
|
||||
key=CONF_LEVEL,
|
||||
),
|
||||
)
|
||||
async def set_heater_level_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
level_ = await cg.templatable(config[CONF_LEVEL], args, int)
|
||||
cg.add(var.set_level(level_))
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"htu21d.set_heater",
|
||||
SetHeaterAction,
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(HTU21DComponent),
|
||||
cv.Required(CONF_STATUS): cv.templatable(cv.boolean),
|
||||
},
|
||||
key=CONF_STATUS,
|
||||
),
|
||||
)
|
||||
async def set_heater_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
status_ = await cg.templatable(config[CONF_LEVEL], args, bool)
|
||||
cg.add(var.set_status(status_))
|
||||
return var
|
||||
|
||||
@@ -42,23 +42,26 @@ pin_with_input_and_output_support = cv.All(
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): _bus_declare_type,
|
||||
cv.Optional(CONF_SDA, default="SDA"): pin_with_input_and_output_support,
|
||||
cv.SplitDefault(CONF_SDA_PULLUP_ENABLED, esp32_idf=True): cv.All(
|
||||
cv.only_with_esp_idf, cv.boolean
|
||||
),
|
||||
cv.Optional(CONF_SCL, default="SCL"): pin_with_input_and_output_support,
|
||||
cv.SplitDefault(CONF_SCL_PULLUP_ENABLED, esp32_idf=True): cv.All(
|
||||
cv.only_with_esp_idf, cv.boolean
|
||||
),
|
||||
cv.Optional(CONF_FREQUENCY, default="50kHz"): cv.All(
|
||||
cv.frequency, cv.Range(min=0, min_included=False)
|
||||
),
|
||||
cv.Optional(CONF_SCAN, default=True): cv.boolean,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): _bus_declare_type,
|
||||
cv.Optional(CONF_SDA, default="SDA"): pin_with_input_and_output_support,
|
||||
cv.SplitDefault(CONF_SDA_PULLUP_ENABLED, esp32_idf=True): cv.All(
|
||||
cv.only_with_esp_idf, cv.boolean
|
||||
),
|
||||
cv.Optional(CONF_SCL, default="SCL"): pin_with_input_and_output_support,
|
||||
cv.SplitDefault(CONF_SCL_PULLUP_ENABLED, esp32_idf=True): cv.All(
|
||||
cv.only_with_esp_idf, cv.boolean
|
||||
),
|
||||
cv.Optional(CONF_FREQUENCY, default="50kHz"): cv.All(
|
||||
cv.frequency, cv.Range(min=0, min_included=False)
|
||||
),
|
||||
cv.Optional(CONF_SCAN, default=True): cv.boolean,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
cv.only_on(["esp32", "esp8266", "rp2040"]),
|
||||
)
|
||||
|
||||
|
||||
@coroutine_with_priority(1.0)
|
||||
|
||||
@@ -202,11 +202,13 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
err = i2c_master_stop(cmd);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGVV(TAG, "TX to %02X master stop failed: %s", address, esp_err_to_name(err));
|
||||
i2c_cmd_link_delete(cmd);
|
||||
return ERROR_UNKNOWN;
|
||||
if (stop) {
|
||||
err = i2c_master_stop(cmd);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGVV(TAG, "TX to %02X master stop failed: %s", address, esp_err_to_name(err));
|
||||
i2c_cmd_link_delete(cmd);
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
err = i2c_master_cmd_begin(port_, cmd, 20 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
@@ -51,7 +51,7 @@ class I2SAudioSpeaker : public Component, public speaker::Speaker, public I2SAud
|
||||
#endif
|
||||
void set_external_dac_channels(uint8_t channels) { this->external_dac_channels_ = channels; }
|
||||
|
||||
void start();
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
size_t play(const uint8_t *data, size_t length) override;
|
||||
|
||||
@@ -25,7 +25,7 @@ def AUTO_LOAD():
|
||||
return []
|
||||
|
||||
|
||||
CODEOWNERS = ["@nielsnl68"]
|
||||
CODEOWNERS = ["@nielsnl68", "@clydebarrow"]
|
||||
|
||||
ili9XXX_ns = cg.esphome_ns.namespace("ili9xxx")
|
||||
ili9XXXSPI = ili9XXX_ns.class_(
|
||||
@@ -42,6 +42,7 @@ MODELS = {
|
||||
"ILI9341": ili9XXX_ns.class_("ILI9XXXILI9341", ili9XXXSPI),
|
||||
"ILI9342": ili9XXX_ns.class_("ILI9XXXILI9342", ili9XXXSPI),
|
||||
"ILI9481": ili9XXX_ns.class_("ILI9XXXILI9481", ili9XXXSPI),
|
||||
"ILI9481-18": ili9XXX_ns.class_("ILI9XXXILI948118", ili9XXXSPI),
|
||||
"ILI9486": ili9XXX_ns.class_("ILI9XXXILI9486", ili9XXXSPI),
|
||||
"ILI9488": ili9XXX_ns.class_("ILI9XXXILI9488", ili9XXXSPI),
|
||||
"ILI9488_A": ili9XXX_ns.class_("ILI9XXXILI9488A", ili9XXXSPI),
|
||||
@@ -140,8 +141,6 @@ async def to_code(config):
|
||||
rhs = []
|
||||
for x in range(256):
|
||||
rhs.extend([HexInt(x), HexInt(x), HexInt(x)])
|
||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||
cg.add(var.set_palette(prog_arr))
|
||||
elif config[CONF_COLOR_PALETTE] == "IMAGE_ADAPTIVE":
|
||||
cg.add(var.set_buffer_color_mode(ILI9XXXColorMode.BITS_8_INDEXED))
|
||||
from PIL import Image
|
||||
@@ -178,6 +177,4 @@ async def to_code(config):
|
||||
if rhs is not None:
|
||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||
cg.add(var.set_palette(prog_arr))
|
||||
|
||||
spi_data_rate = str(spi.SPI_DATA_RATE_OPTIONS[config[CONF_DATA_RATE]])
|
||||
cg.add_define("ILI9XXXDisplay_DATA_RATE", cg.RawExpression(spi_data_rate))
|
||||
cg.add(var.set_data_rate(config[CONF_DATA_RATE]))
|
||||
|
||||
@@ -59,6 +59,7 @@ void ILI9XXXDisplay::dump_config() {
|
||||
if (this->is_18bitdisplay_) {
|
||||
ESP_LOGCONFIG(TAG, " 18-Bit Mode: YES");
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Data rate: %dMHz", (unsigned) (this->data_rate_ / 1000000));
|
||||
|
||||
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||
LOG_PIN(" DC Pin: ", this->dc_pin_);
|
||||
@@ -387,6 +388,17 @@ void ILI9XXXILI9481::initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
void ILI9XXXILI948118::initialize() {
|
||||
this->init_lcd_(INITCMD_ILI9481_18);
|
||||
if (this->width_ == 0) {
|
||||
this->width_ = 320;
|
||||
}
|
||||
if (this->height_ == 0) {
|
||||
this->height_ = 480;
|
||||
}
|
||||
this->is_18bitdisplay_ = true;
|
||||
}
|
||||
|
||||
// 35_TFT display
|
||||
void ILI9XXXILI9486::initialize() {
|
||||
this->init_lcd_(INITCMD_ILI9486);
|
||||
|
||||
@@ -120,6 +120,12 @@ class ILI9XXXILI9481 : public ILI9XXXDisplay {
|
||||
void initialize() override;
|
||||
};
|
||||
|
||||
//----------- ILI9481 in 18 bit mode --------------
|
||||
class ILI9XXXILI948118 : public ILI9XXXDisplay {
|
||||
protected:
|
||||
void initialize() override;
|
||||
};
|
||||
|
||||
//----------- ILI9XXX_35_TFT rotated display --------------
|
||||
class ILI9XXXILI9486 : public ILI9XXXDisplay {
|
||||
protected:
|
||||
|
||||
@@ -94,12 +94,36 @@ static const uint8_t PROGMEM INITCMD_ILI9481[] = {
|
||||
ILI9XXX_IFCTR , 1, 0x83,
|
||||
ILI9XXX_GMCTR ,12, 0x00, 0x26, 0x21, 0x00, 0x00, 0x1F, 0x65, 0x23, 0x77, 0x00, 0x0F, 0x00,
|
||||
ILI9XXX_IFMODE , 1, 0x00, // CommandAccessProtect
|
||||
ILI9XXX_PTLAR , 4, 0, 0, 1, 0xDF,
|
||||
0xE4 , 1, 0xA0,
|
||||
ILI9XXX_MADCTL , 1, MADCTL_MV | MADCTL_BGR, // Memory Access Control
|
||||
ILI9XXX_CSCON , 1, 0x01,
|
||||
ILI9XXX_PIXFMT, 1, 0x55, // 16 bit mode
|
||||
ILI9XXX_INVON, 0,
|
||||
ILI9XXX_DISPON, 0x80, // Set display on
|
||||
0x00 // end
|
||||
};
|
||||
|
||||
static const uint8_t PROGMEM INITCMD_ILI9481_18[] = {
|
||||
ILI9XXX_SLPOUT , 0x80, // Exit sleep mode
|
||||
ILI9XXX_PWSET , 3, 0x07, 0x41, 0x1D,
|
||||
ILI9XXX_VMCTR , 3, 0x00, 0x1C, 0x1F,
|
||||
ILI9XXX_PWSETN , 2, 0x01, 0x11,
|
||||
ILI9XXX_PWCTR1 , 5, 0x10, 0x3B, 0x00, 0x02, 0x11,
|
||||
ILI9XXX_VMCTR1 , 1, 0x03,
|
||||
ILI9XXX_IFCTR , 1, 0x83,
|
||||
ILI9XXX_GMCTR ,12, 0x00, 0x26, 0x21, 0x00, 0x00, 0x1F, 0x65, 0x23, 0x77, 0x00, 0x0F, 0x00,
|
||||
ILI9XXX_IFMODE , 1, 0x00, // CommandAccessProtect
|
||||
ILI9XXX_PTLAR , 4, 0, 0, 1, 0xDF,
|
||||
0xE4 , 1, 0xA0,
|
||||
ILI9XXX_MADCTL , 1, MADCTL_MX| MADCTL_BGR, // Memory Access Control
|
||||
ILI9XXX_CSCON , 1, 0x01,
|
||||
ILI9XXX_PIXFMT, 1, 0x66, // 18 bit mode
|
||||
ILI9XXX_INVON, 0,
|
||||
ILI9XXX_DISPON, 0x80, // Set display on
|
||||
0x00 // end
|
||||
};
|
||||
|
||||
static const uint8_t PROGMEM INITCMD_ILI9486[] = {
|
||||
ILI9XXX_SLPOUT, 0x80,
|
||||
ILI9XXX_PIXFMT, 1, 0x55,
|
||||
|
||||
@@ -52,7 +52,7 @@ Image_ = image_ns.class_("Image")
|
||||
|
||||
|
||||
def _compute_local_icon_path(value) -> Path:
|
||||
base_dir = Path(CORE.config_dir) / ".esphome" / DOMAIN / "mdi"
|
||||
base_dir = Path(CORE.data_dir) / DOMAIN / "mdi"
|
||||
return base_dir / f"{value[CONF_ICON]}.svg"
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ uint8_t ImprovSerialComponent::read_byte_() {
|
||||
this->hw_serial_->readBytes(&data, 1);
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
uart_read_bytes(this->uart_num_, &data, 1, 20 / portTICK_RATE_MS);
|
||||
uart_read_bytes(this->uart_num_, &data, 1, 20 / portTICK_PERIOD_MS);
|
||||
#endif
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ from esphome.const import (
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
CODEOWNERS = ["@MrEditor97"]
|
||||
CODEOWNERS = ["@mreditor97"]
|
||||
|
||||
ina260_ns = cg.esphome_ns.namespace("ina260")
|
||||
INA260Component = ina260_ns.class_(
|
||||
|
||||
@@ -29,6 +29,8 @@ std::string build_json(const json_build_t &f) {
|
||||
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
|
||||
#elif defined(USE_RP2040)
|
||||
const size_t free_heap = rp2040.getFreeHeap();
|
||||
#elif defined(USE_LIBRETINY)
|
||||
const size_t free_heap = lt_heap_get_free();
|
||||
#endif
|
||||
|
||||
size_t request_size = std::min(free_heap, (size_t) 512);
|
||||
@@ -71,6 +73,8 @@ void parse_json(const std::string &data, const json_parse_t &f) {
|
||||
const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
|
||||
#elif defined(USE_RP2040)
|
||||
const size_t free_heap = rp2040.getFreeHeap();
|
||||
#elif defined(USE_LIBRETINY)
|
||||
const size_t free_heap = lt_heap_get_free();
|
||||
#endif
|
||||
bool pass = false;
|
||||
size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5));
|
||||
|
||||
@@ -1,113 +1,64 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID, CONF_TIMEOUT
|
||||
from esphome.const import CONF_ID, CONF_THROTTLE, CONF_TIMEOUT, CONF_PASSWORD
|
||||
from esphome import automation
|
||||
from esphome.automation import maybe_simple_id
|
||||
|
||||
DEPENDENCIES = ["uart"]
|
||||
CODEOWNERS = ["@sebcaps"]
|
||||
CODEOWNERS = ["@sebcaps", "@regevbr"]
|
||||
MULTI_CONF = True
|
||||
|
||||
ld2410_ns = cg.esphome_ns.namespace("ld2410")
|
||||
LD2410Component = ld2410_ns.class_("LD2410Component", cg.Component, uart.UARTDevice)
|
||||
LD2410Restart = ld2410_ns.class_("LD2410Restart", automation.Action)
|
||||
|
||||
CONF_LD2410_ID = "ld2410_id"
|
||||
|
||||
CONF_MAX_MOVE_DISTANCE = "max_move_distance"
|
||||
CONF_MAX_STILL_DISTANCE = "max_still_distance"
|
||||
CONF_G0_MOVE_THRESHOLD = "g0_move_threshold"
|
||||
CONF_G0_STILL_THRESHOLD = "g0_still_threshold"
|
||||
CONF_G1_MOVE_THRESHOLD = "g1_move_threshold"
|
||||
CONF_G1_STILL_THRESHOLD = "g1_still_threshold"
|
||||
CONF_G2_MOVE_THRESHOLD = "g2_move_threshold"
|
||||
CONF_G2_STILL_THRESHOLD = "g2_still_threshold"
|
||||
CONF_G3_MOVE_THRESHOLD = "g3_move_threshold"
|
||||
CONF_G3_STILL_THRESHOLD = "g3_still_threshold"
|
||||
CONF_G4_MOVE_THRESHOLD = "g4_move_threshold"
|
||||
CONF_G4_STILL_THRESHOLD = "g4_still_threshold"
|
||||
CONF_G5_MOVE_THRESHOLD = "g5_move_threshold"
|
||||
CONF_G5_STILL_THRESHOLD = "g5_still_threshold"
|
||||
CONF_G6_MOVE_THRESHOLD = "g6_move_threshold"
|
||||
CONF_G6_STILL_THRESHOLD = "g6_still_threshold"
|
||||
CONF_G7_MOVE_THRESHOLD = "g7_move_threshold"
|
||||
CONF_G7_STILL_THRESHOLD = "g7_still_threshold"
|
||||
CONF_G8_MOVE_THRESHOLD = "g8_move_threshold"
|
||||
CONF_G8_STILL_THRESHOLD = "g8_still_threshold"
|
||||
CONF_STILL_THRESHOLDS = [f"g{x}_still_threshold" for x in range(9)]
|
||||
CONF_MOVE_THRESHOLDS = [f"g{x}_move_threshold" for x in range(9)]
|
||||
|
||||
DISTANCES = [0.75, 1.5, 2.25, 3, 3.75, 4.5, 5.25, 6]
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(LD2410Component),
|
||||
cv.Optional(CONF_THROTTLE, default="1000ms"): cv.All(
|
||||
cv.positive_time_period_milliseconds,
|
||||
cv.Range(min=cv.TimePeriod(milliseconds=1)),
|
||||
),
|
||||
cv.Optional(CONF_MAX_MOVE_DISTANCE): cv.invalid(
|
||||
f"The '{CONF_MAX_MOVE_DISTANCE}' option has been moved to the '{CONF_MAX_MOVE_DISTANCE}'"
|
||||
f" number component"
|
||||
),
|
||||
cv.Optional(CONF_MAX_STILL_DISTANCE): cv.invalid(
|
||||
f"The '{CONF_MAX_STILL_DISTANCE}' option has been moved to the '{CONF_MAX_STILL_DISTANCE}'"
|
||||
f" number component"
|
||||
),
|
||||
cv.Optional(CONF_TIMEOUT): cv.invalid(
|
||||
f"The '{CONF_TIMEOUT}' option has been moved to the '{CONF_TIMEOUT}'"
|
||||
f" number component"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
for i in range(9):
|
||||
CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_MOVE_THRESHOLDS[i]): cv.invalid(
|
||||
f"The '{CONF_MOVE_THRESHOLDS[i]}' option has been moved to the '{CONF_MOVE_THRESHOLDS[i]}'"
|
||||
f" number component"
|
||||
),
|
||||
cv.Optional(CONF_STILL_THRESHOLDS[i]): cv.invalid(
|
||||
f"The '{CONF_STILL_THRESHOLDS[i]}' option has been moved to the '{CONF_STILL_THRESHOLDS[i]}'"
|
||||
f" number component"
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(LD2410Component),
|
||||
cv.Optional(CONF_MAX_MOVE_DISTANCE, default="4.5m"): cv.All(
|
||||
cv.distance, cv.one_of(*DISTANCES, float=True)
|
||||
),
|
||||
cv.Optional(CONF_MAX_STILL_DISTANCE, default="4.5m"): cv.All(
|
||||
cv.distance, cv.one_of(*DISTANCES, float=True)
|
||||
),
|
||||
cv.Optional(CONF_TIMEOUT, default="5s"): cv.All(
|
||||
cv.positive_time_period_seconds,
|
||||
cv.Range(max=cv.TimePeriod(seconds=32767)),
|
||||
),
|
||||
cv.Optional(CONF_G0_MOVE_THRESHOLD, default=50): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G0_STILL_THRESHOLD, default=0): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G1_MOVE_THRESHOLD, default=50): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G1_STILL_THRESHOLD, default=0): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G2_MOVE_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G2_STILL_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G3_MOVE_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G3_STILL_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G4_MOVE_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G4_STILL_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G5_MOVE_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G5_STILL_THRESHOLD, default=40): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G6_MOVE_THRESHOLD, default=30): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G6_STILL_THRESHOLD, default=15): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G7_MOVE_THRESHOLD, default=30): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G7_STILL_THRESHOLD, default=15): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G8_MOVE_THRESHOLD, default=30): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
cv.Optional(CONF_G8_STILL_THRESHOLD, default=15): cv.int_range(
|
||||
min=0, max=100
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
CONFIG_SCHEMA.extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||
@@ -123,31 +74,7 @@ async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
cg.add(var.set_timeout(config[CONF_TIMEOUT]))
|
||||
cg.add(var.set_max_move_distance(int(config[CONF_MAX_MOVE_DISTANCE] / 0.75)))
|
||||
cg.add(var.set_max_still_distance(int(config[CONF_MAX_STILL_DISTANCE] / 0.75)))
|
||||
cg.add(
|
||||
var.set_range_config(
|
||||
config[CONF_G0_MOVE_THRESHOLD],
|
||||
config[CONF_G0_STILL_THRESHOLD],
|
||||
config[CONF_G1_MOVE_THRESHOLD],
|
||||
config[CONF_G1_STILL_THRESHOLD],
|
||||
config[CONF_G2_MOVE_THRESHOLD],
|
||||
config[CONF_G2_STILL_THRESHOLD],
|
||||
config[CONF_G3_MOVE_THRESHOLD],
|
||||
config[CONF_G3_STILL_THRESHOLD],
|
||||
config[CONF_G4_MOVE_THRESHOLD],
|
||||
config[CONF_G4_STILL_THRESHOLD],
|
||||
config[CONF_G5_MOVE_THRESHOLD],
|
||||
config[CONF_G5_STILL_THRESHOLD],
|
||||
config[CONF_G6_MOVE_THRESHOLD],
|
||||
config[CONF_G6_STILL_THRESHOLD],
|
||||
config[CONF_G7_MOVE_THRESHOLD],
|
||||
config[CONF_G7_STILL_THRESHOLD],
|
||||
config[CONF_G8_MOVE_THRESHOLD],
|
||||
config[CONF_G8_STILL_THRESHOLD],
|
||||
)
|
||||
)
|
||||
cg.add(var.set_throttle(config[CONF_THROTTLE]))
|
||||
|
||||
|
||||
CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
|
||||
@@ -155,3 +82,28 @@ CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
|
||||
cv.Required(CONF_ID): cv.use_id(LD2410Component),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# Actions
|
||||
BluetoothPasswordSetAction = ld2410_ns.class_(
|
||||
"BluetoothPasswordSetAction", automation.Action
|
||||
)
|
||||
|
||||
|
||||
BLUETOOTH_PASSWORD_SET_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(LD2410Component),
|
||||
cv.Required(CONF_PASSWORD): cv.templatable(cv.string_strict),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"bluetooth_password.set", BluetoothPasswordSetAction, BLUETOOTH_PASSWORD_SET_SCHEMA
|
||||
)
|
||||
async def bluetooth_password_set_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
template_ = await cg.templatable(config[CONF_PASSWORD], args, cg.std_string)
|
||||
cg.add(var.set_password(template_))
|
||||
return var
|
||||
|
||||
22
esphome/components/ld2410/automation.h
Normal file
22
esphome/components/ld2410/automation.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "ld2410.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
template<typename... Ts> class BluetoothPasswordSetAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit BluetoothPasswordSetAction(LD2410Component *ld2410_comp) : ld2410_comp_(ld2410_comp) {}
|
||||
TEMPLATABLE_VALUE(std::string, password)
|
||||
|
||||
void play(Ts... x) override { this->ld2410_comp_->set_bluetooth_password(this->password_.value(x...)); }
|
||||
|
||||
protected:
|
||||
LD2410Component *ld2410_comp_;
|
||||
};
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
@@ -1,36 +1,55 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_MOTION,
|
||||
DEVICE_CLASS_OCCUPANCY,
|
||||
DEVICE_CLASS_PRESENCE,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
ICON_MOTION_SENSOR,
|
||||
ICON_ACCOUNT,
|
||||
)
|
||||
from . import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
DEPENDENCIES = ["ld2410"]
|
||||
CONF_HAS_TARGET = "has_target"
|
||||
CONF_HAS_MOVING_TARGET = "has_moving_target"
|
||||
CONF_HAS_STILL_TARGET = "has_still_target"
|
||||
CONF_OUT_PIN_PRESENCE_STATUS = "out_pin_presence_status"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Optional(CONF_HAS_TARGET): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_OCCUPANCY
|
||||
device_class=DEVICE_CLASS_OCCUPANCY,
|
||||
icon=ICON_ACCOUNT,
|
||||
),
|
||||
cv.Optional(CONF_HAS_MOVING_TARGET): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_MOTION
|
||||
device_class=DEVICE_CLASS_MOTION,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Optional(CONF_HAS_STILL_TARGET): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_OCCUPANCY
|
||||
device_class=DEVICE_CLASS_OCCUPANCY,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Optional(CONF_OUT_PIN_PRESENCE_STATUS): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_PRESENCE,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_ACCOUNT,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
ld2410_component = await cg.get_variable(config[CONF_LD2410_ID])
|
||||
if CONF_HAS_TARGET in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_TARGET])
|
||||
cg.add(ld2410_component.set_target_sensor(sens))
|
||||
if CONF_HAS_MOVING_TARGET in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_MOVING_TARGET])
|
||||
cg.add(ld2410_component.set_moving_target_sensor(sens))
|
||||
if CONF_HAS_STILL_TARGET in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_STILL_TARGET])
|
||||
cg.add(ld2410_component.set_still_target_sensor(sens))
|
||||
if has_target_config := config.get(CONF_HAS_TARGET):
|
||||
sens = await binary_sensor.new_binary_sensor(has_target_config)
|
||||
cg.add(ld2410_component.set_target_binary_sensor(sens))
|
||||
if has_moving_target_config := config.get(CONF_HAS_MOVING_TARGET):
|
||||
sens = await binary_sensor.new_binary_sensor(has_moving_target_config)
|
||||
cg.add(ld2410_component.set_moving_target_binary_sensor(sens))
|
||||
if has_still_target_config := config.get(CONF_HAS_STILL_TARGET):
|
||||
sens = await binary_sensor.new_binary_sensor(has_still_target_config)
|
||||
cg.add(ld2410_component.set_still_target_binary_sensor(sens))
|
||||
if out_pin_presence_status_config := config.get(CONF_OUT_PIN_PRESENCE_STATUS):
|
||||
sens = await binary_sensor.new_binary_sensor(out_pin_presence_status_config)
|
||||
cg.add(ld2410_component.set_out_pin_presence_status_binary_sensor(sens))
|
||||
|
||||
57
esphome/components/ld2410/button/__init__.py
Normal file
57
esphome/components/ld2410/button/__init__.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_RESTART,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
ICON_RESTART,
|
||||
ICON_RESTART_ALERT,
|
||||
ICON_DATABASE,
|
||||
)
|
||||
from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns
|
||||
|
||||
QueryButton = ld2410_ns.class_("QueryButton", button.Button)
|
||||
ResetButton = ld2410_ns.class_("ResetButton", button.Button)
|
||||
RestartButton = ld2410_ns.class_("RestartButton", button.Button)
|
||||
|
||||
CONF_FACTORY_RESET = "factory_reset"
|
||||
CONF_RESTART = "restart"
|
||||
CONF_QUERY_PARAMS = "query_params"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
ResetButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_RESTART): button.button_schema(
|
||||
RestartButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_RESTART,
|
||||
),
|
||||
cv.Optional(CONF_QUERY_PARAMS): button.button_schema(
|
||||
QueryButton,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
ld2410_component = await cg.get_variable(config[CONF_LD2410_ID])
|
||||
if factory_reset_config := config.get(CONF_FACTORY_RESET):
|
||||
b = await button.new_button(factory_reset_config)
|
||||
await cg.register_parented(b, config[CONF_LD2410_ID])
|
||||
cg.add(ld2410_component.set_reset_button(b))
|
||||
if restart_config := config.get(CONF_RESTART):
|
||||
b = await button.new_button(restart_config)
|
||||
await cg.register_parented(b, config[CONF_LD2410_ID])
|
||||
cg.add(ld2410_component.set_restart_button(b))
|
||||
if query_params_config := config.get(CONF_QUERY_PARAMS):
|
||||
b = await button.new_button(query_params_config)
|
||||
await cg.register_parented(b, config[CONF_LD2410_ID])
|
||||
cg.add(ld2410_component.set_query_button(b))
|
||||
9
esphome/components/ld2410/button/query_button.cpp
Normal file
9
esphome/components/ld2410/button/query_button.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "query_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
void QueryButton::press_action() { this->parent_->read_all_info(); }
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
18
esphome/components/ld2410/button/query_button.h
Normal file
18
esphome/components/ld2410/button/query_button.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
class QueryButton : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
QueryButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
9
esphome/components/ld2410/button/reset_button.cpp
Normal file
9
esphome/components/ld2410/button/reset_button.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "reset_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
void ResetButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
18
esphome/components/ld2410/button/reset_button.h
Normal file
18
esphome/components/ld2410/button/reset_button.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
class ResetButton : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
ResetButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
9
esphome/components/ld2410/button/restart_button.cpp
Normal file
9
esphome/components/ld2410/button/restart_button.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "restart_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
|
||||
|
||||
} // namespace ld2410
|
||||
} // namespace esphome
|
||||
18
esphome/components/ld2410/button/restart_button.h
Normal file
18
esphome/components/ld2410/button/restart_button.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ld2410 {
|
||||
|
||||
class RestartButton : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
RestartButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace ld2410
|
||||
} // 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