mirror of
https://github.com/esphome/esphome.git
synced 2025-11-06 10:01:51 +00:00
Compare commits
51 Commits
2023.11.0b
...
2023.11.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cadbf7463e | ||
|
|
3f40e32eba | ||
|
|
b421fccc08 | ||
|
|
10ca05b686 | ||
|
|
d0ac202a3f | ||
|
|
1c4b06700f | ||
|
|
47d42afda3 | ||
|
|
1a9f66e630 | ||
|
|
8fb6b8f1a2 | ||
|
|
22eef036c7 | ||
|
|
625ce2b8eb | ||
|
|
e5e3b253bc | ||
|
|
c369443263 | ||
|
|
1e061582d3 | ||
|
|
445b13dbc6 | ||
|
|
255483de63 | ||
|
|
4ac49907ca | ||
|
|
c536c976b7 | ||
|
|
0c18872888 | ||
|
|
197b6b4275 | ||
|
|
4e8bdc2155 | ||
|
|
f1e8622187 | ||
|
|
e0c7a02fbc | ||
|
|
2a20a5fc11 | ||
|
|
7100d073f8 | ||
|
|
1ac6cf2ff9 | ||
|
|
2ee089c9d5 | ||
|
|
bd568eecf5 | ||
|
|
3e2b83acb0 | ||
|
|
c1eb5bd675 | ||
|
|
a9772ebf3f | ||
|
|
a9a17ee89d | ||
|
|
f094702a16 | ||
|
|
908f56ff46 | ||
|
|
bd5905c59a | ||
|
|
91299f05f7 | ||
|
|
30e5ff9fff | ||
|
|
163b38e153 | ||
|
|
3b486084c8 | ||
|
|
9d453f0ba2 | ||
|
|
799851a83a | ||
|
|
7a9866f1b6 | ||
|
|
3d30f1f733 | ||
|
|
1e55764d52 | ||
|
|
020da89b6a | ||
|
|
6932422104 | ||
|
|
29aa15b253 | ||
|
|
c40519ec6f | ||
|
|
6c62c00963 | ||
|
|
1bd2e558d6 | ||
|
|
dbb1263a36 |
@@ -246,6 +246,7 @@ esphome/components/radon_eye_rd200/* @jeffeb3
|
|||||||
esphome/components/rc522/* @glmnet
|
esphome/components/rc522/* @glmnet
|
||||||
esphome/components/rc522_i2c/* @glmnet
|
esphome/components/rc522_i2c/* @glmnet
|
||||||
esphome/components/rc522_spi/* @glmnet
|
esphome/components/rc522_spi/* @glmnet
|
||||||
|
esphome/components/resistance_sampler/* @jesserockz
|
||||||
esphome/components/restart/* @esphome/core
|
esphome/components/restart/* @esphome/core
|
||||||
esphome/components/rf_bridge/* @jesserockz
|
esphome/components/rf_bridge/* @jesserockz
|
||||||
esphome/components/rgbct/* @jesserockz
|
esphome/components/rgbct/* @jesserockz
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
# One of "docker", "hassio"
|
# One of "docker", "hassio"
|
||||||
ARG BASEIMGTYPE=docker
|
ARG BASEIMGTYPE=docker
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/hassio-addons/addon-debian-base/releases
|
# https://github.com/hassio-addons/addon-debian-base/releases
|
||||||
FROM ghcr.io/hassio-addons/debian-base:7.2.0 AS base-hassio
|
FROM ghcr.io/hassio-addons/debian-base:7.2.0 AS base-hassio
|
||||||
# https://hub.docker.com/_/debian?tab=tags&page=1&name=bookworm
|
# https://hub.docker.com/_/debian?tab=tags&page=1&name=bookworm
|
||||||
@@ -12,9 +13,11 @@ FROM debian:12.2-slim AS base-docker
|
|||||||
|
|
||||||
FROM base-${BASEIMGTYPE} AS base
|
FROM base-${BASEIMGTYPE} AS base
|
||||||
|
|
||||||
|
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG TARGETVARIANT
|
ARG TARGETVARIANT
|
||||||
|
|
||||||
|
|
||||||
# Note that --break-system-packages is used below because
|
# Note that --break-system-packages is used below because
|
||||||
# https://peps.python.org/pep-0668/ added a safety check that prevents
|
# https://peps.python.org/pep-0668/ added a safety check that prevents
|
||||||
# installing packages with the same name as a system package. This is
|
# installing packages with the same name as a system package. This is
|
||||||
@@ -45,8 +48,10 @@ RUN \
|
|||||||
libfreetype-dev=2.12.1+dfsg-5 \
|
libfreetype-dev=2.12.1+dfsg-5 \
|
||||||
libssl-dev=3.0.11-1~deb12u2 \
|
libssl-dev=3.0.11-1~deb12u2 \
|
||||||
libffi-dev=3.4.4-1 \
|
libffi-dev=3.4.4-1 \
|
||||||
|
libopenjp2-7=2.5.0-2 \
|
||||||
|
libtiff6=4.5.0-6 \
|
||||||
cargo=0.66.0+ds1-1 \
|
cargo=0.66.0+ds1-1 \
|
||||||
pkg-config=1.8.1-1; \
|
pkg-config=1.8.1-1 \
|
||||||
gcc-arm-linux-gnueabihf=4:12.2.0-3; \
|
gcc-arm-linux-gnueabihf=4:12.2.0-3; \
|
||||||
fi; \
|
fi; \
|
||||||
rm -rf \
|
rm -rf \
|
||||||
@@ -60,19 +65,22 @@ ENV \
|
|||||||
# Store globally installed pio libs in /piolibs
|
# Store globally installed pio libs in /piolibs
|
||||||
PLATFORMIO_GLOBALLIB_DIR=/piolibs
|
PLATFORMIO_GLOBALLIB_DIR=/piolibs
|
||||||
|
|
||||||
|
|
||||||
# Support legacy binaries on Debian multiarch system. There is no "correct" way
|
# Support legacy binaries on Debian multiarch system. There is no "correct" way
|
||||||
# to do this, other than using properly built toolchains...
|
# to do this, other than using properly built toolchains...
|
||||||
# See: https://unix.stackexchange.com/questions/553743/correct-way-to-add-lib-ld-linux-so-3-in-debian
|
# See: https://unix.stackexchange.com/questions/553743/correct-way-to-add-lib-ld-linux-so-3-in-debian
|
||||||
RUN \
|
RUN \
|
||||||
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
ln -s /lib/arm-linux-gnueabihf/ld-linux.so.3 /lib/ld-linux.so.3; \
|
ln -s /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 /lib/ld-linux.so.3; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
# Ubuntu python3-pip is missing wheel
|
# Ubuntu python3-pip is missing wheel
|
||||||
pip3 install --break-system-packages --no-cache-dir \
|
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
platformio==6.1.11 \
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
||||||
|
fi; \
|
||||||
|
pip3 install \
|
||||||
|
--break-system-packages --no-cache-dir \
|
||||||
|
platformio==6.1.11 \
|
||||||
# Change some platformio settings
|
# Change some platformio settings
|
||||||
&& platformio settings set enable_telemetry No \
|
&& platformio settings set enable_telemetry No \
|
||||||
&& platformio settings set check_platformio_interval 1000000 \
|
&& platformio settings set check_platformio_interval 1000000 \
|
||||||
@@ -83,8 +91,12 @@ RUN \
|
|||||||
# tmpfs is for https://github.com/rust-lang/cargo/issues/8719
|
# tmpfs is for https://github.com/rust-lang/cargo/issues/8719
|
||||||
|
|
||||||
COPY requirements.txt requirements_optional.txt script/platformio_install_deps.py platformio.ini /
|
COPY requirements.txt requirements_optional.txt script/platformio_install_deps.py platformio.ini /
|
||||||
RUN --mount=type=tmpfs,target=/root/.cargo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse CARGO_HOME=/root/.cargo \
|
RUN --mount=type=tmpfs,target=/root/.cargo if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
pip3 install --break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
||||||
|
fi; \
|
||||||
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse CARGO_HOME=/root/.cargo \
|
||||||
|
pip3 install \
|
||||||
|
--break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
|
||||||
&& /platformio_install_deps.py /platformio.ini --libraries
|
&& /platformio_install_deps.py /platformio.ini --libraries
|
||||||
|
|
||||||
|
|
||||||
@@ -93,7 +105,11 @@ FROM base AS docker
|
|||||||
|
|
||||||
# Copy esphome and install
|
# Copy esphome and install
|
||||||
COPY . /esphome
|
COPY . /esphome
|
||||||
RUN pip3 install --break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
||||||
|
fi; \
|
||||||
|
pip3 install \
|
||||||
|
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
||||||
|
|
||||||
# Settings for dashboard
|
# Settings for dashboard
|
||||||
ENV USERNAME="" PASSWORD=""
|
ENV USERNAME="" PASSWORD=""
|
||||||
@@ -139,7 +155,11 @@ COPY docker/ha-addon-rootfs/ /
|
|||||||
|
|
||||||
# Copy esphome and install
|
# Copy esphome and install
|
||||||
COPY . /esphome
|
COPY . /esphome
|
||||||
RUN pip3 install --break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
||||||
|
fi; \
|
||||||
|
pip3 install \
|
||||||
|
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
|
||||||
|
|
||||||
# Labels
|
# Labels
|
||||||
LABEL \
|
LABEL \
|
||||||
@@ -175,7 +195,11 @@ RUN \
|
|||||||
/var/lib/apt/lists/*
|
/var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY requirements_test.txt /
|
COPY requirements_test.txt /
|
||||||
RUN pip3 install --break-system-packages --no-cache-dir -r /requirements_test.txt
|
RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||||
|
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
|
||||||
|
fi; \
|
||||||
|
pip3 install \
|
||||||
|
--break-system-packages --no-cache-dir -r /requirements_test.txt
|
||||||
|
|
||||||
VOLUME ["/esphome"]
|
VOLUME ["/esphome"]
|
||||||
WORKDIR /esphome
|
WORKDIR /esphome
|
||||||
|
|||||||
@@ -1,71 +1,65 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Any
|
||||||
|
|
||||||
from aioesphomeapi import APIClient, ReconnectLogic, APIConnectionError, LogLevel
|
from aioesphomeapi import APIClient
|
||||||
import zeroconf
|
from aioesphomeapi.api_pb2 import SubscribeLogsResponse
|
||||||
|
from aioesphomeapi.log_runner import async_run
|
||||||
|
from zeroconf.asyncio import AsyncZeroconf
|
||||||
|
|
||||||
|
from esphome.const import CONF_KEY, CONF_PASSWORD, CONF_PORT, __version__
|
||||||
|
from esphome.core import CORE
|
||||||
|
|
||||||
from esphome.const import CONF_KEY, CONF_PORT, CONF_PASSWORD, __version__
|
|
||||||
from esphome.util import safe_print
|
|
||||||
from . import CONF_ENCRYPTION
|
from . import CONF_ENCRYPTION
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_run_logs(config, address):
|
async def async_run_logs(config, address):
|
||||||
|
"""Run the logs command in the event loop."""
|
||||||
conf = config["api"]
|
conf = config["api"]
|
||||||
port: int = int(conf[CONF_PORT])
|
port: int = int(conf[CONF_PORT])
|
||||||
password: str = conf[CONF_PASSWORD]
|
password: str = conf[CONF_PASSWORD]
|
||||||
noise_psk: Optional[str] = None
|
noise_psk: str | None = None
|
||||||
if CONF_ENCRYPTION in conf:
|
if CONF_ENCRYPTION in conf:
|
||||||
noise_psk = conf[CONF_ENCRYPTION][CONF_KEY]
|
noise_psk = conf[CONF_ENCRYPTION][CONF_KEY]
|
||||||
_LOGGER.info("Starting log output from %s using esphome API", address)
|
_LOGGER.info("Starting log output from %s using esphome API", address)
|
||||||
|
aiozc = AsyncZeroconf()
|
||||||
|
|
||||||
cli = APIClient(
|
cli = APIClient(
|
||||||
address,
|
address,
|
||||||
port,
|
port,
|
||||||
password,
|
password,
|
||||||
client_info=f"ESPHome Logs {__version__}",
|
client_info=f"ESPHome Logs {__version__}",
|
||||||
noise_psk=noise_psk,
|
noise_psk=noise_psk,
|
||||||
|
zeroconf_instance=aiozc.zeroconf,
|
||||||
)
|
)
|
||||||
first_connect = True
|
dashboard = CORE.dashboard
|
||||||
|
|
||||||
def on_log(msg):
|
def on_log(msg: SubscribeLogsResponse) -> None:
|
||||||
time_ = datetime.now().time().strftime("[%H:%M:%S]")
|
"""Handle a new log message."""
|
||||||
text = msg.message.decode("utf8", "backslashreplace")
|
time_ = datetime.now()
|
||||||
safe_print(time_ + text)
|
message: bytes = msg.message
|
||||||
|
text = message.decode("utf8", "backslashreplace")
|
||||||
async def on_connect():
|
if dashboard:
|
||||||
nonlocal first_connect
|
text = text.replace("\033", "\\033")
|
||||||
try:
|
print(f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]{text}")
|
||||||
await cli.subscribe_logs(
|
|
||||||
on_log,
|
|
||||||
log_level=LogLevel.LOG_LEVEL_VERY_VERBOSE,
|
|
||||||
dump_config=first_connect,
|
|
||||||
)
|
|
||||||
first_connect = False
|
|
||||||
except APIConnectionError:
|
|
||||||
cli.disconnect()
|
|
||||||
|
|
||||||
async def on_disconnect(expected_disconnect: bool) -> None:
|
|
||||||
_LOGGER.warning("Disconnected from API")
|
|
||||||
|
|
||||||
zc = zeroconf.Zeroconf()
|
|
||||||
reconnect = ReconnectLogic(
|
|
||||||
client=cli,
|
|
||||||
on_connect=on_connect,
|
|
||||||
on_disconnect=on_disconnect,
|
|
||||||
zeroconf_instance=zc,
|
|
||||||
)
|
|
||||||
await reconnect.start()
|
|
||||||
|
|
||||||
|
stop = await async_run(cli, on_log, aio_zeroconf_instance=aiozc)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
finally:
|
||||||
|
await aiozc.async_close()
|
||||||
|
await stop()
|
||||||
|
|
||||||
|
|
||||||
|
def run_logs(config: dict[str, Any], address: str) -> None:
|
||||||
|
"""Run the logs command."""
|
||||||
|
try:
|
||||||
|
asyncio.run(async_run_logs(config, address))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
await reconnect.stop()
|
pass
|
||||||
zc.close()
|
|
||||||
|
|
||||||
|
|
||||||
def run_logs(config, address):
|
|
||||||
asyncio.run(async_run_logs(config, address))
|
|
||||||
|
|||||||
@@ -3,23 +3,26 @@ from typing import Union, Optional
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import esphome.final_validate as fv
|
||||||
|
|
||||||
from esphome.helpers import copy_file_if_changed, write_file_if_changed, mkdir_p
|
from esphome.helpers import copy_file_if_changed, write_file_if_changed, mkdir_p
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
|
CONF_ADVANCED,
|
||||||
CONF_BOARD,
|
CONF_BOARD,
|
||||||
CONF_COMPONENTS,
|
CONF_COMPONENTS,
|
||||||
|
CONF_ESPHOME,
|
||||||
CONF_FRAMEWORK,
|
CONF_FRAMEWORK,
|
||||||
|
CONF_IGNORE_EFUSE_MAC_CRC,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
CONF_PATH,
|
||||||
|
CONF_PLATFORMIO_OPTIONS,
|
||||||
|
CONF_REF,
|
||||||
|
CONF_REFRESH,
|
||||||
CONF_SOURCE,
|
CONF_SOURCE,
|
||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
|
CONF_URL,
|
||||||
CONF_VARIANT,
|
CONF_VARIANT,
|
||||||
CONF_VERSION,
|
CONF_VERSION,
|
||||||
CONF_ADVANCED,
|
|
||||||
CONF_REFRESH,
|
|
||||||
CONF_PATH,
|
|
||||||
CONF_URL,
|
|
||||||
CONF_REF,
|
|
||||||
CONF_IGNORE_EFUSE_MAC_CRC,
|
|
||||||
KEY_CORE,
|
KEY_CORE,
|
||||||
KEY_FRAMEWORK_VERSION,
|
KEY_FRAMEWORK_VERSION,
|
||||||
KEY_NAME,
|
KEY_NAME,
|
||||||
@@ -327,6 +330,32 @@ def _detect_variant(value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def final_validate(config):
|
||||||
|
if CONF_PLATFORMIO_OPTIONS not in fv.full_config.get()[CONF_ESPHOME]:
|
||||||
|
return config
|
||||||
|
|
||||||
|
pio_flash_size_key = "board_upload.flash_size"
|
||||||
|
pio_partitions_key = "board_build.partitions"
|
||||||
|
if (
|
||||||
|
CONF_PARTITIONS in config
|
||||||
|
and pio_partitions_key
|
||||||
|
in fv.full_config.get()[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS]
|
||||||
|
):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"Do not specify '{pio_partitions_key}' in '{CONF_PLATFORMIO_OPTIONS}' with '{CONF_PARTITIONS}' in esp32"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
pio_flash_size_key
|
||||||
|
in fv.full_config.get()[CONF_ESPHOME][CONF_PLATFORMIO_OPTIONS]
|
||||||
|
):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"Please specify {CONF_FLASH_SIZE} within esp32 configuration only"
|
||||||
|
)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
CONF_PLATFORM_VERSION = "platform_version"
|
CONF_PLATFORM_VERSION = "platform_version"
|
||||||
|
|
||||||
ARDUINO_FRAMEWORK_SCHEMA = cv.All(
|
ARDUINO_FRAMEWORK_SCHEMA = cv.All(
|
||||||
@@ -386,10 +415,24 @@ FRAMEWORK_SCHEMA = cv.typed_schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FLASH_SIZES = [
|
||||||
|
"2MB",
|
||||||
|
"4MB",
|
||||||
|
"8MB",
|
||||||
|
"16MB",
|
||||||
|
"32MB",
|
||||||
|
]
|
||||||
|
|
||||||
|
CONF_FLASH_SIZE = "flash_size"
|
||||||
|
CONF_PARTITIONS = "partitions"
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_BOARD): cv.string_strict,
|
cv.Required(CONF_BOARD): cv.string_strict,
|
||||||
|
cv.Optional(CONF_FLASH_SIZE, default="4MB"): cv.one_of(
|
||||||
|
*FLASH_SIZES, upper=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_PARTITIONS): cv.file_,
|
||||||
cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True),
|
cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True),
|
||||||
cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA,
|
cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA,
|
||||||
}
|
}
|
||||||
@@ -399,8 +442,12 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FINAL_VALIDATE_SCHEMA = cv.Schema(final_validate)
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
cg.add_platformio_option("board", config[CONF_BOARD])
|
cg.add_platformio_option("board", config[CONF_BOARD])
|
||||||
|
cg.add_platformio_option("board_upload.flash_size", config[CONF_FLASH_SIZE])
|
||||||
cg.add_build_flag("-DUSE_ESP32")
|
cg.add_build_flag("-DUSE_ESP32")
|
||||||
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
|
||||||
cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}")
|
cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}")
|
||||||
@@ -450,7 +497,10 @@ async def to_code(config):
|
|||||||
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0", False)
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0", False)
|
||||||
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1", False)
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1", False)
|
||||||
|
|
||||||
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
if CONF_PARTITIONS in config:
|
||||||
|
cg.add_platformio_option("board_build.partitions", config[CONF_PARTITIONS])
|
||||||
|
else:
|
||||||
|
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
||||||
|
|
||||||
for name, value in conf[CONF_SDKCONFIG_OPTIONS].items():
|
for name, value in conf[CONF_SDKCONFIG_OPTIONS].items():
|
||||||
add_idf_sdkconfig_option(name, RawSdkconfigValue(value))
|
add_idf_sdkconfig_option(name, RawSdkconfigValue(value))
|
||||||
@@ -495,7 +545,10 @@ async def to_code(config):
|
|||||||
[f"platformio/framework-arduinoespressif32@{conf[CONF_SOURCE]}"],
|
[f"platformio/framework-arduinoespressif32@{conf[CONF_SOURCE]}"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
if CONF_PARTITIONS in config:
|
||||||
|
cg.add_platformio_option("board_build.partitions", config[CONF_PARTITIONS])
|
||||||
|
else:
|
||||||
|
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
||||||
|
|
||||||
cg.add_define(
|
cg.add_define(
|
||||||
"USE_ARDUINO_VERSION_CODE",
|
"USE_ARDUINO_VERSION_CODE",
|
||||||
@@ -505,24 +558,47 @@ async def to_code(config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
ARDUINO_PARTITIONS_CSV = """\
|
APP_PARTITION_SIZES = {
|
||||||
nvs, data, nvs, 0x009000, 0x005000,
|
"2MB": 0x0C0000, # 768 KB
|
||||||
otadata, data, ota, 0x00e000, 0x002000,
|
"4MB": 0x1C0000, # 1792 KB
|
||||||
app0, app, ota_0, 0x010000, 0x1C0000,
|
"8MB": 0x3C0000, # 3840 KB
|
||||||
app1, app, ota_1, 0x1D0000, 0x1C0000,
|
"16MB": 0x7C0000, # 7936 KB
|
||||||
eeprom, data, 0x99, 0x390000, 0x001000,
|
"32MB": 0xFC0000, # 16128 KB
|
||||||
spiffs, data, spiffs, 0x391000, 0x00F000
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_arduino_partition_csv(flash_size):
|
||||||
|
app_partition_size = APP_PARTITION_SIZES[flash_size]
|
||||||
|
eeprom_partition_size = 0x1000 # 4 KB
|
||||||
|
spiffs_partition_size = 0xF000 # 60 KB
|
||||||
|
|
||||||
|
app0_partition_start = 0x010000 # 64 KB
|
||||||
|
app1_partition_start = app0_partition_start + app_partition_size
|
||||||
|
eeprom_partition_start = app1_partition_start + app_partition_size
|
||||||
|
spiffs_partition_start = eeprom_partition_start + eeprom_partition_size
|
||||||
|
|
||||||
|
partition_csv = f"""\
|
||||||
|
nvs, data, nvs, 0x9000, 0x5000,
|
||||||
|
otadata, data, ota, 0xE000, 0x2000,
|
||||||
|
app0, app, ota_0, 0x{app0_partition_start:X}, 0x{app_partition_size:X},
|
||||||
|
app1, app, ota_1, 0x{app1_partition_start:X}, 0x{app_partition_size:X},
|
||||||
|
eeprom, data, 0x99, 0x{eeprom_partition_start:X}, 0x{eeprom_partition_size:X},
|
||||||
|
spiffs, data, spiffs, 0x{spiffs_partition_start:X}, 0x{spiffs_partition_size:X}
|
||||||
"""
|
"""
|
||||||
|
return partition_csv
|
||||||
|
|
||||||
|
|
||||||
IDF_PARTITIONS_CSV = """\
|
def get_idf_partition_csv(flash_size):
|
||||||
# Name, Type, SubType, Offset, Size, Flags
|
app_partition_size = APP_PARTITION_SIZES[flash_size]
|
||||||
|
|
||||||
|
partition_csv = f"""\
|
||||||
otadata, data, ota, , 0x2000,
|
otadata, data, ota, , 0x2000,
|
||||||
phy_init, data, phy, , 0x1000,
|
phy_init, data, phy, , 0x1000,
|
||||||
app0, app, ota_0, , 0x1C0000,
|
app0, app, ota_0, , 0x{app_partition_size:X},
|
||||||
app1, app, ota_1, , 0x1C0000,
|
app1, app, ota_1, , 0x{app_partition_size:X},
|
||||||
nvs, data, nvs, , 0x6d000,
|
nvs, data, nvs, , 0x6D000,
|
||||||
"""
|
"""
|
||||||
|
return partition_csv
|
||||||
|
|
||||||
|
|
||||||
def _format_sdkconfig_val(value: SdkconfigValueType) -> str:
|
def _format_sdkconfig_val(value: SdkconfigValueType) -> str:
|
||||||
@@ -565,13 +641,17 @@ def copy_files():
|
|||||||
if CORE.using_arduino:
|
if CORE.using_arduino:
|
||||||
write_file_if_changed(
|
write_file_if_changed(
|
||||||
CORE.relative_build_path("partitions.csv"),
|
CORE.relative_build_path("partitions.csv"),
|
||||||
ARDUINO_PARTITIONS_CSV,
|
get_arduino_partition_csv(
|
||||||
|
CORE.platformio_options.get("board_upload.flash_size")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
if CORE.using_esp_idf:
|
if CORE.using_esp_idf:
|
||||||
_write_sdkconfig()
|
_write_sdkconfig()
|
||||||
write_file_if_changed(
|
write_file_if_changed(
|
||||||
CORE.relative_build_path("partitions.csv"),
|
CORE.relative_build_path("partitions.csv"),
|
||||||
IDF_PARTITIONS_CSV,
|
get_idf_partition_csv(
|
||||||
|
CORE.platformio_options.get("board_upload.flash_size")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# IDF build scripts look for version string to put in the build.
|
# IDF build scripts look for version string to put in the build.
|
||||||
# However, if the build path does not have an initialized git repo,
|
# However, if the build path does not have an initialized git repo,
|
||||||
|
|||||||
@@ -20,16 +20,21 @@ static const esp_bt_uuid_t NOTIFY_DESC_UUID = {
|
|||||||
void BLEClientBase::setup() {
|
void BLEClientBase::setup() {
|
||||||
static uint8_t connection_index = 0;
|
static uint8_t connection_index = 0;
|
||||||
this->connection_index_ = connection_index++;
|
this->connection_index_ = connection_index++;
|
||||||
|
|
||||||
auto ret = esp_ble_gattc_app_register(this->app_id);
|
|
||||||
if (ret) {
|
|
||||||
ESP_LOGE(TAG, "gattc app register failed. app_id=%d code=%d", this->app_id, ret);
|
|
||||||
this->mark_failed();
|
|
||||||
}
|
|
||||||
this->set_state(espbt::ClientState::IDLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLEClientBase::loop() {
|
void BLEClientBase::loop() {
|
||||||
|
if (!esp32_ble::global_ble->is_active()) {
|
||||||
|
this->set_state(espbt::ClientState::INIT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->state_ == espbt::ClientState::INIT) {
|
||||||
|
auto ret = esp_ble_gattc_app_register(this->app_id);
|
||||||
|
if (ret) {
|
||||||
|
ESP_LOGE(TAG, "gattc app register failed. app_id=%d code=%d", this->app_id, ret);
|
||||||
|
this->mark_failed();
|
||||||
|
}
|
||||||
|
this->set_state(espbt::ClientState::IDLE);
|
||||||
|
}
|
||||||
// READY_TO_CONNECT means we have discovered the device
|
// READY_TO_CONNECT means we have discovered the device
|
||||||
// and the scanner has been stopped by the tracker.
|
// and the scanner has been stopped by the tracker.
|
||||||
if (this->state_ == espbt::ClientState::READY_TO_CONNECT) {
|
if (this->state_ == espbt::ClientState::READY_TO_CONNECT) {
|
||||||
|
|||||||
@@ -93,19 +93,19 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Inclusive(
|
cv.Inclusive(
|
||||||
CONF_BIT0_HIGH,
|
CONF_BIT0_HIGH,
|
||||||
"custom",
|
"custom",
|
||||||
): cv.positive_time_period_microseconds,
|
): cv.positive_time_period_nanoseconds,
|
||||||
cv.Inclusive(
|
cv.Inclusive(
|
||||||
CONF_BIT0_LOW,
|
CONF_BIT0_LOW,
|
||||||
"custom",
|
"custom",
|
||||||
): cv.positive_time_period_microseconds,
|
): cv.positive_time_period_nanoseconds,
|
||||||
cv.Inclusive(
|
cv.Inclusive(
|
||||||
CONF_BIT1_HIGH,
|
CONF_BIT1_HIGH,
|
||||||
"custom",
|
"custom",
|
||||||
): cv.positive_time_period_microseconds,
|
): cv.positive_time_period_nanoseconds,
|
||||||
cv.Inclusive(
|
cv.Inclusive(
|
||||||
CONF_BIT1_LOW,
|
CONF_BIT1_LOW,
|
||||||
"custom",
|
"custom",
|
||||||
): cv.positive_time_period_microseconds,
|
): cv.positive_time_period_nanoseconds,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.has_exactly_one_key(CONF_CHIPSET, CONF_BIT0_HIGH),
|
cv.has_exactly_one_key(CONF_CHIPSET, CONF_BIT0_HIGH),
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ void LD2420Component::dump_config() {
|
|||||||
ESP_LOGCONFIG(TAG, "LD2420:");
|
ESP_LOGCONFIG(TAG, "LD2420:");
|
||||||
ESP_LOGCONFIG(TAG, " Firmware Version : %7s", this->ld2420_firmware_ver_);
|
ESP_LOGCONFIG(TAG, " Firmware Version : %7s", this->ld2420_firmware_ver_);
|
||||||
ESP_LOGCONFIG(TAG, "LD2420 Number:");
|
ESP_LOGCONFIG(TAG, "LD2420 Number:");
|
||||||
|
#ifdef USE_NUMBER
|
||||||
LOG_NUMBER(TAG, " Gate Timeout:", this->gate_timeout_number_);
|
LOG_NUMBER(TAG, " Gate Timeout:", this->gate_timeout_number_);
|
||||||
LOG_NUMBER(TAG, " Gate Max Distance:", this->max_gate_distance_number_);
|
LOG_NUMBER(TAG, " Gate Max Distance:", this->max_gate_distance_number_);
|
||||||
LOG_NUMBER(TAG, " Gate Min Distance:", this->min_gate_distance_number_);
|
LOG_NUMBER(TAG, " Gate Min Distance:", this->min_gate_distance_number_);
|
||||||
@@ -76,10 +77,13 @@ void LD2420Component::dump_config() {
|
|||||||
LOG_NUMBER(TAG, " Gate Move Threshold:", this->gate_move_threshold_numbers_[gate]);
|
LOG_NUMBER(TAG, " Gate Move Threshold:", this->gate_move_threshold_numbers_[gate]);
|
||||||
LOG_NUMBER(TAG, " Gate Still Threshold::", this->gate_still_threshold_numbers_[gate]);
|
LOG_NUMBER(TAG, " Gate Still Threshold::", this->gate_still_threshold_numbers_[gate]);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_BUTTON
|
||||||
LOG_BUTTON(TAG, " Apply Config:", this->apply_config_button_);
|
LOG_BUTTON(TAG, " Apply Config:", this->apply_config_button_);
|
||||||
LOG_BUTTON(TAG, " Revert Edits:", this->revert_config_button_);
|
LOG_BUTTON(TAG, " Revert Edits:", this->revert_config_button_);
|
||||||
LOG_BUTTON(TAG, " Factory Reset:", this->factory_reset_button_);
|
LOG_BUTTON(TAG, " Factory Reset:", this->factory_reset_button_);
|
||||||
LOG_BUTTON(TAG, " Restart Module:", this->restart_module_button_);
|
LOG_BUTTON(TAG, " Restart Module:", this->restart_module_button_);
|
||||||
|
#endif
|
||||||
ESP_LOGCONFIG(TAG, "LD2420 Select:");
|
ESP_LOGCONFIG(TAG, "LD2420 Select:");
|
||||||
LOG_SELECT(TAG, " Operating Mode", this->operating_selector_);
|
LOG_SELECT(TAG, " Operating Mode", this->operating_selector_);
|
||||||
if (this->get_firmware_int_(ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
if (this->get_firmware_int_(ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
||||||
@@ -183,9 +187,11 @@ void LD2420Component::factory_reset_action() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->set_min_max_distances_timeout(FACTORY_MAX_GATE, FACTORY_MIN_GATE, FACTORY_TIMEOUT);
|
this->set_min_max_distances_timeout(FACTORY_MAX_GATE, FACTORY_MIN_GATE, FACTORY_TIMEOUT);
|
||||||
|
#ifdef USE_NUMBER
|
||||||
this->gate_timeout_number_->state = FACTORY_TIMEOUT;
|
this->gate_timeout_number_->state = FACTORY_TIMEOUT;
|
||||||
this->min_gate_distance_number_->state = FACTORY_MIN_GATE;
|
this->min_gate_distance_number_->state = FACTORY_MIN_GATE;
|
||||||
this->max_gate_distance_number_->state = FACTORY_MAX_GATE;
|
this->max_gate_distance_number_->state = FACTORY_MAX_GATE;
|
||||||
|
#endif
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
||||||
this->new_config.move_thresh[gate] = FACTORY_MOVE_THRESH[gate];
|
this->new_config.move_thresh[gate] = FACTORY_MOVE_THRESH[gate];
|
||||||
this->new_config.still_thresh[gate] = FACTORY_STILL_THRESH[gate];
|
this->new_config.still_thresh[gate] = FACTORY_STILL_THRESH[gate];
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ void MQTTClientComponent::dump_config() {
|
|||||||
ESP_LOGCONFIG(TAG, " Availability: '%s'", this->availability_.topic.c_str());
|
ESP_LOGCONFIG(TAG, " Availability: '%s'", this->availability_.topic.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool MQTTClientComponent::can_proceed() { return this->is_connected(); }
|
bool MQTTClientComponent::can_proceed() { return network::is_disabled() || this->is_connected(); }
|
||||||
|
|
||||||
void MQTTClientComponent::start_dnslookup_() {
|
void MQTTClientComponent::start_dnslookup_() {
|
||||||
for (auto &subscription : this->subscriptions_) {
|
for (auto &subscription : this->subscriptions_) {
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; }
|
|||||||
void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
if (this->lock_->traits.get_assumed_state())
|
if (this->lock_->traits.get_assumed_state())
|
||||||
root[MQTT_OPTIMISTIC] = true;
|
root[MQTT_OPTIMISTIC] = true;
|
||||||
|
if (this->lock_->traits.get_supports_open())
|
||||||
|
root[MQTT_PAYLOAD_OPEN] = "OPEN";
|
||||||
}
|
}
|
||||||
bool MQTTLockComponent::send_initial_state() { return this->publish_state(); }
|
bool MQTTLockComponent::send_initial_state() { return this->publish_state(); }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "my9231.h"
|
#include "my9231.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace my9231 {
|
namespace my9231 {
|
||||||
@@ -51,7 +52,11 @@ void MY9231OutputComponent::setup() {
|
|||||||
MY9231_CMD_SCATTER_APDM | MY9231_CMD_FREQUENCY_DIVIDE_1 | MY9231_CMD_REACTION_FAST | MY9231_CMD_ONE_SHOT_DISABLE;
|
MY9231_CMD_SCATTER_APDM | MY9231_CMD_FREQUENCY_DIVIDE_1 | MY9231_CMD_REACTION_FAST | MY9231_CMD_ONE_SHOT_DISABLE;
|
||||||
ESP_LOGV(TAG, " Command: 0x%02X", command);
|
ESP_LOGV(TAG, " Command: 0x%02X", command);
|
||||||
|
|
||||||
this->init_chips_(command);
|
{
|
||||||
|
InterruptLock lock;
|
||||||
|
this->send_dcki_pulses_(32 * this->num_chips_);
|
||||||
|
this->init_chips_(command);
|
||||||
|
}
|
||||||
ESP_LOGV(TAG, " Chips initialized.");
|
ESP_LOGV(TAG, " Chips initialized.");
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::dump_config() {
|
void MY9231OutputComponent::dump_config() {
|
||||||
@@ -66,11 +71,14 @@ void MY9231OutputComponent::loop() {
|
|||||||
if (!this->update_)
|
if (!this->update_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto pwm_amount : this->pwm_amounts_) {
|
{
|
||||||
this->write_word_(pwm_amount, this->bit_depth_);
|
InterruptLock lock;
|
||||||
|
for (auto pwm_amount : this->pwm_amounts_) {
|
||||||
|
this->write_word_(pwm_amount, this->bit_depth_);
|
||||||
|
}
|
||||||
|
// Send 8 DI pulses. After 8 falling edges, the duty data are store.
|
||||||
|
this->send_di_pulses_(8);
|
||||||
}
|
}
|
||||||
// Send 8 DI pulses. After 8 falling edges, the duty data are store.
|
|
||||||
this->send_di_pulses_(8);
|
|
||||||
this->update_ = false;
|
this->update_ = false;
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::set_channel_value_(uint8_t channel, uint16_t value) {
|
void MY9231OutputComponent::set_channel_value_(uint8_t channel, uint16_t value) {
|
||||||
@@ -92,6 +100,7 @@ void MY9231OutputComponent::init_chips_(uint8_t command) {
|
|||||||
// Send 16 DI pulse. After 14 falling edges, the command data are
|
// Send 16 DI pulse. After 14 falling edges, the command data are
|
||||||
// stored and after 16 falling edges the duty mode is activated.
|
// stored and after 16 falling edges the duty mode is activated.
|
||||||
this->send_di_pulses_(16);
|
this->send_di_pulses_(16);
|
||||||
|
delayMicroseconds(12);
|
||||||
}
|
}
|
||||||
void MY9231OutputComponent::write_word_(uint16_t value, uint8_t bits) {
|
void MY9231OutputComponent::write_word_(uint16_t value, uint8_t bits) {
|
||||||
for (uint8_t i = bits; i > 0; i--) {
|
for (uint8_t i = bits; i > 0; i--) {
|
||||||
@@ -106,6 +115,13 @@ void MY9231OutputComponent::send_di_pulses_(uint8_t count) {
|
|||||||
this->pin_di_->digital_write(false);
|
this->pin_di_->digital_write(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MY9231OutputComponent::send_dcki_pulses_(uint8_t count) {
|
||||||
|
delayMicroseconds(12);
|
||||||
|
for (uint8_t i = 0; i < count; i++) {
|
||||||
|
this->pin_dcki_->digital_write(true);
|
||||||
|
this->pin_dcki_->digital_write(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace my9231
|
} // namespace my9231
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class MY9231OutputComponent : public Component {
|
|||||||
void init_chips_(uint8_t command);
|
void init_chips_(uint8_t command);
|
||||||
void write_word_(uint16_t value, uint8_t bits);
|
void write_word_(uint16_t value, uint8_t bits);
|
||||||
void send_di_pulses_(uint8_t count);
|
void send_di_pulses_(uint8_t count);
|
||||||
|
void send_dcki_pulses_(uint8_t count);
|
||||||
|
|
||||||
GPIOPin *pin_di_;
|
GPIOPin *pin_di_;
|
||||||
GPIOPin *pin_dcki_;
|
GPIOPin *pin_dcki_;
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ bool is_connected() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_disabled() {
|
||||||
|
#ifdef USE_WIFI
|
||||||
|
if (wifi::global_wifi_component != nullptr)
|
||||||
|
return wifi::global_wifi_component->is_disabled();
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
network::IPAddress get_ip_address() {
|
network::IPAddress get_ip_address() {
|
||||||
#ifdef USE_ETHERNET
|
#ifdef USE_ETHERNET
|
||||||
if (ethernet::global_eth_component != nullptr)
|
if (ethernet::global_eth_component != nullptr)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace network {
|
|||||||
|
|
||||||
/// Return whether the node is connected to the network (through wifi, eth, ...)
|
/// Return whether the node is connected to the network (through wifi, eth, ...)
|
||||||
bool is_connected();
|
bool is_connected();
|
||||||
|
/// Return whether the network is disabled (only wifi for now)
|
||||||
|
bool is_disabled();
|
||||||
/// Get the active network hostname
|
/// Get the active network hostname
|
||||||
std::string get_use_address();
|
std::string get_use_address();
|
||||||
IPAddress get_ip_address();
|
IPAddress get_ip_address();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from math import log
|
|||||||
|
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.components import sensor
|
from esphome.components import sensor, resistance_sampler
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_CALIBRATION,
|
CONF_CALIBRATION,
|
||||||
CONF_REFERENCE_RESISTANCE,
|
CONF_REFERENCE_RESISTANCE,
|
||||||
@@ -15,6 +15,8 @@ from esphome.const import (
|
|||||||
UNIT_CELSIUS,
|
UNIT_CELSIUS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
AUTO_LOAD = ["resistance_sampler"]
|
||||||
|
|
||||||
ntc_ns = cg.esphome_ns.namespace("ntc")
|
ntc_ns = cg.esphome_ns.namespace("ntc")
|
||||||
NTC = ntc_ns.class_("NTC", cg.Component, sensor.Sensor)
|
NTC = ntc_ns.class_("NTC", cg.Component, sensor.Sensor)
|
||||||
|
|
||||||
@@ -124,7 +126,7 @@ CONFIG_SCHEMA = (
|
|||||||
)
|
)
|
||||||
.extend(
|
.extend(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
|
cv.Required(CONF_SENSOR): cv.use_id(resistance_sampler.ResistanceSampler),
|
||||||
cv.Required(CONF_CALIBRATION): process_calibration,
|
cv.Required(CONF_CALIBRATION): process_calibration,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/components/resistance_sampler/resistance_sampler.h"
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace resistance {
|
namespace resistance {
|
||||||
@@ -11,7 +12,7 @@ enum ResistanceConfiguration {
|
|||||||
DOWNSTREAM,
|
DOWNSTREAM,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResistanceSensor : public Component, public sensor::Sensor {
|
class ResistanceSensor : public Component, public sensor::Sensor, resistance_sampler::ResistanceSampler {
|
||||||
public:
|
public:
|
||||||
void set_sensor(Sensor *sensor) { sensor_ = sensor; }
|
void set_sensor(Sensor *sensor) { sensor_ = sensor; }
|
||||||
void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
|
void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import sensor
|
from esphome.components import sensor, resistance_sampler
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_SENSOR,
|
CONF_SENSOR,
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
@@ -8,8 +8,15 @@ from esphome.const import (
|
|||||||
ICON_FLASH,
|
ICON_FLASH,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
AUTO_LOAD = ["resistance_sampler"]
|
||||||
|
|
||||||
resistance_ns = cg.esphome_ns.namespace("resistance")
|
resistance_ns = cg.esphome_ns.namespace("resistance")
|
||||||
ResistanceSensor = resistance_ns.class_("ResistanceSensor", cg.Component, sensor.Sensor)
|
ResistanceSensor = resistance_ns.class_(
|
||||||
|
"ResistanceSensor",
|
||||||
|
cg.Component,
|
||||||
|
sensor.Sensor,
|
||||||
|
resistance_sampler.ResistanceSampler,
|
||||||
|
)
|
||||||
|
|
||||||
CONF_REFERENCE_VOLTAGE = "reference_voltage"
|
CONF_REFERENCE_VOLTAGE = "reference_voltage"
|
||||||
CONF_CONFIGURATION = "configuration"
|
CONF_CONFIGURATION = "configuration"
|
||||||
|
|||||||
6
esphome/components/resistance_sampler/__init__.py
Normal file
6
esphome/components/resistance_sampler/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
|
||||||
|
resistance_sampler_ns = cg.esphome_ns.namespace("resistance_sampler")
|
||||||
|
ResistanceSampler = resistance_sampler_ns.class_("ResistanceSampler")
|
||||||
|
|
||||||
|
CODEOWNERS = ["@jesserockz"]
|
||||||
10
esphome/components/resistance_sampler/resistance_sampler.h
Normal file
10
esphome/components/resistance_sampler/resistance_sampler.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace resistance_sampler {
|
||||||
|
|
||||||
|
/// Abstract interface to mark components that provide resistance values.
|
||||||
|
class ResistanceSampler {};
|
||||||
|
|
||||||
|
} // namespace resistance_sampler
|
||||||
|
} // namespace esphome
|
||||||
@@ -18,20 +18,27 @@ DEPENDENCIES = ["api", "microphone"]
|
|||||||
|
|
||||||
CODEOWNERS = ["@jesserockz"]
|
CODEOWNERS = ["@jesserockz"]
|
||||||
|
|
||||||
CONF_SILENCE_DETECTION = "silence_detection"
|
|
||||||
CONF_ON_LISTENING = "on_listening"
|
|
||||||
CONF_ON_START = "on_start"
|
|
||||||
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
|
||||||
CONF_ON_STT_END = "on_stt_end"
|
|
||||||
CONF_ON_TTS_START = "on_tts_start"
|
|
||||||
CONF_ON_TTS_END = "on_tts_end"
|
|
||||||
CONF_ON_END = "on_end"
|
CONF_ON_END = "on_end"
|
||||||
CONF_ON_ERROR = "on_error"
|
CONF_ON_ERROR = "on_error"
|
||||||
|
CONF_ON_INTENT_END = "on_intent_end"
|
||||||
|
CONF_ON_INTENT_START = "on_intent_start"
|
||||||
|
CONF_ON_LISTENING = "on_listening"
|
||||||
|
CONF_ON_START = "on_start"
|
||||||
|
CONF_ON_STT_END = "on_stt_end"
|
||||||
|
CONF_ON_STT_VAD_END = "on_stt_vad_end"
|
||||||
|
CONF_ON_STT_VAD_START = "on_stt_vad_start"
|
||||||
|
CONF_ON_TTS_END = "on_tts_end"
|
||||||
|
CONF_ON_TTS_START = "on_tts_start"
|
||||||
|
CONF_ON_TTS_STREAM_START = "on_tts_stream_start"
|
||||||
|
CONF_ON_TTS_STREAM_END = "on_tts_stream_end"
|
||||||
|
CONF_ON_WAKE_WORD_DETECTED = "on_wake_word_detected"
|
||||||
|
|
||||||
|
CONF_SILENCE_DETECTION = "silence_detection"
|
||||||
CONF_USE_WAKE_WORD = "use_wake_word"
|
CONF_USE_WAKE_WORD = "use_wake_word"
|
||||||
CONF_VAD_THRESHOLD = "vad_threshold"
|
CONF_VAD_THRESHOLD = "vad_threshold"
|
||||||
|
|
||||||
CONF_NOISE_SUPPRESSION_LEVEL = "noise_suppression_level"
|
|
||||||
CONF_AUTO_GAIN = "auto_gain"
|
CONF_AUTO_GAIN = "auto_gain"
|
||||||
|
CONF_NOISE_SUPPRESSION_LEVEL = "noise_suppression_level"
|
||||||
CONF_VOLUME_MULTIPLIER = "volume_multiplier"
|
CONF_VOLUME_MULTIPLIER = "volume_multiplier"
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +58,17 @@ IsRunningCondition = voice_assistant_ns.class_(
|
|||||||
"IsRunningCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
|
"IsRunningCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def tts_stream_validate(config):
|
||||||
|
if CONF_SPEAKER not in config and (
|
||||||
|
CONF_ON_TTS_STREAM_START in config or CONF_ON_TTS_STREAM_END in config
|
||||||
|
):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"{CONF_SPEAKER} is required when using {CONF_ON_TTS_STREAM_START} and/or {CONF_ON_TTS_STREAM_END}"
|
||||||
|
)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
@@ -88,8 +106,27 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Optional(CONF_ON_CLIENT_DISCONNECTED): automation.validate_automation(
|
cv.Optional(CONF_ON_CLIENT_DISCONNECTED): automation.validate_automation(
|
||||||
single=True
|
single=True
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_INTENT_START): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_INTENT_END): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STT_VAD_START): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STT_VAD_END): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_TTS_STREAM_START): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_TTS_STREAM_END): automation.validate_automation(
|
||||||
|
single=True
|
||||||
|
),
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
|
tts_stream_validate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +214,48 @@ async def to_code(config):
|
|||||||
config[CONF_ON_CLIENT_DISCONNECTED],
|
config[CONF_ON_CLIENT_DISCONNECTED],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if CONF_ON_INTENT_START in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_intent_start_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_INTENT_START],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_INTENT_END in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_intent_end_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_INTENT_END],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_STT_VAD_START in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_stt_vad_start_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_STT_VAD_START],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_STT_VAD_END in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_stt_vad_end_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_STT_VAD_END],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_TTS_STREAM_START in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_tts_stream_start_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_TTS_STREAM_START],
|
||||||
|
)
|
||||||
|
|
||||||
|
if CONF_ON_TTS_STREAM_END in config:
|
||||||
|
await automation.build_automation(
|
||||||
|
var.get_tts_stream_end_trigger(),
|
||||||
|
[],
|
||||||
|
config[CONF_ON_TTS_STREAM_END],
|
||||||
|
)
|
||||||
|
|
||||||
cg.add_define("USE_VOICE_ASSISTANT")
|
cg.add_define("USE_VOICE_ASSISTANT")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ void VoiceAssistant::setup() {
|
|||||||
|
|
||||||
this->socket_ = socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
this->socket_ = socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
if (socket_ == nullptr) {
|
if (socket_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not create socket.");
|
ESP_LOGW(TAG, "Could not create socket");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<uint8_t> speaker_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<uint8_t> speaker_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||||
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
|
this->speaker_buffer_ = speaker_allocator.allocate(SPEAKER_BUFFER_SIZE);
|
||||||
if (this->speaker_buffer_ == nullptr) {
|
if (this->speaker_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate speaker buffer.");
|
ESP_LOGW(TAG, "Could not allocate speaker buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<int16_t> allocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<int16_t> allocator(ExternalRAMAllocator<int16_t>::ALLOW_FAILURE);
|
||||||
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
|
this->input_buffer_ = allocator.allocate(INPUT_BUFFER_SIZE);
|
||||||
if (this->input_buffer_ == nullptr) {
|
if (this->input_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate input buffer.");
|
ESP_LOGW(TAG, "Could not allocate input buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ void VoiceAssistant::setup() {
|
|||||||
|
|
||||||
this->ring_buffer_ = rb_create(BUFFER_SIZE, sizeof(int16_t));
|
this->ring_buffer_ = rb_create(BUFFER_SIZE, sizeof(int16_t));
|
||||||
if (this->ring_buffer_ == nullptr) {
|
if (this->ring_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate ring buffer.");
|
ESP_LOGW(TAG, "Could not allocate ring buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ void VoiceAssistant::setup() {
|
|||||||
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<uint8_t> send_allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
|
||||||
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
|
this->send_buffer_ = send_allocator.allocate(SEND_BUFFER_SIZE);
|
||||||
if (send_buffer_ == nullptr) {
|
if (send_buffer_ == nullptr) {
|
||||||
ESP_LOGW(TAG, "Could not allocate send buffer.");
|
ESP_LOGW(TAG, "Could not allocate send buffer");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -221,8 +221,8 @@ void VoiceAssistant::loop() {
|
|||||||
msg.audio_settings = audio_settings;
|
msg.audio_settings = audio_settings;
|
||||||
|
|
||||||
if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
|
if (this->api_client_ == nullptr || !this->api_client_->send_voice_assistant_request(msg)) {
|
||||||
ESP_LOGW(TAG, "Could not request start.");
|
ESP_LOGW(TAG, "Could not request start");
|
||||||
this->error_trigger_->trigger("not-connected", "Could not request start.");
|
this->error_trigger_->trigger("not-connected", "Could not request start");
|
||||||
this->continuous_ = false;
|
this->continuous_ = false;
|
||||||
this->set_state_(State::IDLE, State::IDLE);
|
this->set_state_(State::IDLE, State::IDLE);
|
||||||
break;
|
break;
|
||||||
@@ -280,7 +280,7 @@ void VoiceAssistant::loop() {
|
|||||||
this->speaker_buffer_size_ += len;
|
this->speaker_buffer_size_ += len;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Receive buffer full.");
|
ESP_LOGW(TAG, "Receive buffer full");
|
||||||
}
|
}
|
||||||
if (this->speaker_buffer_size_ > 0) {
|
if (this->speaker_buffer_size_ > 0) {
|
||||||
size_t written = this->speaker_->play(this->speaker_buffer_, this->speaker_buffer_size_);
|
size_t written = this->speaker_->play(this->speaker_buffer_, this->speaker_buffer_size_);
|
||||||
@@ -290,7 +290,7 @@ void VoiceAssistant::loop() {
|
|||||||
this->speaker_buffer_index_ -= written;
|
this->speaker_buffer_index_ -= written;
|
||||||
this->set_timeout("speaker-timeout", 2000, [this]() { this->speaker_->stop(); });
|
this->set_timeout("speaker-timeout", 2000, [this]() { this->speaker_->stop(); });
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Speaker buffer full.");
|
ESP_LOGW(TAG, "Speaker buffer full");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->wait_for_stream_end_) {
|
if (this->wait_for_stream_end_) {
|
||||||
@@ -513,7 +513,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case api::enums::VOICE_ASSISTANT_STT_START:
|
case api::enums::VOICE_ASSISTANT_STT_START:
|
||||||
ESP_LOGD(TAG, "STT Started");
|
ESP_LOGD(TAG, "STT started");
|
||||||
this->listening_trigger_->trigger();
|
this->listening_trigger_->trigger();
|
||||||
break;
|
break;
|
||||||
case api::enums::VOICE_ASSISTANT_STT_END: {
|
case api::enums::VOICE_ASSISTANT_STT_END: {
|
||||||
@@ -525,19 +525,24 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.empty()) {
|
if (text.empty()) {
|
||||||
ESP_LOGW(TAG, "No text in STT_END event.");
|
ESP_LOGW(TAG, "No text in STT_END event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Speech recognised as: \"%s\"", text.c_str());
|
ESP_LOGD(TAG, "Speech recognised as: \"%s\"", text.c_str());
|
||||||
this->stt_end_trigger_->trigger(text);
|
this->stt_end_trigger_->trigger(text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case api::enums::VOICE_ASSISTANT_INTENT_START:
|
||||||
|
ESP_LOGD(TAG, "Intent started");
|
||||||
|
this->intent_start_trigger_->trigger();
|
||||||
|
break;
|
||||||
case api::enums::VOICE_ASSISTANT_INTENT_END: {
|
case api::enums::VOICE_ASSISTANT_INTENT_END: {
|
||||||
for (auto arg : msg.data) {
|
for (auto arg : msg.data) {
|
||||||
if (arg.name == "conversation_id") {
|
if (arg.name == "conversation_id") {
|
||||||
this->conversation_id_ = std::move(arg.value);
|
this->conversation_id_ = std::move(arg.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->intent_end_trigger_->trigger();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case api::enums::VOICE_ASSISTANT_TTS_START: {
|
case api::enums::VOICE_ASSISTANT_TTS_START: {
|
||||||
@@ -548,7 +553,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.empty()) {
|
if (text.empty()) {
|
||||||
ESP_LOGW(TAG, "No text in TTS_START event.");
|
ESP_LOGW(TAG, "No text in TTS_START event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Response: \"%s\"", text.c_str());
|
ESP_LOGD(TAG, "Response: \"%s\"", text.c_str());
|
||||||
@@ -566,7 +571,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (url.empty()) {
|
if (url.empty()) {
|
||||||
ESP_LOGW(TAG, "No url in TTS_END event.");
|
ESP_LOGW(TAG, "No url in TTS_END event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Response URL: \"%s\"", url.c_str());
|
ESP_LOGD(TAG, "Response URL: \"%s\"", url.c_str());
|
||||||
@@ -610,6 +615,11 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
if (code == "wake-word-timeout" || code == "wake_word_detection_aborted") {
|
if (code == "wake-word-timeout" || code == "wake_word_detection_aborted") {
|
||||||
// Don't change state here since either the "tts-end" or "run-end" events will do it.
|
// Don't change state here since either the "tts-end" or "run-end" events will do it.
|
||||||
return;
|
return;
|
||||||
|
} else if (code == "wake-provider-missing" || code == "wake-engine-missing") {
|
||||||
|
// Wake word is not set up or not ready on Home Assistant so stop and do not retry until user starts again.
|
||||||
|
this->request_stop();
|
||||||
|
this->error_trigger_->trigger(code, message);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGE(TAG, "Error: %s - %s", code.c_str(), message.c_str());
|
ESP_LOGE(TAG, "Error: %s - %s", code.c_str(), message.c_str());
|
||||||
if (this->state_ != State::IDLE) {
|
if (this->state_ != State::IDLE) {
|
||||||
@@ -622,13 +632,27 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
case api::enums::VOICE_ASSISTANT_TTS_STREAM_START: {
|
case api::enums::VOICE_ASSISTANT_TTS_STREAM_START: {
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
this->wait_for_stream_end_ = true;
|
this->wait_for_stream_end_ = true;
|
||||||
|
ESP_LOGD(TAG, "TTS stream start");
|
||||||
|
this->tts_stream_start_trigger_->trigger();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case api::enums::VOICE_ASSISTANT_TTS_STREAM_END: {
|
case api::enums::VOICE_ASSISTANT_TTS_STREAM_END: {
|
||||||
this->set_state_(State::RESPONSE_FINISHED, State::IDLE);
|
this->set_state_(State::RESPONSE_FINISHED, State::IDLE);
|
||||||
|
#ifdef USE_SPEAKER
|
||||||
|
ESP_LOGD(TAG, "TTS stream end");
|
||||||
|
this->tts_stream_end_trigger_->trigger();
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case api::enums::VOICE_ASSISTANT_STT_VAD_START:
|
||||||
|
ESP_LOGD(TAG, "Starting STT by VAD");
|
||||||
|
this->stt_vad_start_trigger_->trigger();
|
||||||
|
break;
|
||||||
|
case api::enums::VOICE_ASSISTANT_STT_VAD_END:
|
||||||
|
ESP_LOGD(TAG, "STT by VAD end");
|
||||||
|
this->stt_vad_end_trigger_->trigger();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGD(TAG, "Unhandled event type: %d", msg.event_type);
|
ESP_LOGD(TAG, "Unhandled event type: %d", msg.event_type);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -100,13 +100,21 @@ class VoiceAssistant : public Component {
|
|||||||
void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; }
|
void set_auto_gain(uint8_t auto_gain) { this->auto_gain_ = auto_gain; }
|
||||||
void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; }
|
void set_volume_multiplier(float volume_multiplier) { this->volume_multiplier_ = volume_multiplier; }
|
||||||
|
|
||||||
|
Trigger<> *get_intent_end_trigger() const { return this->intent_end_trigger_; }
|
||||||
|
Trigger<> *get_intent_start_trigger() const { return this->intent_start_trigger_; }
|
||||||
Trigger<> *get_listening_trigger() const { return this->listening_trigger_; }
|
Trigger<> *get_listening_trigger() const { return this->listening_trigger_; }
|
||||||
|
Trigger<> *get_end_trigger() const { return this->end_trigger_; }
|
||||||
Trigger<> *get_start_trigger() const { return this->start_trigger_; }
|
Trigger<> *get_start_trigger() const { return this->start_trigger_; }
|
||||||
|
Trigger<> *get_stt_vad_end_trigger() const { return this->stt_vad_end_trigger_; }
|
||||||
|
Trigger<> *get_stt_vad_start_trigger() const { return this->stt_vad_start_trigger_; }
|
||||||
|
#ifdef USE_SPEAKER
|
||||||
|
Trigger<> *get_tts_stream_start_trigger() const { return this->tts_stream_start_trigger_; }
|
||||||
|
Trigger<> *get_tts_stream_end_trigger() const { return this->tts_stream_end_trigger_; }
|
||||||
|
#endif
|
||||||
Trigger<> *get_wake_word_detected_trigger() const { return this->wake_word_detected_trigger_; }
|
Trigger<> *get_wake_word_detected_trigger() const { return this->wake_word_detected_trigger_; }
|
||||||
Trigger<std::string> *get_stt_end_trigger() const { return this->stt_end_trigger_; }
|
Trigger<std::string> *get_stt_end_trigger() const { return this->stt_end_trigger_; }
|
||||||
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
|
||||||
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
Trigger<std::string> *get_tts_end_trigger() const { return this->tts_end_trigger_; }
|
||||||
Trigger<> *get_end_trigger() const { return this->end_trigger_; }
|
Trigger<std::string> *get_tts_start_trigger() const { return this->tts_start_trigger_; }
|
||||||
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
Trigger<std::string, std::string> *get_error_trigger() const { return this->error_trigger_; }
|
||||||
|
|
||||||
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
Trigger<> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
||||||
@@ -124,13 +132,21 @@ class VoiceAssistant : public Component {
|
|||||||
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
||||||
struct sockaddr_storage dest_addr_;
|
struct sockaddr_storage dest_addr_;
|
||||||
|
|
||||||
|
Trigger<> *intent_end_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *intent_start_trigger_ = new Trigger<>();
|
||||||
Trigger<> *listening_trigger_ = new Trigger<>();
|
Trigger<> *listening_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *end_trigger_ = new Trigger<>();
|
||||||
Trigger<> *start_trigger_ = new Trigger<>();
|
Trigger<> *start_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *stt_vad_start_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *stt_vad_end_trigger_ = new Trigger<>();
|
||||||
|
#ifdef USE_SPEAKER
|
||||||
|
Trigger<> *tts_stream_start_trigger_ = new Trigger<>();
|
||||||
|
Trigger<> *tts_stream_end_trigger_ = new Trigger<>();
|
||||||
|
#endif
|
||||||
Trigger<> *wake_word_detected_trigger_ = new Trigger<>();
|
Trigger<> *wake_word_detected_trigger_ = new Trigger<>();
|
||||||
Trigger<std::string> *stt_end_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *stt_end_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
|
||||||
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> *tts_end_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<> *end_trigger_ = new Trigger<>();
|
Trigger<std::string> *tts_start_trigger_ = new Trigger<std::string>();
|
||||||
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
Trigger<std::string, std::string> *error_trigger_ = new Trigger<std::string, std::string>();
|
||||||
|
|
||||||
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
Trigger<> *client_connected_trigger_ = new Trigger<>();
|
||||||
|
|||||||
@@ -389,6 +389,10 @@ void WiFiComponent::print_connect_params_() {
|
|||||||
bssid_t bssid = wifi_bssid();
|
bssid_t bssid = wifi_bssid();
|
||||||
|
|
||||||
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str());
|
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str());
|
||||||
|
if (this->is_disabled()) {
|
||||||
|
ESP_LOGCONFIG(TAG, " WiFi is disabled!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
ESP_LOGCONFIG(TAG, " SSID: " LOG_SECRET("'%s'"), wifi_ssid().c_str());
|
ESP_LOGCONFIG(TAG, " SSID: " LOG_SECRET("'%s'"), wifi_ssid().c_str());
|
||||||
ESP_LOGCONFIG(TAG, " IP Address: %s", wifi_sta_ip().str().c_str());
|
ESP_LOGCONFIG(TAG, " IP Address: %s", wifi_sta_ip().str().c_str());
|
||||||
ESP_LOGCONFIG(TAG, " BSSID: " LOG_SECRET("%02X:%02X:%02X:%02X:%02X:%02X"), bssid[0], bssid[1], bssid[2], bssid[3],
|
ESP_LOGCONFIG(TAG, " BSSID: " LOG_SECRET("%02X:%02X:%02X:%02X:%02X:%02X"), bssid[0], bssid[1], bssid[2], bssid[3],
|
||||||
|
|||||||
@@ -674,6 +674,11 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (it.number == 0) {
|
||||||
|
// no results
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t number = it.number;
|
uint16_t number = it.number;
|
||||||
std::vector<wifi_ap_record_t> records(number);
|
std::vector<wifi_ap_record_t> records(number);
|
||||||
err = esp_wifi_scan_get_ap_records(&number, records.data());
|
err = esp_wifi_scan_get_ap_records(&number, records.data());
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ from esphome.core import (
|
|||||||
TimePeriod,
|
TimePeriod,
|
||||||
TimePeriodMicroseconds,
|
TimePeriodMicroseconds,
|
||||||
TimePeriodMilliseconds,
|
TimePeriodMilliseconds,
|
||||||
|
TimePeriodNanoseconds,
|
||||||
TimePeriodSeconds,
|
TimePeriodSeconds,
|
||||||
TimePeriodMinutes,
|
TimePeriodMinutes,
|
||||||
)
|
)
|
||||||
@@ -718,6 +719,8 @@ def time_period_str_unit(value):
|
|||||||
raise Invalid("Expected string for time period with unit.")
|
raise Invalid("Expected string for time period with unit.")
|
||||||
|
|
||||||
unit_to_kwarg = {
|
unit_to_kwarg = {
|
||||||
|
"ns": "nanoseconds",
|
||||||
|
"nanoseconds": "nanoseconds",
|
||||||
"us": "microseconds",
|
"us": "microseconds",
|
||||||
"microseconds": "microseconds",
|
"microseconds": "microseconds",
|
||||||
"ms": "milliseconds",
|
"ms": "milliseconds",
|
||||||
@@ -739,7 +742,10 @@ def time_period_str_unit(value):
|
|||||||
raise Invalid(f"Expected time period with unit, got {value}")
|
raise Invalid(f"Expected time period with unit, got {value}")
|
||||||
kwarg = unit_to_kwarg[one_of(*unit_to_kwarg)(match.group(2))]
|
kwarg = unit_to_kwarg[one_of(*unit_to_kwarg)(match.group(2))]
|
||||||
|
|
||||||
return TimePeriod(**{kwarg: float(match.group(1))})
|
try:
|
||||||
|
return TimePeriod(**{kwarg: float(match.group(1))})
|
||||||
|
except ValueError as e:
|
||||||
|
raise Invalid(e) from e
|
||||||
|
|
||||||
|
|
||||||
def time_period_in_milliseconds_(value):
|
def time_period_in_milliseconds_(value):
|
||||||
@@ -749,10 +755,18 @@ def time_period_in_milliseconds_(value):
|
|||||||
|
|
||||||
|
|
||||||
def time_period_in_microseconds_(value):
|
def time_period_in_microseconds_(value):
|
||||||
|
if value.nanoseconds is not None and value.nanoseconds != 0:
|
||||||
|
raise Invalid("Maximum precision is microseconds")
|
||||||
return TimePeriodMicroseconds(**value.as_dict())
|
return TimePeriodMicroseconds(**value.as_dict())
|
||||||
|
|
||||||
|
|
||||||
|
def time_period_in_nanoseconds_(value):
|
||||||
|
return TimePeriodNanoseconds(**value.as_dict())
|
||||||
|
|
||||||
|
|
||||||
def time_period_in_seconds_(value):
|
def time_period_in_seconds_(value):
|
||||||
|
if value.nanoseconds is not None and value.nanoseconds != 0:
|
||||||
|
raise Invalid("Maximum precision is seconds")
|
||||||
if value.microseconds is not None and value.microseconds != 0:
|
if value.microseconds is not None and value.microseconds != 0:
|
||||||
raise Invalid("Maximum precision is seconds")
|
raise Invalid("Maximum precision is seconds")
|
||||||
if value.milliseconds is not None and value.milliseconds != 0:
|
if value.milliseconds is not None and value.milliseconds != 0:
|
||||||
@@ -761,6 +775,8 @@ def time_period_in_seconds_(value):
|
|||||||
|
|
||||||
|
|
||||||
def time_period_in_minutes_(value):
|
def time_period_in_minutes_(value):
|
||||||
|
if value.nanoseconds is not None and value.nanoseconds != 0:
|
||||||
|
raise Invalid("Maximum precision is minutes")
|
||||||
if value.microseconds is not None and value.microseconds != 0:
|
if value.microseconds is not None and value.microseconds != 0:
|
||||||
raise Invalid("Maximum precision is minutes")
|
raise Invalid("Maximum precision is minutes")
|
||||||
if value.milliseconds is not None and value.milliseconds != 0:
|
if value.milliseconds is not None and value.milliseconds != 0:
|
||||||
@@ -787,6 +803,9 @@ time_period_microseconds = All(time_period, time_period_in_microseconds_)
|
|||||||
positive_time_period_microseconds = All(
|
positive_time_period_microseconds = All(
|
||||||
positive_time_period, time_period_in_microseconds_
|
positive_time_period, time_period_in_microseconds_
|
||||||
)
|
)
|
||||||
|
positive_time_period_nanoseconds = All(
|
||||||
|
positive_time_period, time_period_in_nanoseconds_
|
||||||
|
)
|
||||||
positive_not_null_time_period = All(
|
positive_not_null_time_period = All(
|
||||||
time_period, Range(min=TimePeriod(), min_included=False)
|
time_period, Range(min=TimePeriod(), min_included=False)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2023.11.0b1"
|
__version__ = "2023.11.3"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ def is_approximately_integer(value):
|
|||||||
class TimePeriod:
|
class TimePeriod:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
nanoseconds=None,
|
||||||
microseconds=None,
|
microseconds=None,
|
||||||
milliseconds=None,
|
milliseconds=None,
|
||||||
seconds=None,
|
seconds=None,
|
||||||
@@ -136,13 +137,23 @@ class TimePeriod:
|
|||||||
|
|
||||||
if microseconds is not None:
|
if microseconds is not None:
|
||||||
if not is_approximately_integer(microseconds):
|
if not is_approximately_integer(microseconds):
|
||||||
raise ValueError("Maximum precision is microseconds")
|
frac_microseconds, microseconds = math.modf(microseconds)
|
||||||
|
nanoseconds = (nanoseconds or 0) + frac_microseconds * 1000
|
||||||
self.microseconds = int(round(microseconds))
|
self.microseconds = int(round(microseconds))
|
||||||
else:
|
else:
|
||||||
self.microseconds = None
|
self.microseconds = None
|
||||||
|
|
||||||
|
if nanoseconds is not None:
|
||||||
|
if not is_approximately_integer(nanoseconds):
|
||||||
|
raise ValueError("Maximum precision is nanoseconds")
|
||||||
|
self.nanoseconds = int(round(nanoseconds))
|
||||||
|
else:
|
||||||
|
self.nanoseconds = None
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
out = OrderedDict()
|
out = OrderedDict()
|
||||||
|
if self.nanoseconds is not None:
|
||||||
|
out["nanoseconds"] = self.nanoseconds
|
||||||
if self.microseconds is not None:
|
if self.microseconds is not None:
|
||||||
out["microseconds"] = self.microseconds
|
out["microseconds"] = self.microseconds
|
||||||
if self.milliseconds is not None:
|
if self.milliseconds is not None:
|
||||||
@@ -158,6 +169,8 @@ class TimePeriod:
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if self.nanoseconds is not None:
|
||||||
|
return f"{self.total_nanoseconds}ns"
|
||||||
if self.microseconds is not None:
|
if self.microseconds is not None:
|
||||||
return f"{self.total_microseconds}us"
|
return f"{self.total_microseconds}us"
|
||||||
if self.milliseconds is not None:
|
if self.milliseconds is not None:
|
||||||
@@ -173,7 +186,11 @@ class TimePeriod:
|
|||||||
return "0s"
|
return "0s"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"TimePeriod<{self.total_microseconds}>"
|
return f"TimePeriod<{self.total_nanoseconds}ns>"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total_nanoseconds(self):
|
||||||
|
return self.total_microseconds * 1000 + (self.nanoseconds or 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_microseconds(self):
|
def total_microseconds(self):
|
||||||
@@ -201,35 +218,39 @@ class TimePeriod:
|
|||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds == other.total_microseconds
|
return self.total_nanoseconds == other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds != other.total_microseconds
|
return self.total_nanoseconds != other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds < other.total_microseconds
|
return self.total_nanoseconds < other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds > other.total_microseconds
|
return self.total_nanoseconds > other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds <= other.total_microseconds
|
return self.total_nanoseconds <= other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
if isinstance(other, TimePeriod):
|
if isinstance(other, TimePeriod):
|
||||||
return self.total_microseconds >= other.total_microseconds
|
return self.total_nanoseconds >= other.total_nanoseconds
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
|
class TimePeriodNanoseconds(TimePeriod):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TimePeriodMicroseconds(TimePeriod):
|
class TimePeriodMicroseconds(TimePeriod):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from esphome.core import (
|
|||||||
TimePeriodMicroseconds,
|
TimePeriodMicroseconds,
|
||||||
TimePeriodMilliseconds,
|
TimePeriodMilliseconds,
|
||||||
TimePeriodMinutes,
|
TimePeriodMinutes,
|
||||||
|
TimePeriodNanoseconds,
|
||||||
TimePeriodSeconds,
|
TimePeriodSeconds,
|
||||||
)
|
)
|
||||||
from esphome.helpers import cpp_string_escape, indent_all_but_first_and_last
|
from esphome.helpers import cpp_string_escape, indent_all_but_first_and_last
|
||||||
@@ -351,6 +352,8 @@ def safe_exp(obj: SafeExpType) -> Expression:
|
|||||||
return IntLiteral(obj)
|
return IntLiteral(obj)
|
||||||
if isinstance(obj, float):
|
if isinstance(obj, float):
|
||||||
return FloatLiteral(obj)
|
return FloatLiteral(obj)
|
||||||
|
if isinstance(obj, TimePeriodNanoseconds):
|
||||||
|
return IntLiteral(int(obj.total_nanoseconds))
|
||||||
if isinstance(obj, TimePeriodMicroseconds):
|
if isinstance(obj, TimePeriodMicroseconds):
|
||||||
return IntLiteral(int(obj.total_microseconds))
|
return IntLiteral(int(obj.total_microseconds))
|
||||||
if isinstance(obj, TimePeriodMilliseconds):
|
if isinstance(obj, TimePeriodMilliseconds):
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import codecs
|
|
||||||
import collections
|
import collections
|
||||||
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import gzip
|
import gzip
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -338,8 +339,8 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
|||||||
def handle_stdin(self, json_message):
|
def handle_stdin(self, json_message):
|
||||||
if not self.is_process_active:
|
if not self.is_process_active:
|
||||||
return
|
return
|
||||||
data = json_message["data"]
|
text: str = json_message["data"]
|
||||||
data = codecs.encode(data, "utf8", "replace")
|
data = text.encode("utf-8", "replace")
|
||||||
_LOGGER.debug("< stdin: %s", data)
|
_LOGGER.debug("< stdin: %s", data)
|
||||||
self._proc.stdin.write(data)
|
self._proc.stdin.write(data)
|
||||||
|
|
||||||
@@ -350,18 +351,18 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if self._use_popen:
|
if self._use_popen:
|
||||||
data = yield self._queue.get()
|
data: bytes = yield self._queue.get()
|
||||||
if data is None:
|
if data is None:
|
||||||
self._proc_on_exit(self._proc.poll())
|
self._proc_on_exit(self._proc.poll())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
data = yield self._proc.stdout.read_until_regex(reg)
|
data: bytes = yield self._proc.stdout.read_until_regex(reg)
|
||||||
except tornado.iostream.StreamClosedError:
|
except tornado.iostream.StreamClosedError:
|
||||||
break
|
break
|
||||||
data = codecs.decode(data, "utf8", "replace")
|
|
||||||
|
|
||||||
_LOGGER.debug("> stdout: %s", data)
|
text = data.decode("utf-8", "replace")
|
||||||
self.write_message({"event": "line", "data": data})
|
_LOGGER.debug("> stdout: %s", text)
|
||||||
|
self.write_message({"event": "line", "data": text})
|
||||||
|
|
||||||
def _stdout_thread(self):
|
def _stdout_thread(self):
|
||||||
if not self._use_popen:
|
if not self._use_popen:
|
||||||
@@ -508,8 +509,8 @@ class EsphomeUpdateAllHandler(EsphomeCommandWebSocket):
|
|||||||
|
|
||||||
class SerialPortRequestHandler(BaseHandler):
|
class SerialPortRequestHandler(BaseHandler):
|
||||||
@authenticated
|
@authenticated
|
||||||
def get(self):
|
async def get(self):
|
||||||
ports = get_serial_ports()
|
ports = await asyncio.get_running_loop().run_in_executor(None, get_serial_ports)
|
||||||
data = []
|
data = []
|
||||||
for port in ports:
|
for port in ports:
|
||||||
desc = port.description
|
desc = port.description
|
||||||
@@ -972,6 +973,7 @@ class MDNSStatusThread(threading.Thread):
|
|||||||
self.host_name_to_filename: dict[str, str] = {}
|
self.host_name_to_filename: dict[str, str] = {}
|
||||||
# This is a set of host names to track (i.e no_mdns = false)
|
# This is a set of host names to track (i.e no_mdns = false)
|
||||||
self.host_name_with_mdns_enabled: set[set] = set()
|
self.host_name_with_mdns_enabled: set[set] = set()
|
||||||
|
self.zc: EsphomeZeroconf | None = None
|
||||||
self._refresh_hosts()
|
self._refresh_hosts()
|
||||||
|
|
||||||
def _refresh_hosts(self):
|
def _refresh_hosts(self):
|
||||||
@@ -995,7 +997,14 @@ class MDNSStatusThread(threading.Thread):
|
|||||||
# If we just adopted/imported this host, we likely
|
# If we just adopted/imported this host, we likely
|
||||||
# already have a state for it, so we should make sure
|
# already have a state for it, so we should make sure
|
||||||
# to set it so the dashboard shows it as online
|
# to set it so the dashboard shows it as online
|
||||||
if name in host_mdns_state:
|
if self.zc and (
|
||||||
|
entry.loaded_integrations and "api" not in entry.loaded_integrations
|
||||||
|
):
|
||||||
|
# No api available so we have to poll since
|
||||||
|
# the device won't respond to a request to ._esphomelib._tcp.local.
|
||||||
|
PING_RESULT[filename] = bool(self.zc.resolve_host(entry.name))
|
||||||
|
elif name in host_mdns_state:
|
||||||
|
# We already have a state for this host
|
||||||
PING_RESULT[filename] = host_mdns_state[name]
|
PING_RESULT[filename] = host_mdns_state[name]
|
||||||
|
|
||||||
# Make sure the mapping is up to date
|
# Make sure the mapping is up to date
|
||||||
@@ -1006,7 +1015,8 @@ class MDNSStatusThread(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
global IMPORT_RESULT
|
global IMPORT_RESULT
|
||||||
|
|
||||||
zc = EsphomeZeroconf()
|
self.zc = EsphomeZeroconf()
|
||||||
|
zc = self.zc
|
||||||
host_mdns_state = self.host_mdns_state
|
host_mdns_state = self.host_mdns_state
|
||||||
host_name_to_filename = self.host_name_to_filename
|
host_name_to_filename = self.host_name_to_filename
|
||||||
host_name_with_mdns_enabled = self.host_name_with_mdns_enabled
|
host_name_with_mdns_enabled = self.host_name_with_mdns_enabled
|
||||||
@@ -1406,15 +1416,17 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class StaticFileHandler(tornado.web.StaticFileHandler):
|
class StaticFileHandler(tornado.web.StaticFileHandler):
|
||||||
def set_extra_headers(self, path):
|
def get_cache_time(
|
||||||
if "favicon.ico" in path:
|
self, path: str, modified: datetime.datetime | None, mime_type: str
|
||||||
self.set_header("Cache-Control", "max-age=84600, public")
|
) -> int:
|
||||||
else:
|
"""Override to customize cache control behavior."""
|
||||||
if debug:
|
if debug:
|
||||||
self.set_header(
|
return 0
|
||||||
"Cache-Control",
|
# Assets that are hashed have ?hash= in the URL, all javascript
|
||||||
"no-store, no-cache, must-revalidate, max-age=0",
|
# filenames hashed so we can cache them for a long time
|
||||||
)
|
if "hash" in self.request.arguments or "/javascript" in mime_type:
|
||||||
|
return self.CACHE_MAX_AGE
|
||||||
|
return super().get_cache_time(path, modified, mime_type)
|
||||||
|
|
||||||
app_settings = {
|
app_settings = {
|
||||||
"debug": debug,
|
"debug": debug,
|
||||||
|
|||||||
@@ -147,12 +147,17 @@ class DashboardImportDiscovery:
|
|||||||
|
|
||||||
|
|
||||||
class EsphomeZeroconf(Zeroconf):
|
class EsphomeZeroconf(Zeroconf):
|
||||||
def resolve_host(self, host: str, timeout=3.0):
|
def resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
|
||||||
"""Resolve a host name to an IP address."""
|
"""Resolve a host name to an IP address."""
|
||||||
name = host.partition(".")[0]
|
name = host.partition(".")[0]
|
||||||
info = HostResolver(f"{name}.{ESPHOME_SERVICE_TYPE}", ESPHOME_SERVICE_TYPE)
|
info = HostResolver(
|
||||||
if (info.load_from_cache(self) or info.request(self, timeout * 1000)) and (
|
ESPHOME_SERVICE_TYPE,
|
||||||
addresses := info.ip_addresses_by_version(IPVersion.V4Only)
|
f"{name}.{ESPHOME_SERVICE_TYPE}",
|
||||||
):
|
server=f"{name}.local.",
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
info.load_from_cache(self)
|
||||||
|
or (timeout and info.request(self, timeout * 1000))
|
||||||
|
) and (addresses := info.ip_addresses_by_version(IPVersion.V4Only)):
|
||||||
return str(addresses[0])
|
return str(addresses[0])
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ platformio==6.1.11 # When updating platformio, also update Dockerfile
|
|||||||
esptool==4.6.2
|
esptool==4.6.2
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
esphome-dashboard==20231107.0
|
esphome-dashboard==20231107.0
|
||||||
aioesphomeapi==18.2.4
|
aioesphomeapi==18.5.2
|
||||||
zeroconf==0.120.0
|
zeroconf==0.123.0
|
||||||
|
|
||||||
# esp-idf requires this, but doesn't bundle it by default
|
# esp-idf requires this, but doesn't bundle it by default
|
||||||
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
|
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
|
||||||
|
|||||||
@@ -116,14 +116,16 @@ class TestTimePeriod:
|
|||||||
|
|
||||||
assert actual == expected
|
assert actual == expected
|
||||||
|
|
||||||
def test_init__microseconds_with_fraction(self):
|
def test_init__nanoseconds_with_fraction(self):
|
||||||
with pytest.raises(ValueError, match="Maximum precision is microseconds"):
|
with pytest.raises(ValueError, match="Maximum precision is nanoseconds"):
|
||||||
core.TimePeriod(microseconds=1.1)
|
core.TimePeriod(nanoseconds=1.1)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"kwargs, expected",
|
"kwargs, expected",
|
||||||
(
|
(
|
||||||
({}, "0s"),
|
({}, "0s"),
|
||||||
|
({"nanoseconds": 1}, "1ns"),
|
||||||
|
({"nanoseconds": 1.0001}, "1ns"),
|
||||||
({"microseconds": 1}, "1us"),
|
({"microseconds": 1}, "1us"),
|
||||||
({"microseconds": 1.0001}, "1us"),
|
({"microseconds": 1.0001}, "1us"),
|
||||||
({"milliseconds": 2}, "2ms"),
|
({"milliseconds": 2}, "2ms"),
|
||||||
|
|||||||
Reference in New Issue
Block a user