mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 00:51:49 +00:00 
			
		
		
		
	Compare commits
	
		
			308 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					a7ad4482f0 | ||
| 
						 | 
					aa17661002 | ||
| 
						 | 
					4e65aac7ae | ||
| 
						 | 
					229ba18e6c | ||
| 
						 | 
					b99be250a0 | ||
| 
						 | 
					b9d4e2e501 | ||
| 
						 | 
					ef2531edf3 | ||
| 
						 | 
					eae3089201 | ||
| 
						 | 
					0ea4de5f4c | ||
| 
						 | 
					1e0daefa16 | ||
| 
						 | 
					6d991a1fc8 | ||
| 
						 | 
					a1845e1e72 | ||
| 
						 | 
					f96a839bcf | ||
| 
						 | 
					1282a15b14 | ||
| 
						 | 
					35039b45e4 | ||
| 
						 | 
					390766eb67 | ||
| 
						 | 
					899d280ac7 | ||
| 
						 | 
					96dc7f0259 | ||
| 
						 | 
					0104bf3fc8 | ||
| 
						 | 
					9b1e1bf56c | ||
| 
						 | 
					33e0f16b3b | ||
| 
						 | 
					0807d60c6a | ||
| 
						 | 
					f018fde369 | ||
| 
						 | 
					c47f8fc02c | ||
| 
						 | 
					76ab923780 | ||
| 
						 | 
					11dba3147d | ||
| 
						 | 
					8c2d9101d5 | ||
| 
						 | 
					61b8004536 | ||
| 
						 | 
					db02c4ea21 | ||
| 
						 | 
					f077a5962d | ||
| 
						 | 
					fa4ba43eb9 | ||
| 
						 | 
					9579423b24 | ||
| 
						 | 
					02449f24c9 | ||
| 
						 | 
					b973238323 | ||
| 
						 | 
					582b8383d2 | ||
| 
						 | 
					e1c9418aee | ||
| 
						 | 
					2aa787f5f0 | ||
| 
						 | 
					2189a40a39 | ||
| 
						 | 
					51688d4078 | ||
| 
						 | 
					cc4c0e3e0b | ||
| 
						 | 
					1a44c6487e | ||
| 
						 | 
					5e7ce610a0 | ||
| 
						 | 
					1f02096edb | ||
| 
						 | 
					fd7d3c4332 | ||
| 
						 | 
					61cf566560 | ||
| 
						 | 
					97d624114d | ||
| 
						 | 
					52e8a2e9e4 | ||
| 
						 | 
					261c271d60 | ||
| 
						 | 
					cb6e314336 | ||
| 
						 | 
					90315b3c40 | ||
| 
						 | 
					5d7c3d1622 | ||
| 
						 | 
					8c1ad1e9a6 | ||
| 
						 | 
					969f6dbe13 | ||
| 
						 | 
					6cce6d4c36 | ||
| 
						 | 
					d27e5e9c97 | ||
| 
						 | 
					af3b22f8b7 | ||
| 
						 | 
					cbc1b29f3e | ||
| 
						 | 
					f4ce8b8b6c | ||
| 
						 | 
					54363f1246 | ||
| 
						 | 
					11727391ad | ||
| 
						 | 
					d500531c04 | ||
| 
						 | 
					689dcd1e24 | ||
| 
						 | 
					2fc4e88271 | ||
| 
						 | 
					853d81c6dd | ||
| 
						 | 
					e35de626a4 | ||
| 
						 | 
					41f29c46d0 | ||
| 
						 | 
					9d95f5c1da | ||
| 
						 | 
					5d5cc96017 | ||
| 
						 | 
					c9a8911029 | ||
| 
						 | 
					c77a9ad363 | ||
| 
						 | 
					511af5845e | ||
| 
						 | 
					6b96089f02 | ||
| 
						 | 
					46be886ca6 | ||
| 
						 | 
					be7e167c63 | ||
| 
						 | 
					c65d78f568 | ||
| 
						 | 
					412a866de8 | ||
| 
						 | 
					e09c217fde | ||
| 
						 | 
					af62c2d9cf | ||
| 
						 | 
					aba3cd557a | ||
| 
						 | 
					7e7c83b3ca | ||
| 
						 | 
					ee4ccf2762 | ||
| 
						 | 
					fa0dcac2c7 | ||
| 
						 | 
					44e5b0c745 | ||
| 
						 | 
					b6d5cb4142 | ||
| 
						 | 
					4e8cba49f1 | ||
| 
						 | 
					506c2ba6c7 | ||
| 
						 | 
					050fa0d4c1 | ||
| 
						 | 
					88bb051f37 | ||
| 
						 | 
					0d800958aa | ||
| 
						 | 
					471533d041 | ||
| 
						 | 
					7dfc4c74da | ||
| 
						 | 
					f709350b04 | ||
| 
						 | 
					85c5928baa | ||
| 
						 | 
					f5dfbaff4b | ||
| 
						 | 
					689c2f11a3 | ||
| 
						 | 
					f73fd97525 | ||
| 
						 | 
					f38849828d | ||
| 
						 | 
					e95ba57a61 | ||
| 
						 | 
					4913256597 | ||
| 
						 | 
					401a386219 | ||
| 
						 | 
					205f41509b | ||
| 
						 | 
					e87c8d550b | ||
| 
						 | 
					a33b8abce8 | ||
| 
						 | 
					40523e6823 | ||
| 
						 | 
					5e1472185c | ||
| 
						 | 
					af005a6554 | ||
| 
						 | 
					efd31be21c | ||
| 
						 | 
					e9bda2810f | ||
| 
						 | 
					ec4777b8d0 | ||
| 
						 | 
					589b9e10b2 | ||
| 
						 | 
					2513ede3ec | ||
| 
						 | 
					0b5a57ead4 | ||
| 
						 | 
					b3dc2d43a5 | ||
| 
						 | 
					d3913be7e5 | ||
| 
						 | 
					2c94c3d96f | ||
| 
						 | 
					4d81153150 | ||
| 
						 | 
					507dc5f496 | ||
| 
						 | 
					4335543575 | ||
| 
						 | 
					9b75121337 | ||
| 
						 | 
					d262548d2e | ||
| 
						 | 
					b5b654e054 | ||
| 
						 | 
					dae8ab563c | ||
| 
						 | 
					12365976c4 | ||
| 
						 | 
					4ac4492241 | ||
| 
						 | 
					57b7dd0fa2 | ||
| 
						 | 
					9d4f471855 | ||
| 
						 | 
					5751e9ec59 | ||
| 
						 | 
					cc1b7a7a56 | ||
| 
						 | 
					29249cdc1b | ||
| 
						 | 
					e5bae8187f | ||
| 
						 | 
					69adebfefa | ||
| 
						 | 
					7dabbb65d0 | ||
| 
						 | 
					b30bab8c1b | ||
| 
						 | 
					5360e14a9c | ||
| 
						 | 
					86db559f6e | ||
| 
						 | 
					2f7a378c7b | ||
| 
						 | 
					607d0b4264 | ||
| 
						 | 
					0a1ed58454 | ||
| 
						 | 
					5f5ee9c920 | ||
| 
						 | 
					0aeebdd289 | ||
| 
						 | 
					33e2aa341e | ||
| 
						 | 
					a42788812e | ||
| 
						 | 
					b07a038bc8 | ||
| 
						 | 
					17e1d4c245 | ||
| 
						 | 
					a031cc3b84 | ||
| 
						 | 
					c34d5111fc | ||
| 
						 | 
					727056a28c | ||
| 
						 | 
					0ca8dcd08e | ||
| 
						 | 
					3c7c4e1dba | ||
| 
						 | 
					518ecb4cc4 | ||
| 
						 | 
					55e36ab982 | ||
| 
						 | 
					90835ab917 | ||
| 
						 | 
					5b46088ae4 | ||
| 
						 | 
					d7e267eca5 | ||
| 
						 | 
					807c47a076 | ||
| 
						 | 
					7ebe6a5894 | ||
| 
						 | 
					41c829fa32 | ||
| 
						 | 
					8f1ce8c7f7 | ||
| 
						 | 
					e55636ed52 | ||
| 
						 | 
					e886262055 | ||
| 
						 | 
					2fa7f8c511 | ||
| 
						 | 
					4622ef770d | ||
| 
						 | 
					d76f18b4f2 | ||
| 
						 | 
					ec20778d83 | ||
| 
						 | 
					b3ca71c6fb | ||
| 
						 | 
					1100f67b66 | ||
| 
						 | 
					056a28906b | ||
| 
						 | 
					2c2821cd96 | ||
| 
						 | 
					157a3e53dd | ||
| 
						 | 
					61edf8c196 | ||
| 
						 | 
					397f57ce74 | ||
| 
						 | 
					bf253c21fa | ||
| 
						 | 
					e3eef1cc6d | ||
| 
						 | 
					11f6e555f9 | ||
| 
						 | 
					164631fcec | ||
| 
						 | 
					a61e3fadf6 | ||
| 
						 | 
					b5f2d69ca5 | ||
| 
						 | 
					55b5c0fc32 | ||
| 
						 | 
					280b090dfc | ||
| 
						 | 
					2d53dd05d8 | ||
| 
						 | 
					9d97807587 | ||
| 
						 | 
					11433c8c17 | ||
| 
						 | 
					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 | ||
| 
						 | 
					c287e529a8 | ||
| 
						 | 
					164d05fdce | ||
| 
						 | 
					c11c4dad2f | ||
| 
						 | 
					0af8d0b7ea | ||
| 
						 | 
					2b4ed0c273 | ||
| 
						 | 
					9fc50e8dbc | ||
| 
						 | 
					c5be5e6d12 | ||
| 
						 | 
					63fc16d872 | ||
| 
						 | 
					5f99ed943a | ||
| 
						 | 
					5cb5594288 | ||
| 
						 | 
					87629191b3 | ||
| 
						 | 
					4a518e3e7a | ||
| 
						 | 
					6089526975 | ||
| 
						 | 
					b9e9223fdd | ||
| 
						 | 
					e963eedb64 | ||
| 
						 | 
					3b2c61e813 | ||
| 
						 | 
					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.1.0
 | 
			
		||||
      - name: Set up Python
 | 
			
		||||
        uses: actions/setup-python@v4
 | 
			
		||||
        uses: actions/setup-python@v4.7.1
 | 
			
		||||
        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: |
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										60
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										60
									
								
								.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.1.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.1
 | 
			
		||||
        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.1.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.1.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.1.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.1.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.1.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.1.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.1.0
 | 
			
		||||
      - name: Restore Python
 | 
			
		||||
        uses: ./.github/actions/restore-python
 | 
			
		||||
        with:
 | 
			
		||||
@@ -215,6 +210,17 @@ jobs:
 | 
			
		||||
        run: script/ci-suggest-changes
 | 
			
		||||
        if: always()
 | 
			
		||||
 | 
			
		||||
  compile-tests-list:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    outputs:
 | 
			
		||||
      matrix: ${{ steps.set-matrix.outputs.matrix }}
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Check out code from GitHub
 | 
			
		||||
        uses: actions/checkout@v4.1.0
 | 
			
		||||
      - name: Find all YAML test files
 | 
			
		||||
        id: set-matrix
 | 
			
		||||
        run: echo "matrix=$(ls tests/test*.yaml | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
 | 
			
		||||
 | 
			
		||||
  compile-tests:
 | 
			
		||||
    name: Run YAML test ${{ matrix.file }}
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
@@ -227,24 +233,24 @@ jobs:
 | 
			
		||||
      - pylint
 | 
			
		||||
      - pytest
 | 
			
		||||
      - pyupgrade
 | 
			
		||||
      - yamllint
 | 
			
		||||
      - compile-tests-list
 | 
			
		||||
    strategy:
 | 
			
		||||
      fail-fast: false
 | 
			
		||||
      max-parallel: 2
 | 
			
		||||
      matrix:
 | 
			
		||||
        file: [1, 2, 3, 3.1, 4, 5, 6, 7, 8]
 | 
			
		||||
        file: ${{ fromJson(needs.compile-tests-list.outputs.matrix) }}
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Check out code from GitHub
 | 
			
		||||
        uses: actions/checkout@v3.5.2
 | 
			
		||||
        uses: actions/checkout@v4.1.0
 | 
			
		||||
      - name: Restore Python
 | 
			
		||||
        uses: ./.github/actions/restore-python
 | 
			
		||||
        with:
 | 
			
		||||
          python-version: ${{ env.DEFAULT_PYTHON }}
 | 
			
		||||
          cache-key: ${{ needs.common.outputs.cache-key }}
 | 
			
		||||
      - name: Run esphome compile tests/test${{ matrix.file }}.yaml
 | 
			
		||||
      - name: Run esphome compile ${{ matrix.file }}
 | 
			
		||||
        run: |
 | 
			
		||||
          . venv/bin/activate
 | 
			
		||||
          esphome compile tests/test${{ matrix.file }}.yaml
 | 
			
		||||
          esphome compile ${{ matrix.file }}
 | 
			
		||||
 | 
			
		||||
  clang-tidy:
 | 
			
		||||
    name: ${{ matrix.name }}
 | 
			
		||||
@@ -258,7 +264,6 @@ jobs:
 | 
			
		||||
      - pylint
 | 
			
		||||
      - pytest
 | 
			
		||||
      - pyupgrade
 | 
			
		||||
      - yamllint
 | 
			
		||||
    strategy:
 | 
			
		||||
      fail-fast: false
 | 
			
		||||
      max-parallel: 2
 | 
			
		||||
@@ -291,14 +296,14 @@ jobs:
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Check out code from GitHub
 | 
			
		||||
        uses: actions/checkout@v3.5.2
 | 
			
		||||
        uses: actions/checkout@v4.1.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 +342,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.1.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.1.0
 | 
			
		||||
      - name: Set up Python
 | 
			
		||||
        uses: actions/setup-python@v4
 | 
			
		||||
        uses: actions/setup-python@v4.7.1
 | 
			
		||||
        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.1.0
 | 
			
		||||
      - name: Set up Python
 | 
			
		||||
        uses: actions/setup-python@v4
 | 
			
		||||
        uses: actions/setup-python@v4.7.1
 | 
			
		||||
        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.1.0
 | 
			
		||||
 | 
			
		||||
      - name: Checkout Home Assistant
 | 
			
		||||
        uses: actions/checkout@v3
 | 
			
		||||
        uses: actions/checkout@v4.1.0
 | 
			
		||||
        with:
 | 
			
		||||
          repository: home-assistant/core
 | 
			
		||||
          path: lib/home-assistant
 | 
			
		||||
 | 
			
		||||
      - name: Setup Python
 | 
			
		||||
        uses: actions/setup-python@v4
 | 
			
		||||
        uses: actions/setup-python@v4.7.1
 | 
			
		||||
        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.1.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:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								CODEOWNERS
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								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
 | 
			
		||||
@@ -146,7 +148,10 @@ esphome/components/kuntze/* @ssieb
 | 
			
		||||
esphome/components/lcd_menu/* @numo68
 | 
			
		||||
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
 | 
			
		||||
@@ -181,6 +186,7 @@ esphome/components/mitsubishi/* @RubyBailey
 | 
			
		||||
esphome/components/mlx90393/* @functionpointer
 | 
			
		||||
esphome/components/mlx90614/* @jesserockz
 | 
			
		||||
esphome/components/mmc5603/* @benhoff
 | 
			
		||||
esphome/components/mmc5983/* @agoode
 | 
			
		||||
esphome/components/modbus_controller/* @martgras
 | 
			
		||||
esphome/components/modbus_controller/binary_sensor/* @martgras
 | 
			
		||||
esphome/components/modbus_controller/number/* @martgras
 | 
			
		||||
@@ -212,13 +218,14 @@ 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
 | 
			
		||||
esphome/components/power_supply/* @esphome/core
 | 
			
		||||
esphome/components/preferences/* @esphome/core
 | 
			
		||||
esphome/components/psram/* @esphome/core
 | 
			
		||||
esphome/components/pulse_meter/* @cstaahl @stevebaxter
 | 
			
		||||
esphome/components/pulse_meter/* @TrentHouliston @cstaahl @stevebaxter
 | 
			
		||||
esphome/components/pvvx_mithermometer/* @pasiz
 | 
			
		||||
esphome/components/qmp6988/* @andrewpc
 | 
			
		||||
esphome/components/qr_code/* @wjtje
 | 
			
		||||
@@ -233,6 +240,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 +249,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
 | 
			
		||||
@@ -262,7 +271,9 @@ esphome/components/sn74hc165/* @jesserockz
 | 
			
		||||
esphome/components/socket/* @esphome/core
 | 
			
		||||
esphome/components/sonoff_d1/* @anatoly-savchenkov
 | 
			
		||||
esphome/components/speaker/* @jesserockz
 | 
			
		||||
esphome/components/spi/* @esphome/core
 | 
			
		||||
esphome/components/spi/* @clydebarrow @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 +334,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
 | 
			
		||||
 
 | 
			
		||||
@@ -26,16 +26,17 @@ RUN \
 | 
			
		||||
        python3-venv=3.9.2-3 \
 | 
			
		||||
        iputils-ping=3:20210202-1 \
 | 
			
		||||
        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; \
 | 
			
		||||
        curl=7.74.0-1.3+deb11u10 \
 | 
			
		||||
        openssh-client=1:8.4p1-5+deb11u2 \
 | 
			
		||||
        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 \
 | 
			
		||||
@@ -61,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,23 @@ 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}"
 | 
			
		||||
 | 
			
		||||
mkdir -p /config/esphome
 | 
			
		||||
 | 
			
		||||
if bashio::fs.directory_exists '/config/esphome/.esphome'; then
 | 
			
		||||
    bashio::log.info "Migrating old .esphome directory..."
 | 
			
		||||
    if bashio::fs.file_exists '/config/esphome/.esphome/esphome.json'; then
 | 
			
		||||
        mv /config/esphome/.esphome/esphome.json /data/esphome.json
 | 
			
		||||
    fi
 | 
			
		||||
    mkdir -p "/data/storage"
 | 
			
		||||
    mv /config/esphome/.esphome/*.json /data/storage/ || true
 | 
			
		||||
    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!")
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ from esphome.const import (
 | 
			
		||||
    CONF_TRIGGER_ID,
 | 
			
		||||
    CONF_TYPE_ID,
 | 
			
		||||
    CONF_TIME,
 | 
			
		||||
    CONF_UPDATE_INTERVAL,
 | 
			
		||||
)
 | 
			
		||||
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
 | 
			
		||||
from esphome.util import Registry
 | 
			
		||||
@@ -69,6 +70,8 @@ WhileAction = cg.esphome_ns.class_("WhileAction", Action)
 | 
			
		||||
RepeatAction = cg.esphome_ns.class_("RepeatAction", Action)
 | 
			
		||||
WaitUntilAction = cg.esphome_ns.class_("WaitUntilAction", Action, cg.Component)
 | 
			
		||||
UpdateComponentAction = cg.esphome_ns.class_("UpdateComponentAction", Action)
 | 
			
		||||
SuspendComponentAction = cg.esphome_ns.class_("SuspendComponentAction", Action)
 | 
			
		||||
ResumeComponentAction = cg.esphome_ns.class_("ResumeComponentAction", Action)
 | 
			
		||||
Automation = cg.esphome_ns.class_("Automation")
 | 
			
		||||
 | 
			
		||||
LambdaCondition = cg.esphome_ns.class_("LambdaCondition", Condition)
 | 
			
		||||
@@ -138,6 +141,7 @@ AUTOMATION_SCHEMA = cv.Schema(
 | 
			
		||||
AndCondition = cg.esphome_ns.class_("AndCondition", Condition)
 | 
			
		||||
OrCondition = cg.esphome_ns.class_("OrCondition", Condition)
 | 
			
		||||
NotCondition = cg.esphome_ns.class_("NotCondition", Condition)
 | 
			
		||||
XorCondition = cg.esphome_ns.class_("XorCondition", Condition)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_condition("and", AndCondition, validate_condition_list)
 | 
			
		||||
@@ -158,6 +162,12 @@ async def not_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    return cg.new_Pvariable(condition_id, template_arg, condition)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_condition("xor", XorCondition, validate_condition_list)
 | 
			
		||||
async def xor_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    conditions = await build_condition_list(config, template_arg, args)
 | 
			
		||||
    return cg.new_Pvariable(condition_id, template_arg, conditions)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_condition("lambda", LambdaCondition, cv.returning_lambda)
 | 
			
		||||
async def lambda_condition_to_code(config, condition_id, template_arg, args):
 | 
			
		||||
    lambda_ = await cg.process_lambda(config, args, return_type=bool)
 | 
			
		||||
@@ -303,6 +313,41 @@ async def component_update_action_to_code(config, action_id, template_arg, args)
 | 
			
		||||
    return cg.new_Pvariable(action_id, template_arg, comp)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_action(
 | 
			
		||||
    "component.suspend",
 | 
			
		||||
    SuspendComponentAction,
 | 
			
		||||
    maybe_simple_id(
 | 
			
		||||
        {
 | 
			
		||||
            cv.Required(CONF_ID): cv.use_id(cg.PollingComponent),
 | 
			
		||||
        }
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
async def component_suspend_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    comp = await cg.get_variable(config[CONF_ID])
 | 
			
		||||
    return cg.new_Pvariable(action_id, template_arg, comp)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register_action(
 | 
			
		||||
    "component.resume",
 | 
			
		||||
    ResumeComponentAction,
 | 
			
		||||
    maybe_simple_id(
 | 
			
		||||
        {
 | 
			
		||||
            cv.Required(CONF_ID): cv.use_id(cg.PollingComponent),
 | 
			
		||||
            cv.Optional(CONF_UPDATE_INTERVAL): cv.templatable(
 | 
			
		||||
                cv.positive_time_period_milliseconds
 | 
			
		||||
            ),
 | 
			
		||||
        }
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
async def component_resume_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    comp = await cg.get_variable(config[CONF_ID])
 | 
			
		||||
    var = cg.new_Pvariable(action_id, template_arg, comp)
 | 
			
		||||
    if CONF_UPDATE_INTERVAL in config:
 | 
			
		||||
        template_ = await cg.templatable(config[CONF_UPDATE_INTERVAL], args, int)
 | 
			
		||||
        cg.add(var.set_update_interval(template_))
 | 
			
		||||
    return var
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def build_action(full_config, template_arg, args):
 | 
			
		||||
    registry_entry, config = cg.extract_registry_entry_config(
 | 
			
		||||
        ACTION_REGISTRY, full_config
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -4,13 +4,14 @@ from esphome.components import sensor, i2c
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    CONF_ID,
 | 
			
		||||
    CONF_IRQ_PIN,
 | 
			
		||||
    CONF_VOLTAGE,
 | 
			
		||||
    DEVICE_CLASS_CURRENT,
 | 
			
		||||
    DEVICE_CLASS_POWER,
 | 
			
		||||
    DEVICE_CLASS_VOLTAGE,
 | 
			
		||||
    STATE_CLASS_MEASUREMENT,
 | 
			
		||||
    UNIT_VOLT,
 | 
			
		||||
    UNIT_AMPERE,
 | 
			
		||||
    UNIT_VOLT,
 | 
			
		||||
    UNIT_WATT,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -19,7 +20,6 @@ DEPENDENCIES = ["i2c"]
 | 
			
		||||
ade7953_ns = cg.esphome_ns.namespace("ade7953")
 | 
			
		||||
ADE7953 = ade7953_ns.class_("ADE7953", cg.PollingComponent, i2c.I2CDevice)
 | 
			
		||||
 | 
			
		||||
CONF_IRQ_PIN = "irq_pin"
 | 
			
		||||
CONF_CURRENT_A = "current_a"
 | 
			
		||||
CONF_CURRENT_B = "current_b"
 | 
			
		||||
CONF_ACTIVE_POWER_A = "active_power_a"
 | 
			
		||||
 
 | 
			
		||||
@@ -151,7 +151,7 @@ async def to_code(config):
 | 
			
		||||
        pos = 0
 | 
			
		||||
        for frameIndex in range(frames):
 | 
			
		||||
            image.seek(frameIndex)
 | 
			
		||||
            frame = image.convert("LA", dither=Image.NONE)
 | 
			
		||||
            frame = image.convert("LA", dither=Image.Dither.NONE)
 | 
			
		||||
            if CONF_RESIZE in config:
 | 
			
		||||
                frame = frame.resize([width, height])
 | 
			
		||||
            pixels = list(frame.getdata())
 | 
			
		||||
@@ -259,7 +259,7 @@ async def to_code(config):
 | 
			
		||||
            if transparent:
 | 
			
		||||
                alpha = image.split()[-1]
 | 
			
		||||
                has_alpha = alpha.getextrema()[0] < 0xFF
 | 
			
		||||
            frame = image.convert("1", dither=Image.NONE)
 | 
			
		||||
            frame = image.convert("1", dither=Image.Dither.NONE)
 | 
			
		||||
            if CONF_RESIZE in config:
 | 
			
		||||
                frame = frame.resize([width, height])
 | 
			
		||||
                if transparent:
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,8 @@ from esphome.const import (
 | 
			
		||||
    CONF_TRIGGER_ID,
 | 
			
		||||
    CONF_EVENT,
 | 
			
		||||
    CONF_TAG,
 | 
			
		||||
    CONF_ON_CLIENT_CONNECTED,
 | 
			
		||||
    CONF_ON_CLIENT_DISCONNECTED,
 | 
			
		||||
)
 | 
			
		||||
from esphome.core import coroutine_with_priority
 | 
			
		||||
 | 
			
		||||
@@ -87,6 +89,12 @@ CONFIG_SCHEMA = cv.Schema(
 | 
			
		||||
                cv.Required(CONF_KEY): validate_encryption_key,
 | 
			
		||||
            }
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_ON_CLIENT_CONNECTED): automation.validate_automation(
 | 
			
		||||
            single=True
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_ON_CLIENT_DISCONNECTED): automation.validate_automation(
 | 
			
		||||
            single=True
 | 
			
		||||
        ),
 | 
			
		||||
    }
 | 
			
		||||
).extend(cv.COMPONENT_SCHEMA)
 | 
			
		||||
 | 
			
		||||
@@ -116,6 +124,20 @@ async def to_code(config):
 | 
			
		||||
        cg.add(var.register_user_service(trigger))
 | 
			
		||||
        await automation.build_automation(trigger, func_args, conf)
 | 
			
		||||
 | 
			
		||||
    if CONF_ON_CLIENT_CONNECTED in config:
 | 
			
		||||
        await automation.build_automation(
 | 
			
		||||
            var.get_client_connected_trigger(),
 | 
			
		||||
            [(cg.std_string, "client_info"), (cg.std_string, "client_address")],
 | 
			
		||||
            config[CONF_ON_CLIENT_CONNECTED],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    if CONF_ON_CLIENT_DISCONNECTED in config:
 | 
			
		||||
        await automation.build_automation(
 | 
			
		||||
            var.get_client_disconnected_trigger(),
 | 
			
		||||
            [(cg.std_string, "client_info"), (cg.std_string, "client_address")],
 | 
			
		||||
            config[CONF_ON_CLIENT_DISCONNECTED],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    if encryption_config := config.get(CONF_ENCRYPTION):
 | 
			
		||||
        decoded = base64.b64decode(encryption_config[CONF_KEY])
 | 
			
		||||
        cg.add(var.set_noise_psk(list(decoded)))
 | 
			
		||||
 
 | 
			
		||||
@@ -1413,6 +1413,18 @@ message SubscribeVoiceAssistantRequest {
 | 
			
		||||
  bool subscribe = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum VoiceAssistantRequestFlag {
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_NONE = 0;
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_USE_VAD = 1;
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD = 2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message VoiceAssistantAudioSettings {
 | 
			
		||||
  uint32 noise_suppression_level = 1;
 | 
			
		||||
  uint32 auto_gain = 2;
 | 
			
		||||
  float volume_multiplier = 3;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message VoiceAssistantRequest {
 | 
			
		||||
  option (id) = 90;
 | 
			
		||||
  option (source) = SOURCE_SERVER;
 | 
			
		||||
@@ -1420,7 +1432,8 @@ message VoiceAssistantRequest {
 | 
			
		||||
 | 
			
		||||
  bool start = 1;
 | 
			
		||||
  string conversation_id = 2;
 | 
			
		||||
  bool use_vad = 3;
 | 
			
		||||
  uint32 flags = 3;
 | 
			
		||||
  VoiceAssistantAudioSettings audio_settings = 4;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message VoiceAssistantResponse {
 | 
			
		||||
@@ -1442,6 +1455,12 @@ enum VoiceAssistantEvent {
 | 
			
		||||
  VOICE_ASSISTANT_INTENT_END = 6;
 | 
			
		||||
  VOICE_ASSISTANT_TTS_START = 7;
 | 
			
		||||
  VOICE_ASSISTANT_TTS_END = 8;
 | 
			
		||||
  VOICE_ASSISTANT_WAKE_WORD_START = 9;
 | 
			
		||||
  VOICE_ASSISTANT_WAKE_WORD_END = 10;
 | 
			
		||||
  VOICE_ASSISTANT_STT_VAD_START = 11;
 | 
			
		||||
  VOICE_ASSISTANT_STT_VAD_END = 12;
 | 
			
		||||
  VOICE_ASSISTANT_TTS_STREAM_START = 98;
 | 
			
		||||
  VOICE_ASSISTANT_TTS_STREAM_END = 99;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message VoiceAssistantEventData {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,9 +31,9 @@ APIConnection::APIConnection(std::unique_ptr<socket::Socket> sock, APIServer *pa
 | 
			
		||||
  this->proto_write_buffer_.reserve(64);
 | 
			
		||||
 | 
			
		||||
#if defined(USE_API_PLAINTEXT)
 | 
			
		||||
  helper_ = std::unique_ptr<APIFrameHelper>{new APIPlaintextFrameHelper(std::move(sock))};
 | 
			
		||||
  this->helper_ = std::unique_ptr<APIFrameHelper>{new APIPlaintextFrameHelper(std::move(sock))};
 | 
			
		||||
#elif defined(USE_API_NOISE)
 | 
			
		||||
  helper_ = std::unique_ptr<APIFrameHelper>{new APINoiseFrameHelper(std::move(sock), parent->get_noise_ctx())};
 | 
			
		||||
  this->helper_ = std::unique_ptr<APIFrameHelper>{new APINoiseFrameHelper(std::move(sock), parent->get_noise_ctx())};
 | 
			
		||||
#else
 | 
			
		||||
#error "No frame helper defined"
 | 
			
		||||
#endif
 | 
			
		||||
@@ -41,14 +41,16 @@ APIConnection::APIConnection(std::unique_ptr<socket::Socket> sock, APIServer *pa
 | 
			
		||||
void APIConnection::start() {
 | 
			
		||||
  this->last_traffic_ = millis();
 | 
			
		||||
 | 
			
		||||
  APIError err = helper_->init();
 | 
			
		||||
  APIError err = this->helper_->init();
 | 
			
		||||
  if (err != APIError::OK) {
 | 
			
		||||
    on_fatal_error();
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Helper init failed: %s errno=%d", client_info_.c_str(), api_error_to_str(err), errno);
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Helper init failed: %s errno=%d", this->client_combined_info_.c_str(), api_error_to_str(err),
 | 
			
		||||
             errno);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  client_info_ = helper_->getpeername();
 | 
			
		||||
  helper_->set_log_info(client_info_);
 | 
			
		||||
  this->client_info_ = helper_->getpeername();
 | 
			
		||||
  this->client_peername_ = this->client_info_;
 | 
			
		||||
  this->helper_->set_log_info(this->client_info_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
APIConnection::~APIConnection() {
 | 
			
		||||
@@ -57,6 +59,11 @@ APIConnection::~APIConnection() {
 | 
			
		||||
    bluetooth_proxy::global_bluetooth_proxy->unsubscribe_api_connection(this);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
  if (voice_assistant::global_voice_assistant->get_api_connection() == this) {
 | 
			
		||||
    voice_assistant::global_voice_assistant->client_subscription(this, false);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void APIConnection::loop() {
 | 
			
		||||
@@ -67,7 +74,7 @@ void APIConnection::loop() {
 | 
			
		||||
    // when network is disconnected force disconnect immediately
 | 
			
		||||
    // don't wait for timeout
 | 
			
		||||
    this->on_fatal_error();
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Network unavailable, disconnecting", client_info_.c_str());
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Network unavailable, disconnecting", this->client_combined_info_.c_str());
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (this->next_close_) {
 | 
			
		||||
@@ -77,24 +84,26 @@ void APIConnection::loop() {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  APIError err = helper_->loop();
 | 
			
		||||
  APIError err = this->helper_->loop();
 | 
			
		||||
  if (err != APIError::OK) {
 | 
			
		||||
    on_fatal_error();
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", client_info_.c_str(), api_error_to_str(err), errno);
 | 
			
		||||
    ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->client_combined_info_.c_str(),
 | 
			
		||||
             api_error_to_str(err), errno);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  ReadPacketBuffer buffer;
 | 
			
		||||
  err = helper_->read_packet(&buffer);
 | 
			
		||||
  err = this->helper_->read_packet(&buffer);
 | 
			
		||||
  if (err == APIError::WOULD_BLOCK) {
 | 
			
		||||
    // pass
 | 
			
		||||
  } else if (err != APIError::OK) {
 | 
			
		||||
    on_fatal_error();
 | 
			
		||||
    if (err == APIError::SOCKET_READ_FAILED && errno == ECONNRESET) {
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection reset", client_info_.c_str());
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection reset", this->client_combined_info_.c_str());
 | 
			
		||||
    } else if (err == APIError::CONNECTION_CLOSED) {
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection closed", client_info_.c_str());
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection closed", this->client_combined_info_.c_str());
 | 
			
		||||
    } else {
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Reading failed: %s errno=%d", client_info_.c_str(), api_error_to_str(err), errno);
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Reading failed: %s errno=%d", this->client_combined_info_.c_str(), api_error_to_str(err),
 | 
			
		||||
               errno);
 | 
			
		||||
    }
 | 
			
		||||
    return;
 | 
			
		||||
  } else {
 | 
			
		||||
@@ -114,7 +123,7 @@ void APIConnection::loop() {
 | 
			
		||||
    // Disconnect if not responded within 2.5*keepalive
 | 
			
		||||
    if (now - this->last_traffic_ > (keepalive * 5) / 2) {
 | 
			
		||||
      on_fatal_error();
 | 
			
		||||
      ESP_LOGW(TAG, "%s didn't respond to ping request in time. Disconnecting...", this->client_info_.c_str());
 | 
			
		||||
      ESP_LOGW(TAG, "%s didn't respond to ping request in time. Disconnecting...", this->client_combined_info_.c_str());
 | 
			
		||||
    }
 | 
			
		||||
  } else if (now - this->last_traffic_ > keepalive) {
 | 
			
		||||
    ESP_LOGVV(TAG, "Sending keepalive PING...");
 | 
			
		||||
@@ -168,7 +177,7 @@ DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) {
 | 
			
		||||
  // remote initiated disconnect_client
 | 
			
		||||
  // don't close yet, we still need to send the disconnect response
 | 
			
		||||
  // close will happen on next loop
 | 
			
		||||
  ESP_LOGD(TAG, "%s requested disconnected", client_info_.c_str());
 | 
			
		||||
  ESP_LOGD(TAG, "%s requested disconnected", this->client_combined_info_.c_str());
 | 
			
		||||
  this->next_close_ = true;
 | 
			
		||||
  DisconnectResponse resp;
 | 
			
		||||
  return resp;
 | 
			
		||||
@@ -907,25 +916,33 @@ BluetoothConnectionsFreeResponse APIConnection::subscribe_bluetooth_connections_
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
bool APIConnection::request_voice_assistant(bool start, const std::string &conversation_id, bool use_vad) {
 | 
			
		||||
  if (!this->voice_assistant_subscription_)
 | 
			
		||||
    return false;
 | 
			
		||||
  VoiceAssistantRequest msg;
 | 
			
		||||
  msg.start = start;
 | 
			
		||||
  msg.conversation_id = conversation_id;
 | 
			
		||||
  msg.use_vad = use_vad;
 | 
			
		||||
  return this->send_voice_assistant_request(msg);
 | 
			
		||||
void APIConnection::subscribe_voice_assistant(const SubscribeVoiceAssistantRequest &msg) {
 | 
			
		||||
  if (voice_assistant::global_voice_assistant != nullptr) {
 | 
			
		||||
    voice_assistant::global_voice_assistant->client_subscription(this, msg.subscribe);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
void APIConnection::on_voice_assistant_response(const VoiceAssistantResponse &msg) {
 | 
			
		||||
  if (voice_assistant::global_voice_assistant != nullptr) {
 | 
			
		||||
    if (voice_assistant::global_voice_assistant->get_api_connection() != this) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (msg.error) {
 | 
			
		||||
      voice_assistant::global_voice_assistant->failed_to_start();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    struct sockaddr_storage storage;
 | 
			
		||||
    socklen_t len = sizeof(storage);
 | 
			
		||||
    this->helper_->getpeername((struct sockaddr *) &storage, &len);
 | 
			
		||||
    voice_assistant::global_voice_assistant->start(&storage, msg.port);
 | 
			
		||||
    voice_assistant::global_voice_assistant->start_streaming(&storage, msg.port);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
void APIConnection::on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) {
 | 
			
		||||
  if (voice_assistant::global_voice_assistant != nullptr) {
 | 
			
		||||
    if (voice_assistant::global_voice_assistant->get_api_connection() != this) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    voice_assistant::global_voice_assistant->on_event(msg);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1005,12 +1022,14 @@ bool APIConnection::send_log_message(int level, const char *tag, const char *lin
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HelloResponse APIConnection::hello(const HelloRequest &msg) {
 | 
			
		||||
  this->client_info_ = msg.client_info + " (" + this->helper_->getpeername() + ")";
 | 
			
		||||
  this->helper_->set_log_info(client_info_);
 | 
			
		||||
  this->client_info_ = msg.client_info;
 | 
			
		||||
  this->client_peername_ = this->helper_->getpeername();
 | 
			
		||||
  this->client_combined_info_ = this->client_info_ + " (" + this->client_peername_ + ")";
 | 
			
		||||
  this->helper_->set_log_info(this->client_combined_info_);
 | 
			
		||||
  this->client_api_version_major_ = msg.api_version_major;
 | 
			
		||||
  this->client_api_version_minor_ = msg.api_version_minor;
 | 
			
		||||
  ESP_LOGV(TAG, "Hello from client: '%s' | API Version %" PRIu32 ".%" PRIu32, this->client_info_.c_str(),
 | 
			
		||||
           this->client_api_version_major_, this->client_api_version_minor_);
 | 
			
		||||
  ESP_LOGV(TAG, "Hello from client: '%s' | %s | API Version %" PRIu32 ".%" PRIu32, this->client_info_.c_str(),
 | 
			
		||||
           this->client_peername_.c_str(), this->client_api_version_major_, this->client_api_version_minor_);
 | 
			
		||||
 | 
			
		||||
  HelloResponse resp;
 | 
			
		||||
  resp.api_version_major = 1;
 | 
			
		||||
@@ -1028,9 +1047,9 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
 | 
			
		||||
  // bool invalid_password = 1;
 | 
			
		||||
  resp.invalid_password = !correct;
 | 
			
		||||
  if (correct) {
 | 
			
		||||
    ESP_LOGD(TAG, "%s: Connected successfully", this->client_info_.c_str());
 | 
			
		||||
    ESP_LOGD(TAG, "%s: Connected successfully", this->client_combined_info_.c_str());
 | 
			
		||||
    this->connection_state_ = ConnectionState::AUTHENTICATED;
 | 
			
		||||
 | 
			
		||||
    this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_);
 | 
			
		||||
#ifdef USE_HOMEASSISTANT_TIME
 | 
			
		||||
    if (homeassistant::global_homeassistant_time != nullptr) {
 | 
			
		||||
      this->send_time_request();
 | 
			
		||||
@@ -1051,6 +1070,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
 | 
			
		||||
@@ -1100,10 +1123,11 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
 | 
			
		||||
    return false;
 | 
			
		||||
  if (!this->helper_->can_write_without_blocking()) {
 | 
			
		||||
    delay(0);
 | 
			
		||||
    APIError err = helper_->loop();
 | 
			
		||||
    APIError err = this->helper_->loop();
 | 
			
		||||
    if (err != APIError::OK) {
 | 
			
		||||
      on_fatal_error();
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", client_info_.c_str(), api_error_to_str(err), errno);
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->client_combined_info_.c_str(),
 | 
			
		||||
               api_error_to_str(err), errno);
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (!this->helper_->can_write_without_blocking()) {
 | 
			
		||||
@@ -1122,9 +1146,10 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
 | 
			
		||||
  if (err != APIError::OK) {
 | 
			
		||||
    on_fatal_error();
 | 
			
		||||
    if (err == APIError::SOCKET_WRITE_FAILED && errno == ECONNRESET) {
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection reset", client_info_.c_str());
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Connection reset", this->client_combined_info_.c_str());
 | 
			
		||||
    } else {
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Packet write failed %s errno=%d", client_info_.c_str(), api_error_to_str(err), errno);
 | 
			
		||||
      ESP_LOGW(TAG, "%s: Packet write failed %s errno=%d", this->client_combined_info_.c_str(), api_error_to_str(err),
 | 
			
		||||
               errno);
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
@@ -1133,11 +1158,11 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
 | 
			
		||||
}
 | 
			
		||||
void APIConnection::on_unauthenticated_access() {
 | 
			
		||||
  this->on_fatal_error();
 | 
			
		||||
  ESP_LOGD(TAG, "%s: tried to access without authentication.", this->client_info_.c_str());
 | 
			
		||||
  ESP_LOGD(TAG, "%s: tried to access without authentication.", this->client_combined_info_.c_str());
 | 
			
		||||
}
 | 
			
		||||
void APIConnection::on_no_setup_connection() {
 | 
			
		||||
  this->on_fatal_error();
 | 
			
		||||
  ESP_LOGD(TAG, "%s: tried to access without full connection.", this->client_info_.c_str());
 | 
			
		||||
  ESP_LOGD(TAG, "%s: tried to access without full connection.", this->client_combined_info_.c_str());
 | 
			
		||||
}
 | 
			
		||||
void APIConnection::on_fatal_error() {
 | 
			
		||||
  this->helper_->close();
 | 
			
		||||
 
 | 
			
		||||
@@ -121,10 +121,7 @@ class APIConnection : public APIServerConnection {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
  void subscribe_voice_assistant(const SubscribeVoiceAssistantRequest &msg) override {
 | 
			
		||||
    this->voice_assistant_subscription_ = msg.subscribe;
 | 
			
		||||
  }
 | 
			
		||||
  bool request_voice_assistant(bool start, const std::string &conversation_id, bool use_vad);
 | 
			
		||||
  void subscribe_voice_assistant(const SubscribeVoiceAssistantRequest &msg) override;
 | 
			
		||||
  void on_voice_assistant_response(const VoiceAssistantResponse &msg) override;
 | 
			
		||||
  void on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) override;
 | 
			
		||||
#endif
 | 
			
		||||
@@ -183,6 +180,8 @@ class APIConnection : public APIServerConnection {
 | 
			
		||||
  }
 | 
			
		||||
  bool send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) override;
 | 
			
		||||
 | 
			
		||||
  std::string get_client_combined_info() const { return this->client_combined_info_; }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  friend APIServer;
 | 
			
		||||
 | 
			
		||||
@@ -202,6 +201,8 @@ class APIConnection : public APIServerConnection {
 | 
			
		||||
  std::unique_ptr<APIFrameHelper> helper_;
 | 
			
		||||
 | 
			
		||||
  std::string client_info_;
 | 
			
		||||
  std::string client_peername_;
 | 
			
		||||
  std::string client_combined_info_;
 | 
			
		||||
  uint32_t client_api_version_major_{0};
 | 
			
		||||
  uint32_t client_api_version_minor_{0};
 | 
			
		||||
#ifdef USE_ESP32_CAMERA
 | 
			
		||||
@@ -213,9 +214,6 @@ class APIConnection : public APIServerConnection {
 | 
			
		||||
  uint32_t last_traffic_;
 | 
			
		||||
  bool sent_ping_{false};
 | 
			
		||||
  bool service_call_subscription_{false};
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
  bool voice_assistant_subscription_{false};
 | 
			
		||||
#endif
 | 
			
		||||
  bool next_close_ = false;
 | 
			
		||||
  APIServer *parent_;
 | 
			
		||||
  InitialStateIterator initial_state_iterator_;
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,8 @@
 | 
			
		||||
#include "api_pb2.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
 | 
			
		||||
#include <cinttypes>
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace api {
 | 
			
		||||
 | 
			
		||||
@@ -408,6 +410,20 @@ const char *proto_enum_to_string<enums::BluetoothDeviceRequestType>(enums::Bluet
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
template<> const char *proto_enum_to_string<enums::VoiceAssistantRequestFlag>(enums::VoiceAssistantRequestFlag value) {
 | 
			
		||||
  switch (value) {
 | 
			
		||||
    case enums::VOICE_ASSISTANT_REQUEST_NONE:
 | 
			
		||||
      return "VOICE_ASSISTANT_REQUEST_NONE";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_REQUEST_USE_VAD:
 | 
			
		||||
      return "VOICE_ASSISTANT_REQUEST_USE_VAD";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD:
 | 
			
		||||
      return "VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD";
 | 
			
		||||
    default:
 | 
			
		||||
      return "UNKNOWN";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
template<> const char *proto_enum_to_string<enums::VoiceAssistantEvent>(enums::VoiceAssistantEvent value) {
 | 
			
		||||
  switch (value) {
 | 
			
		||||
    case enums::VOICE_ASSISTANT_ERROR:
 | 
			
		||||
@@ -428,6 +444,18 @@ template<> const char *proto_enum_to_string<enums::VoiceAssistantEvent>(enums::V
 | 
			
		||||
      return "VOICE_ASSISTANT_TTS_START";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_TTS_END:
 | 
			
		||||
      return "VOICE_ASSISTANT_TTS_END";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_WAKE_WORD_START:
 | 
			
		||||
      return "VOICE_ASSISTANT_WAKE_WORD_START";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_WAKE_WORD_END:
 | 
			
		||||
      return "VOICE_ASSISTANT_WAKE_WORD_END";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_STT_VAD_START:
 | 
			
		||||
      return "VOICE_ASSISTANT_STT_VAD_START";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_STT_VAD_END:
 | 
			
		||||
      return "VOICE_ASSISTANT_STT_VAD_END";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_TTS_STREAM_START:
 | 
			
		||||
      return "VOICE_ASSISTANT_TTS_STREAM_START";
 | 
			
		||||
    case enums::VOICE_ASSISTANT_TTS_STREAM_END:
 | 
			
		||||
      return "VOICE_ASSISTANT_TTS_STREAM_END";
 | 
			
		||||
    default:
 | 
			
		||||
      return "UNKNOWN";
 | 
			
		||||
  }
 | 
			
		||||
@@ -522,12 +550,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 +600,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 +811,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 +834,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 +926,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 +994,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 +1097,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 +1187,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 +1270,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 +1390,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 +1415,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 +1482,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 +1503,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 +1583,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 +1624,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 +1738,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 +1892,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 +2115,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 +2213,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 +2222,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 +2330,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 +2351,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 +2415,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 +2504,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 +2567,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 +2606,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 +2680,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 +2746,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 +3053,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 +3137,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 +3231,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 +3245,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 +3257,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 +3308,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 +3384,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 +3450,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 +3642,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 +3830,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 +4018,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 +4201,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 +4288,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 +4326,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 +4408,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 +4480,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 +4523,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 +4617,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 +4688,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 +4743,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 +4830,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 +4876,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 +4951,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 +5020,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 +5099,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 +5148,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 +5195,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 +5275,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 +5298,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 +5348,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 +5436,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 +5484,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 +5549,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 +5605,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 +5667,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 +5774,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 +5819,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 +5873,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 +5915,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 +5960,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 +6003,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 +6052,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 +6091,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 +6135,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 +6174,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 +6208,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 +6251,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 +6294,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 +6343,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("}");
 | 
			
		||||
@@ -6342,6 +6370,56 @@ void SubscribeVoiceAssistantRequest::dump_to(std::string &out) const {
 | 
			
		||||
  out.append("}");
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
bool VoiceAssistantAudioSettings::decode_varint(uint32_t field_id, ProtoVarInt value) {
 | 
			
		||||
  switch (field_id) {
 | 
			
		||||
    case 1: {
 | 
			
		||||
      this->noise_suppression_level = value.as_uint32();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    case 2: {
 | 
			
		||||
      this->auto_gain = value.as_uint32();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    default:
 | 
			
		||||
      return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
bool VoiceAssistantAudioSettings::decode_32bit(uint32_t field_id, Proto32Bit value) {
 | 
			
		||||
  switch (field_id) {
 | 
			
		||||
    case 3: {
 | 
			
		||||
      this->volume_multiplier = value.as_float();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    default:
 | 
			
		||||
      return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
void VoiceAssistantAudioSettings::encode(ProtoWriteBuffer buffer) const {
 | 
			
		||||
  buffer.encode_uint32(1, this->noise_suppression_level);
 | 
			
		||||
  buffer.encode_uint32(2, this->auto_gain);
 | 
			
		||||
  buffer.encode_float(3, this->volume_multiplier);
 | 
			
		||||
}
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
void VoiceAssistantAudioSettings::dump_to(std::string &out) const {
 | 
			
		||||
  __attribute__((unused)) char buffer[64];
 | 
			
		||||
  out.append("VoiceAssistantAudioSettings {\n");
 | 
			
		||||
  out.append("  noise_suppression_level: ");
 | 
			
		||||
  sprintf(buffer, "%" PRIu32, this->noise_suppression_level);
 | 
			
		||||
  out.append(buffer);
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
 | 
			
		||||
  out.append("  auto_gain: ");
 | 
			
		||||
  sprintf(buffer, "%" PRIu32, this->auto_gain);
 | 
			
		||||
  out.append(buffer);
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
 | 
			
		||||
  out.append("  volume_multiplier: ");
 | 
			
		||||
  sprintf(buffer, "%g", this->volume_multiplier);
 | 
			
		||||
  out.append(buffer);
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
  out.append("}");
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
bool VoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
 | 
			
		||||
  switch (field_id) {
 | 
			
		||||
    case 1: {
 | 
			
		||||
@@ -6349,7 +6427,7 @@ bool VoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value)
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    case 3: {
 | 
			
		||||
      this->use_vad = value.as_bool();
 | 
			
		||||
      this->flags = value.as_uint32();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    default:
 | 
			
		||||
@@ -6362,6 +6440,10 @@ bool VoiceAssistantRequest::decode_length(uint32_t field_id, ProtoLengthDelimite
 | 
			
		||||
      this->conversation_id = value.as_string();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    case 4: {
 | 
			
		||||
      this->audio_settings = value.as_message<VoiceAssistantAudioSettings>();
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    default:
 | 
			
		||||
      return false;
 | 
			
		||||
  }
 | 
			
		||||
@@ -6369,7 +6451,8 @@ bool VoiceAssistantRequest::decode_length(uint32_t field_id, ProtoLengthDelimite
 | 
			
		||||
void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const {
 | 
			
		||||
  buffer.encode_bool(1, this->start);
 | 
			
		||||
  buffer.encode_string(2, this->conversation_id);
 | 
			
		||||
  buffer.encode_bool(3, this->use_vad);
 | 
			
		||||
  buffer.encode_uint32(3, this->flags);
 | 
			
		||||
  buffer.encode_message<VoiceAssistantAudioSettings>(4, this->audio_settings);
 | 
			
		||||
}
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
void VoiceAssistantRequest::dump_to(std::string &out) const {
 | 
			
		||||
@@ -6383,8 +6466,13 @@ void VoiceAssistantRequest::dump_to(std::string &out) const {
 | 
			
		||||
  out.append("'").append(this->conversation_id).append("'");
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
 | 
			
		||||
  out.append("  use_vad: ");
 | 
			
		||||
  out.append(YESNO(this->use_vad));
 | 
			
		||||
  out.append("  flags: ");
 | 
			
		||||
  sprintf(buffer, "%" PRIu32, this->flags);
 | 
			
		||||
  out.append(buffer);
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
 | 
			
		||||
  out.append("  audio_settings: ");
 | 
			
		||||
  this->audio_settings.dump_to(out);
 | 
			
		||||
  out.append("\n");
 | 
			
		||||
  out.append("}");
 | 
			
		||||
}
 | 
			
		||||
@@ -6412,7 +6500,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 +6663,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 +6688,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 +6731,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 +6781,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");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -165,6 +165,11 @@ enum BluetoothDeviceRequestType : uint32_t {
 | 
			
		||||
  BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE = 5,
 | 
			
		||||
  BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE = 6,
 | 
			
		||||
};
 | 
			
		||||
enum VoiceAssistantRequestFlag : uint32_t {
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_NONE = 0,
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_USE_VAD = 1,
 | 
			
		||||
  VOICE_ASSISTANT_REQUEST_USE_WAKE_WORD = 2,
 | 
			
		||||
};
 | 
			
		||||
enum VoiceAssistantEvent : uint32_t {
 | 
			
		||||
  VOICE_ASSISTANT_ERROR = 0,
 | 
			
		||||
  VOICE_ASSISTANT_RUN_START = 1,
 | 
			
		||||
@@ -175,6 +180,12 @@ enum VoiceAssistantEvent : uint32_t {
 | 
			
		||||
  VOICE_ASSISTANT_INTENT_END = 6,
 | 
			
		||||
  VOICE_ASSISTANT_TTS_START = 7,
 | 
			
		||||
  VOICE_ASSISTANT_TTS_END = 8,
 | 
			
		||||
  VOICE_ASSISTANT_WAKE_WORD_START = 9,
 | 
			
		||||
  VOICE_ASSISTANT_WAKE_WORD_END = 10,
 | 
			
		||||
  VOICE_ASSISTANT_STT_VAD_START = 11,
 | 
			
		||||
  VOICE_ASSISTANT_STT_VAD_END = 12,
 | 
			
		||||
  VOICE_ASSISTANT_TTS_STREAM_START = 98,
 | 
			
		||||
  VOICE_ASSISTANT_TTS_STREAM_END = 99,
 | 
			
		||||
};
 | 
			
		||||
enum AlarmControlPanelState : uint32_t {
 | 
			
		||||
  ALARM_STATE_DISARMED = 0,
 | 
			
		||||
@@ -1651,11 +1662,26 @@ class SubscribeVoiceAssistantRequest : public ProtoMessage {
 | 
			
		||||
 protected:
 | 
			
		||||
  bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
 | 
			
		||||
};
 | 
			
		||||
class VoiceAssistantAudioSettings : public ProtoMessage {
 | 
			
		||||
 public:
 | 
			
		||||
  uint32_t noise_suppression_level{0};
 | 
			
		||||
  uint32_t auto_gain{0};
 | 
			
		||||
  float volume_multiplier{0.0f};
 | 
			
		||||
  void encode(ProtoWriteBuffer buffer) const override;
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
  void dump_to(std::string &out) const override;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
 | 
			
		||||
  bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
 | 
			
		||||
};
 | 
			
		||||
class VoiceAssistantRequest : public ProtoMessage {
 | 
			
		||||
 public:
 | 
			
		||||
  bool start{false};
 | 
			
		||||
  std::string conversation_id{};
 | 
			
		||||
  bool use_vad{false};
 | 
			
		||||
  uint32_t flags{0};
 | 
			
		||||
  VoiceAssistantAudioSettings audio_settings{};
 | 
			
		||||
  void encode(ProtoWriteBuffer buffer) const override;
 | 
			
		||||
#ifdef HAS_PROTO_MESSAGE_DUMP
 | 
			
		||||
  void dump_to(std::string &out) const override;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
#include "api_server.h"
 | 
			
		||||
#include <cerrno>
 | 
			
		||||
#include "api_connection.h"
 | 
			
		||||
#include "esphome/components/network/util.h"
 | 
			
		||||
#include "esphome/core/application.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/hal.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/core/util.h"
 | 
			
		||||
#include "esphome/core/version.h"
 | 
			
		||||
#include "esphome/core/hal.h"
 | 
			
		||||
#include "esphome/components/network/util.h"
 | 
			
		||||
#include <cerrno>
 | 
			
		||||
 | 
			
		||||
#ifdef USE_LOGGER
 | 
			
		||||
#include "esphome/components/logger/logger.h"
 | 
			
		||||
@@ -111,6 +111,7 @@ void APIServer::loop() {
 | 
			
		||||
                                [](const std::unique_ptr<APIConnection> &conn) { return !conn->remove_; });
 | 
			
		||||
  // print disconnection messages
 | 
			
		||||
  for (auto it = new_end; it != this->clients_.end(); ++it) {
 | 
			
		||||
    this->client_disconnected_trigger_->trigger((*it)->client_info_, (*it)->client_peername_);
 | 
			
		||||
    ESP_LOGV(TAG, "Removing connection to %s", (*it)->client_info_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
  // resize vector
 | 
			
		||||
@@ -322,22 +323,6 @@ void APIServer::on_shutdown() {
 | 
			
		||||
  delay(10);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
bool APIServer::start_voice_assistant(const std::string &conversation_id, bool use_vad) {
 | 
			
		||||
  for (auto &c : this->clients_) {
 | 
			
		||||
    if (c->request_voice_assistant(true, conversation_id, use_vad))
 | 
			
		||||
      return true;
 | 
			
		||||
  }
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
void APIServer::stop_voice_assistant() {
 | 
			
		||||
  for (auto &c : this->clients_) {
 | 
			
		||||
    if (c->request_voice_assistant(false, "", false))
 | 
			
		||||
      return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ALARM_CONTROL_PANEL
 | 
			
		||||
void APIServer::on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) {
 | 
			
		||||
  if (obj->is_internal())
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,17 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "api_noise_context.h"
 | 
			
		||||
#include "api_pb2.h"
 | 
			
		||||
#include "api_pb2_service.h"
 | 
			
		||||
#include "esphome/components/socket/socket.h"
 | 
			
		||||
#include "esphome/core/automation.h"
 | 
			
		||||
#include "esphome/core/component.h"
 | 
			
		||||
#include "esphome/core/controller.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
#include "esphome/components/socket/socket.h"
 | 
			
		||||
#include "api_pb2.h"
 | 
			
		||||
#include "api_pb2_service.h"
 | 
			
		||||
#include "list_entities.h"
 | 
			
		||||
#include "subscribe_state.h"
 | 
			
		||||
#include "user_services.h"
 | 
			
		||||
#include "api_noise_context.h"
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
@@ -80,11 +81,6 @@ class APIServer : public Component, public Controller {
 | 
			
		||||
  void request_time();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_VOICE_ASSISTANT
 | 
			
		||||
  bool start_voice_assistant(const std::string &conversation_id, bool use_vad);
 | 
			
		||||
  void stop_voice_assistant();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ALARM_CONTROL_PANEL
 | 
			
		||||
  void on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj) override;
 | 
			
		||||
#endif
 | 
			
		||||
@@ -102,6 +98,11 @@ class APIServer : public Component, public Controller {
 | 
			
		||||
  const std::vector<HomeAssistantStateSubscription> &get_state_subs() const;
 | 
			
		||||
  const std::vector<UserServiceDescriptor *> &get_user_services() const { return this->user_services_; }
 | 
			
		||||
 | 
			
		||||
  Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
 | 
			
		||||
  Trigger<std::string, std::string> *get_client_disconnected_trigger() const {
 | 
			
		||||
    return this->client_disconnected_trigger_;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  std::unique_ptr<socket::Socket> socket_ = nullptr;
 | 
			
		||||
  uint16_t port_{6053};
 | 
			
		||||
@@ -111,6 +112,8 @@ class APIServer : public Component, public Controller {
 | 
			
		||||
  std::string password_;
 | 
			
		||||
  std::vector<HomeAssistantStateSubscription> state_subs_;
 | 
			
		||||
  std::vector<UserServiceDescriptor *> user_services_;
 | 
			
		||||
  Trigger<std::string, std::string> *client_connected_trigger_ = new Trigger<std::string, std::string>();
 | 
			
		||||
  Trigger<std::string, std::string> *client_disconnected_trigger_ = new Trigger<std::string, std::string>();
 | 
			
		||||
 | 
			
		||||
#ifdef USE_API_NOISE
 | 
			
		||||
  std::shared_ptr<APINoiseContext> noise_ctx_ = std::make_shared<APINoiseContext>();
 | 
			
		||||
 
 | 
			
		||||
@@ -2,14 +2,17 @@ import esphome.codegen as cg
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome import pins
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    CONF_CAPACITANCE,
 | 
			
		||||
    CONF_DIV_RATIO,
 | 
			
		||||
    CONF_INDOOR,
 | 
			
		||||
    CONF_WATCHDOG_THRESHOLD,
 | 
			
		||||
    CONF_NOISE_LEVEL,
 | 
			
		||||
    CONF_SPIKE_REJECTION,
 | 
			
		||||
    CONF_IRQ_PIN,
 | 
			
		||||
    CONF_LIGHTNING_THRESHOLD,
 | 
			
		||||
    CONF_MASK_DISTURBER,
 | 
			
		||||
    CONF_DIV_RATIO,
 | 
			
		||||
    CONF_CAPACITANCE,
 | 
			
		||||
    CONF_CALIBRATION,
 | 
			
		||||
    CONF_TUNE_ANTENNA,
 | 
			
		||||
    CONF_NOISE_LEVEL,
 | 
			
		||||
    CONF_SPIKE_REJECTION,
 | 
			
		||||
    CONF_WATCHDOG_THRESHOLD,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
@@ -19,7 +22,6 @@ CONF_AS3935_ID = "as3935_id"
 | 
			
		||||
as3935_ns = cg.esphome_ns.namespace("as3935")
 | 
			
		||||
AS3935 = as3935_ns.class_("AS3935Component", cg.Component)
 | 
			
		||||
 | 
			
		||||
CONF_IRQ_PIN = "irq_pin"
 | 
			
		||||
AS3935_SCHEMA = cv.Schema(
 | 
			
		||||
    {
 | 
			
		||||
        cv.GenerateID(): cv.declare_id(AS3935),
 | 
			
		||||
@@ -34,6 +36,8 @@ AS3935_SCHEMA = cv.Schema(
 | 
			
		||||
        cv.Optional(CONF_MASK_DISTURBER, default=False): cv.boolean,
 | 
			
		||||
        cv.Optional(CONF_DIV_RATIO, default=0): cv.one_of(0, 16, 32, 64, 128, int=True),
 | 
			
		||||
        cv.Optional(CONF_CAPACITANCE, default=0): cv.int_range(min=0, max=15),
 | 
			
		||||
        cv.Optional(CONF_TUNE_ANTENNA, default=False): cv.boolean,
 | 
			
		||||
        cv.Optional(CONF_CALIBRATION, default=True): cv.boolean,
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -51,3 +55,5 @@ async def setup_as3935(var, config):
 | 
			
		||||
    cg.add(var.set_mask_disturber(config[CONF_MASK_DISTURBER]))
 | 
			
		||||
    cg.add(var.set_div_ratio(config[CONF_DIV_RATIO]))
 | 
			
		||||
    cg.add(var.set_capacitance(config[CONF_CAPACITANCE]))
 | 
			
		||||
    cg.add(var.set_tune_antenna(config[CONF_TUNE_ANTENNA]))
 | 
			
		||||
    cg.add(var.set_calibration(config[CONF_CALIBRATION]))
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,14 @@ void AS3935Component::setup() {
 | 
			
		||||
  this->write_mask_disturber(this->mask_disturber_);
 | 
			
		||||
  this->write_div_ratio(this->div_ratio_);
 | 
			
		||||
  this->write_capacitance(this->capacitance_);
 | 
			
		||||
 | 
			
		||||
  // Handle setting up tuning or auto-calibration
 | 
			
		||||
  if (this->tune_antenna_) {
 | 
			
		||||
    ESP_LOGCONFIG(TAG, "  Antenna tuning: ENABLED - lightning detection will not function in this mode");
 | 
			
		||||
    this->tune_antenna();
 | 
			
		||||
  } else if (this->calibration_) {
 | 
			
		||||
    this->calibrate_oscillator();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AS3935Component::dump_config() {
 | 
			
		||||
@@ -227,6 +235,87 @@ uint32_t AS3935Component::get_lightning_energy_() {
 | 
			
		||||
  return pure_light;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// REG0x03, bit [7:6], manufacturer default: 0 (16 division ratio).
 | 
			
		||||
// This function returns the current division ratio of the resonance frequency.
 | 
			
		||||
// The antenna resonance frequency should be within 3.5 percent of 500kHz, and
 | 
			
		||||
// so when modifying the resonance frequency with the internal capacitors
 | 
			
		||||
// (tuneCap()) it's important to keep in mind that the displayed frequency on
 | 
			
		||||
// the IRQ pin is divided by this number.
 | 
			
		||||
uint8_t AS3935Component::read_div_ratio() {
 | 
			
		||||
  ESP_LOGV(TAG, "Calling read_div_ratio");
 | 
			
		||||
  uint8_t reg_val = this->read_register_(INT_MASK_ANT, DIV_MASK);
 | 
			
		||||
  reg_val >>= 6;  // Front of the line.
 | 
			
		||||
 | 
			
		||||
  if (reg_val == 0) {
 | 
			
		||||
    return 16;
 | 
			
		||||
  } else if (reg_val == 1) {
 | 
			
		||||
    return 32;
 | 
			
		||||
  } else if (reg_val == 2) {
 | 
			
		||||
    return 64;
 | 
			
		||||
  } else if (reg_val == 3) {
 | 
			
		||||
    return 128;
 | 
			
		||||
  }
 | 
			
		||||
  ESP_LOGW(TAG, "Unknown response received for div_ratio");
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t AS3935Component::read_capacitance() {
 | 
			
		||||
  ESP_LOGV(TAG, "Calling read_capacitance");
 | 
			
		||||
  uint8_t reg_val = this->read_register_(FREQ_DISP_IRQ, CAP_MASK) * 8;
 | 
			
		||||
  return (reg_val);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// REG0x08, bits [5,6,7], manufacturer default: 0.
 | 
			
		||||
// This will send the frequency of the oscillators to the IRQ pin.
 | 
			
		||||
//  _osc 1, bit[5] = TRCO - System RCO at 32.768kHz
 | 
			
		||||
//  _osc 2, bit[6] = SRCO - Timer RCO Oscillators 1.1MHz
 | 
			
		||||
//  _osc 3, bit[7] = LCO - Frequency of the Antenna
 | 
			
		||||
void AS3935Component::display_oscillator(bool state, uint8_t osc) {
 | 
			
		||||
  if ((osc < 1) || (osc > 3))
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  this->write_register(FREQ_DISP_IRQ, OSC_MASK, state, 4 + osc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// REG0x3D, bits[7:0]
 | 
			
		||||
// This function calibrates both internal oscillators The oscillators are tuned
 | 
			
		||||
// based on the resonance frequency of the antenna and so it should be trimmed
 | 
			
		||||
// before the calibration is done.
 | 
			
		||||
bool AS3935Component::calibrate_oscillator() {
 | 
			
		||||
  ESP_LOGI(TAG, "Starting oscillators calibration...");
 | 
			
		||||
  this->write_register(CALIB_RCO, WIPE_ALL, DIRECT_COMMAND, 0);  // Send command to calibrate the oscillators
 | 
			
		||||
 | 
			
		||||
  this->display_oscillator(true, 2);
 | 
			
		||||
  delay(2);  // Give time for the internal oscillators to start up.
 | 
			
		||||
  this->display_oscillator(false, 2);
 | 
			
		||||
 | 
			
		||||
  // Check it they were calibrated successfully.
 | 
			
		||||
  uint8_t reg_val_srco = this->read_register_(CALIB_SRCO, CALIB_MASK_NOK);
 | 
			
		||||
  uint8_t reg_val_trco = this->read_register_(CALIB_TRCO, CALIB_MASK_NOK);
 | 
			
		||||
 | 
			
		||||
  // reg_val_srco &= CALIB_MASK;
 | 
			
		||||
  // reg_val_srco >>= 6;
 | 
			
		||||
  // reg_val_trco &= CALIB_MASK;
 | 
			
		||||
  // reg_val_trco >>= 6;
 | 
			
		||||
  if (!reg_val_srco && !reg_val_trco) {  // Zero upon success
 | 
			
		||||
    ESP_LOGI(TAG, "Calibration was succesful");
 | 
			
		||||
    return true;
 | 
			
		||||
  } else {
 | 
			
		||||
    ESP_LOGW(TAG, "Calibration was NOT succesful");
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AS3935Component::tune_antenna() {
 | 
			
		||||
  ESP_LOGI(TAG, "Starting antenna tuning...");
 | 
			
		||||
  uint8_t div_ratio = this->read_div_ratio();
 | 
			
		||||
  uint8_t tune_val = this->read_capacitance();
 | 
			
		||||
  ESP_LOGI(TAG, "Division Ratio is set to: %d", div_ratio);
 | 
			
		||||
  ESP_LOGI(TAG, "Internal Capacitor is set to: %d", tune_val);
 | 
			
		||||
  ESP_LOGI(TAG, "Displaying oscillator on INT pin. Measure its frequency - multiply value by Division Ratio");
 | 
			
		||||
  this->display_oscillator(true, ANTFREQ);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t AS3935Component::read_register_(uint8_t reg, uint8_t mask) {
 | 
			
		||||
  uint8_t value = this->read_register(reg);
 | 
			
		||||
  value &= (~mask);
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,9 @@
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace as3935 {
 | 
			
		||||
 | 
			
		||||
static const uint8_t DIRECT_COMMAND = 0x96;
 | 
			
		||||
static const uint8_t ANTFREQ = 3;
 | 
			
		||||
 | 
			
		||||
enum AS3935RegisterNames {
 | 
			
		||||
  AFE_GAIN = 0x00,
 | 
			
		||||
  THRESHOLD,
 | 
			
		||||
@@ -30,6 +33,7 @@ enum AS3935RegisterNames {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum AS3935RegisterMasks {
 | 
			
		||||
  WIPE_ALL = 0x0,
 | 
			
		||||
  GAIN_MASK = 0x3E,
 | 
			
		||||
  SPIKE_MASK = 0xF,
 | 
			
		||||
  IO_MASK = 0xC1,
 | 
			
		||||
@@ -44,6 +48,7 @@ enum AS3935RegisterMasks {
 | 
			
		||||
  NOISE_FLOOR_MASK = 0x70,
 | 
			
		||||
  OSC_MASK = 0xE0,
 | 
			
		||||
  CALIB_MASK = 0x7F,
 | 
			
		||||
  CALIB_MASK_NOK = 0xBF,
 | 
			
		||||
  DIV_MASK = 0x3F
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -90,6 +95,13 @@ class AS3935Component : public Component {
 | 
			
		||||
  void write_div_ratio(uint8_t div_ratio);
 | 
			
		||||
  void set_capacitance(uint8_t capacitance) { capacitance_ = capacitance; }
 | 
			
		||||
  void write_capacitance(uint8_t capacitance);
 | 
			
		||||
  uint8_t read_div_ratio();
 | 
			
		||||
  uint8_t read_capacitance();
 | 
			
		||||
  bool calibrate_oscillator();
 | 
			
		||||
  void display_oscillator(bool state, uint8_t osc);
 | 
			
		||||
  void tune_antenna();
 | 
			
		||||
  void set_tune_antenna(bool tune_antenna) { tune_antenna_ = tune_antenna; }
 | 
			
		||||
  void set_calibration(bool calibration) { calibration_ = calibration; }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  uint8_t read_interrupt_register_();
 | 
			
		||||
@@ -112,6 +124,8 @@ class AS3935Component : public Component {
 | 
			
		||||
  bool mask_disturber_;
 | 
			
		||||
  uint8_t div_ratio_;
 | 
			
		||||
  uint8_t capacitance_;
 | 
			
		||||
  bool tune_antenna_;
 | 
			
		||||
  bool calibration_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace as3935
 | 
			
		||||
 
 | 
			
		||||
@@ -2,21 +2,27 @@
 | 
			
		||||
import esphome.codegen as cg
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.core import CORE, coroutine_with_priority
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    PLATFORM_ESP32,
 | 
			
		||||
    PLATFORM_ESP8266,
 | 
			
		||||
    PLATFORM_BK72XX,
 | 
			
		||||
    PLATFORM_RTL87XX,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
CODEOWNERS = ["@OttoWinter"]
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.All(
 | 
			
		||||
    cv.Schema({}),
 | 
			
		||||
    cv.only_with_arduino,
 | 
			
		||||
    cv.only_on(["esp32", "esp8266"]),
 | 
			
		||||
    cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_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))
 | 
			
		||||
@@ -12,6 +12,8 @@ static const uint8_t BP1658CJ_ADDR_START_3CH = 0x10;
 | 
			
		||||
static const uint8_t BP1658CJ_ADDR_START_2CH = 0x20;
 | 
			
		||||
static const uint8_t BP1658CJ_ADDR_START_5CH = 0x30;
 | 
			
		||||
 | 
			
		||||
static const uint8_t BP1658CJ_DELAY = 2;
 | 
			
		||||
 | 
			
		||||
void BP1658CJ::setup() {
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "Setting up BP1658CJ Output Component...");
 | 
			
		||||
  this->data_pin_->setup();
 | 
			
		||||
@@ -35,10 +37,14 @@ void BP1658CJ::loop() {
 | 
			
		||||
  uint8_t data[12];
 | 
			
		||||
  if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
 | 
			
		||||
      this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
 | 
			
		||||
    // Off / Sleep
 | 
			
		||||
    data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_STANDBY;
 | 
			
		||||
    for (int i = 1; i < 12; i++)
 | 
			
		||||
      data[i] = 0;
 | 
			
		||||
 | 
			
		||||
    // First turn all channels off
 | 
			
		||||
    data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_START_5CH;
 | 
			
		||||
    this->write_buffer_(data, 12);
 | 
			
		||||
    // Then sleep
 | 
			
		||||
    data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_STANDBY;
 | 
			
		||||
    this->write_buffer_(data, 12);
 | 
			
		||||
  } else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
 | 
			
		||||
             (this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
 | 
			
		||||
@@ -81,27 +87,41 @@ void BP1658CJ::set_channel_value_(uint8_t channel, uint16_t value) {
 | 
			
		||||
  }
 | 
			
		||||
  this->pwm_amounts_[channel] = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BP1658CJ::write_bit_(bool value) {
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  this->data_pin_->digital_write(value);
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
 | 
			
		||||
  delayMicroseconds(BP1658CJ_DELAY);
 | 
			
		||||
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BP1658CJ::write_byte_(uint8_t data) {
 | 
			
		||||
  for (uint8_t mask = 0x80; mask; mask >>= 1) {
 | 
			
		||||
    this->write_bit_(data & mask);
 | 
			
		||||
    delayMicroseconds(BP1658CJ_DELAY);
 | 
			
		||||
  }
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  this->data_pin_->digital_write(true);
 | 
			
		||||
 | 
			
		||||
  // ack bit
 | 
			
		||||
  this->data_pin_->pin_mode(gpio::FLAG_INPUT);
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
 | 
			
		||||
  delayMicroseconds(BP1658CJ_DELAY);
 | 
			
		||||
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BP1658CJ::write_buffer_(uint8_t *buffer, uint8_t size) {
 | 
			
		||||
  this->data_pin_->digital_write(false);
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
 | 
			
		||||
  for (uint32_t i = 0; i < size; i++) {
 | 
			
		||||
    this->write_byte_(buffer[i]);
 | 
			
		||||
    delayMicroseconds(BP1658CJ_DELAY);
 | 
			
		||||
  }
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
  this->data_pin_->digital_write(true);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,16 @@ static const uint8_t BP5758D_ADDR_START_2CH = 0b00100000;
 | 
			
		||||
static const uint8_t BP5758D_ADDR_START_5CH = 0b00110000;
 | 
			
		||||
static const uint8_t BP5758D_ALL_DATA_CHANNEL_ENABLEMENT = 0b00011111;
 | 
			
		||||
 | 
			
		||||
static const uint8_t BP5758D_DELAY = 2;
 | 
			
		||||
 | 
			
		||||
void BP5758D::setup() {
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "Setting up BP5758D Output Component...");
 | 
			
		||||
  this->data_pin_->setup();
 | 
			
		||||
  this->data_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->clock_pin_->setup();
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->channel_current_.resize(5, 0);
 | 
			
		||||
  this->pwm_amounts_.resize(5, 0);
 | 
			
		||||
}
 | 
			
		||||
@@ -39,10 +43,14 @@ void BP5758D::loop() {
 | 
			
		||||
  uint8_t data[17];
 | 
			
		||||
  if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
 | 
			
		||||
      this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
 | 
			
		||||
    // Off / Sleep
 | 
			
		||||
    data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_STANDBY;
 | 
			
		||||
    for (int i = 1; i < 16; i++)
 | 
			
		||||
    for (int i = 1; i < 17; i++)
 | 
			
		||||
      data[i] = 0;
 | 
			
		||||
 | 
			
		||||
    // First turn all channels off
 | 
			
		||||
    data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_START_5CH;
 | 
			
		||||
    this->write_buffer_(data, 17);
 | 
			
		||||
    // Then sleep
 | 
			
		||||
    data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_STANDBY;
 | 
			
		||||
    this->write_buffer_(data, 17);
 | 
			
		||||
  } else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
 | 
			
		||||
             (this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
 | 
			
		||||
@@ -119,28 +127,42 @@ void BP5758D::set_channel_value_(uint8_t channel, uint16_t value) {
 | 
			
		||||
void BP5758D::set_channel_current_(uint8_t channel, uint8_t current) { this->channel_current_[channel] = current; }
 | 
			
		||||
 | 
			
		||||
void BP5758D::write_bit_(bool value) {
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  this->data_pin_->digital_write(value);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BP5758D::write_byte_(uint8_t data) {
 | 
			
		||||
  for (uint8_t mask = 0x80; mask; mask >>= 1) {
 | 
			
		||||
    this->write_bit_(data & mask);
 | 
			
		||||
  }
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  this->data_pin_->digital_write(true);
 | 
			
		||||
 | 
			
		||||
  // ack bit
 | 
			
		||||
  this->data_pin_->pin_mode(gpio::FLAG_INPUT);
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BP5758D::write_buffer_(uint8_t *buffer, uint8_t size) {
 | 
			
		||||
  this->data_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
 | 
			
		||||
  for (uint32_t i = 0; i < size; i++) {
 | 
			
		||||
    this->write_byte_(buffer[i]);
 | 
			
		||||
  }
 | 
			
		||||
  this->clock_pin_->digital_write(false);
 | 
			
		||||
 | 
			
		||||
  this->clock_pin_->digital_write(true);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
  this->data_pin_->digital_write(true);
 | 
			
		||||
  delayMicroseconds(BP5758D_DELAY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace bp5758d
 | 
			
		||||
 
 | 
			
		||||
@@ -17,11 +17,12 @@ CONF_ON_FRAME = "on_frame"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def validate_id(config):
 | 
			
		||||
    can_id = config[CONF_CAN_ID]
 | 
			
		||||
    id_ext = config[CONF_USE_EXTENDED_ID]
 | 
			
		||||
    if not id_ext:
 | 
			
		||||
        if can_id > 0x7FF:
 | 
			
		||||
            raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
 | 
			
		||||
    if CONF_CAN_ID in config:
 | 
			
		||||
        can_id = config[CONF_CAN_ID]
 | 
			
		||||
        id_ext = config[CONF_USE_EXTENDED_ID]
 | 
			
		||||
        if not id_ext:
 | 
			
		||||
            if can_id > 0x7FF:
 | 
			
		||||
                raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
 | 
			
		||||
    return config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -45,9 +46,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 +65,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),
 | 
			
		||||
@@ -147,22 +152,18 @@ async def canbus_action_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    if can_id := config.get(CONF_CAN_ID):
 | 
			
		||||
        can_id = await cg.templatable(can_id, args, cg.uint32)
 | 
			
		||||
        cg.add(var.set_can_id(can_id))
 | 
			
		||||
    use_extended_id = await cg.templatable(
 | 
			
		||||
        config[CONF_USE_EXTENDED_ID], args, cg.uint32
 | 
			
		||||
    )
 | 
			
		||||
    cg.add(var.set_use_extended_id(use_extended_id))
 | 
			
		||||
        cg.add(var.set_use_extended_id(config[CONF_USE_EXTENDED_ID]))
 | 
			
		||||
 | 
			
		||||
    remote_transmission_request = await cg.templatable(
 | 
			
		||||
        config[CONF_REMOTE_TRANSMISSION_REQUEST], args, bool
 | 
			
		||||
    cg.add(
 | 
			
		||||
        var.set_remote_transmission_request(config[CONF_REMOTE_TRANSMISSION_REQUEST])
 | 
			
		||||
    )
 | 
			
		||||
    cg.add(var.set_remote_transmission_request(remote_transmission_request))
 | 
			
		||||
 | 
			
		||||
    data = config[CONF_DATA]
 | 
			
		||||
    if isinstance(data, bytes):
 | 
			
		||||
        data = [int(x) for x in data]
 | 
			
		||||
    if cg.is_template(data):
 | 
			
		||||
        templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
 | 
			
		||||
        cg.add(var.set_data_template(templ))
 | 
			
		||||
    else:
 | 
			
		||||
        if isinstance(data, bytes):
 | 
			
		||||
            data = [int(x) for x in data]
 | 
			
		||||
        cg.add(var.set_data_static(data))
 | 
			
		||||
    return var
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,13 @@ import esphome.codegen as cg
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
from esphome.components import web_server_base
 | 
			
		||||
from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID
 | 
			
		||||
from esphome.const import CONF_ID
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    CONF_ID,
 | 
			
		||||
    PLATFORM_ESP32,
 | 
			
		||||
    PLATFORM_ESP8266,
 | 
			
		||||
    PLATFORM_BK72XX,
 | 
			
		||||
    PLATFORM_RTL87XX,
 | 
			
		||||
)
 | 
			
		||||
from esphome.core import coroutine_with_priority, CORE
 | 
			
		||||
 | 
			
		||||
AUTO_LOAD = ["web_server_base"]
 | 
			
		||||
@@ -21,7 +27,7 @@ CONFIG_SCHEMA = cv.All(
 | 
			
		||||
            ),
 | 
			
		||||
        }
 | 
			
		||||
    ).extend(cv.COMPONENT_SCHEMA),
 | 
			
		||||
    cv.only_on(["esp32", "esp8266"]),
 | 
			
		||||
    cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_RTL87XX]),
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -39,3 +45,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)
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,7 @@ void CaptivePortal::start() {
 | 
			
		||||
  this->dns_server_ = make_unique<DNSServer>();
 | 
			
		||||
  this->dns_server_->setErrorReplyCode(DNSReplyCode::NoError);
 | 
			
		||||
  network::IPAddress ip = wifi::global_wifi_component->wifi_soft_ap_ip();
 | 
			
		||||
  this->dns_server_->start(53, "*", (uint32_t) ip);
 | 
			
		||||
  this->dns_server_->start(53, "*", ip);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  this->base_->get_server()->onNotFound([this](AsyncWebServerRequest *req) {
 | 
			
		||||
 
 | 
			
		||||
@@ -213,6 +213,8 @@ ClimateCall &ClimateCall::set_preset(const std::string &preset) {
 | 
			
		||||
    this->set_preset(CLIMATE_PRESET_SLEEP);
 | 
			
		||||
  } else if (str_equals_case_insensitive(preset, "ACTIVITY")) {
 | 
			
		||||
    this->set_preset(CLIMATE_PRESET_ACTIVITY);
 | 
			
		||||
  } else if (str_equals_case_insensitive(preset, "NONE")) {
 | 
			
		||||
    this->set_preset(CLIMATE_PRESET_NONE);
 | 
			
		||||
  } else {
 | 
			
		||||
    if (this->parent_->get_traits().supports_custom_preset(preset)) {
 | 
			
		||||
      this->custom_preset_ = preset;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
@@ -104,7 +104,8 @@ void CurrentBasedCover::loop() {
 | 
			
		||||
      ESP_LOGD(TAG, "'%s' - Close position reached. Took %.1fs.", this->name_.c_str(), dur);
 | 
			
		||||
      this->direction_idle_(COVER_CLOSED);
 | 
			
		||||
    }
 | 
			
		||||
  } else if (now - this->start_dir_time_ > this->max_duration_) {
 | 
			
		||||
  }
 | 
			
		||||
  if (now - this->start_dir_time_ > this->max_duration_) {
 | 
			
		||||
    ESP_LOGD(TAG, "'%s' - Max duration reached. Stopping cover.", this->name_.c_str());
 | 
			
		||||
    this->direction_idle_();
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -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))
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ from esphome.const import (
 | 
			
		||||
    CONF_SLEEP_DURATION,
 | 
			
		||||
    CONF_TIME_ID,
 | 
			
		||||
    CONF_WAKEUP_PIN,
 | 
			
		||||
    PLATFORM_ESP32,
 | 
			
		||||
    PLATFORM_ESP8266,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from esphome.components.esp32 import get_esp32_variant
 | 
			
		||||
@@ -22,6 +24,9 @@ from esphome.components.esp32.const import (
 | 
			
		||||
    VARIANT_ESP32C3,
 | 
			
		||||
    VARIANT_ESP32S2,
 | 
			
		||||
    VARIANT_ESP32S3,
 | 
			
		||||
    VARIANT_ESP32C2,
 | 
			
		||||
    VARIANT_ESP32C6,
 | 
			
		||||
    VARIANT_ESP32H2,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
WAKEUP_PINS = {
 | 
			
		||||
@@ -94,6 +99,9 @@ WAKEUP_PINS = {
 | 
			
		||||
        20,
 | 
			
		||||
        21,
 | 
			
		||||
    ],
 | 
			
		||||
    VARIANT_ESP32C2: [0, 1, 2, 3, 4, 5],
 | 
			
		||||
    VARIANT_ESP32C6: [0, 1, 2, 3, 4, 5, 6, 7],
 | 
			
		||||
    VARIANT_ESP32H2: [7, 8, 9, 10, 11, 12, 13, 14],
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -159,34 +167,39 @@ WAKEUP_CAUSES_SCHEMA = cv.Schema(
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
CONFIG_SCHEMA = cv.Schema(
 | 
			
		||||
    {
 | 
			
		||||
        cv.GenerateID(): cv.declare_id(DeepSleepComponent),
 | 
			
		||||
        cv.Optional(CONF_RUN_DURATION): cv.Any(
 | 
			
		||||
            cv.All(cv.only_on_esp32, WAKEUP_CAUSES_SCHEMA),
 | 
			
		||||
            cv.positive_time_period_milliseconds,
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds,
 | 
			
		||||
        cv.Optional(CONF_WAKEUP_PIN): cv.All(
 | 
			
		||||
            cv.only_on_esp32, pins.internal_gpio_input_pin_schema, validate_pin_number
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_WAKEUP_PIN_MODE): cv.All(
 | 
			
		||||
            cv.only_on_esp32, cv.enum(WAKEUP_PIN_MODES), upper=True
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_ESP32_EXT1_WAKEUP): cv.All(
 | 
			
		||||
            cv.only_on_esp32,
 | 
			
		||||
            cv.Schema(
 | 
			
		||||
                {
 | 
			
		||||
                    cv.Required(CONF_PINS): cv.ensure_list(
 | 
			
		||||
                        pins.internal_gpio_input_pin_schema, validate_pin_number
 | 
			
		||||
                    ),
 | 
			
		||||
                    cv.Required(CONF_MODE): cv.enum(EXT1_WAKEUP_MODES, upper=True),
 | 
			
		||||
                }
 | 
			
		||||
CONFIG_SCHEMA = cv.All(
 | 
			
		||||
    cv.Schema(
 | 
			
		||||
        {
 | 
			
		||||
            cv.GenerateID(): cv.declare_id(DeepSleepComponent),
 | 
			
		||||
            cv.Optional(CONF_RUN_DURATION): cv.Any(
 | 
			
		||||
                cv.All(cv.only_on_esp32, WAKEUP_CAUSES_SCHEMA),
 | 
			
		||||
                cv.positive_time_period_milliseconds,
 | 
			
		||||
            ),
 | 
			
		||||
        ),
 | 
			
		||||
        cv.Optional(CONF_TOUCH_WAKEUP): cv.All(cv.only_on_esp32, cv.boolean),
 | 
			
		||||
    }
 | 
			
		||||
).extend(cv.COMPONENT_SCHEMA)
 | 
			
		||||
            cv.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds,
 | 
			
		||||
            cv.Optional(CONF_WAKEUP_PIN): cv.All(
 | 
			
		||||
                cv.only_on_esp32,
 | 
			
		||||
                pins.internal_gpio_input_pin_schema,
 | 
			
		||||
                validate_pin_number,
 | 
			
		||||
            ),
 | 
			
		||||
            cv.Optional(CONF_WAKEUP_PIN_MODE): cv.All(
 | 
			
		||||
                cv.only_on_esp32, cv.enum(WAKEUP_PIN_MODES), upper=True
 | 
			
		||||
            ),
 | 
			
		||||
            cv.Optional(CONF_ESP32_EXT1_WAKEUP): cv.All(
 | 
			
		||||
                cv.only_on_esp32,
 | 
			
		||||
                cv.Schema(
 | 
			
		||||
                    {
 | 
			
		||||
                        cv.Required(CONF_PINS): cv.ensure_list(
 | 
			
		||||
                            pins.internal_gpio_input_pin_schema, validate_pin_number
 | 
			
		||||
                        ),
 | 
			
		||||
                        cv.Required(CONF_MODE): cv.enum(EXT1_WAKEUP_MODES, upper=True),
 | 
			
		||||
                    }
 | 
			
		||||
                ),
 | 
			
		||||
            ),
 | 
			
		||||
            cv.Optional(CONF_TOUCH_WAKEUP): cv.All(cv.only_on_esp32, cv.boolean),
 | 
			
		||||
        }
 | 
			
		||||
    ).extend(cv.COMPONENT_SCHEMA),
 | 
			
		||||
    cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266]),
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def to_code(config):
 | 
			
		||||
 
 | 
			
		||||
@@ -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_;
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,6 @@ void E131Component::setup() {
 | 
			
		||||
    this->mark_failed();
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  server.ss_family = AF_INET;
 | 
			
		||||
 | 
			
		||||
  err = this->socket_->bind((struct sockaddr *) &server, sizeof(server));
 | 
			
		||||
  if (err != 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -67,8 +67,8 @@ bool E131Component::join_igmp_groups_() {
 | 
			
		||||
    if (!universe.second)
 | 
			
		||||
      continue;
 | 
			
		||||
 | 
			
		||||
    ip4_addr_t multicast_addr = {static_cast<uint32_t>(
 | 
			
		||||
        network::IPAddress(239, 255, ((universe.first >> 8) & 0xff), ((universe.first >> 0) & 0xff)))};
 | 
			
		||||
    ip4_addr_t multicast_addr =
 | 
			
		||||
        network::IPAddress(239, 255, ((universe.first >> 8) & 0xff), ((universe.first >> 0) & 0xff));
 | 
			
		||||
 | 
			
		||||
    auto err = igmp_joingroup(IP4_ADDR_ANY4, &multicast_addr);
 | 
			
		||||
 | 
			
		||||
@@ -101,8 +101,7 @@ void E131Component::leave_(int universe) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (listen_method_ == E131_MULTICAST) {
 | 
			
		||||
    ip4_addr_t multicast_addr = {
 | 
			
		||||
        static_cast<uint32_t>(network::IPAddress(239, 255, ((universe >> 8) & 0xff), ((universe >> 0) & 0xff)))};
 | 
			
		||||
    ip4_addr_t multicast_addr = network::IPAddress(239, 255, ((universe >> 8) & 0xff), ((universe >> 0) & 0xff));
 | 
			
		||||
 | 
			
		||||
    igmp_leavegroup(IP4_ADDR_ANY4, &multicast_addr);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -22,8 +22,10 @@ from esphome.const import (
 | 
			
		||||
    CONF_IGNORE_EFUSE_MAC_CRC,
 | 
			
		||||
    KEY_CORE,
 | 
			
		||||
    KEY_FRAMEWORK_VERSION,
 | 
			
		||||
    KEY_NAME,
 | 
			
		||||
    KEY_TARGET_FRAMEWORK,
 | 
			
		||||
    KEY_TARGET_PLATFORM,
 | 
			
		||||
    PLATFORM_ESP32,
 | 
			
		||||
    TYPE_GIT,
 | 
			
		||||
    TYPE_LOCAL,
 | 
			
		||||
    __version__,
 | 
			
		||||
@@ -37,6 +39,7 @@ from .const import (  # noqa
 | 
			
		||||
    KEY_BOARD,
 | 
			
		||||
    KEY_COMPONENTS,
 | 
			
		||||
    KEY_ESP32,
 | 
			
		||||
    KEY_EXTRA_BUILD_FILES,
 | 
			
		||||
    KEY_PATH,
 | 
			
		||||
    KEY_REF,
 | 
			
		||||
    KEY_REFRESH,
 | 
			
		||||
@@ -44,7 +47,6 @@ from .const import (  # noqa
 | 
			
		||||
    KEY_SDKCONFIG_OPTIONS,
 | 
			
		||||
    KEY_SUBMODULES,
 | 
			
		||||
    KEY_VARIANT,
 | 
			
		||||
    VARIANT_ESP32C3,
 | 
			
		||||
    VARIANT_FRIENDLY,
 | 
			
		||||
    VARIANTS,
 | 
			
		||||
)
 | 
			
		||||
@@ -61,7 +63,7 @@ AUTO_LOAD = ["preferences"]
 | 
			
		||||
 | 
			
		||||
def set_core_data(config):
 | 
			
		||||
    CORE.data[KEY_ESP32] = {}
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "esp32"
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_ESP32
 | 
			
		||||
    conf = config[CONF_FRAMEWORK]
 | 
			
		||||
    if conf[CONF_TYPE] == FRAMEWORK_ESP_IDF:
 | 
			
		||||
        CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "esp-idf"
 | 
			
		||||
@@ -74,6 +76,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 +89,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 +171,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 +413,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 +631,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]),
 | 
			
		||||
            )
 | 
			
		||||
 
 | 
			
		||||
@@ -235,6 +235,7 @@ ESP32_BOARD_PINS = {
 | 
			
		||||
        "SDA": 5,
 | 
			
		||||
        "SS": 15,
 | 
			
		||||
    },
 | 
			
		||||
    "denky_d4": {"RX": 8, "LED": 14},
 | 
			
		||||
    "esp-wrover-kit": {},
 | 
			
		||||
    "esp32-devkitlipo": {},
 | 
			
		||||
    "esp32-evb": {
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ _ESP_SDIO_PINS = {
 | 
			
		||||
    11: "Flash Command",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_ESP32_STRAPPING_PINS = {0, 2, 4, 12, 15}
 | 
			
		||||
_ESP32_STRAPPING_PINS = {0, 2, 5, 12, 15}
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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
 | 
			
		||||
@@ -1,11 +1,53 @@
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from esphome.const import CONF_INPUT, CONF_MODE, CONF_NUMBER
 | 
			
		||||
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
 | 
			
		||||
_ESP32H2_SPI_FLASH_PINS = {6, 7, 15, 16, 17, 18, 19, 20, 21}
 | 
			
		||||
 | 
			
		||||
_ESP32H2_USB_JTAG_PINS = {26, 27}
 | 
			
		||||
 | 
			
		||||
_ESP32H2_STRAPPING_PINS = {2, 3, 8, 9, 25}
 | 
			
		||||
 | 
			
		||||
_LOGGER = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def esp32_h2_validate_gpio_pin(value):
 | 
			
		||||
    # ESP32-H2 not yet supported
 | 
			
		||||
    raise cv.Invalid("ESP32-H2 isn't supported yet")
 | 
			
		||||
    if value < 0 or value > 27:
 | 
			
		||||
        raise cv.Invalid(f"Invalid pin number: {value} (must be 0-27)")
 | 
			
		||||
    if value in _ESP32H2_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,
 | 
			
		||||
        )
 | 
			
		||||
    if value in _ESP32H2_SPI_FLASH_PINS:
 | 
			
		||||
        _LOGGER.warning(
 | 
			
		||||
            "GPIO%d is reserved for SPI Flash communication on some ESP32-H2 chip variants.\n"
 | 
			
		||||
            "Utilizing SPI-reserved pins could cause unexpected failures.\n"
 | 
			
		||||
            "See https://docs.espressif.com/projects/esp-idf/en/latest/esp32h2/api-reference/peripherals/gpio.html",
 | 
			
		||||
            value,
 | 
			
		||||
        )
 | 
			
		||||
    if value in _ESP32H2_USB_JTAG_PINS:
 | 
			
		||||
        _LOGGER.warning(
 | 
			
		||||
            "GPIO%d is reserved for the USB-Serial-JTAG interface.\n"
 | 
			
		||||
            "To use this pin as GPIO, USB-Serial-JTAG will be disabled.",
 | 
			
		||||
            value,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    return value
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def esp32_h2_validate_supports(value):
 | 
			
		||||
    # ESP32-H2 not yet supported
 | 
			
		||||
    raise cv.Invalid("ESP32-H2 isn't supported yet")
 | 
			
		||||
    num = value[CONF_NUMBER]
 | 
			
		||||
    mode = value[CONF_MODE]
 | 
			
		||||
    is_input = mode[CONF_INPUT]
 | 
			
		||||
 | 
			
		||||
    if num < 0 or num > 27:
 | 
			
		||||
        raise cv.Invalid(f"Invalid pin number: {value} (must be 0-27)")
 | 
			
		||||
    if is_input:
 | 
			
		||||
        # All ESP32 pins support input mode
 | 
			
		||||
        pass
 | 
			
		||||
    return value
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ESP32
 | 
			
		||||
 | 
			
		||||
#include "ble_uuid.h"
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include "ble_uuid.h"
 | 
			
		||||
#include "esphome/core/log.h"
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
@@ -16,8 +16,8 @@ BLEAdvertising::BLEAdvertising() {
 | 
			
		||||
  this->advertising_data_.set_scan_rsp = false;
 | 
			
		||||
  this->advertising_data_.include_name = true;
 | 
			
		||||
  this->advertising_data_.include_txpower = true;
 | 
			
		||||
  this->advertising_data_.min_interval = 0x20;
 | 
			
		||||
  this->advertising_data_.max_interval = 0x40;
 | 
			
		||||
  this->advertising_data_.min_interval = 0;
 | 
			
		||||
  this->advertising_data_.max_interval = 0;
 | 
			
		||||
  this->advertising_data_.appearance = 0x00;
 | 
			
		||||
  this->advertising_data_.manufacturer_len = 0;
 | 
			
		||||
  this->advertising_data_.p_manufacturer_data = nullptr;
 | 
			
		||||
@@ -42,9 +42,26 @@ 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_service_data(const std::vector<uint8_t> &data) {
 | 
			
		||||
  delete[] this->advertising_data_.p_service_data;
 | 
			
		||||
  this->advertising_data_.p_service_data = nullptr;
 | 
			
		||||
  this->advertising_data_.service_data_len = data.size();
 | 
			
		||||
  if (!data.empty()) {
 | 
			
		||||
    // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
 | 
			
		||||
    this->advertising_data_.p_service_data = new uint8_t[data.size()];
 | 
			
		||||
    memcpy(this->advertising_data_.p_service_data, data.data(), data.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 +91,19 @@ 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_.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,8 @@ 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 set_service_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};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -90,6 +90,8 @@ void BLEService::stop() {
 | 
			
		||||
    ESP_LOGE(TAG, "esp_ble_gatts_stop_service failed: %d", err);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  esp32_ble::global_ble->get_advertising()->remove_service_uuid(this->uuid_);
 | 
			
		||||
  esp32_ble::global_ble->get_advertising()->start();
 | 
			
		||||
  this->running_state_ = STOPPING;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,11 @@
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ESP32
 | 
			
		||||
 | 
			
		||||
#include <esp_bt_defs.h>
 | 
			
		||||
#include <esp_gap_ble_api.h>
 | 
			
		||||
#include <esp_gatt_defs.h>
 | 
			
		||||
#include <esp_gattc_api.h>
 | 
			
		||||
#include <esp_gatts_api.h>
 | 
			
		||||
#include <esp_bt_defs.h>
 | 
			
		||||
 | 
			
		||||
namespace esphome {
 | 
			
		||||
namespace esp32_ble_server {
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ from esphome.components import binary_sensor, output, esp32_ble_server
 | 
			
		||||
from esphome.const import CONF_ID
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
AUTO_LOAD = ["binary_sensor", "output", "esp32_ble_server"]
 | 
			
		||||
AUTO_LOAD = ["esp32_ble_server"]
 | 
			
		||||
CODEOWNERS = ["@jesserockz"]
 | 
			
		||||
CONFLICTS_WITH = ["esp32_ble_beacon"]
 | 
			
		||||
DEPENDENCIES = ["wifi", "esp32"]
 | 
			
		||||
@@ -36,6 +36,9 @@ CONFIG_SCHEMA = cv.Schema(
 | 
			
		||||
        cv.Optional(
 | 
			
		||||
            CONF_AUTHORIZED_DURATION, default="1min"
 | 
			
		||||
        ): cv.positive_time_period_milliseconds,
 | 
			
		||||
        cv.Optional(
 | 
			
		||||
            CONF_WIFI_TIMEOUT, default="1min"
 | 
			
		||||
        ): cv.positive_time_period_milliseconds,
 | 
			
		||||
    }
 | 
			
		||||
).extend(cv.COMPONENT_SCHEMA)
 | 
			
		||||
 | 
			
		||||
@@ -53,6 +56,8 @@ async def to_code(config):
 | 
			
		||||
    cg.add(var.set_identify_duration(config[CONF_IDENTIFY_DURATION]))
 | 
			
		||||
    cg.add(var.set_authorized_duration(config[CONF_AUTHORIZED_DURATION]))
 | 
			
		||||
 | 
			
		||||
    cg.add(var.set_wifi_timeout(config[CONF_WIFI_TIMEOUT]))
 | 
			
		||||
 | 
			
		||||
    if CONF_AUTHORIZER in config and config[CONF_AUTHORIZER] is not None:
 | 
			
		||||
        activator = await cg.get_variable(config[CONF_AUTHORIZER])
 | 
			
		||||
        cg.add(var.set_authorizer(activator))
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,17 @@ ESP32ImprovComponent::ESP32ImprovComponent() { global_improv_component = this; }
 | 
			
		||||
void ESP32ImprovComponent::setup() {
 | 
			
		||||
  this->service_ = global_ble_server->create_service(improv::SERVICE_UUID, true);
 | 
			
		||||
  this->setup_characteristics();
 | 
			
		||||
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
  if (this->authorizer_ != nullptr) {
 | 
			
		||||
    this->authorizer_->add_on_state_callback([this](bool state) {
 | 
			
		||||
      if (state) {
 | 
			
		||||
        this->authorized_start_ = millis();
 | 
			
		||||
        this->identify_start_ = 0;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP32ImprovComponent::setup_characteristics() {
 | 
			
		||||
@@ -50,8 +61,10 @@ void ESP32ImprovComponent::setup_characteristics() {
 | 
			
		||||
  BLEDescriptor *capabilities_descriptor = new BLE2902();
 | 
			
		||||
  this->capabilities_->add_descriptor(capabilities_descriptor);
 | 
			
		||||
  uint8_t capabilities = 0x00;
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  if (this->status_indicator_ != nullptr)
 | 
			
		||||
    capabilities |= improv::CAPABILITY_IDENTIFY;
 | 
			
		||||
#endif
 | 
			
		||||
  this->capabilities_->set_value(capabilities);
 | 
			
		||||
  this->setup_complete_ = true;
 | 
			
		||||
}
 | 
			
		||||
@@ -63,8 +76,7 @@ void ESP32ImprovComponent::loop() {
 | 
			
		||||
 | 
			
		||||
  switch (this->state_) {
 | 
			
		||||
    case improv::STATE_STOPPED:
 | 
			
		||||
      if (this->status_indicator_ != nullptr)
 | 
			
		||||
        this->status_indicator_->turn_off();
 | 
			
		||||
      this->set_status_indicator_state_(false);
 | 
			
		||||
 | 
			
		||||
      if (this->service_->is_created() && this->should_start_ && this->setup_complete_) {
 | 
			
		||||
        if (this->service_->is_running()) {
 | 
			
		||||
@@ -80,18 +92,22 @@ void ESP32ImprovComponent::loop() {
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case improv::STATE_AWAITING_AUTHORIZATION: {
 | 
			
		||||
      if (this->authorizer_ == nullptr || this->authorizer_->state) {
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
      if (this->authorizer_ == nullptr ||
 | 
			
		||||
          (this->authorized_start_ != 0 && ((now - this->authorized_start_) < this->authorized_duration_))) {
 | 
			
		||||
        this->set_state_(improv::STATE_AUTHORIZED);
 | 
			
		||||
        this->authorized_start_ = now;
 | 
			
		||||
      } else {
 | 
			
		||||
        if (this->status_indicator_ != nullptr) {
 | 
			
		||||
          if (!this->check_identify_())
 | 
			
		||||
            this->status_indicator_->turn_on();
 | 
			
		||||
        }
 | 
			
		||||
      } else
 | 
			
		||||
#else
 | 
			
		||||
      this->set_state_(improv::STATE_AUTHORIZED);
 | 
			
		||||
#endif
 | 
			
		||||
      {
 | 
			
		||||
        if (!this->check_identify_())
 | 
			
		||||
          this->set_status_indicator_state_(true);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case improv::STATE_AUTHORIZED: {
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
      if (this->authorizer_ != nullptr) {
 | 
			
		||||
        if (now - this->authorized_start_ > this->authorized_duration_) {
 | 
			
		||||
          ESP_LOGD(TAG, "Authorization timeout");
 | 
			
		||||
@@ -99,25 +115,14 @@ void ESP32ImprovComponent::loop() {
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (this->status_indicator_ != nullptr) {
 | 
			
		||||
        if (!this->check_identify_()) {
 | 
			
		||||
          if ((now % 1000) < 500) {
 | 
			
		||||
            this->status_indicator_->turn_on();
 | 
			
		||||
          } else {
 | 
			
		||||
            this->status_indicator_->turn_off();
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
      if (!this->check_identify_()) {
 | 
			
		||||
        this->set_status_indicator_state_((now % 1000) < 500);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    case improv::STATE_PROVISIONING: {
 | 
			
		||||
      if (this->status_indicator_ != nullptr) {
 | 
			
		||||
        if ((now % 200) < 100) {
 | 
			
		||||
          this->status_indicator_->turn_on();
 | 
			
		||||
        } else {
 | 
			
		||||
          this->status_indicator_->turn_off();
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      this->set_status_indicator_state_((now % 200) < 100);
 | 
			
		||||
      if (wifi::global_wifi_component->is_connected()) {
 | 
			
		||||
        wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(),
 | 
			
		||||
                                                   this->connecting_sta_.get_password());
 | 
			
		||||
@@ -142,13 +147,27 @@ void ESP32ImprovComponent::loop() {
 | 
			
		||||
    }
 | 
			
		||||
    case improv::STATE_PROVISIONED: {
 | 
			
		||||
      this->incoming_data_.clear();
 | 
			
		||||
      if (this->status_indicator_ != nullptr)
 | 
			
		||||
        this->status_indicator_->turn_off();
 | 
			
		||||
      this->set_status_indicator_state_(false);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP32ImprovComponent::set_status_indicator_state_(bool state) {
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  if (this->status_indicator_ == nullptr)
 | 
			
		||||
    return;
 | 
			
		||||
  if (this->status_indicator_state_ == state)
 | 
			
		||||
    return;
 | 
			
		||||
  this->status_indicator_state_ = state;
 | 
			
		||||
  if (state) {
 | 
			
		||||
    this->status_indicator_->turn_on();
 | 
			
		||||
  } else {
 | 
			
		||||
    this->status_indicator_->turn_off();
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ESP32ImprovComponent::check_identify_() {
 | 
			
		||||
  uint32_t now = millis();
 | 
			
		||||
 | 
			
		||||
@@ -156,11 +175,7 @@ bool ESP32ImprovComponent::check_identify_() {
 | 
			
		||||
 | 
			
		||||
  if (identify) {
 | 
			
		||||
    uint32_t time = now % 1000;
 | 
			
		||||
    if (time < 600 && time % 200 < 100) {
 | 
			
		||||
      this->status_indicator_->turn_on();
 | 
			
		||||
    } else {
 | 
			
		||||
      this->status_indicator_->turn_off();
 | 
			
		||||
    }
 | 
			
		||||
    this->set_status_indicator_state_(time < 600 && time % 200 < 100);
 | 
			
		||||
  }
 | 
			
		||||
  return identify;
 | 
			
		||||
}
 | 
			
		||||
@@ -174,6 +189,25 @@ void ESP32ImprovComponent::set_state_(improv::State state) {
 | 
			
		||||
    if (state != improv::STATE_STOPPED)
 | 
			
		||||
      this->status_->notify();
 | 
			
		||||
  }
 | 
			
		||||
  std::vector<uint8_t> service_data(8, 0);
 | 
			
		||||
  service_data[0] = 0x77;  // PR
 | 
			
		||||
  service_data[1] = 0x46;  // IM
 | 
			
		||||
  service_data[2] = static_cast<uint8_t>(state);
 | 
			
		||||
 | 
			
		||||
  uint8_t capabilities = 0x00;
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  if (this->status_indicator_ != nullptr)
 | 
			
		||||
    capabilities |= improv::CAPABILITY_IDENTIFY;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  service_data[3] = capabilities;
 | 
			
		||||
  service_data[4] = 0x00;  // Reserved
 | 
			
		||||
  service_data[5] = 0x00;  // Reserved
 | 
			
		||||
  service_data[6] = 0x00;  // Reserved
 | 
			
		||||
  service_data[7] = 0x00;  // Reserved
 | 
			
		||||
 | 
			
		||||
  esp32_ble::global_ble->get_advertising()->set_service_data(service_data);
 | 
			
		||||
  esp32_ble::global_ble->get_advertising()->start();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP32ImprovComponent::set_error_(improv::Error error) {
 | 
			
		||||
@@ -213,8 +247,12 @@ float ESP32ImprovComponent::get_setup_priority() const { return setup_priority::
 | 
			
		||||
 | 
			
		||||
void ESP32ImprovComponent::dump_config() {
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "ESP32 Improv:");
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
  LOG_BINARY_SENSOR("  ", "Authorizer", this->authorizer_);
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Status Indicator: '%s'", YESNO(this->status_indicator_ != nullptr));
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP32ImprovComponent::process_incoming_data_() {
 | 
			
		||||
@@ -273,8 +311,10 @@ void ESP32ImprovComponent::process_incoming_data_() {
 | 
			
		||||
void ESP32ImprovComponent::on_wifi_connect_timeout_() {
 | 
			
		||||
  this->set_error_(improv::ERROR_UNABLE_TO_CONNECT);
 | 
			
		||||
  this->set_state_(improv::STATE_AUTHORIZED);
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
  if (this->authorizer_ != nullptr)
 | 
			
		||||
    this->authorized_start_ = millis();
 | 
			
		||||
#endif
 | 
			
		||||
  ESP_LOGW(TAG, "Timed out trying to connect to given WiFi network");
 | 
			
		||||
  wifi::global_wifi_component->clear_sta();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,22 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "esphome/components/binary_sensor/binary_sensor.h"
 | 
			
		||||
#include "esphome/components/esp32_ble_server/ble_characteristic.h"
 | 
			
		||||
#include "esphome/components/esp32_ble_server/ble_server.h"
 | 
			
		||||
#include "esphome/components/output/binary_output.h"
 | 
			
		||||
#include "esphome/components/wifi/wifi_component.h"
 | 
			
		||||
#include "esphome/core/component.h"
 | 
			
		||||
#include "esphome/core/defines.h"
 | 
			
		||||
#include "esphome/core/helpers.h"
 | 
			
		||||
#include "esphome/core/preferences.h"
 | 
			
		||||
 | 
			
		||||
#include "esphome/components/esp32_ble_server/ble_characteristic.h"
 | 
			
		||||
#include "esphome/components/esp32_ble_server/ble_server.h"
 | 
			
		||||
#include "esphome/components/wifi/wifi_component.h"
 | 
			
		||||
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
#include "esphome/components/binary_sensor/binary_sensor.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
#include "esphome/components/output/binary_output.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#ifdef USE_ESP32
 | 
			
		||||
@@ -34,11 +42,18 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
 | 
			
		||||
  void stop() override;
 | 
			
		||||
  bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
 | 
			
		||||
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
  void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
 | 
			
		||||
#endif
 | 
			
		||||
  void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
 | 
			
		||||
  void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
 | 
			
		||||
 | 
			
		||||
  void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
 | 
			
		||||
  uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  bool should_start_{false};
 | 
			
		||||
  bool setup_complete_{false};
 | 
			
		||||
@@ -48,6 +63,8 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
 | 
			
		||||
  uint32_t authorized_start_{0};
 | 
			
		||||
  uint32_t authorized_duration_;
 | 
			
		||||
 | 
			
		||||
  uint32_t wifi_timeout_{};
 | 
			
		||||
 | 
			
		||||
  std::vector<uint8_t> incoming_data_;
 | 
			
		||||
  wifi::WiFiAP connecting_sta_;
 | 
			
		||||
 | 
			
		||||
@@ -58,12 +75,19 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
 | 
			
		||||
  BLECharacteristic *rpc_response_;
 | 
			
		||||
  BLECharacteristic *capabilities_;
 | 
			
		||||
 | 
			
		||||
#ifdef USE_BINARY_SENSOR
 | 
			
		||||
  binary_sensor::BinarySensor *authorizer_{nullptr};
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef USE_OUTPUT
 | 
			
		||||
  output::BinaryOutput *status_indicator_{nullptr};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  improv::State state_{improv::STATE_STOPPED};
 | 
			
		||||
  improv::Error error_state_{improv::ERROR_NONE};
 | 
			
		||||
 | 
			
		||||
  bool status_indicator_state_{false};
 | 
			
		||||
  void set_status_indicator_state_(bool state);
 | 
			
		||||
 | 
			
		||||
  void set_state_(improv::State state);
 | 
			
		||||
  void set_error_(improv::Error error);
 | 
			
		||||
  void send_response_(std::vector<uint8_t> &response);
 | 
			
		||||
 
 | 
			
		||||
@@ -63,6 +63,8 @@ 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],
 | 
			
		||||
    esp32.const.VARIANT_ESP32H2: [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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ from esphome.const import (
 | 
			
		||||
    KEY_FRAMEWORK_VERSION,
 | 
			
		||||
    KEY_TARGET_FRAMEWORK,
 | 
			
		||||
    KEY_TARGET_PLATFORM,
 | 
			
		||||
    PLATFORM_ESP8266,
 | 
			
		||||
)
 | 
			
		||||
from esphome.core import CORE, coroutine_with_priority
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
@@ -38,7 +39,7 @@ AUTO_LOAD = ["preferences"]
 | 
			
		||||
 | 
			
		||||
def set_core_data(config):
 | 
			
		||||
    CORE.data[KEY_ESP8266] = {}
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "esp8266"
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_ESP8266
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "arduino"
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version.parse(
 | 
			
		||||
        config[CONF_FRAMEWORK][CONF_VERSION]
 | 
			
		||||
@@ -50,6 +51,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;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -236,7 +236,7 @@ bool EthernetComponent::can_proceed() { return this->is_connected(); }
 | 
			
		||||
network::IPAddress EthernetComponent::get_ip_address() {
 | 
			
		||||
  esp_netif_ip_info_t ip;
 | 
			
		||||
  esp_netif_get_ip_info(this->eth_netif_, &ip);
 | 
			
		||||
  return {ip.ip.addr};
 | 
			
		||||
  return network::IPAddress(&ip.ip);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EthernetComponent::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event, void *event_data) {
 | 
			
		||||
@@ -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();
 | 
			
		||||
@@ -293,9 +293,9 @@ void EthernetComponent::start_connect_() {
 | 
			
		||||
 | 
			
		||||
  esp_netif_ip_info_t info;
 | 
			
		||||
  if (this->manual_ip_.has_value()) {
 | 
			
		||||
    info.ip.addr = static_cast<uint32_t>(this->manual_ip_->static_ip);
 | 
			
		||||
    info.gw.addr = static_cast<uint32_t>(this->manual_ip_->gateway);
 | 
			
		||||
    info.netmask.addr = static_cast<uint32_t>(this->manual_ip_->subnet);
 | 
			
		||||
    info.ip = this->manual_ip_->static_ip;
 | 
			
		||||
    info.gw = this->manual_ip_->gateway;
 | 
			
		||||
    info.netmask = this->manual_ip_->subnet;
 | 
			
		||||
  } else {
 | 
			
		||||
    info.ip.addr = 0;
 | 
			
		||||
    info.gw.addr = 0;
 | 
			
		||||
@@ -318,24 +318,14 @@ void EthernetComponent::start_connect_() {
 | 
			
		||||
  ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
 | 
			
		||||
 | 
			
		||||
  if (this->manual_ip_.has_value()) {
 | 
			
		||||
    if (uint32_t(this->manual_ip_->dns1) != 0) {
 | 
			
		||||
    if (this->manual_ip_->dns1.is_set()) {
 | 
			
		||||
      ip_addr_t d;
 | 
			
		||||
#if LWIP_IPV6
 | 
			
		||||
      d.type = IPADDR_TYPE_V4;
 | 
			
		||||
      d.u_addr.ip4.addr = static_cast<uint32_t>(this->manual_ip_->dns1);
 | 
			
		||||
#else
 | 
			
		||||
      d.addr = static_cast<uint32_t>(this->manual_ip_->dns1);
 | 
			
		||||
#endif
 | 
			
		||||
      d = this->manual_ip_->dns1;
 | 
			
		||||
      dns_setserver(0, &d);
 | 
			
		||||
    }
 | 
			
		||||
    if (uint32_t(this->manual_ip_->dns2) != 0) {
 | 
			
		||||
    if (this->manual_ip_->dns2.is_set()) {
 | 
			
		||||
      ip_addr_t d;
 | 
			
		||||
#if LWIP_IPV6
 | 
			
		||||
      d.type = IPADDR_TYPE_V4;
 | 
			
		||||
      d.u_addr.ip4.addr = static_cast<uint32_t>(this->manual_ip_->dns2);
 | 
			
		||||
#else
 | 
			
		||||
      d.addr = static_cast<uint32_t>(this->manual_ip_->dns2);
 | 
			
		||||
#endif
 | 
			
		||||
      d = this->manual_ip_->dns2;
 | 
			
		||||
      dns_setserver(1, &d);
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
@@ -343,12 +333,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();
 | 
			
		||||
@@ -360,23 +350,18 @@ bool EthernetComponent::is_connected() { return this->state_ == EthernetComponen
 | 
			
		||||
void EthernetComponent::dump_connect_params_() {
 | 
			
		||||
  esp_netif_ip_info_t ip;
 | 
			
		||||
  esp_netif_get_ip_info(this->eth_netif_, &ip);
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  IP Address: %s", network::IPAddress(ip.ip.addr).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  IP Address: %s", network::IPAddress(&ip.ip).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Hostname: '%s'", App.get_name().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Subnet: %s", network::IPAddress(ip.netmask.addr).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Gateway: %s", network::IPAddress(ip.gw.addr).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Subnet: %s", network::IPAddress(&ip.netmask).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  Gateway: %s", network::IPAddress(&ip.gw).str().c_str());
 | 
			
		||||
 | 
			
		||||
  const ip_addr_t *dns_ip1 = dns_getserver(0);
 | 
			
		||||
  const ip_addr_t *dns_ip2 = dns_getserver(1);
 | 
			
		||||
 | 
			
		||||
#if LWIP_IPV6
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS1: %s", network::IPAddress(dns_ip1->u_addr.ip4.addr).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS2: %s", network::IPAddress(dns_ip2->u_addr.ip4.addr).str().c_str());
 | 
			
		||||
#else
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS1: %s", network::IPAddress(dns_ip1->addr).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS2: %s", network::IPAddress(dns_ip2->addr).str().c_str());
 | 
			
		||||
#endif
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS1: %s", network::IPAddress(dns_ip1).str().c_str());
 | 
			
		||||
  ESP_LOGCONFIG(TAG, "  DNS2: %s", network::IPAddress(dns_ip2).str().c_str());
 | 
			
		||||
 | 
			
		||||
#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 +372,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"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -67,18 +67,13 @@ def validate_pillow_installed(value):
 | 
			
		||||
    except ImportError as err:
 | 
			
		||||
        raise cv.Invalid(
 | 
			
		||||
            "Please install the pillow python package to use this feature. "
 | 
			
		||||
            '(pip install pillow">4.0.0,<10.0.0")'
 | 
			
		||||
            '(pip install "pillow==10.0.1")'
 | 
			
		||||
        ) from err
 | 
			
		||||
 | 
			
		||||
    if version.parse(PIL.__version__) < version.parse("4.0.0"):
 | 
			
		||||
    if version.parse(PIL.__version__) != version.parse("10.0.1"):
 | 
			
		||||
        raise cv.Invalid(
 | 
			
		||||
            "Please update your pillow installation to at least 4.0.x. "
 | 
			
		||||
            '(pip install pillow">4.0.0,<10.0.0")'
 | 
			
		||||
        )
 | 
			
		||||
    if version.parse(PIL.__version__) >= version.parse("10.0.0"):
 | 
			
		||||
        raise cv.Invalid(
 | 
			
		||||
            "Please downgrade your pillow installation to below 10.0.0. "
 | 
			
		||||
            '(pip install pillow">4.0.0,<10.0.0")'
 | 
			
		||||
            "Please update your pillow installation to 10.0.1. "
 | 
			
		||||
            '(pip install "pillow==10.0.1")'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    return value
 | 
			
		||||
@@ -98,10 +93,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:
 | 
			
		||||
@@ -143,11 +137,10 @@ def validate_weight_name(value):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def download_gfonts(value):
 | 
			
		||||
    wght = value[CONF_WEIGHT]
 | 
			
		||||
    if value[CONF_ITALIC]:
 | 
			
		||||
        wght = f"1,{wght}"
 | 
			
		||||
    name = f"{value[CONF_FAMILY]}@{value[CONF_WEIGHT]}"
 | 
			
		||||
    url = f"https://fonts.googleapis.com/css2?family={value[CONF_FAMILY]}:wght@{wght}"
 | 
			
		||||
    name = (
 | 
			
		||||
        f"{value[CONF_FAMILY]}:ital,wght@{int(value[CONF_ITALIC])},{value[CONF_WEIGHT]}"
 | 
			
		||||
    )
 | 
			
		||||
    url = f"https://fonts.googleapis.com/css2?family={name}"
 | 
			
		||||
 | 
			
		||||
    path = _compute_gfonts_local_path(value)
 | 
			
		||||
    if path.is_file():
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,15 @@ from esphome.const import (
 | 
			
		||||
    CONF_CHANNEL,
 | 
			
		||||
    CONF_SPEED,
 | 
			
		||||
    CONF_DIRECTION,
 | 
			
		||||
    CONF_ADDRESS,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
DEPENDENCIES = ["i2c"]
 | 
			
		||||
 | 
			
		||||
CODEOWNERS = ["@max246"]
 | 
			
		||||
 | 
			
		||||
MULTI_CONF = True
 | 
			
		||||
 | 
			
		||||
grove_tb6612fng_ns = cg.esphome_ns.namespace("grove_tb6612fng")
 | 
			
		||||
GROVE_TB6612FNG = grove_tb6612fng_ns.class_(
 | 
			
		||||
    "GroveMotorDriveTB6612FNG", cg.Component, i2c.I2CDevice
 | 
			
		||||
@@ -33,6 +36,9 @@ GROVETB6612FNGMotorStandbyAction = grove_tb6612fng_ns.class_(
 | 
			
		||||
GROVETB6612FNGMotorNoStandbyAction = grove_tb6612fng_ns.class_(
 | 
			
		||||
    "GROVETB6612FNGMotorNoStandbyAction", automation.Action
 | 
			
		||||
)
 | 
			
		||||
GROVETB6612FNGMotorChangeAddressAction = grove_tb6612fng_ns.class_(
 | 
			
		||||
    "GROVETB6612FNGMotorChangeAddressAction", automation.Action
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
DIRECTION_TYPE = {
 | 
			
		||||
    "FORWARD": 1,
 | 
			
		||||
@@ -150,3 +156,22 @@ async def grove_tb6612fng_no_standby_to_code(config, action_id, template_arg, ar
 | 
			
		||||
    await cg.register_parented(var, config[CONF_ID])
 | 
			
		||||
 | 
			
		||||
    return var
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@automation.register_action(
 | 
			
		||||
    "grove_tb6612fng.change_address",
 | 
			
		||||
    GROVETB6612FNGMotorChangeAddressAction,
 | 
			
		||||
    cv.Schema(
 | 
			
		||||
        {
 | 
			
		||||
            cv.Required(CONF_ID): cv.use_id(GROVE_TB6612FNG),
 | 
			
		||||
            cv.Required(CONF_ADDRESS): cv.i2c_address,
 | 
			
		||||
        }
 | 
			
		||||
    ),
 | 
			
		||||
)
 | 
			
		||||
async def grove_tb6612fng_change_address_to_code(config, action_id, template_arg, args):
 | 
			
		||||
    var = cg.new_Pvariable(action_id, template_arg)
 | 
			
		||||
    await cg.register_parented(var, config[CONF_ID])
 | 
			
		||||
 | 
			
		||||
    template_channel = await cg.templatable(config[CONF_ADDRESS], args, int)
 | 
			
		||||
    cg.add(var.set_address(template_channel))
 | 
			
		||||
    return var
 | 
			
		||||
 
 | 
			
		||||
@@ -84,8 +84,7 @@ class GroveMotorDriveTB6612FNG : public Component, public i2c::I2CDevice {
 | 
			
		||||
  *************************************************************/
 | 
			
		||||
  void set_i2c_addr(uint8_t addr);
 | 
			
		||||
 | 
			
		||||
  /*************************************************************
 | 
			
		||||
      Description
 | 
			
		||||
  /***********************************change_address
 | 
			
		||||
       Drive a motor.
 | 
			
		||||
      Parameter
 | 
			
		||||
       chl: MOTOR_CHA or MOTOR_CHB
 | 
			
		||||
@@ -204,5 +203,13 @@ class GROVETB6612FNGMotorNoStandbyAction : public Action<Ts...>, public Parented
 | 
			
		||||
  void play(Ts... x) override { this->parent_->not_standby(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template<typename... Ts>
 | 
			
		||||
class GROVETB6612FNGMotorChangeAddressAction : public Action<Ts...>, public Parented<GroveMotorDriveTB6612FNG> {
 | 
			
		||||
 public:
 | 
			
		||||
  TEMPLATABLE_VALUE(uint8_t, address)
 | 
			
		||||
 | 
			
		||||
  void play(Ts... x) override { this->parent_->set_i2c_addr(this->address_.value(x...)); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace grove_tb6612fng
 | 
			
		||||
}  // 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"
 | 
			
		||||
 
 | 
			
		||||
@@ -136,12 +136,10 @@ def validate_visual(config):
 | 
			
		||||
                    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,
 | 
			
		||||
                },
 | 
			
		||||
            )
 | 
			
		||||
            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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,9 @@ import esphome.config_validation as cv
 | 
			
		||||
from esphome.components import i2c, sensor
 | 
			
		||||
from esphome.const import (
 | 
			
		||||
    CONF_ADDRESS,
 | 
			
		||||
    CONF_FIELD_STRENGTH_X,
 | 
			
		||||
    CONF_FIELD_STRENGTH_Y,
 | 
			
		||||
    CONF_FIELD_STRENGTH_Z,
 | 
			
		||||
    CONF_ID,
 | 
			
		||||
    CONF_OVERSAMPLING,
 | 
			
		||||
    CONF_RANGE,
 | 
			
		||||
@@ -18,9 +21,6 @@ DEPENDENCIES = ["i2c"]
 | 
			
		||||
 | 
			
		||||
hmc5883l_ns = cg.esphome_ns.namespace("hmc5883l")
 | 
			
		||||
 | 
			
		||||
CONF_FIELD_STRENGTH_X = "field_strength_x"
 | 
			
		||||
CONF_FIELD_STRENGTH_Y = "field_strength_y"
 | 
			
		||||
CONF_FIELD_STRENGTH_Z = "field_strength_z"
 | 
			
		||||
CONF_HEADING = "heading"
 | 
			
		||||
 | 
			
		||||
HMC5883LComponent = hmc5883l_ns.class_(
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ from esphome.const import (
 | 
			
		||||
    KEY_FRAMEWORK_VERSION,
 | 
			
		||||
    KEY_TARGET_FRAMEWORK,
 | 
			
		||||
    KEY_TARGET_PLATFORM,
 | 
			
		||||
    PLATFORM_HOST,
 | 
			
		||||
)
 | 
			
		||||
from esphome.core import CORE
 | 
			
		||||
import esphome.config_validation as cv
 | 
			
		||||
@@ -20,7 +21,7 @@ AUTO_LOAD = ["network"]
 | 
			
		||||
 | 
			
		||||
def set_core_data(config):
 | 
			
		||||
    CORE.data[KEY_HOST] = {}
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "host"
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_HOST
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "host"
 | 
			
		||||
    CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version(1, 0, 0)
 | 
			
		||||
    return config
 | 
			
		||||
 
 | 
			
		||||
@@ -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(heater_level);
 | 
			
		||||
  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
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user