mirror of
https://github.com/esphome/esphome.git
synced 2025-11-13 13:25:50 +00:00
Compare commits
12 Commits
2023.11.0b
...
2023.11.0b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d453f0ba2 | ||
|
|
799851a83a | ||
|
|
7a9866f1b6 | ||
|
|
3d30f1f733 | ||
|
|
1e55764d52 | ||
|
|
020da89b6a | ||
|
|
6932422104 | ||
|
|
29aa15b253 | ||
|
|
c40519ec6f | ||
|
|
6c62c00963 | ||
|
|
1bd2e558d6 | ||
|
|
dbb1263a36 |
@@ -5,6 +5,7 @@
|
||||
# One of "docker", "hassio"
|
||||
ARG BASEIMGTYPE=docker
|
||||
|
||||
|
||||
# https://github.com/hassio-addons/addon-debian-base/releases
|
||||
FROM ghcr.io/hassio-addons/debian-base:7.2.0 AS base-hassio
|
||||
# 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
|
||||
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
|
||||
|
||||
# Note that --break-system-packages is used below because
|
||||
# https://peps.python.org/pep-0668/ added a safety check that prevents
|
||||
# installing packages with the same name as a system package. This is
|
||||
@@ -46,7 +49,7 @@ RUN \
|
||||
libssl-dev=3.0.11-1~deb12u2 \
|
||||
libffi-dev=3.4.4-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; \
|
||||
fi; \
|
||||
rm -rf \
|
||||
@@ -60,7 +63,6 @@ ENV \
|
||||
# Store globally installed pio libs in /piolibs
|
||||
PLATFORMIO_GLOBALLIB_DIR=/piolibs
|
||||
|
||||
|
||||
# Support legacy binaries on Debian multiarch system. There is no "correct" way
|
||||
# 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
|
||||
@@ -71,8 +73,12 @@ RUN \
|
||||
|
||||
RUN \
|
||||
# Ubuntu python3-pip is missing wheel
|
||||
pip3 install --break-system-packages --no-cache-dir \
|
||||
platformio==6.1.11 \
|
||||
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||
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
|
||||
&& platformio settings set enable_telemetry No \
|
||||
&& platformio settings set check_platformio_interval 1000000 \
|
||||
@@ -83,8 +89,12 @@ RUN \
|
||||
# tmpfs is for https://github.com/rust-lang/cargo/issues/8719
|
||||
|
||||
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 \
|
||||
pip3 install --break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
|
||||
RUN --mount=type=tmpfs,target=/root/.cargo if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
|
||||
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
|
||||
|
||||
|
||||
@@ -93,7 +103,11 @@ FROM base AS docker
|
||||
|
||||
# Copy esphome and install
|
||||
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
|
||||
ENV USERNAME="" PASSWORD=""
|
||||
@@ -139,7 +153,11 @@ COPY docker/ha-addon-rootfs/ /
|
||||
|
||||
# Copy esphome and install
|
||||
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
|
||||
LABEL \
|
||||
@@ -175,7 +193,11 @@ RUN \
|
||||
/var/lib/apt/lists/*
|
||||
|
||||
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"]
|
||||
WORKDIR /esphome
|
||||
|
||||
@@ -20,16 +20,21 @@ static const esp_bt_uuid_t NOTIFY_DESC_UUID = {
|
||||
void BLEClientBase::setup() {
|
||||
static uint8_t connection_index = 0;
|
||||
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() {
|
||||
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
|
||||
// and the scanner has been stopped by the tracker.
|
||||
if (this->state_ == espbt::ClientState::READY_TO_CONNECT) {
|
||||
|
||||
@@ -93,19 +93,19 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Inclusive(
|
||||
CONF_BIT0_HIGH,
|
||||
"custom",
|
||||
): cv.positive_time_period_microseconds,
|
||||
): cv.positive_time_period_nanoseconds,
|
||||
cv.Inclusive(
|
||||
CONF_BIT0_LOW,
|
||||
"custom",
|
||||
): cv.positive_time_period_microseconds,
|
||||
): cv.positive_time_period_nanoseconds,
|
||||
cv.Inclusive(
|
||||
CONF_BIT1_HIGH,
|
||||
"custom",
|
||||
): cv.positive_time_period_microseconds,
|
||||
): cv.positive_time_period_nanoseconds,
|
||||
cv.Inclusive(
|
||||
CONF_BIT1_LOW,
|
||||
"custom",
|
||||
): cv.positive_time_period_microseconds,
|
||||
): cv.positive_time_period_nanoseconds,
|
||||
}
|
||||
),
|
||||
cv.has_exactly_one_key(CONF_CHIPSET, CONF_BIT0_HIGH),
|
||||
|
||||
@@ -66,6 +66,7 @@ from esphome.core import (
|
||||
TimePeriod,
|
||||
TimePeriodMicroseconds,
|
||||
TimePeriodMilliseconds,
|
||||
TimePeriodNanoseconds,
|
||||
TimePeriodSeconds,
|
||||
TimePeriodMinutes,
|
||||
)
|
||||
@@ -718,6 +719,8 @@ def time_period_str_unit(value):
|
||||
raise Invalid("Expected string for time period with unit.")
|
||||
|
||||
unit_to_kwarg = {
|
||||
"ns": "nanoseconds",
|
||||
"nanoseconds": "nanoseconds",
|
||||
"us": "microseconds",
|
||||
"microseconds": "microseconds",
|
||||
"ms": "milliseconds",
|
||||
@@ -739,7 +742,10 @@ def time_period_str_unit(value):
|
||||
raise Invalid(f"Expected time period with unit, got {value}")
|
||||
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):
|
||||
@@ -749,10 +755,18 @@ def time_period_in_milliseconds_(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())
|
||||
|
||||
|
||||
def time_period_in_nanoseconds_(value):
|
||||
return TimePeriodNanoseconds(**value.as_dict())
|
||||
|
||||
|
||||
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:
|
||||
raise Invalid("Maximum precision is seconds")
|
||||
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):
|
||||
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:
|
||||
raise Invalid("Maximum precision is minutes")
|
||||
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, time_period_in_microseconds_
|
||||
)
|
||||
positive_time_period_nanoseconds = All(
|
||||
positive_time_period, time_period_in_nanoseconds_
|
||||
)
|
||||
positive_not_null_time_period = All(
|
||||
time_period, Range(min=TimePeriod(), min_included=False)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2023.11.0b1"
|
||||
__version__ = "2023.11.0b3"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||
|
||||
@@ -87,6 +87,7 @@ def is_approximately_integer(value):
|
||||
class TimePeriod:
|
||||
def __init__(
|
||||
self,
|
||||
nanoseconds=None,
|
||||
microseconds=None,
|
||||
milliseconds=None,
|
||||
seconds=None,
|
||||
@@ -136,13 +137,23 @@ class TimePeriod:
|
||||
|
||||
if microseconds is not None:
|
||||
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))
|
||||
else:
|
||||
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):
|
||||
out = OrderedDict()
|
||||
if self.nanoseconds is not None:
|
||||
out["nanoseconds"] = self.nanoseconds
|
||||
if self.microseconds is not None:
|
||||
out["microseconds"] = self.microseconds
|
||||
if self.milliseconds is not None:
|
||||
@@ -158,6 +169,8 @@ class TimePeriod:
|
||||
return out
|
||||
|
||||
def __str__(self):
|
||||
if self.nanoseconds is not None:
|
||||
return f"{self.total_nanoseconds}ns"
|
||||
if self.microseconds is not None:
|
||||
return f"{self.total_microseconds}us"
|
||||
if self.milliseconds is not None:
|
||||
@@ -173,7 +186,11 @@ class TimePeriod:
|
||||
return "0s"
|
||||
|
||||
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
|
||||
def total_microseconds(self):
|
||||
@@ -201,35 +218,39 @@ class TimePeriod:
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds == other.total_microseconds
|
||||
return self.total_nanoseconds == other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
def __ne__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds != other.total_microseconds
|
||||
return self.total_nanoseconds != other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
def __lt__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds < other.total_microseconds
|
||||
return self.total_nanoseconds < other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
def __gt__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds > other.total_microseconds
|
||||
return self.total_nanoseconds > other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
def __le__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds <= other.total_microseconds
|
||||
return self.total_nanoseconds <= other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
def __ge__(self, other):
|
||||
if isinstance(other, TimePeriod):
|
||||
return self.total_microseconds >= other.total_microseconds
|
||||
return self.total_nanoseconds >= other.total_nanoseconds
|
||||
return NotImplemented
|
||||
|
||||
|
||||
class TimePeriodNanoseconds(TimePeriod):
|
||||
pass
|
||||
|
||||
|
||||
class TimePeriodMicroseconds(TimePeriod):
|
||||
pass
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from esphome.core import (
|
||||
TimePeriodMicroseconds,
|
||||
TimePeriodMilliseconds,
|
||||
TimePeriodMinutes,
|
||||
TimePeriodNanoseconds,
|
||||
TimePeriodSeconds,
|
||||
)
|
||||
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)
|
||||
if isinstance(obj, float):
|
||||
return FloatLiteral(obj)
|
||||
if isinstance(obj, TimePeriodNanoseconds):
|
||||
return IntLiteral(int(obj.total_nanoseconds))
|
||||
if isinstance(obj, TimePeriodMicroseconds):
|
||||
return IntLiteral(int(obj.total_microseconds))
|
||||
if isinstance(obj, TimePeriodMilliseconds):
|
||||
|
||||
@@ -4,6 +4,7 @@ import base64
|
||||
import binascii
|
||||
import codecs
|
||||
import collections
|
||||
import datetime
|
||||
import functools
|
||||
import gzip
|
||||
import hashlib
|
||||
@@ -1406,15 +1407,17 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||
)
|
||||
|
||||
class StaticFileHandler(tornado.web.StaticFileHandler):
|
||||
def set_extra_headers(self, path):
|
||||
if "favicon.ico" in path:
|
||||
self.set_header("Cache-Control", "max-age=84600, public")
|
||||
else:
|
||||
if debug:
|
||||
self.set_header(
|
||||
"Cache-Control",
|
||||
"no-store, no-cache, must-revalidate, max-age=0",
|
||||
)
|
||||
def get_cache_time(
|
||||
self, path: str, modified: datetime.datetime | None, mime_type: str
|
||||
) -> int:
|
||||
"""Override to customize cache control behavior."""
|
||||
if debug:
|
||||
return 0
|
||||
# Assets that are hashed have ?hash= in the URL, all javascript
|
||||
# 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 = {
|
||||
"debug": debug,
|
||||
|
||||
@@ -10,8 +10,8 @@ platformio==6.1.11 # When updating platformio, also update Dockerfile
|
||||
esptool==4.6.2
|
||||
click==8.1.7
|
||||
esphome-dashboard==20231107.0
|
||||
aioesphomeapi==18.2.4
|
||||
zeroconf==0.120.0
|
||||
aioesphomeapi==18.2.7
|
||||
zeroconf==0.122.3
|
||||
|
||||
# esp-idf requires this, but doesn't bundle it by default
|
||||
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
|
||||
|
||||
@@ -116,14 +116,16 @@ class TestTimePeriod:
|
||||
|
||||
assert actual == expected
|
||||
|
||||
def test_init__microseconds_with_fraction(self):
|
||||
with pytest.raises(ValueError, match="Maximum precision is microseconds"):
|
||||
core.TimePeriod(microseconds=1.1)
|
||||
def test_init__nanoseconds_with_fraction(self):
|
||||
with pytest.raises(ValueError, match="Maximum precision is nanoseconds"):
|
||||
core.TimePeriod(nanoseconds=1.1)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"kwargs, expected",
|
||||
(
|
||||
({}, "0s"),
|
||||
({"nanoseconds": 1}, "1ns"),
|
||||
({"nanoseconds": 1.0001}, "1ns"),
|
||||
({"microseconds": 1}, "1us"),
|
||||
({"microseconds": 1.0001}, "1us"),
|
||||
({"milliseconds": 2}, "2ms"),
|
||||
|
||||
Reference in New Issue
Block a user