mirror of
https://github.com/esphome/esphome.git
synced 2025-11-02 08:01:50 +00:00
Compare commits
159 Commits
jesserockz
...
2023.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd8dc1ef1d | ||
|
|
bc427de16a | ||
|
|
db5988bbe1 | ||
|
|
a3875af4b4 | ||
|
|
e6737479f7 | ||
|
|
7f75832bf1 | ||
|
|
33339e3bd8 | ||
|
|
c298c1166f | ||
|
|
c3d9eef01f | ||
|
|
5ffdc66864 | ||
|
|
9922c1503a | ||
|
|
fce99d4b17 | ||
|
|
11567085d8 | ||
|
|
83f8e84247 | ||
|
|
11eb5cb0fa | ||
|
|
9a7af97b2d | ||
|
|
5e11469f50 | ||
|
|
0c7a3d1fff | ||
|
|
8a705bf4b0 | ||
|
|
6a89180deb | ||
|
|
65d2b806cc | ||
|
|
c149a3033c | ||
|
|
4b7c233f1a | ||
|
|
6e8e9c2aa9 | ||
|
|
b6f628ee40 | ||
|
|
bf79a700b7 | ||
|
|
cdeb6e750f | ||
|
|
dd226360bb | ||
|
|
1a9aedf152 | ||
|
|
d82c6df57e | ||
|
|
7c91b4474a | ||
|
|
a4f21db272 | ||
|
|
58a8e1859e | ||
|
|
2bed5b18c1 | ||
|
|
fb5eb57345 | ||
|
|
63db42a1d4 | ||
|
|
f58ffe41f8 | ||
|
|
445d2e372c | ||
|
|
c037e95861 | ||
|
|
2e1b35959f | ||
|
|
7f46d9e0f9 | ||
|
|
069b5f81a0 | ||
|
|
3a36d0b13f | ||
|
|
f0760e99b7 | ||
|
|
18fecf8c09 | ||
|
|
414cf1b333 | ||
|
|
d10f891f51 | ||
|
|
b5927322e6 | ||
|
|
1cf4107e1c | ||
|
|
c12408326c | ||
|
|
4434e59e5a | ||
|
|
45180d98f6 | ||
|
|
44494ad18e | ||
|
|
1447536906 | ||
|
|
27ec517084 | ||
|
|
ce1f034bac | ||
|
|
f1f96f16e9 | ||
|
|
7665e9b076 | ||
|
|
227d94f38d | ||
|
|
b724ae9e0e | ||
|
|
df6cc14201 | ||
|
|
d981d7859d | ||
|
|
0f1ec515c1 | ||
|
|
78e18256f7 | ||
|
|
4899dfe642 | ||
|
|
d6b6e94059 | ||
|
|
310355a00b | ||
|
|
8cf26d6f3c | ||
|
|
b15a10f905 | ||
|
|
5dcf1debd7 | ||
|
|
9b57e1ac1d | ||
|
|
68683e3a50 | ||
|
|
d83324c4dc | ||
|
|
ecde4c1d2d | ||
|
|
bd8e470726 | ||
|
|
d2913fe627 | ||
|
|
43acc7dc2c | ||
|
|
e2a16d758b | ||
|
|
4af4649e23 | ||
|
|
8bcddef39d | ||
|
|
4ac96ccea2 | ||
|
|
3c5de77ae9 | ||
|
|
a2925b1d37 | ||
|
|
73748e9e20 | ||
|
|
75c9823899 | ||
|
|
c8c0bd3351 | ||
|
|
e1cdeb7c8f | ||
|
|
7f97f42552 | ||
|
|
aa7f3569ec | ||
|
|
2d0a08442e | ||
|
|
d2380756b2 | ||
|
|
925e3cb6c9 | ||
|
|
6757acba56 | ||
|
|
5cc91cdd95 | ||
|
|
2b41886819 | ||
|
|
72c6efd6a0 | ||
|
|
a1f1804112 | ||
|
|
a8b1ceb4e9 | ||
|
|
4fb0f7f8c6 | ||
|
|
958cadeca8 | ||
|
|
00f2655f1a | ||
|
|
074f5029eb | ||
|
|
1691976587 | ||
|
|
60e6b4d21e | ||
|
|
5750591df2 | ||
|
|
a75da54455 | ||
|
|
de7f6c3f5f | ||
|
|
4245480656 | ||
|
|
1824c8131e | ||
|
|
4e9606d2e0 | ||
|
|
78500fa933 | ||
|
|
9c69b98a49 | ||
|
|
e6d8ef98d3 | ||
|
|
3f1af1690b | ||
|
|
84374b6b1e | ||
|
|
391316c9b5 | ||
|
|
705c62ebd7 | ||
|
|
cb520c00a5 | ||
|
|
2f24138345 | ||
|
|
96512b80cc | ||
|
|
fcb9b51978 | ||
|
|
f408f1a368 | ||
|
|
7d8d563c62 | ||
|
|
0a1f705fda | ||
|
|
1952c1880b | ||
|
|
b03967dac1 | ||
|
|
bcae2596a6 | ||
|
|
fc0347c86c | ||
|
|
d9563d4de1 | ||
|
|
cc7e2bf8db | ||
|
|
5d98e2923b | ||
|
|
07197d12f6 | ||
|
|
7b0a298497 | ||
|
|
21679cf2ba | ||
|
|
4be7cd12a1 | ||
|
|
dee4d0ccb7 | ||
|
|
7209dd8bae | ||
|
|
ab736c89bb | ||
|
|
6911639617 | ||
|
|
b9720d0715 | ||
|
|
47b3267ed4 | ||
|
|
e16ba2adb5 | ||
|
|
0a19b1e32c | ||
|
|
bae9a950c0 | ||
|
|
72b2943332 | ||
|
|
4ec0ef7548 | ||
|
|
25bc6761f6 | ||
|
|
81b6562c25 | ||
|
|
ae74189fc2 | ||
|
|
9e516efe10 | ||
|
|
366e29439e | ||
|
|
1c9c700d7f | ||
|
|
b2e6b9d31f | ||
|
|
7623f63846 | ||
|
|
2bfaf9dce3 | ||
|
|
5c2c1560bb | ||
|
|
f7096ab78e | ||
|
|
98f8feb625 | ||
|
|
9944ca414e |
@@ -51,6 +51,6 @@
|
||||
"files.associations": {
|
||||
"**/.vscode/*.json": "jsonc"
|
||||
},
|
||||
"C_Cpp.clang_format_path": "/usr/bin/clang-format-13",
|
||||
"C_Cpp.clang_format_path": "/usr/bin/clang-format-11",
|
||||
}
|
||||
}
|
||||
|
||||
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -41,10 +41,6 @@ jobs:
|
||||
file: tests/test3.yaml
|
||||
name: Test tests/test3.yaml
|
||||
pio_cache_key: test3
|
||||
- id: test
|
||||
file: tests/test3.1.yaml
|
||||
name: Test tests/test3.1.yaml
|
||||
pio_cache_key: test3.1
|
||||
- id: test
|
||||
file: tests/test4.yaml
|
||||
name: Test tests/test4.yaml
|
||||
@@ -133,7 +129,7 @@ jobs:
|
||||
- name: Install clang tools
|
||||
run: |
|
||||
sudo apt-get install \
|
||||
clang-format-13 \
|
||||
clang-format-11 \
|
||||
clang-tidy-11
|
||||
if: matrix.id == 'clang-tidy' || matrix.id == 'clang-format'
|
||||
|
||||
|
||||
4
.github/workflows/stale.yml
vendored
4
.github/workflows/stale.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v8
|
||||
- uses: actions/stale@v7
|
||||
with:
|
||||
days-before-pr-stale: 90
|
||||
days-before-pr-close: 7
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
close-issues:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v8
|
||||
- uses: actions/stale@v7
|
||||
with:
|
||||
days-before-pr-stale: -1
|
||||
days-before-pr-close: -1
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/psf/black
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: 23.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
@@ -135,7 +135,7 @@ RUN \
|
||||
apt-get update \
|
||||
# Use pinned versions so that we get updates with build caching
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
clang-format-13=1:13.0.1-6~deb11u1 \
|
||||
clang-format-11=1:11.0.1-2 \
|
||||
clang-tidy-11=1:11.0.1-2 \
|
||||
patch=2.7.6-7 \
|
||||
software-properties-common=0.96.20.2-2.1 \
|
||||
|
||||
@@ -65,7 +65,7 @@ void Am43Component::control(const CoverCall &call) {
|
||||
|
||||
if (this->invert_position_)
|
||||
pos = 1 - pos;
|
||||
auto *packet = this->encoder_->get_set_position_request(100 - (uint8_t) (pos * 100));
|
||||
auto *packet = this->encoder_->get_set_position_request(100 - (uint8_t)(pos * 100));
|
||||
auto status =
|
||||
esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
|
||||
packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
|
||||
|
||||
@@ -76,6 +76,8 @@ async def to_code(config):
|
||||
pos = 0
|
||||
for frameIndex in range(frames):
|
||||
image.seek(frameIndex)
|
||||
if CONF_RESIZE in config:
|
||||
image.thumbnail(config[CONF_RESIZE])
|
||||
frame = image.convert("RGB")
|
||||
if CONF_RESIZE in config:
|
||||
frame = frame.resize([width, height])
|
||||
|
||||
@@ -1156,7 +1156,6 @@ enum BluetoothDeviceRequestType {
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_UNPAIR = 3;
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITH_CACHE = 4;
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE = 5;
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE = 6;
|
||||
}
|
||||
|
||||
message BluetoothDeviceRequest {
|
||||
@@ -1360,13 +1359,3 @@ message BluetoothDeviceUnpairingResponse {
|
||||
bool success = 2;
|
||||
int32 error = 3;
|
||||
}
|
||||
|
||||
message BluetoothDeviceClearCacheResponse {
|
||||
option (id) = 88;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_BLUETOOTH_PROXY";
|
||||
|
||||
uint64 address = 1;
|
||||
bool success = 2;
|
||||
int32 error = 3;
|
||||
}
|
||||
|
||||
@@ -180,8 +180,7 @@ bool APIConnection::send_binary_sensor_info(binary_sensor::BinarySensor *binary_
|
||||
ListEntitiesBinarySensorResponse msg;
|
||||
msg.object_id = binary_sensor->get_object_id();
|
||||
msg.key = binary_sensor->get_object_id_hash();
|
||||
if (binary_sensor->has_own_name())
|
||||
msg.name = binary_sensor->get_name();
|
||||
msg.name = binary_sensor->get_name();
|
||||
msg.unique_id = get_default_unique_id("binary_sensor", binary_sensor);
|
||||
msg.device_class = binary_sensor->get_device_class();
|
||||
msg.is_status_binary_sensor = binary_sensor->is_status_binary_sensor();
|
||||
@@ -213,8 +212,7 @@ bool APIConnection::send_cover_info(cover::Cover *cover) {
|
||||
ListEntitiesCoverResponse msg;
|
||||
msg.key = cover->get_object_id_hash();
|
||||
msg.object_id = cover->get_object_id();
|
||||
if (cover->has_own_name())
|
||||
msg.name = cover->get_name();
|
||||
msg.name = cover->get_name();
|
||||
msg.unique_id = get_default_unique_id("cover", cover);
|
||||
msg.assumed_state = traits.get_is_assumed_state();
|
||||
msg.supports_position = traits.get_supports_position();
|
||||
@@ -277,8 +275,7 @@ bool APIConnection::send_fan_info(fan::Fan *fan) {
|
||||
ListEntitiesFanResponse msg;
|
||||
msg.key = fan->get_object_id_hash();
|
||||
msg.object_id = fan->get_object_id();
|
||||
if (fan->has_own_name())
|
||||
msg.name = fan->get_name();
|
||||
msg.name = fan->get_name();
|
||||
msg.unique_id = get_default_unique_id("fan", fan);
|
||||
msg.supports_oscillation = traits.supports_oscillation();
|
||||
msg.supports_speed = traits.supports_speed();
|
||||
@@ -340,8 +337,7 @@ bool APIConnection::send_light_info(light::LightState *light) {
|
||||
ListEntitiesLightResponse msg;
|
||||
msg.key = light->get_object_id_hash();
|
||||
msg.object_id = light->get_object_id();
|
||||
if (light->has_own_name())
|
||||
msg.name = light->get_name();
|
||||
msg.name = light->get_name();
|
||||
msg.unique_id = get_default_unique_id("light", light);
|
||||
|
||||
msg.disabled_by_default = light->is_disabled_by_default();
|
||||
@@ -422,8 +418,7 @@ bool APIConnection::send_sensor_info(sensor::Sensor *sensor) {
|
||||
ListEntitiesSensorResponse msg;
|
||||
msg.key = sensor->get_object_id_hash();
|
||||
msg.object_id = sensor->get_object_id();
|
||||
if (sensor->has_own_name())
|
||||
msg.name = sensor->get_name();
|
||||
msg.name = sensor->get_name();
|
||||
msg.unique_id = sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("sensor", sensor);
|
||||
@@ -453,8 +448,7 @@ bool APIConnection::send_switch_info(switch_::Switch *a_switch) {
|
||||
ListEntitiesSwitchResponse msg;
|
||||
msg.key = a_switch->get_object_id_hash();
|
||||
msg.object_id = a_switch->get_object_id();
|
||||
if (a_switch->has_own_name())
|
||||
msg.name = a_switch->get_name();
|
||||
msg.name = a_switch->get_name();
|
||||
msg.unique_id = get_default_unique_id("switch", a_switch);
|
||||
msg.icon = a_switch->get_icon();
|
||||
msg.assumed_state = a_switch->assumed_state();
|
||||
@@ -539,8 +533,7 @@ bool APIConnection::send_climate_info(climate::Climate *climate) {
|
||||
ListEntitiesClimateResponse msg;
|
||||
msg.key = climate->get_object_id_hash();
|
||||
msg.object_id = climate->get_object_id();
|
||||
if (climate->has_own_name())
|
||||
msg.name = climate->get_name();
|
||||
msg.name = climate->get_name();
|
||||
msg.unique_id = get_default_unique_id("climate", climate);
|
||||
|
||||
msg.disabled_by_default = climate->is_disabled_by_default();
|
||||
@@ -618,8 +611,7 @@ bool APIConnection::send_number_info(number::Number *number) {
|
||||
ListEntitiesNumberResponse msg;
|
||||
msg.key = number->get_object_id_hash();
|
||||
msg.object_id = number->get_object_id();
|
||||
if (number->has_own_name())
|
||||
msg.name = number->get_name();
|
||||
msg.name = number->get_name();
|
||||
msg.unique_id = get_default_unique_id("number", number);
|
||||
msg.icon = number->get_icon();
|
||||
msg.disabled_by_default = number->is_disabled_by_default();
|
||||
@@ -660,8 +652,7 @@ bool APIConnection::send_select_info(select::Select *select) {
|
||||
ListEntitiesSelectResponse msg;
|
||||
msg.key = select->get_object_id_hash();
|
||||
msg.object_id = select->get_object_id();
|
||||
if (select->has_own_name())
|
||||
msg.name = select->get_name();
|
||||
msg.name = select->get_name();
|
||||
msg.unique_id = get_default_unique_id("select", select);
|
||||
msg.icon = select->get_icon();
|
||||
msg.disabled_by_default = select->is_disabled_by_default();
|
||||
@@ -688,8 +679,7 @@ bool APIConnection::send_button_info(button::Button *button) {
|
||||
ListEntitiesButtonResponse msg;
|
||||
msg.key = button->get_object_id_hash();
|
||||
msg.object_id = button->get_object_id();
|
||||
if (button->has_own_name())
|
||||
msg.name = button->get_name();
|
||||
msg.name = button->get_name();
|
||||
msg.unique_id = get_default_unique_id("button", button);
|
||||
msg.icon = button->get_icon();
|
||||
msg.disabled_by_default = button->is_disabled_by_default();
|
||||
@@ -720,8 +710,7 @@ bool APIConnection::send_lock_info(lock::Lock *a_lock) {
|
||||
ListEntitiesLockResponse msg;
|
||||
msg.key = a_lock->get_object_id_hash();
|
||||
msg.object_id = a_lock->get_object_id();
|
||||
if (a_lock->has_own_name())
|
||||
msg.name = a_lock->get_name();
|
||||
msg.name = a_lock->get_name();
|
||||
msg.unique_id = get_default_unique_id("lock", a_lock);
|
||||
msg.icon = a_lock->get_icon();
|
||||
msg.assumed_state = a_lock->traits.get_assumed_state();
|
||||
@@ -766,8 +755,7 @@ bool APIConnection::send_media_player_info(media_player::MediaPlayer *media_play
|
||||
ListEntitiesMediaPlayerResponse msg;
|
||||
msg.key = media_player->get_object_id_hash();
|
||||
msg.object_id = media_player->get_object_id();
|
||||
if (media_player->has_own_name())
|
||||
msg.name = media_player->get_name();
|
||||
msg.name = media_player->get_name();
|
||||
msg.unique_id = get_default_unique_id("media_player", media_player);
|
||||
msg.icon = media_player->get_icon();
|
||||
msg.disabled_by_default = media_player->is_disabled_by_default();
|
||||
@@ -811,8 +799,7 @@ bool APIConnection::send_camera_info(esp32_camera::ESP32Camera *camera) {
|
||||
ListEntitiesCameraResponse msg;
|
||||
msg.key = camera->get_object_id_hash();
|
||||
msg.object_id = camera->get_object_id();
|
||||
if (camera->has_own_name())
|
||||
msg.name = camera->get_name();
|
||||
msg.name = camera->get_name();
|
||||
msg.unique_id = get_default_unique_id("camera", camera);
|
||||
msg.disabled_by_default = camera->is_disabled_by_default();
|
||||
msg.icon = camera->get_icon();
|
||||
@@ -966,9 +953,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
resp.webserver_port = USE_WEBSERVER_PORT;
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
resp.bluetooth_proxy_version = bluetooth_proxy::global_bluetooth_proxy->has_active()
|
||||
? bluetooth_proxy::ACTIVE_CONNECTIONS_VERSION
|
||||
: bluetooth_proxy::PASSIVE_ONLY_VERSION;
|
||||
resp.bluetooth_proxy_version = bluetooth_proxy::global_bluetooth_proxy->has_active() ? 4 : 1;
|
||||
#endif
|
||||
return resp;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ APIError APINoiseFrameHelper::state_action_() {
|
||||
if (aerr != APIError::OK)
|
||||
return aerr;
|
||||
// ignore contents, may be used in future for flags
|
||||
prologue_.push_back((uint8_t) (frame.msg.size() >> 8));
|
||||
prologue_.push_back((uint8_t)(frame.msg.size() >> 8));
|
||||
prologue_.push_back((uint8_t) frame.msg.size());
|
||||
prologue_.insert(prologue_.end(), frame.msg.begin(), frame.msg.end());
|
||||
|
||||
@@ -492,9 +492,9 @@ APIError APINoiseFrameHelper::write_packet(uint16_t type, const uint8_t *payload
|
||||
// tmpbuf[1], tmpbuf[2] to be set later
|
||||
const uint8_t msg_offset = 3;
|
||||
const uint8_t payload_offset = msg_offset + 4;
|
||||
tmpbuf[msg_offset + 0] = (uint8_t) (type >> 8); // type
|
||||
tmpbuf[msg_offset + 0] = (uint8_t)(type >> 8); // type
|
||||
tmpbuf[msg_offset + 1] = (uint8_t) type;
|
||||
tmpbuf[msg_offset + 2] = (uint8_t) (payload_len >> 8); // data_len
|
||||
tmpbuf[msg_offset + 2] = (uint8_t)(payload_len >> 8); // data_len
|
||||
tmpbuf[msg_offset + 3] = (uint8_t) payload_len;
|
||||
// copy data
|
||||
std::copy(payload, payload + payload_len, &tmpbuf[payload_offset]);
|
||||
@@ -512,7 +512,7 @@ APIError APINoiseFrameHelper::write_packet(uint16_t type, const uint8_t *payload
|
||||
}
|
||||
|
||||
size_t total_len = 3 + mbuf.size;
|
||||
tmpbuf[1] = (uint8_t) (mbuf.size >> 8);
|
||||
tmpbuf[1] = (uint8_t)(mbuf.size >> 8);
|
||||
tmpbuf[2] = (uint8_t) mbuf.size;
|
||||
|
||||
struct iovec iov;
|
||||
@@ -610,7 +610,7 @@ APIError APINoiseFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) {
|
||||
APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, size_t len) {
|
||||
uint8_t header[3];
|
||||
header[0] = 0x01; // indicator
|
||||
header[1] = (uint8_t) (len >> 8);
|
||||
header[1] = (uint8_t)(len >> 8);
|
||||
header[2] = (uint8_t) len;
|
||||
|
||||
struct iovec iov[2];
|
||||
|
||||
@@ -400,8 +400,6 @@ const char *proto_enum_to_string<enums::BluetoothDeviceRequestType>(enums::Bluet
|
||||
return "BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITH_CACHE";
|
||||
case enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE:
|
||||
return "BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE";
|
||||
case enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE:
|
||||
return "BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
@@ -6062,49 +6060,6 @@ void BluetoothDeviceUnpairingResponse::dump_to(std::string &out) const {
|
||||
out.append("}");
|
||||
}
|
||||
#endif
|
||||
bool BluetoothDeviceClearCacheResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
switch (field_id) {
|
||||
case 1: {
|
||||
this->address = value.as_uint64();
|
||||
return true;
|
||||
}
|
||||
case 2: {
|
||||
this->success = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
case 3: {
|
||||
this->error = value.as_int32();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void BluetoothDeviceClearCacheResponse::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_uint64(1, this->address);
|
||||
buffer.encode_bool(2, this->success);
|
||||
buffer.encode_int32(3, this->error);
|
||||
}
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void BluetoothDeviceClearCacheResponse::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("BluetoothDeviceClearCacheResponse {\n");
|
||||
out.append(" address: ");
|
||||
sprintf(buffer, "%llu", this->address);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
|
||||
out.append(" success: ");
|
||||
out.append(YESNO(this->success));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" error: ");
|
||||
sprintf(buffer, "%d", this->error);
|
||||
out.append(buffer);
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace api
|
||||
} // namespace esphome
|
||||
|
||||
@@ -163,7 +163,6 @@ enum BluetoothDeviceRequestType : uint32_t {
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_UNPAIR = 3,
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITH_CACHE = 4,
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE = 5,
|
||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE = 6,
|
||||
};
|
||||
|
||||
} // namespace enums
|
||||
@@ -1555,19 +1554,6 @@ class BluetoothDeviceUnpairingResponse : public ProtoMessage {
|
||||
protected:
|
||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||
};
|
||||
class BluetoothDeviceClearCacheResponse : public ProtoMessage {
|
||||
public:
|
||||
uint64_t address{0};
|
||||
bool success{false};
|
||||
int32_t error{0};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace esphome
|
||||
|
||||
@@ -441,14 +441,6 @@ bool APIServerConnectionBase::send_bluetooth_device_unpairing_response(const Blu
|
||||
return this->send_message_<BluetoothDeviceUnpairingResponse>(msg, 86);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
bool APIServerConnectionBase::send_bluetooth_device_clear_cache_response(const BluetoothDeviceClearCacheResponse &msg) {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
ESP_LOGVV(TAG, "send_bluetooth_device_clear_cache_response: %s", msg.dump().c_str());
|
||||
#endif
|
||||
return this->send_message_<BluetoothDeviceClearCacheResponse>(msg, 88);
|
||||
}
|
||||
#endif
|
||||
bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) {
|
||||
switch (msg_type) {
|
||||
case 1: {
|
||||
|
||||
@@ -215,9 +215,6 @@ class APIServerConnectionBase : public ProtoService {
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
bool send_bluetooth_device_unpairing_response(const BluetoothDeviceUnpairingResponse &msg);
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
bool send_bluetooth_device_clear_cache_response(const BluetoothDeviceClearCacheResponse &msg);
|
||||
#endif
|
||||
protected:
|
||||
bool read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) override;
|
||||
|
||||
@@ -45,7 +45,7 @@ void APIServer::setup() {
|
||||
|
||||
struct sockaddr_storage server;
|
||||
|
||||
socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), this->port_);
|
||||
socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), htons(this->port_));
|
||||
if (sl == 0) {
|
||||
ESP_LOGW(TAG, "Socket unable to set sockaddr: errno %d", errno);
|
||||
this->mark_failed();
|
||||
@@ -331,17 +331,6 @@ void APIServer::send_bluetooth_device_unpairing(uint64_t address, bool success,
|
||||
}
|
||||
}
|
||||
|
||||
void APIServer::send_bluetooth_device_clear_cache(uint64_t address, bool success, esp_err_t error) {
|
||||
BluetoothDeviceClearCacheResponse call;
|
||||
call.address = address;
|
||||
call.success = success;
|
||||
call.error = error;
|
||||
|
||||
for (auto &client : this->clients_) {
|
||||
client->send_bluetooth_device_clear_cache_response(call);
|
||||
}
|
||||
}
|
||||
|
||||
void APIServer::send_bluetooth_connections_free(uint8_t free, uint8_t limit) {
|
||||
BluetoothConnectionsFreeResponse call;
|
||||
call.free = free;
|
||||
|
||||
@@ -80,7 +80,6 @@ class APIServer : public Component, public Controller {
|
||||
void send_bluetooth_device_connection(uint64_t address, bool connected, uint16_t mtu = 0, esp_err_t error = ESP_OK);
|
||||
void send_bluetooth_device_pairing(uint64_t address, bool paired, esp_err_t error = ESP_OK);
|
||||
void send_bluetooth_device_unpairing(uint64_t address, bool success, esp_err_t error = ESP_OK);
|
||||
void send_bluetooth_device_clear_cache(uint64_t address, bool success, esp_err_t error = ESP_OK);
|
||||
void send_bluetooth_connections_free(uint8_t free, uint8_t limit);
|
||||
void send_bluetooth_gatt_read_response(const BluetoothGATTReadResponse &call);
|
||||
void send_bluetooth_gatt_write_response(const BluetoothGATTWriteResponse &call);
|
||||
|
||||
@@ -41,13 +41,16 @@ void BinarySensor::send_state_internal(bool state, bool is_initial) {
|
||||
this->state_callback_.call(state);
|
||||
}
|
||||
}
|
||||
|
||||
std::string BinarySensor::device_class() { return ""; }
|
||||
BinarySensor::BinarySensor() : state(false) {}
|
||||
void BinarySensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
|
||||
std::string BinarySensor::get_device_class() {
|
||||
if (this->device_class_.has_value())
|
||||
return *this->device_class_;
|
||||
return "";
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->device_class();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
void BinarySensor::add_filter(Filter *filter) {
|
||||
filter->parent_ = this;
|
||||
|
||||
@@ -80,6 +80,14 @@ class BinarySensor : public EntityBase {
|
||||
|
||||
virtual bool is_status_binary_sensor() const;
|
||||
|
||||
// ========== OVERRIDE METHODS ==========
|
||||
// (You'll only need this when creating your own custom binary sensor)
|
||||
/** Override this to set the default device class.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual std::string device_class();
|
||||
|
||||
protected:
|
||||
CallbackManager<void(bool)> state_callback_{};
|
||||
optional<std::string> device_class_{}; ///< Stores the override of the device class
|
||||
|
||||
@@ -306,13 +306,6 @@ void BluetoothProxy::bluetooth_device_request(const api::BluetoothDeviceRequest
|
||||
api::global_api_server->send_bluetooth_device_unpairing(msg.address, ret == ESP_OK, ret);
|
||||
break;
|
||||
}
|
||||
case api::enums::BLUETOOTH_DEVICE_REQUEST_TYPE_CLEAR_CACHE: {
|
||||
esp_bd_addr_t address;
|
||||
uint64_to_bd_addr(msg.address, address);
|
||||
esp_err_t ret = esp_ble_gattc_cache_clean(address);
|
||||
api::global_api_server->send_bluetooth_device_clear_cache(msg.address, ret == ESP_OK, ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,14 +68,6 @@ class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Com
|
||||
|
||||
extern BluetoothProxy *global_bluetooth_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
// Version 1: Initial version without active connections
|
||||
// Version 2: Support for active connections
|
||||
// Version 3: New connection API
|
||||
// Version 4: Pairing support
|
||||
// Version 5: Cache clear support
|
||||
static const uint32_t ACTIVE_CONNECTIONS_VERSION = 5;
|
||||
static const uint32_t PASSIVE_ONLY_VERSION = 1;
|
||||
|
||||
} // namespace bluetooth_proxy
|
||||
} // namespace esphome
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "bme680.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace bme680 {
|
||||
@@ -275,8 +275,8 @@ uint8_t BME680Component::calc_heater_resistance_(uint16_t temperature) {
|
||||
var3 = var1 + (var2 / 2);
|
||||
var4 = (var3 / (res_heat_range + 4));
|
||||
var5 = (131 * res_heat_val) + 65536;
|
||||
heatr_res_x100 = (int32_t) (((var4 / var5) - 250) * 34);
|
||||
heatr_res = (uint8_t) ((heatr_res_x100 + 50) / 100);
|
||||
heatr_res_x100 = (int32_t)(((var4 / var5) - 250) * 34);
|
||||
heatr_res = (uint8_t)((heatr_res_x100 + 50) / 100);
|
||||
|
||||
return heatr_res;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ void BME680Component::read_data_() {
|
||||
uint32_t raw_temperature = (uint32_t(data[5]) << 12) | (uint32_t(data[6]) << 4) | (uint32_t(data[7]) >> 4);
|
||||
uint32_t raw_pressure = (uint32_t(data[2]) << 12) | (uint32_t(data[3]) << 4) | (uint32_t(data[4]) >> 4);
|
||||
uint32_t raw_humidity = (uint32_t(data[8]) << 8) | uint32_t(data[9]);
|
||||
uint16_t raw_gas = (uint16_t) ((uint32_t) data[13] * 4 | (((uint32_t) data[14]) / 64));
|
||||
uint16_t raw_gas = (uint16_t)((uint32_t) data[13] * 4 | (((uint32_t) data[14]) / 64));
|
||||
uint8_t gas_range = data[14] & 0x0F;
|
||||
|
||||
float temperature = this->calc_temperature_(raw_temperature);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, esp32
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@trvrnrth"]
|
||||
@@ -32,31 +32,22 @@ BME680BSECComponent = bme680_bsec_ns.class_(
|
||||
"BME680BSECComponent", cg.Component, i2c.I2CDevice
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(BME680BSECComponent),
|
||||
cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature,
|
||||
cv.Optional(CONF_IAQ_MODE, default="STATIC"): cv.enum(
|
||||
IAQ_MODE_OPTIONS, upper=True
|
||||
),
|
||||
cv.Optional(CONF_SAMPLE_RATE, default="LP"): cv.enum(
|
||||
SAMPLE_RATE_OPTIONS, upper=True
|
||||
),
|
||||
cv.Optional(
|
||||
CONF_STATE_SAVE_INTERVAL, default="6hours"
|
||||
): cv.positive_time_period_minutes,
|
||||
}
|
||||
).extend(i2c.i2c_device_schema(0x76)),
|
||||
cv.only_with_arduino,
|
||||
cv.Any(
|
||||
cv.only_on_esp8266,
|
||||
cv.All(
|
||||
cv.only_on_esp32,
|
||||
esp32.only_on_variant(supported=[esp32.const.VARIANT_ESP32]),
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(BME680BSECComponent),
|
||||
cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature,
|
||||
cv.Optional(CONF_IAQ_MODE, default="STATIC"): cv.enum(
|
||||
IAQ_MODE_OPTIONS, upper=True
|
||||
),
|
||||
),
|
||||
)
|
||||
cv.Optional(CONF_SAMPLE_RATE, default="LP"): cv.enum(
|
||||
SAMPLE_RATE_OPTIONS, upper=True
|
||||
),
|
||||
cv.Optional(
|
||||
CONF_STATE_SAVE_INTERVAL, default="6hours"
|
||||
): cv.positive_time_period_minutes,
|
||||
},
|
||||
cv.only_with_arduino,
|
||||
).extend(i2c.i2c_device_schema(0x76))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
||||
@@ -145,8 +145,8 @@ void CCS811Component::send_env_data_() {
|
||||
// https://github.com/adafruit/Adafruit_CCS811/blob/0990f5c620354d8bc087c4706bec091d8e6e5dfd/Adafruit_CCS811.cpp#L135-L142
|
||||
uint16_t hum_conv = static_cast<uint16_t>(lroundf(humidity * 512.0f + 0.5f));
|
||||
uint16_t temp_conv = static_cast<uint16_t>(lroundf(temperature * 512.0f + 0.5f));
|
||||
this->write_bytes(0x05, {(uint8_t) ((hum_conv >> 8) & 0xff), (uint8_t) ((hum_conv & 0xff)),
|
||||
(uint8_t) ((temp_conv >> 8) & 0xff), (uint8_t) ((temp_conv & 0xff))});
|
||||
this->write_bytes(0x05, {(uint8_t)((hum_conv >> 8) & 0xff), (uint8_t)((hum_conv & 0xff)),
|
||||
(uint8_t)((temp_conv >> 8) & 0xff), (uint8_t)((temp_conv & 0xff))});
|
||||
}
|
||||
void CCS811Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "CCS811");
|
||||
|
||||
@@ -14,15 +14,12 @@ from .. import copy_ns
|
||||
CopySelect = copy_ns.class_("CopySelect", select.Select, cg.Component)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
select.select_schema(CopySelect)
|
||||
.extend(
|
||||
{
|
||||
cv.Required(CONF_SOURCE_ID): cv.use_id(select.Select),
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
CONFIG_SCHEMA = select.SELECT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CopySelect),
|
||||
cv.Required(CONF_SOURCE_ID): cv.use_id(select.Select),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = cv.All(
|
||||
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
|
||||
|
||||
@@ -208,10 +208,14 @@ Cover::Cover() : Cover("") {}
|
||||
std::string Cover::get_device_class() {
|
||||
if (this->device_class_override_.has_value())
|
||||
return *this->device_class_override_;
|
||||
return "";
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->device_class();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
bool Cover::is_fully_open() const { return this->position == COVER_OPEN; }
|
||||
bool Cover::is_fully_closed() const { return this->position == COVER_CLOSED; }
|
||||
std::string Cover::device_class() { return ""; }
|
||||
|
||||
CoverCall CoverRestoreState::to_call(Cover *cover) {
|
||||
auto call = cover->make_call();
|
||||
|
||||
@@ -170,6 +170,12 @@ class Cover : public EntityBase {
|
||||
|
||||
virtual void control(const CoverCall &call) = 0;
|
||||
|
||||
/** Override this to set the default device class.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual std::string device_class();
|
||||
|
||||
optional<CoverRestoreState> restore_state_();
|
||||
|
||||
CallbackManager<void()> state_callback_{};
|
||||
|
||||
@@ -305,7 +305,7 @@ bool CS5460AComponent::check_status_() {
|
||||
voltage_sensor_->publish_state(raw_voltage * voltage_multiplier_);
|
||||
|
||||
if (power_sensor_ != nullptr && raw_energy != prev_raw_energy_) {
|
||||
int32_t raw = (int32_t) (raw_energy << 8) >> 8; /* Sign-extend */
|
||||
int32_t raw = (int32_t)(raw_energy << 8) >> 8; /* Sign-extend */
|
||||
power_sensor_->publish_state(raw * power_multiplier_);
|
||||
prev_raw_energy_ = raw_energy;
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ void CTClampSensor::update() {
|
||||
|
||||
const float rms_ac_dc_squared = this->sample_squared_sum_ / this->num_samples_;
|
||||
const float rms_dc = this->sample_sum_ / this->num_samples_;
|
||||
const float rms_ac_squared = rms_ac_dc_squared - rms_dc * rms_dc;
|
||||
float rms_ac = 0;
|
||||
if (rms_ac_squared > 0)
|
||||
rms_ac = std::sqrt(rms_ac_squared);
|
||||
const float rms_ac = std::sqrt(rms_ac_dc_squared - rms_dc * rms_dc);
|
||||
ESP_LOGD(TAG, "'%s' - Raw AC Value: %.3fA after %d different samples (%d SPS)", this->name_.c_str(), rms_ac,
|
||||
this->num_samples_, 1000 * this->num_samples_ / this->sample_duration_);
|
||||
this->publish_state(rms_ac);
|
||||
|
||||
@@ -61,8 +61,8 @@ void DalyBmsComponent::request_data_(uint8_t data_id) {
|
||||
request_message[9] = 0x00; // |
|
||||
request_message[10] = 0x00; // |
|
||||
request_message[11] = 0x00; // Empty Data
|
||||
request_message[12] = (uint8_t) (request_message[0] + request_message[1] + request_message[2] +
|
||||
request_message[3]); // Checksum (Lower byte of the other bytes sum)
|
||||
request_message[12] = (uint8_t)(request_message[0] + request_message[1] + request_message[2] +
|
||||
request_message[3]); // Checksum (Lower byte of the other bytes sum)
|
||||
|
||||
this->write_array(request_message, sizeof(request_message));
|
||||
this->flush();
|
||||
|
||||
@@ -19,7 +19,7 @@ void DFPlayer::play_folder(uint16_t folder, uint16_t file) {
|
||||
}
|
||||
|
||||
void DFPlayer::send_cmd_(uint8_t cmd, uint16_t argument) {
|
||||
uint8_t buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
|
||||
uint8_t buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t)(argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
|
||||
uint16_t checksum = 0;
|
||||
for (uint8_t i = 1; i < 7; i++)
|
||||
checksum += buffer[i];
|
||||
|
||||
@@ -664,7 +664,7 @@ bool Animation::get_pixel(int x, int y) const {
|
||||
return false;
|
||||
const uint32_t width_8 = ((this->width_ + 7u) / 8u) * 8u;
|
||||
const uint32_t frame_index = this->height_ * width_8 * this->current_frame_;
|
||||
if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_))
|
||||
if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_))
|
||||
return false;
|
||||
const uint32_t pos = x + y * width_8 + frame_index;
|
||||
return progmem_read_byte(this->data_start_ + (pos / 8u)) & (0x80 >> (pos % 8u));
|
||||
@@ -673,7 +673,7 @@ Color Animation::get_color_pixel(int x, int y) const {
|
||||
if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
|
||||
return Color::BLACK;
|
||||
const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_;
|
||||
if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_))
|
||||
if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_))
|
||||
return Color::BLACK;
|
||||
const uint32_t pos = (x + y * this->width_ + frame_index) * 3;
|
||||
const uint32_t color32 = (progmem_read_byte(this->data_start_ + pos + 2) << 0) |
|
||||
@@ -685,7 +685,7 @@ Color Animation::get_rgb565_pixel(int x, int y) const {
|
||||
if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
|
||||
return Color::BLACK;
|
||||
const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_;
|
||||
if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_))
|
||||
if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_))
|
||||
return Color::BLACK;
|
||||
const uint32_t pos = (x + y * this->width_ + frame_index) * 2;
|
||||
uint16_t rgb565 =
|
||||
@@ -699,7 +699,7 @@ Color Animation::get_grayscale_pixel(int x, int y) const {
|
||||
if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
|
||||
return Color::BLACK;
|
||||
const uint32_t frame_index = this->width_ * this->height_ * this->current_frame_;
|
||||
if (frame_index >= (uint32_t) (this->width_ * this->height_ * this->animation_frame_count_))
|
||||
if (frame_index >= (uint32_t)(this->width_ * this->height_ * this->animation_frame_count_))
|
||||
return Color::BLACK;
|
||||
const uint32_t pos = (x + y * this->width_ + frame_index);
|
||||
const uint8_t gray = progmem_read_byte(this->data_start_ + pos);
|
||||
|
||||
@@ -168,7 +168,7 @@ void ENS210Component::update() {
|
||||
return;
|
||||
}
|
||||
// Pack bytes for humidity
|
||||
h_val_data = (uint32_t) ((uint32_t) data[5] << 16 | (uint32_t) data[4] << 8 | (uint32_t) data[3]);
|
||||
h_val_data = (uint32_t)((uint32_t) data[5] << 16 | (uint32_t) data[4] << 8 | (uint32_t) data[3]);
|
||||
// Extract humidity data and update the status
|
||||
extract_measurement_(h_val_data, &humidity_data, &humidity_status);
|
||||
|
||||
@@ -183,7 +183,7 @@ void ENS210Component::update() {
|
||||
return;
|
||||
}
|
||||
// Pack bytes for temperature
|
||||
t_val_data = (uint32_t) ((uint32_t) data[2] << 16 | (uint32_t) data[1] << 8 | (uint32_t) data[0]);
|
||||
t_val_data = (uint32_t)((uint32_t) data[2] << 16 | (uint32_t) data[1] << 8 | (uint32_t) data[0]);
|
||||
// Extract temperature data and update the status
|
||||
extract_measurement_(t_val_data, &temperature_data, &temperature_status);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ void loop();
|
||||
namespace esphome {
|
||||
|
||||
void IRAM_ATTR HOT yield() { vPortYield(); }
|
||||
uint32_t IRAM_ATTR HOT millis() { return (uint32_t) (esp_timer_get_time() / 1000ULL); }
|
||||
uint32_t IRAM_ATTR HOT millis() { return (uint32_t)(esp_timer_get_time() / 1000ULL); }
|
||||
void IRAM_ATTR HOT delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }
|
||||
uint32_t IRAM_ATTR HOT micros() { return (uint32_t) esp_timer_get_time(); }
|
||||
void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
|
||||
|
||||
@@ -12,6 +12,8 @@ CONF_BLE_ID = "ble_id"
|
||||
|
||||
NO_BLUTOOTH_VARIANTS = [const.VARIANT_ESP32S2]
|
||||
|
||||
NO_BLUTOOTH_VARIANTS = [const.VARIANT_ESP32S2]
|
||||
|
||||
esp32_ble_ns = cg.esphome_ns.namespace("esp32_ble")
|
||||
ESP32BLE = esp32_ble_ns.class_("ESP32BLE", cg.Component)
|
||||
|
||||
|
||||
@@ -316,18 +316,18 @@ float BLEClientBase::parse_char_value(uint8_t *value, uint16_t length) {
|
||||
case 0xD: // int12.
|
||||
case 0xE: // int16.
|
||||
if (length > 2) {
|
||||
return (float) ((int16_t) (value[1] << 8) + (int16_t) value[2]);
|
||||
return (float) ((int16_t)(value[1] << 8) + (int16_t) value[2]);
|
||||
}
|
||||
// fall through
|
||||
case 0xF: // int24.
|
||||
if (length > 3) {
|
||||
return (float) ((int32_t) (value[1] << 16) + (int32_t) (value[2] << 8) + (int32_t) (value[3]));
|
||||
return (float) ((int32_t)(value[1] << 16) + (int32_t)(value[2] << 8) + (int32_t)(value[3]));
|
||||
}
|
||||
// fall through
|
||||
case 0x10: // int32.
|
||||
if (length > 4) {
|
||||
return (float) ((int32_t) (value[1] << 24) + (int32_t) (value[2] << 16) + (int32_t) (value[3] << 8) +
|
||||
(int32_t) (value[4]));
|
||||
return (float) ((int32_t)(value[1] << 24) + (int32_t)(value[2] << 16) + (int32_t)(value[3] << 8) +
|
||||
(int32_t)(value[4]));
|
||||
}
|
||||
}
|
||||
ESP_LOGW(TAG, "[%d] [%s] Cannot parse characteristic value of type 0x%x length %d", this->connection_index_,
|
||||
|
||||
@@ -45,11 +45,10 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
|
||||
memset(this->remote_bda_, 0, sizeof(this->remote_bda_));
|
||||
this->address_str_ = "";
|
||||
} else {
|
||||
this->address_str_ =
|
||||
str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, (uint8_t) (this->address_ >> 40) & 0xff,
|
||||
(uint8_t) (this->address_ >> 32) & 0xff, (uint8_t) (this->address_ >> 24) & 0xff,
|
||||
(uint8_t) (this->address_ >> 16) & 0xff, (uint8_t) (this->address_ >> 8) & 0xff,
|
||||
(uint8_t) (this->address_ >> 0) & 0xff);
|
||||
this->address_str_ = str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, (uint8_t)(this->address_ >> 40) & 0xff,
|
||||
(uint8_t)(this->address_ >> 32) & 0xff, (uint8_t)(this->address_ >> 24) & 0xff,
|
||||
(uint8_t)(this->address_ >> 16) & 0xff, (uint8_t)(this->address_ >> 8) & 0xff,
|
||||
(uint8_t)(this->address_ >> 0) & 0xff);
|
||||
}
|
||||
}
|
||||
std::string address_str() const { return this->address_str_; }
|
||||
|
||||
@@ -148,44 +148,44 @@ bool BLECharacteristic::is_failed() {
|
||||
|
||||
void BLECharacteristic::set_broadcast_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_indicate_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_notify_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_read_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_write_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_write_no_response_property(bool value) {
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t) (this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,22 +55,6 @@ FRAME_SIZES = {
|
||||
"SXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1280X1024,
|
||||
"1600X1200": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1600X1200,
|
||||
"UXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1600X1200,
|
||||
"1920X1080": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1920X1080,
|
||||
"FHD": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1920X1080,
|
||||
"720X1280": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_720X1280,
|
||||
"PHD": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_720X1280,
|
||||
"864X1536": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_864X1536,
|
||||
"P3MP": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_864X1536,
|
||||
"2048X1536": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2048X1536,
|
||||
"QXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2048X1536,
|
||||
"2560X1440": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1440,
|
||||
"QHD": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1440,
|
||||
"2560X1600": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1600,
|
||||
"WQXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1600,
|
||||
"1080X1920": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1080X1920,
|
||||
"PFHD": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_1080X1920,
|
||||
"2560X1920": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1920,
|
||||
"QSXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1920,
|
||||
}
|
||||
ESP32GainControlMode = esp32_camera_ns.enum("ESP32GainControlMode")
|
||||
ENUM_GAIN_CONTROL_MODE = {
|
||||
@@ -156,7 +140,7 @@ CONFIG_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(
|
||||
{
|
||||
cv.Required(CONF_PIN): pins.internal_gpio_input_pin_number,
|
||||
cv.Optional(CONF_FREQUENCY, default="20MHz"): cv.All(
|
||||
cv.frequency, cv.Range(min=8e6, max=20e6)
|
||||
cv.frequency, cv.one_of(20e6, 10e6)
|
||||
),
|
||||
}
|
||||
),
|
||||
|
||||
@@ -91,30 +91,6 @@ void ESP32Camera::dump_config() {
|
||||
case FRAMESIZE_UXGA:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 1600x1200 (UXGA)");
|
||||
break;
|
||||
case FRAMESIZE_FHD:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 1920x1080 (FHD)");
|
||||
break;
|
||||
case FRAMESIZE_P_HD:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 720x1280 (P_HD)");
|
||||
break;
|
||||
case FRAMESIZE_P_3MP:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 864x1536 (P_3MP)");
|
||||
break;
|
||||
case FRAMESIZE_QXGA:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 2048x1536 (QXGA)");
|
||||
break;
|
||||
case FRAMESIZE_QHD:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 2560x1440 (QHD)");
|
||||
break;
|
||||
case FRAMESIZE_WQXGA:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 2560x1600 (WQXGA)");
|
||||
break;
|
||||
case FRAMESIZE_P_FHD:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 1080x1920 (P_FHD)");
|
||||
break;
|
||||
case FRAMESIZE_QSXGA:
|
||||
ESP_LOGCONFIG(TAG, " Resolution: 2560x1920 (QSXGA)");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -281,30 +257,6 @@ void ESP32Camera::set_frame_size(ESP32CameraFrameSize size) {
|
||||
case ESP32_CAMERA_SIZE_1600X1200:
|
||||
this->config_.frame_size = FRAMESIZE_UXGA;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_1920X1080:
|
||||
this->config_.frame_size = FRAMESIZE_FHD;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_720X1280:
|
||||
this->config_.frame_size = FRAMESIZE_P_HD;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_864X1536:
|
||||
this->config_.frame_size = FRAMESIZE_P_3MP;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_2048X1536:
|
||||
this->config_.frame_size = FRAMESIZE_QXGA;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_2560X1440:
|
||||
this->config_.frame_size = FRAMESIZE_QHD;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_2560X1600:
|
||||
this->config_.frame_size = FRAMESIZE_WQXGA;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_1080X1920:
|
||||
this->config_.frame_size = FRAMESIZE_P_FHD;
|
||||
break;
|
||||
case ESP32_CAMERA_SIZE_2560X1920:
|
||||
this->config_.frame_size = FRAMESIZE_QSXGA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ESP32Camera::set_jpeg_quality(uint8_t quality) { this->config_.jpeg_quality = quality; }
|
||||
|
||||
@@ -29,14 +29,6 @@ enum ESP32CameraFrameSize {
|
||||
ESP32_CAMERA_SIZE_1024X768, // XGA
|
||||
ESP32_CAMERA_SIZE_1280X1024, // SXGA
|
||||
ESP32_CAMERA_SIZE_1600X1200, // UXGA
|
||||
ESP32_CAMERA_SIZE_1920X1080, // FHD
|
||||
ESP32_CAMERA_SIZE_720X1280, // PHD
|
||||
ESP32_CAMERA_SIZE_864X1536, // P3MP
|
||||
ESP32_CAMERA_SIZE_2048X1536, // QXGA
|
||||
ESP32_CAMERA_SIZE_2560X1440, // QHD
|
||||
ESP32_CAMERA_SIZE_2560X1600, // WQXGA
|
||||
ESP32_CAMERA_SIZE_1080X1920, // PFHD
|
||||
ESP32_CAMERA_SIZE_2560X1920, // QSXGA
|
||||
};
|
||||
|
||||
enum ESP32AgcGainCeiling {
|
||||
|
||||
@@ -22,12 +22,20 @@ ESP32ImprovComponent = esp32_improv_ns.class_(
|
||||
)
|
||||
|
||||
|
||||
def validate_none_(value):
|
||||
if value in ("none", "None"):
|
||||
return None
|
||||
if cv.boolean(value) is False:
|
||||
return None
|
||||
raise cv.Invalid("Must be none")
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ESP32ImprovComponent),
|
||||
cv.GenerateID(CONF_BLE_SERVER_ID): cv.use_id(esp32_ble_server.BLEServer),
|
||||
cv.Required(CONF_AUTHORIZER): cv.Any(
|
||||
cv.none, cv.use_id(binary_sensor.BinarySensor)
|
||||
validate_none_, cv.use_id(binary_sensor.BinarySensor)
|
||||
),
|
||||
cv.Optional(CONF_STATUS_INDICATOR): cv.use_id(output.BinaryOutput),
|
||||
cv.Optional(
|
||||
|
||||
@@ -255,22 +255,14 @@ void EthernetComponent::start_connect_() {
|
||||
if (this->manual_ip_.has_value()) {
|
||||
if (uint32_t(this->manual_ip_->dns1) != 0) {
|
||||
ip_addr_t d;
|
||||
#if LWIP_IPV6
|
||||
d.type = IPADDR_TYPE_V4;
|
||||
d.u_addr.ip4.addr = static_cast<uint32_t>(this->manual_ip_->dns1);
|
||||
#else
|
||||
d.addr = static_cast<uint32_t>(this->manual_ip_->dns1);
|
||||
#endif
|
||||
dns_setserver(0, &d);
|
||||
}
|
||||
if (uint32_t(this->manual_ip_->dns1) != 0) {
|
||||
ip_addr_t d;
|
||||
#if LWIP_IPV6
|
||||
d.type = IPADDR_TYPE_V4;
|
||||
d.u_addr.ip4.addr = static_cast<uint32_t>(this->manual_ip_->dns2);
|
||||
#else
|
||||
d.addr = static_cast<uint32_t>(this->manual_ip_->dns2);
|
||||
#endif
|
||||
dns_setserver(1, &d);
|
||||
}
|
||||
} else {
|
||||
@@ -297,13 +289,8 @@ void EthernetComponent::dump_connect_params_() {
|
||||
const ip_addr_t *dns_ip1 = dns_getserver(0);
|
||||
const ip_addr_t *dns_ip2 = dns_getserver(1);
|
||||
|
||||
#if LWIP_IPV6
|
||||
ESP_LOGCONFIG(TAG, " DNS1: %s", network::IPAddress(dns_ip1->u_addr.ip4.addr).str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->u_addr.ip4.addr).str().c_str());
|
||||
#else
|
||||
ESP_LOGCONFIG(TAG, " DNS1: %s", network::IPAddress(dns_ip1->addr).str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->addr).str().c_str());
|
||||
#endif
|
||||
|
||||
esp_err_t err;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ void FingerprintGrowComponent::scan_and_match_() {
|
||||
}
|
||||
if (this->scan_image_(1) == OK) {
|
||||
this->waiting_removal_ = true;
|
||||
this->data_ = {SEARCH, 0x01, 0x00, 0x00, (uint8_t) (this->capacity_ >> 8), (uint8_t) (this->capacity_ & 0xFF)};
|
||||
this->data_ = {SEARCH, 0x01, 0x00, 0x00, (uint8_t)(this->capacity_ >> 8), (uint8_t)(this->capacity_ & 0xFF)};
|
||||
switch (this->send_command_()) {
|
||||
case OK: {
|
||||
ESP_LOGD(TAG, "Fingerprint matched");
|
||||
@@ -171,7 +171,7 @@ uint8_t FingerprintGrowComponent::save_fingerprint_() {
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Storing model");
|
||||
this->data_ = {STORE, 0x01, (uint8_t) (this->enrollment_slot_ >> 8), (uint8_t) (this->enrollment_slot_ & 0xFF)};
|
||||
this->data_ = {STORE, 0x01, (uint8_t)(this->enrollment_slot_ >> 8), (uint8_t)(this->enrollment_slot_ & 0xFF)};
|
||||
switch (this->send_command_()) {
|
||||
case OK:
|
||||
ESP_LOGI(TAG, "Stored model");
|
||||
@@ -188,8 +188,8 @@ uint8_t FingerprintGrowComponent::save_fingerprint_() {
|
||||
|
||||
bool FingerprintGrowComponent::check_password_() {
|
||||
ESP_LOGD(TAG, "Checking password");
|
||||
this->data_ = {VERIFY_PASSWORD, (uint8_t) (this->password_ >> 24), (uint8_t) (this->password_ >> 16),
|
||||
(uint8_t) (this->password_ >> 8), (uint8_t) (this->password_ & 0xFF)};
|
||||
this->data_ = {VERIFY_PASSWORD, (uint8_t)(this->password_ >> 24), (uint8_t)(this->password_ >> 16),
|
||||
(uint8_t)(this->password_ >> 8), (uint8_t)(this->password_ & 0xFF)};
|
||||
switch (this->send_command_()) {
|
||||
case OK:
|
||||
ESP_LOGD(TAG, "Password verified");
|
||||
@@ -203,8 +203,8 @@ bool FingerprintGrowComponent::check_password_() {
|
||||
|
||||
bool FingerprintGrowComponent::set_password_() {
|
||||
ESP_LOGI(TAG, "Setting new password: %d", this->new_password_);
|
||||
this->data_ = {SET_PASSWORD, (uint8_t) (this->new_password_ >> 24), (uint8_t) (this->new_password_ >> 16),
|
||||
(uint8_t) (this->new_password_ >> 8), (uint8_t) (this->new_password_ & 0xFF)};
|
||||
this->data_ = {SET_PASSWORD, (uint8_t)(this->new_password_ >> 24), (uint8_t)(this->new_password_ >> 16),
|
||||
(uint8_t)(this->new_password_ >> 8), (uint8_t)(this->new_password_ & 0xFF)};
|
||||
if (this->send_command_() == OK) {
|
||||
ESP_LOGI(TAG, "New password successfully set");
|
||||
ESP_LOGI(TAG, "Define the new password in your configuration and reflash now");
|
||||
@@ -250,7 +250,7 @@ void FingerprintGrowComponent::get_fingerprint_count_() {
|
||||
|
||||
void FingerprintGrowComponent::delete_fingerprint(uint16_t finger_id) {
|
||||
ESP_LOGI(TAG, "Deleting fingerprint in slot %d", finger_id);
|
||||
this->data_ = {DELETE, (uint8_t) (finger_id >> 8), (uint8_t) (finger_id & 0xFF), 0x00, 0x01};
|
||||
this->data_ = {DELETE, (uint8_t)(finger_id >> 8), (uint8_t)(finger_id & 0xFF), 0x00, 0x01};
|
||||
switch (this->send_command_()) {
|
||||
case OK:
|
||||
ESP_LOGI(TAG, "Deleted fingerprint");
|
||||
@@ -320,8 +320,8 @@ void FingerprintGrowComponent::aura_led_control(uint8_t state, uint8_t speed, ui
|
||||
}
|
||||
|
||||
uint8_t FingerprintGrowComponent::send_command_() {
|
||||
this->write((uint8_t) (START_CODE >> 8));
|
||||
this->write((uint8_t) (START_CODE & 0xFF));
|
||||
this->write((uint8_t)(START_CODE >> 8));
|
||||
this->write((uint8_t)(START_CODE & 0xFF));
|
||||
this->write(this->address_[0]);
|
||||
this->write(this->address_[1]);
|
||||
this->write(this->address_[2]);
|
||||
@@ -329,8 +329,8 @@ uint8_t FingerprintGrowComponent::send_command_() {
|
||||
this->write(COMMAND);
|
||||
|
||||
uint16_t wire_length = this->data_.size() + 2;
|
||||
this->write((uint8_t) (wire_length >> 8));
|
||||
this->write((uint8_t) (wire_length & 0xFF));
|
||||
this->write((uint8_t)(wire_length >> 8));
|
||||
this->write((uint8_t)(wire_length & 0xFF));
|
||||
|
||||
uint16_t sum = ((wire_length) >> 8) + ((wire_length) &0xFF) + COMMAND;
|
||||
for (auto data : this->data_) {
|
||||
@@ -338,8 +338,8 @@ uint8_t FingerprintGrowComponent::send_command_() {
|
||||
sum += data;
|
||||
}
|
||||
|
||||
this->write((uint8_t) (sum >> 8));
|
||||
this->write((uint8_t) (sum & 0xFF));
|
||||
this->write((uint8_t)(sum >> 8));
|
||||
this->write((uint8_t)(sum & 0xFF));
|
||||
|
||||
this->data_.clear();
|
||||
|
||||
@@ -354,11 +354,11 @@ uint8_t FingerprintGrowComponent::send_command_() {
|
||||
byte = this->read();
|
||||
switch (idx) {
|
||||
case 0:
|
||||
if (byte != (uint8_t) (START_CODE >> 8))
|
||||
if (byte != (uint8_t)(START_CODE >> 8))
|
||||
continue;
|
||||
break;
|
||||
case 1:
|
||||
if (byte != (uint8_t) (START_CODE & 0xFF)) {
|
||||
if (byte != (uint8_t)(START_CODE & 0xFF)) {
|
||||
idx = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -91,10 +91,10 @@ class FingerprintGrowComponent : public PollingComponent, public uart::UARTDevic
|
||||
void dump_config() override;
|
||||
|
||||
void set_address(uint32_t address) {
|
||||
this->address_[0] = (uint8_t) (address >> 24);
|
||||
this->address_[1] = (uint8_t) (address >> 16);
|
||||
this->address_[2] = (uint8_t) (address >> 8);
|
||||
this->address_[3] = (uint8_t) (address & 0xFF);
|
||||
this->address_[0] = (uint8_t)(address >> 24);
|
||||
this->address_[1] = (uint8_t)(address >> 16);
|
||||
this->address_[2] = (uint8_t)(address >> 8);
|
||||
this->address_[3] = (uint8_t)(address & 0xFF);
|
||||
}
|
||||
void set_sensing_pin(GPIOPin *sensing_pin) { this->sensing_pin_ = sensing_pin; }
|
||||
void set_password(uint32_t password) { this->password_ = password; }
|
||||
|
||||
@@ -12,7 +12,7 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con
|
||||
uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits));
|
||||
// Calculate the mask & clear the space for the data.
|
||||
// Clear the destination bits.
|
||||
*dst &= ~(uint8_t) (mask << offset);
|
||||
*dst &= ~(uint8_t)(mask << offset);
|
||||
// Merge in the data.
|
||||
*dst |= ((data & mask) << offset);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con
|
||||
uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits));
|
||||
// Calculate the mask & clear the space for the data.
|
||||
// Clear the destination bits.
|
||||
*dst &= ~(uint8_t) (mask << offset);
|
||||
*dst &= ~(uint8_t)(mask << offset);
|
||||
// Merge in the data.
|
||||
*dst |= ((data & mask) << offset);
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ uint8_t HONEYWELLABPSensor::readsensor_() {
|
||||
// if device is normal and there is new data, bitmask and save the raw data
|
||||
if (status_ == 0) {
|
||||
// 14 - bit pressure is the last 6 bits of byte 0 (high bits) & all of byte 1 (lowest 8 bits)
|
||||
pressure_count_ = ((uint16_t) (buf_[0]) << 8 & 0x3F00) | ((uint16_t) (buf_[1]) & 0xFF);
|
||||
pressure_count_ = ((uint16_t)(buf_[0]) << 8 & 0x3F00) | ((uint16_t)(buf_[1]) & 0xFF);
|
||||
// 11 - bit temperature is all of byte 2 (lowest 8 bits) and the first three bits of byte 3
|
||||
temperature_count_ = (((uint16_t) (buf_[2]) << 3) & 0x7F8) | (((uint16_t) (buf_[3]) >> 5) & 0x7);
|
||||
temperature_count_ = (((uint16_t)(buf_[2]) << 3) & 0x7F8) | (((uint16_t)(buf_[3]) >> 5) & 0x7);
|
||||
ESP_LOGV(TAG, "Sensor pressure_count_ %d", pressure_count_);
|
||||
ESP_LOGV(TAG, "Sensor temperature_count_ %d", temperature_count_);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "ili9xxx_display.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ili9xxx {
|
||||
@@ -85,7 +85,7 @@ void ILI9XXXDisplay::fill(Color color) {
|
||||
case BITS_16:
|
||||
new_color = display::ColorUtil::color_to_565(color);
|
||||
for (uint32_t i = 0; i < this->get_buffer_length_() * 2; i = i + 2) {
|
||||
this->buffer_[i] = (uint8_t) (new_color >> 8);
|
||||
this->buffer_[i] = (uint8_t)(new_color >> 8);
|
||||
this->buffer_[i + 1] = (uint8_t) new_color;
|
||||
}
|
||||
return;
|
||||
@@ -111,8 +111,8 @@ void HOT ILI9XXXDisplay::draw_absolute_pixel_internal(int x, int y, Color color)
|
||||
case BITS_16:
|
||||
pos = pos * 2;
|
||||
new_color = display::ColorUtil::color_to_565(color, display::ColorOrder::COLOR_ORDER_RGB);
|
||||
if (this->buffer_[pos] != (uint8_t) (new_color >> 8)) {
|
||||
this->buffer_[pos] = (uint8_t) (new_color >> 8);
|
||||
if (this->buffer_[pos] != (uint8_t)(new_color >> 8)) {
|
||||
this->buffer_[pos] = (uint8_t)(new_color >> 8);
|
||||
updated = true;
|
||||
}
|
||||
pos = pos + 1;
|
||||
@@ -192,9 +192,9 @@ void ILI9XXXDisplay::display_() {
|
||||
|
||||
uint8_t pass_buff[3];
|
||||
|
||||
pass_buff[2] = (uint8_t) ((red / 32.0) * 64) << 2;
|
||||
pass_buff[2] = (uint8_t)((red / 32.0) * 64) << 2;
|
||||
pass_buff[1] = (uint8_t) green << 2;
|
||||
pass_buff[0] = (uint8_t) ((blue / 32.0) * 64) << 2;
|
||||
pass_buff[0] = (uint8_t)((blue / 32.0) * 64) << 2;
|
||||
|
||||
this->write_array(pass_buff, sizeof(pass_buff));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ void parse_json(const std::string &data, const json_parse_t &f) {
|
||||
const size_t free_heap = rp2040.getFreeHeap();
|
||||
#endif
|
||||
bool pass = false;
|
||||
size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5));
|
||||
size_t request_size = std::min(free_heap, (size_t)(data.size() * 1.5));
|
||||
do {
|
||||
DynamicJsonDocument json_document(request_size);
|
||||
if (json_document.capacity() == 0) {
|
||||
|
||||
@@ -17,7 +17,7 @@ void GPIOLCDDisplay::setup() {
|
||||
this->enable_pin_->setup(); // OUTPUT
|
||||
this->enable_pin_->digital_write(false);
|
||||
|
||||
for (uint8_t i = 0; i < (uint8_t) (this->is_four_bit_mode() ? 4u : 8u); i++) {
|
||||
for (uint8_t i = 0; i < (uint8_t)(this->is_four_bit_mode() ? 4u : 8u); i++) {
|
||||
this->data_pins_[i]->setup(); // OUTPUT
|
||||
this->data_pins_[i]->digital_write(false);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class LD2410Component : public Component, public uart::UARTDevice {
|
||||
#endif
|
||||
|
||||
std::vector<uint8_t> rx_buffer_;
|
||||
int two_byte_to_int_(char firstbyte, char secondbyte) { return (int16_t) (secondbyte << 8) + firstbyte; }
|
||||
int two_byte_to_int_(char firstbyte, char secondbyte) { return (int16_t)(secondbyte << 8) + firstbyte; }
|
||||
void send_command_(uint8_t command_str, uint8_t *command_value, int command_value_len);
|
||||
|
||||
void set_max_distances_timeout_(uint8_t max_moving_distance_range, uint8_t max_still_distance_range,
|
||||
|
||||
@@ -52,26 +52,25 @@ enum class ColorMode : uint8_t {
|
||||
/// Only on/off control.
|
||||
ON_OFF = (uint8_t) ColorCapability::ON_OFF,
|
||||
/// Dimmable light.
|
||||
BRIGHTNESS = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS),
|
||||
BRIGHTNESS = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS),
|
||||
/// White output only (use only if the light also has another color mode such as RGB).
|
||||
WHITE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::WHITE),
|
||||
WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::WHITE),
|
||||
/// Controllable color temperature output.
|
||||
COLOR_TEMPERATURE =
|
||||
(uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLOR_TEMPERATURE),
|
||||
(uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLOR_TEMPERATURE),
|
||||
/// Cold and warm white output with individually controllable brightness.
|
||||
COLD_WARM_WHITE =
|
||||
(uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLD_WARM_WHITE),
|
||||
COLD_WARM_WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::COLD_WARM_WHITE),
|
||||
/// RGB color output.
|
||||
RGB = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB),
|
||||
RGB = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB),
|
||||
/// RGB color output and a separate white output.
|
||||
RGB_WHITE =
|
||||
(uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | ColorCapability::WHITE),
|
||||
(uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB | ColorCapability::WHITE),
|
||||
/// RGB color output and a separate white output with controllable color temperature.
|
||||
RGB_COLOR_TEMPERATURE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB |
|
||||
ColorCapability::WHITE | ColorCapability::COLOR_TEMPERATURE),
|
||||
RGB_COLOR_TEMPERATURE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB |
|
||||
ColorCapability::WHITE | ColorCapability::COLOR_TEMPERATURE),
|
||||
/// RGB color output, and separate cold and warm white outputs.
|
||||
RGB_COLD_WARM_WHITE = (uint8_t) (ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB |
|
||||
ColorCapability::COLD_WARM_WHITE),
|
||||
RGB_COLD_WARM_WHITE = (uint8_t)(ColorCapability::ON_OFF | ColorCapability::BRIGHTNESS | ColorCapability::RGB |
|
||||
ColorCapability::COLD_WARM_WHITE),
|
||||
};
|
||||
|
||||
/// Helper class to allow bitwise operations on ColorMode with ColorCapability
|
||||
|
||||
@@ -113,8 +113,8 @@ void LilygoT547Touchscreen::loop() {
|
||||
if (tp.state == 0x06)
|
||||
tp.state = 0x07;
|
||||
|
||||
uint16_t y = (uint16_t) ((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F));
|
||||
uint16_t x = (uint16_t) ((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F));
|
||||
uint16_t y = (uint16_t)((buffer[i * 5 + 1 + offset] << 4) | ((buffer[i * 5 + 3 + offset] >> 4) & 0x0F));
|
||||
uint16_t x = (uint16_t)((buffer[i * 5 + 2 + offset] << 4) | (buffer[i * 5 + 3 + offset] & 0x0F));
|
||||
|
||||
switch (this->rotation_) {
|
||||
case ROTATE_0_DEGREES:
|
||||
@@ -142,8 +142,8 @@ void LilygoT547Touchscreen::loop() {
|
||||
tp.id = (buffer[0] >> 4) & 0x0F;
|
||||
tp.state = 0x06;
|
||||
|
||||
uint16_t y = (uint16_t) ((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F));
|
||||
uint16_t x = (uint16_t) ((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F));
|
||||
uint16_t y = (uint16_t)((buffer[0 * 5 + 1] << 4) | ((buffer[0 * 5 + 3] >> 4) & 0x0F));
|
||||
uint16_t x = (uint16_t)((buffer[0 * 5 + 2] << 4) | (buffer[0 * 5 + 3] & 0x0F));
|
||||
|
||||
switch (this->rotation_) {
|
||||
case ROTATE_0_DEGREES:
|
||||
|
||||
@@ -7,7 +7,6 @@ CODEOWNERS = ["@rspaargaren"]
|
||||
DEPENDENCIES = ["spi"]
|
||||
|
||||
CONF_ROTATE_CHIP = "rotate_chip"
|
||||
CONF_FLIP_X = "flip_x"
|
||||
CONF_SCROLL_SPEED = "scroll_speed"
|
||||
CONF_SCROLL_DWELL = "scroll_dwell"
|
||||
CONF_SCROLL_DELAY = "scroll_delay"
|
||||
@@ -68,7 +67,6 @@ CONFIG_SCHEMA = (
|
||||
CONF_SCROLL_DWELL, default="1000ms"
|
||||
): cv.positive_time_period_milliseconds,
|
||||
cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean,
|
||||
cv.Optional(CONF_FLIP_X, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("500ms"))
|
||||
@@ -93,7 +91,6 @@ async def to_code(config):
|
||||
cg.add(var.set_scroll(config[CONF_SCROLL_ENABLE]))
|
||||
cg.add(var.set_scroll_mode(config[CONF_SCROLL_MODE]))
|
||||
cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE]))
|
||||
cg.add(var.set_flip_x([CONF_FLIP_X]))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = await cg.process_lambda(
|
||||
|
||||
@@ -261,21 +261,13 @@ void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) {
|
||||
if (this->orientation_ == 0) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
// run this loop 8 times for all the pixels[8] received
|
||||
if (this->flip_x_) {
|
||||
b |= ((pixels[i] >> col) & 1) << i; // change the column bits into row bits
|
||||
} else {
|
||||
b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits
|
||||
}
|
||||
b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits
|
||||
}
|
||||
} else if (this->orientation_ == 1) {
|
||||
b = pixels[col];
|
||||
} else if (this->orientation_ == 2) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
if (this->flip_x_) {
|
||||
b |= ((pixels[i] >> (7 - col)) & 1) << (7 - i);
|
||||
} else {
|
||||
b |= ((pixels[i] >> (7 - col)) & 1) << i;
|
||||
}
|
||||
b |= ((pixels[i] >> (7 - col)) & 1) << i;
|
||||
}
|
||||
} else {
|
||||
b = pixels[7 - col];
|
||||
|
||||
@@ -67,7 +67,6 @@ class MAX7219Component : public PollingComponent,
|
||||
void set_scroll(bool on_off) { this->scroll_ = on_off; };
|
||||
void set_scroll_mode(ScrollMode mode) { this->scroll_mode_ = mode; };
|
||||
void set_reverse(bool on_off) { this->reverse_ = on_off; };
|
||||
void set_flip_x(bool flip_x) { this->flip_x_ = flip_x; };
|
||||
|
||||
void send_char(uint8_t chip, uint8_t data);
|
||||
void send64pixels(uint8_t chip, const uint8_t pixels[8]);
|
||||
@@ -109,7 +108,6 @@ class MAX7219Component : public PollingComponent,
|
||||
ChipLinesStyle chip_lines_style_;
|
||||
bool scroll_;
|
||||
bool reverse_;
|
||||
bool flip_x_;
|
||||
bool update_{false};
|
||||
uint16_t scroll_speed_;
|
||||
uint16_t scroll_delay_;
|
||||
|
||||
@@ -148,19 +148,19 @@ canbus::Error MCP2515::set_clk_out_(const CanClkOut divisor) {
|
||||
}
|
||||
|
||||
void MCP2515::prepare_id_(uint8_t *buffer, const bool extended, const uint32_t id) {
|
||||
uint16_t canid = (uint16_t) (id & 0x0FFFF);
|
||||
uint16_t canid = (uint16_t)(id & 0x0FFFF);
|
||||
|
||||
if (extended) {
|
||||
buffer[MCP_EID0] = (uint8_t) (canid & 0xFF);
|
||||
buffer[MCP_EID8] = (uint8_t) (canid >> 8);
|
||||
canid = (uint16_t) (id >> 16);
|
||||
buffer[MCP_SIDL] = (uint8_t) (canid & 0x03);
|
||||
buffer[MCP_SIDL] += (uint8_t) ((canid & 0x1C) << 3);
|
||||
buffer[MCP_EID0] = (uint8_t)(canid & 0xFF);
|
||||
buffer[MCP_EID8] = (uint8_t)(canid >> 8);
|
||||
canid = (uint16_t)(id >> 16);
|
||||
buffer[MCP_SIDL] = (uint8_t)(canid & 0x03);
|
||||
buffer[MCP_SIDL] += (uint8_t)((canid & 0x1C) << 3);
|
||||
buffer[MCP_SIDL] |= TXB_EXIDE_MASK;
|
||||
buffer[MCP_SIDH] = (uint8_t) (canid >> 5);
|
||||
buffer[MCP_SIDH] = (uint8_t)(canid >> 5);
|
||||
} else {
|
||||
buffer[MCP_SIDH] = (uint8_t) (canid >> 3);
|
||||
buffer[MCP_SIDL] = (uint8_t) ((canid & 0x07) << 5);
|
||||
buffer[MCP_SIDH] = (uint8_t)(canid >> 3);
|
||||
buffer[MCP_SIDL] = (uint8_t)((canid & 0x07) << 5);
|
||||
buffer[MCP_EID0] = 0;
|
||||
buffer[MCP_EID8] = 0;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void MCP9600Component::setup() {
|
||||
|
||||
uint16_t dev_id = 0;
|
||||
this->read_byte_16(MCP9600_REGISTER_DEVICE_ID, &dev_id);
|
||||
this->device_id_ = (uint8_t) (dev_id >> 8);
|
||||
this->device_id_ = (uint8_t)(dev_id >> 8);
|
||||
|
||||
// Allows both MCP9600's and MCP9601's to be connected.
|
||||
if (this->device_id_ != (uint8_t) 0x40 && this->device_id_ != (uint8_t) 0x41) {
|
||||
|
||||
@@ -54,16 +54,16 @@ void MCP9808Sensor::update() {
|
||||
}
|
||||
|
||||
float temp = NAN;
|
||||
uint8_t msb = (uint8_t) ((raw_temp & 0xff00) >> 8);
|
||||
uint8_t msb = (uint8_t)((raw_temp & 0xff00) >> 8);
|
||||
uint8_t lsb = raw_temp & 0x00ff;
|
||||
|
||||
msb = msb & MCP9808_AMBIENT_CLEAR_FLAGS;
|
||||
|
||||
if ((msb & MCP9808_AMBIENT_TEMP_NEGATIVE) == MCP9808_AMBIENT_TEMP_NEGATIVE) {
|
||||
msb = msb & MCP9808_AMBIENT_CLEAR_SIGN;
|
||||
temp = (256 - ((uint16_t) (msb) *16 + lsb / 16.0f)) * -1;
|
||||
temp = (256 - ((uint16_t)(msb) *16 + lsb / 16.0f)) * -1;
|
||||
} else {
|
||||
temp = (uint16_t) (msb) *16 + lsb / 16.0f;
|
||||
temp = (uint16_t)(msb) *16 + lsb / 16.0f;
|
||||
}
|
||||
|
||||
if (std::isnan(temp)) {
|
||||
|
||||
@@ -64,10 +64,9 @@ INTEGER_SENSOR_VALUE_TYPE = {
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
select.select_schema(ModbusSelect)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(
|
||||
select.SELECT_SCHEMA.extend(cv.COMPONENT_SCHEMA).extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ModbusSelect),
|
||||
cv.GenerateID(CONF_MODBUS_CONTROLLER_ID): cv.use_id(ModbusController),
|
||||
cv.Required(CONF_ADDRESS): cv.positive_int,
|
||||
cv.Optional(CONF_VALUE_TYPE, default="U_WORD"): cv.enum(
|
||||
|
||||
@@ -123,8 +123,7 @@ uint32_t MopekaProCheck::parse_distance_(const std::vector<uint8_t> &message) {
|
||||
double raw_level = raw & 0x3FFF;
|
||||
double raw_t = (message[2] & 0x7F);
|
||||
|
||||
return (uint32_t) (raw_level *
|
||||
(MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t));
|
||||
return (uint32_t)(raw_level * (MOPEKA_LPG_COEF[0] + MOPEKA_LPG_COEF[1] * raw_t + MOPEKA_LPG_COEF[2] * raw_t * raw_t));
|
||||
}
|
||||
|
||||
uint8_t MopekaProCheck::parse_temperature_(const std::vector<uint8_t> &message) { return (message[2] & 0x7F) - 40; }
|
||||
|
||||
@@ -216,7 +216,7 @@ uint8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) {
|
||||
if (tmp == 0x0) {
|
||||
return -40;
|
||||
} else {
|
||||
return (uint8_t) ((tmp - 25.0f) * 1.776964f);
|
||||
return (uint8_t)((tmp - 25.0f) * 1.776964f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
#ifdef USE_MQTT
|
||||
|
||||
#include <utility>
|
||||
#include "esphome/components/network/util.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
#include <utility>
|
||||
#ifdef USE_LOGGER
|
||||
#include "esphome/components/logger/logger.h"
|
||||
#endif
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "mqtt_component.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -104,11 +104,7 @@ void MQTTClientComponent::start_dnslookup_() {
|
||||
// Got IP immediately
|
||||
this->dns_resolved_ = true;
|
||||
#ifdef USE_ESP32
|
||||
#if LWIP_IPV6
|
||||
this->ip_ = addr.u_addr.ip4.addr;
|
||||
#else
|
||||
this->ip_ = addr.addr;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef USE_ESP8266
|
||||
this->ip_ = addr.addr;
|
||||
@@ -164,12 +160,8 @@ void MQTTClientComponent::dns_found_callback(const char *name, const ip_addr_t *
|
||||
a_this->dns_resolve_error_ = true;
|
||||
} else {
|
||||
#ifdef USE_ESP32
|
||||
#if LWIP_IPV6
|
||||
a_this->ip_ = ipaddr->u_addr.ip4.addr;
|
||||
#else
|
||||
a_this->ip_ = ipaddr->addr;
|
||||
#endif
|
||||
#endif // USE_ESP32
|
||||
#ifdef USE_ESP8266
|
||||
a_this->ip_ = ipaddr->addr;
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
if CONF_ENABLE_IPV6 in config:
|
||||
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", config[CONF_ENABLE_IPV6])
|
||||
add_idf_sdkconfig_option(
|
||||
"CONFIG_LWIP_IPV6_AUTOCONFIG", config[CONF_ENABLE_IPV6]
|
||||
)
|
||||
if CONF_ENABLE_IPV6 in config and config[CONF_ENABLE_IPV6]:
|
||||
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", True)
|
||||
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6_AUTOCONFIG", True)
|
||||
|
||||
@@ -12,10 +12,10 @@ struct IPAddress {
|
||||
IPAddress() : addr_({0, 0, 0, 0}) {}
|
||||
IPAddress(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth) : addr_({first, second, third, fourth}) {}
|
||||
IPAddress(uint32_t raw) {
|
||||
addr_[0] = (uint8_t) (raw >> 0);
|
||||
addr_[1] = (uint8_t) (raw >> 8);
|
||||
addr_[2] = (uint8_t) (raw >> 16);
|
||||
addr_[3] = (uint8_t) (raw >> 24);
|
||||
addr_[0] = (uint8_t)(raw >> 0);
|
||||
addr_[1] = (uint8_t)(raw >> 8);
|
||||
addr_[2] = (uint8_t)(raw >> 16);
|
||||
addr_[3] = (uint8_t)(raw >> 24);
|
||||
}
|
||||
operator uint32_t() const {
|
||||
uint32_t res = 0;
|
||||
|
||||
@@ -204,13 +204,14 @@ def number_schema(
|
||||
|
||||
|
||||
async def setup_number_core_(
|
||||
var, config, *, min_value: float, max_value: float, step: float
|
||||
var, config, *, min_value: float, max_value: float, step: Optional[float]
|
||||
):
|
||||
await setup_entity(var, config)
|
||||
|
||||
cg.add(var.traits.set_min_value(min_value))
|
||||
cg.add(var.traits.set_max_value(max_value))
|
||||
cg.add(var.traits.set_step(step))
|
||||
if step is not None:
|
||||
cg.add(var.traits.set_step(step))
|
||||
|
||||
cg.add(var.traits.set_mode(config[CONF_MODE]))
|
||||
|
||||
@@ -238,7 +239,7 @@ async def setup_number_core_(
|
||||
|
||||
|
||||
async def register_number(
|
||||
var, config, *, min_value: float, max_value: float, step: float
|
||||
var, config, *, min_value: float, max_value: float, step: Optional[float] = None
|
||||
):
|
||||
if not CORE.has_id(config[CONF_ID]):
|
||||
var = cg.Pvariable(config[CONF_ID], var)
|
||||
|
||||
@@ -65,7 +65,7 @@ void OTAComponent::setup() {
|
||||
|
||||
struct sockaddr_storage server;
|
||||
|
||||
socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), this->port_);
|
||||
socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), htons(this->port_));
|
||||
if (sl == 0) {
|
||||
ESP_LOGW(TAG, "Socket unable to set sockaddr: errno %d", errno);
|
||||
this->mark_failed();
|
||||
|
||||
@@ -770,15 +770,15 @@ uint8_t Pipsolar::check_incoming_crc_() {
|
||||
uint16_t crc16;
|
||||
crc16 = cal_crc_half_(read_buffer_, read_pos_ - 3);
|
||||
ESP_LOGD(TAG, "checking crc on incoming message");
|
||||
if (((uint8_t) ((crc16) >> 8)) == read_buffer_[read_pos_ - 3] &&
|
||||
((uint8_t) ((crc16) &0xff)) == read_buffer_[read_pos_ - 2]) {
|
||||
if (((uint8_t)((crc16) >> 8)) == read_buffer_[read_pos_ - 3] &&
|
||||
((uint8_t)((crc16) &0xff)) == read_buffer_[read_pos_ - 2]) {
|
||||
ESP_LOGD(TAG, "CRC OK");
|
||||
read_buffer_[read_pos_ - 1] = 0;
|
||||
read_buffer_[read_pos_ - 2] = 0;
|
||||
read_buffer_[read_pos_ - 3] = 0;
|
||||
return 1;
|
||||
}
|
||||
ESP_LOGD(TAG, "CRC NOK expected: %X %X but got: %X %X", ((uint8_t) ((crc16) >> 8)), ((uint8_t) ((crc16) &0xff)),
|
||||
ESP_LOGD(TAG, "CRC NOK expected: %X %X but got: %X %X", ((uint8_t)((crc16) >> 8)), ((uint8_t)((crc16) &0xff)),
|
||||
read_buffer_[read_pos_ - 3], read_buffer_[read_pos_ - 2]);
|
||||
return 0;
|
||||
}
|
||||
@@ -800,8 +800,8 @@ uint8_t Pipsolar::send_next_command_() {
|
||||
crc16 = cal_crc_half_(byte_command, length);
|
||||
this->write_str(command);
|
||||
// checksum
|
||||
this->write(((uint8_t) ((crc16) >> 8))); // highbyte
|
||||
this->write(((uint8_t) ((crc16) &0xff))); // lowbyte
|
||||
this->write(((uint8_t)((crc16) >> 8))); // highbyte
|
||||
this->write(((uint8_t)((crc16) &0xff))); // lowbyte
|
||||
// end Byte
|
||||
this->write(0x0D);
|
||||
ESP_LOGD(TAG, "Sending command from queue: %s with length %d", command, length);
|
||||
@@ -829,8 +829,8 @@ void Pipsolar::send_next_poll_() {
|
||||
this->write_array(this->used_polling_commands_[this->last_polling_command_].command,
|
||||
this->used_polling_commands_[this->last_polling_command_].length);
|
||||
// checksum
|
||||
this->write(((uint8_t) ((crc16) >> 8))); // highbyte
|
||||
this->write(((uint8_t) ((crc16) &0xff))); // lowbyte
|
||||
this->write(((uint8_t)((crc16) >> 8))); // highbyte
|
||||
this->write(((uint8_t)((crc16) &0xff))); // lowbyte
|
||||
// end Byte
|
||||
this->write(0x0D);
|
||||
ESP_LOGD(TAG, "Sending polling command : %s with length %d",
|
||||
@@ -882,7 +882,7 @@ void Pipsolar::add_polling_command_(const char *command, ENUMPollingCommand poll
|
||||
used_polling_command.command = new uint8_t[length]; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
size_t i = 0;
|
||||
for (; beg != end; ++beg, ++i) {
|
||||
used_polling_command.command[i] = (uint8_t) (*beg);
|
||||
used_polling_command.command[i] = (uint8_t)(*beg);
|
||||
}
|
||||
used_polling_command.errors = 0;
|
||||
used_polling_command.identifier = polling_command;
|
||||
@@ -907,17 +907,17 @@ uint16_t Pipsolar::cal_crc_half_(uint8_t *msg, uint8_t len) {
|
||||
crc = 0;
|
||||
|
||||
while (len-- != 0) {
|
||||
da = ((uint8_t) (crc >> 8)) >> 4;
|
||||
da = ((uint8_t)(crc >> 8)) >> 4;
|
||||
crc <<= 4;
|
||||
crc ^= crc_ta[da ^ (*ptr >> 4)];
|
||||
da = ((uint8_t) (crc >> 8)) >> 4;
|
||||
da = ((uint8_t)(crc >> 8)) >> 4;
|
||||
crc <<= 4;
|
||||
crc ^= crc_ta[da ^ (*ptr & 0x0f)];
|
||||
ptr++;
|
||||
}
|
||||
|
||||
b_crc_low = crc;
|
||||
b_crc_hign = (uint8_t) (crc >> 8);
|
||||
b_crc_hign = (uint8_t)(crc >> 8);
|
||||
|
||||
if (b_crc_low == 0x28 || b_crc_low == 0x0d || b_crc_low == 0x0a)
|
||||
b_crc_low++;
|
||||
|
||||
@@ -264,52 +264,13 @@ void PMSX003Component::parse_data_() {
|
||||
break;
|
||||
}
|
||||
case PMSX003_TYPE_5003T: {
|
||||
uint16_t pm_1_0_std_concentration = this->get_16_bit_uint_(4);
|
||||
uint16_t pm_2_5_std_concentration = this->get_16_bit_uint_(6);
|
||||
uint16_t pm_10_0_std_concentration = this->get_16_bit_uint_(8);
|
||||
|
||||
uint16_t pm_1_0_concentration = this->get_16_bit_uint_(10);
|
||||
uint16_t pm_2_5_concentration = this->get_16_bit_uint_(12);
|
||||
uint16_t pm_10_0_concentration = this->get_16_bit_uint_(14);
|
||||
|
||||
uint16_t pm_particles_03um = this->get_16_bit_uint_(16);
|
||||
uint16_t pm_particles_05um = this->get_16_bit_uint_(18);
|
||||
uint16_t pm_particles_10um = this->get_16_bit_uint_(20);
|
||||
uint16_t pm_particles_25um = this->get_16_bit_uint_(22);
|
||||
// Note the pm particles 50um & 100um are not returned,
|
||||
// as PMS5003T uses those data values for temperature and humidity.
|
||||
|
||||
float temperature = this->get_16_bit_uint_(24) / 10.0f;
|
||||
float humidity = this->get_16_bit_uint_(26) / 10.0f;
|
||||
|
||||
ESP_LOGD(TAG,
|
||||
"Got PM1.0 Concentration: %u µg/m^3, PM2.5 Concentration %u µg/m^3, PM10.0 Concentration: %u µg/m^3, "
|
||||
"Temperature: %.1f°C, Humidity: %.1f%%",
|
||||
pm_1_0_concentration, pm_2_5_concentration, pm_10_0_concentration, temperature, humidity);
|
||||
|
||||
if (this->pm_1_0_std_sensor_ != nullptr)
|
||||
this->pm_1_0_std_sensor_->publish_state(pm_1_0_std_concentration);
|
||||
if (this->pm_2_5_std_sensor_ != nullptr)
|
||||
this->pm_2_5_std_sensor_->publish_state(pm_2_5_std_concentration);
|
||||
if (this->pm_10_0_std_sensor_ != nullptr)
|
||||
this->pm_10_0_std_sensor_->publish_state(pm_10_0_std_concentration);
|
||||
|
||||
if (this->pm_1_0_sensor_ != nullptr)
|
||||
this->pm_1_0_sensor_->publish_state(pm_1_0_concentration);
|
||||
ESP_LOGD(TAG, "Got PM2.5 Concentration: %u µg/m^3, Temperature: %.1f°C, Humidity: %.1f%%", pm_2_5_concentration,
|
||||
temperature, humidity);
|
||||
if (this->pm_2_5_sensor_ != nullptr)
|
||||
this->pm_2_5_sensor_->publish_state(pm_2_5_concentration);
|
||||
if (this->pm_10_0_sensor_ != nullptr)
|
||||
this->pm_10_0_sensor_->publish_state(pm_10_0_concentration);
|
||||
|
||||
if (this->pm_particles_03um_sensor_ != nullptr)
|
||||
this->pm_particles_03um_sensor_->publish_state(pm_particles_03um);
|
||||
if (this->pm_particles_05um_sensor_ != nullptr)
|
||||
this->pm_particles_05um_sensor_->publish_state(pm_particles_05um);
|
||||
if (this->pm_particles_10um_sensor_ != nullptr)
|
||||
this->pm_particles_10um_sensor_->publish_state(pm_particles_10um);
|
||||
if (this->pm_particles_25um_sensor_ != nullptr)
|
||||
this->pm_particles_25um_sensor_->publish_state(pm_particles_25um);
|
||||
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(temperature);
|
||||
if (this->humidity_sensor_ != nullptr)
|
||||
|
||||
@@ -55,9 +55,9 @@ PMSX003_TYPES = {
|
||||
}
|
||||
|
||||
SENSORS_TO_TYPE = {
|
||||
CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
CONF_PM_2_5: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
CONF_TEMPERATURE: [TYPE_PMS5003T, TYPE_PMS5003ST],
|
||||
CONF_HUMIDITY: [TYPE_PMS5003T, TYPE_PMS5003ST],
|
||||
CONF_FORMALDEHYDE: [TYPE_PMS5003ST, TYPE_PMS5003S],
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/modbus/modbus.h"
|
||||
|
||||
@@ -121,38 +121,38 @@ bool QMP6988Component::get_calibration_data_() {
|
||||
}
|
||||
|
||||
qmp6988_data_.qmp6988_cali.COE_a0 =
|
||||
(QMP6988_S32_t) (((a_data_uint8_tr[18] << SHIFT_LEFT_12_POSITION) |
|
||||
(a_data_uint8_tr[19] << SHIFT_LEFT_4_POSITION) | (a_data_uint8_tr[24] & 0x0f))
|
||||
<< 12);
|
||||
(QMP6988_S32_t)(((a_data_uint8_tr[18] << SHIFT_LEFT_12_POSITION) |
|
||||
(a_data_uint8_tr[19] << SHIFT_LEFT_4_POSITION) | (a_data_uint8_tr[24] & 0x0f))
|
||||
<< 12);
|
||||
qmp6988_data_.qmp6988_cali.COE_a0 = qmp6988_data_.qmp6988_cali.COE_a0 >> 12;
|
||||
|
||||
qmp6988_data_.qmp6988_cali.COE_a1 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[20]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[21]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[20]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[21]);
|
||||
qmp6988_data_.qmp6988_cali.COE_a2 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[22]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[23]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[22]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[23]);
|
||||
|
||||
qmp6988_data_.qmp6988_cali.COE_b00 =
|
||||
(QMP6988_S32_t) (((a_data_uint8_tr[0] << SHIFT_LEFT_12_POSITION) | (a_data_uint8_tr[1] << SHIFT_LEFT_4_POSITION) |
|
||||
((a_data_uint8_tr[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION))
|
||||
<< 12);
|
||||
(QMP6988_S32_t)(((a_data_uint8_tr[0] << SHIFT_LEFT_12_POSITION) | (a_data_uint8_tr[1] << SHIFT_LEFT_4_POSITION) |
|
||||
((a_data_uint8_tr[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION))
|
||||
<< 12);
|
||||
qmp6988_data_.qmp6988_cali.COE_b00 = qmp6988_data_.qmp6988_cali.COE_b00 >> 12;
|
||||
|
||||
qmp6988_data_.qmp6988_cali.COE_bt1 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[2]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[3]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[2]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[3]);
|
||||
qmp6988_data_.qmp6988_cali.COE_bt2 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[4]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[5]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[4]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[5]);
|
||||
qmp6988_data_.qmp6988_cali.COE_bp1 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[6]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[7]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[6]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[7]);
|
||||
qmp6988_data_.qmp6988_cali.COE_b11 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[8]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[9]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[8]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[9]);
|
||||
qmp6988_data_.qmp6988_cali.COE_bp2 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[10]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[11]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[10]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[11]);
|
||||
qmp6988_data_.qmp6988_cali.COE_b12 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[12]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[13]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[12]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[13]);
|
||||
qmp6988_data_.qmp6988_cali.COE_b21 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[14]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[15]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[14]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[15]);
|
||||
qmp6988_data_.qmp6988_cali.COE_bp3 =
|
||||
(QMP6988_S16_t) (((a_data_uint8_tr[16]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[17]);
|
||||
(QMP6988_S16_t)(((a_data_uint8_tr[16]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[17]);
|
||||
|
||||
ESP_LOGV(TAG, "<-----------calibration data-------------->\r\n");
|
||||
ESP_LOGV(TAG, "COE_a0[%d] COE_a1[%d] COE_a2[%d] COE_b00[%d]\r\n", qmp6988_data_.qmp6988_cali.COE_a0,
|
||||
@@ -197,7 +197,7 @@ QMP6988_S16_t QMP6988Component::get_compensated_temperature_(qmp6988_ik_data_t *
|
||||
wk2 = ((QMP6988_S64_t) ik->a2 * (QMP6988_S64_t) dt) >> 14; // 30Q47+24-1=53 (39Q33)
|
||||
wk2 = (wk2 * (QMP6988_S64_t) dt) >> 10; // 39Q33+24-1=62 (52Q23)
|
||||
wk2 = ((wk1 + wk2) / 32767) >> 19; // 54,52->55Q23 (20Q04)
|
||||
ret = (QMP6988_S16_t) ((ik->a0 + wk2) >> 4); // 21Q4 -> 17Q0
|
||||
ret = (QMP6988_S16_t)((ik->a0 + wk2) >> 4); // 21Q4 -> 17Q0
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -332,13 +332,13 @@ void QMP6988Component::calculate_pressure_() {
|
||||
ESP_LOGE(TAG, "Error reading raw pressure/temp values");
|
||||
return;
|
||||
}
|
||||
p_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[0])) << SHIFT_LEFT_16_POSITION) |
|
||||
(((QMP6988_U16_t) (a_data_uint8_tr[1])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[2]));
|
||||
p_raw = (QMP6988_S32_t) (p_read - SUBTRACTOR);
|
||||
p_read = (QMP6988_U32_t)((((QMP6988_U32_t)(a_data_uint8_tr[0])) << SHIFT_LEFT_16_POSITION) |
|
||||
(((QMP6988_U16_t)(a_data_uint8_tr[1])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[2]));
|
||||
p_raw = (QMP6988_S32_t)(p_read - SUBTRACTOR);
|
||||
|
||||
t_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[3])) << SHIFT_LEFT_16_POSITION) |
|
||||
(((QMP6988_U16_t) (a_data_uint8_tr[4])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[5]));
|
||||
t_raw = (QMP6988_S32_t) (t_read - SUBTRACTOR);
|
||||
t_read = (QMP6988_U32_t)((((QMP6988_U32_t)(a_data_uint8_tr[3])) << SHIFT_LEFT_16_POSITION) |
|
||||
(((QMP6988_U16_t)(a_data_uint8_tr[4])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[5]));
|
||||
t_raw = (QMP6988_S32_t)(t_read - SUBTRACTOR);
|
||||
|
||||
t_int = this->get_compensated_temperature_(&(qmp6988_data_.ik), t_raw);
|
||||
p_int = this->get_compensated_pressure_(&(qmp6988_data_.ik), p_raw, t_int);
|
||||
|
||||
@@ -78,7 +78,7 @@ optional<RC5Data> RC5Protocol::decode(RemoteReceiveData src) {
|
||||
out_data |= 1;
|
||||
}
|
||||
|
||||
out.command = (uint8_t) (out_data & 0x3F) + (1 - field_bit) * 64u;
|
||||
out.command = (uint8_t)(out_data & 0x3F) + (1 - field_bit) * 64u;
|
||||
out.address = (out_data >> 6) & 0x1F;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ from esphome.const import (
|
||||
CONF_TOLERANCE,
|
||||
CONF_MEMORY_BLOCKS,
|
||||
)
|
||||
from esphome.core import CORE, TimePeriod
|
||||
from esphome.core import CORE
|
||||
|
||||
AUTO_LOAD = ["remote_base"]
|
||||
remote_receiver_ns = cg.esphome_ns.namespace("remote_receiver")
|
||||
@@ -33,10 +33,9 @@ CONFIG_SCHEMA = remote_base.validate_triggers(
|
||||
cv.SplitDefault(
|
||||
CONF_BUFFER_SIZE, esp32="10000b", esp8266="1000b"
|
||||
): cv.validate_bytes,
|
||||
cv.Optional(CONF_FILTER, default="50us"): cv.All(
|
||||
cv.positive_time_period_microseconds,
|
||||
cv.Range(max=TimePeriod(microseconds=255)),
|
||||
),
|
||||
cv.Optional(
|
||||
CONF_FILTER, default="50us"
|
||||
): cv.positive_time_period_microseconds,
|
||||
cv.Optional(
|
||||
CONF_IDLE, default="10ms"
|
||||
): cv.positive_time_period_microseconds,
|
||||
|
||||
@@ -43,7 +43,7 @@ void SCD30Component::setup() {
|
||||
uint16_t(raw_firmware_version[0] & 0xFF));
|
||||
|
||||
if (this->temperature_offset_ != 0) {
|
||||
if (!this->write_command(SCD30_CMD_TEMPERATURE_OFFSET, (uint16_t) (temperature_offset_ * 100.0))) {
|
||||
if (!this->write_command(SCD30_CMD_TEMPERATURE_OFFSET, (uint16_t)(temperature_offset_ * 100.0))) {
|
||||
ESP_LOGE(TAG, "Sensor SCD30 error setting temperature offset.");
|
||||
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
||||
this->mark_failed();
|
||||
|
||||
@@ -16,7 +16,7 @@ class SCD30Component : public Component, public sensirion_common::SensirionI2CDe
|
||||
void set_automatic_self_calibration(bool asc) { enable_asc_ = asc; }
|
||||
void set_altitude_compensation(uint16_t altitude) { altitude_compensation_ = altitude; }
|
||||
void set_ambient_pressure_compensation(float pressure) {
|
||||
ambient_pressure_compensation_ = (uint16_t) (pressure * 1000);
|
||||
ambient_pressure_compensation_ = (uint16_t)(pressure * 1000);
|
||||
}
|
||||
void set_temperature_offset(float offset) { temperature_offset_ = offset; }
|
||||
void set_update_interval(uint16_t interval) { update_interval_ = interval; }
|
||||
|
||||
@@ -50,7 +50,7 @@ void SCD4XComponent::setup() {
|
||||
uint16_t(raw_serial_number[0] & 0xFF), (uint16_t(raw_serial_number[1]) >> 8));
|
||||
|
||||
if (!this->write_command(SCD4X_CMD_TEMPERATURE_OFFSET,
|
||||
(uint16_t) (temperature_offset_ * SCD4X_TEMPERATURE_OFFSET_MULTIPLIER))) {
|
||||
(uint16_t)(temperature_offset_ * SCD4X_TEMPERATURE_OFFSET_MULTIPLIER))) {
|
||||
ESP_LOGE(TAG, "Error setting temperature offset.");
|
||||
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
||||
this->mark_failed();
|
||||
|
||||
@@ -3,8 +3,6 @@ import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.components import mqtt
|
||||
from esphome.const import (
|
||||
CONF_ENTITY_CATEGORY,
|
||||
CONF_ICON,
|
||||
CONF_ID,
|
||||
CONF_ON_VALUE,
|
||||
CONF_OPTION,
|
||||
@@ -16,7 +14,6 @@ from esphome.const import (
|
||||
CONF_INDEX,
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
from esphome.cpp_generator import MockObjClass
|
||||
from esphome.cpp_helpers import setup_entity
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
@@ -46,6 +43,8 @@ SELECT_OPERATION_OPTIONS = {
|
||||
"LAST": SelectOperation.SELECT_OP_LAST,
|
||||
}
|
||||
|
||||
icon = cv.icon
|
||||
|
||||
|
||||
SELECT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend(
|
||||
{
|
||||
@@ -59,30 +58,6 @@ SELECT_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).e
|
||||
}
|
||||
)
|
||||
|
||||
_UNDEF = object()
|
||||
|
||||
|
||||
def select_schema(
|
||||
class_: MockObjClass = _UNDEF,
|
||||
*,
|
||||
entity_category: str = _UNDEF,
|
||||
icon: str = _UNDEF,
|
||||
):
|
||||
schema = cv.Schema({})
|
||||
if class_ is not _UNDEF:
|
||||
schema = schema.extend({cv.GenerateID(): cv.declare_id(class_)})
|
||||
if entity_category is not _UNDEF:
|
||||
schema = schema.extend(
|
||||
{
|
||||
cv.Optional(
|
||||
CONF_ENTITY_CATEGORY, default=entity_category
|
||||
): cv.entity_category
|
||||
}
|
||||
)
|
||||
if icon is not _UNDEF:
|
||||
schema = schema.extend({cv.Optional(CONF_ICON, default=icon): cv.icon})
|
||||
return SELECT_SCHEMA.extend(schema)
|
||||
|
||||
|
||||
async def setup_select_core_(var, config, *, options: list[str]):
|
||||
await setup_entity(var, config)
|
||||
|
||||
@@ -194,7 +194,6 @@ SensorPublishAction = sensor_ns.class_("SensorPublishAction", automation.Action)
|
||||
Filter = sensor_ns.class_("Filter")
|
||||
QuantileFilter = sensor_ns.class_("QuantileFilter", Filter)
|
||||
MedianFilter = sensor_ns.class_("MedianFilter", Filter)
|
||||
SkipInitialFilter = sensor_ns.class_("SkipInitialFilter", Filter)
|
||||
MinFilter = sensor_ns.class_("MinFilter", Filter)
|
||||
MaxFilter = sensor_ns.class_("MaxFilter", Filter)
|
||||
SlidingWindowMovingAverageFilter = sensor_ns.class_(
|
||||
@@ -366,11 +365,6 @@ MIN_SCHEMA = cv.All(
|
||||
)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("skip_initial", SkipInitialFilter, cv.positive_not_null_int)
|
||||
async def skip_initial_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("min", MinFilter, MIN_SCHEMA)
|
||||
async def min_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
@@ -472,21 +466,9 @@ async def lambda_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, lambda_)
|
||||
|
||||
|
||||
def validate_delta(config):
|
||||
try:
|
||||
return (cv.positive_float(config), False)
|
||||
except cv.Invalid:
|
||||
pass
|
||||
try:
|
||||
return (cv.percentage(config), True)
|
||||
except cv.Invalid:
|
||||
pass
|
||||
raise cv.Invalid("Delta filter requires a positive number or percentage value.")
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("delta", DeltaFilter, validate_delta)
|
||||
@FILTER_REGISTRY.register("delta", DeltaFilter, cv.float_)
|
||||
async def delta_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, *config)
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("or", OrFilter, validate_filters)
|
||||
|
||||
@@ -74,19 +74,6 @@ optional<float> MedianFilter::new_value(float value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// SkipInitialFilter
|
||||
SkipInitialFilter::SkipInitialFilter(size_t num_to_ignore) : num_to_ignore_(num_to_ignore) {}
|
||||
optional<float> SkipInitialFilter::new_value(float value) {
|
||||
if (num_to_ignore_ > 0) {
|
||||
num_to_ignore_--;
|
||||
ESP_LOGV(TAG, "SkipInitialFilter(%p)::new_value(%f) SKIPPING, %u left", this, value, num_to_ignore_);
|
||||
return {};
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "SkipInitialFilter(%p)::new_value(%f) SENDING", this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
// QuantileFilter
|
||||
QuantileFilter::QuantileFilter(size_t window_size, size_t send_every, size_t send_first_at, float quantile)
|
||||
: send_every_(send_every), send_at_(send_every - send_first_at), window_size_(window_size), quantile_(quantile) {}
|
||||
@@ -328,23 +315,19 @@ optional<float> ThrottleFilter::new_value(float value) {
|
||||
}
|
||||
|
||||
// DeltaFilter
|
||||
DeltaFilter::DeltaFilter(float delta, bool percentage_mode)
|
||||
: delta_(delta), current_delta_(delta), percentage_mode_(percentage_mode), last_value_(NAN) {}
|
||||
DeltaFilter::DeltaFilter(float min_delta) : min_delta_(min_delta), last_value_(NAN) {}
|
||||
optional<float> DeltaFilter::new_value(float value) {
|
||||
if (std::isnan(value)) {
|
||||
if (std::isnan(this->last_value_)) {
|
||||
return {};
|
||||
} else {
|
||||
if (this->percentage_mode_) {
|
||||
this->current_delta_ = fabsf(value * this->delta_);
|
||||
}
|
||||
return this->last_value_ = value;
|
||||
}
|
||||
}
|
||||
if (std::isnan(this->last_value_) || fabsf(value - this->last_value_) >= this->current_delta_) {
|
||||
if (this->percentage_mode_) {
|
||||
this->current_delta_ = fabsf(value * this->delta_);
|
||||
}
|
||||
if (std::isnan(this->last_value_)) {
|
||||
return this->last_value_ = value;
|
||||
}
|
||||
if (fabsf(value - this->last_value_) >= this->min_delta_) {
|
||||
return this->last_value_ = value;
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -102,24 +102,6 @@ class MedianFilter : public Filter {
|
||||
size_t window_size_;
|
||||
};
|
||||
|
||||
/** Simple skip filter.
|
||||
*
|
||||
* Skips the first N values, then passes everything else.
|
||||
*/
|
||||
class SkipInitialFilter : public Filter {
|
||||
public:
|
||||
/** Construct a SkipInitialFilter.
|
||||
*
|
||||
* @param num_to_ignore How many values to ignore before the filter becomes a no-op.
|
||||
*/
|
||||
explicit SkipInitialFilter(size_t num_to_ignore);
|
||||
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
protected:
|
||||
size_t num_to_ignore_;
|
||||
};
|
||||
|
||||
/** Simple min filter.
|
||||
*
|
||||
* Takes the min of the last <send_every> values and pushes it out every <send_every>.
|
||||
@@ -343,14 +325,12 @@ class HeartbeatFilter : public Filter, public Component {
|
||||
|
||||
class DeltaFilter : public Filter {
|
||||
public:
|
||||
explicit DeltaFilter(float delta, bool percentage_mode);
|
||||
explicit DeltaFilter(float min_delta);
|
||||
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
protected:
|
||||
float delta_;
|
||||
float current_delta_;
|
||||
bool percentage_mode_;
|
||||
float min_delta_;
|
||||
float last_value_{NAN};
|
||||
};
|
||||
|
||||
|
||||
@@ -26,32 +26,48 @@ Sensor::Sensor() : Sensor("") {}
|
||||
std::string Sensor::get_unit_of_measurement() {
|
||||
if (this->unit_of_measurement_.has_value())
|
||||
return *this->unit_of_measurement_;
|
||||
return "";
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->unit_of_measurement();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
void Sensor::set_unit_of_measurement(const std::string &unit_of_measurement) {
|
||||
this->unit_of_measurement_ = unit_of_measurement;
|
||||
}
|
||||
std::string Sensor::unit_of_measurement() { return ""; }
|
||||
|
||||
int8_t Sensor::get_accuracy_decimals() {
|
||||
if (this->accuracy_decimals_.has_value())
|
||||
return *this->accuracy_decimals_;
|
||||
return 0;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->accuracy_decimals();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
void Sensor::set_accuracy_decimals(int8_t accuracy_decimals) { this->accuracy_decimals_ = accuracy_decimals; }
|
||||
int8_t Sensor::accuracy_decimals() { return 0; }
|
||||
|
||||
std::string Sensor::get_device_class() {
|
||||
if (this->device_class_.has_value())
|
||||
return *this->device_class_;
|
||||
return "";
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->device_class();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
void Sensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
|
||||
std::string Sensor::device_class() { return ""; }
|
||||
|
||||
void Sensor::set_state_class(StateClass state_class) { this->state_class_ = state_class; }
|
||||
StateClass Sensor::get_state_class() {
|
||||
if (this->state_class_.has_value())
|
||||
return *this->state_class_;
|
||||
return StateClass::STATE_CLASS_NONE;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return this->state_class();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
StateClass Sensor::state_class() { return StateClass::STATE_CLASS_NONE; }
|
||||
|
||||
void Sensor::publish_state(float state) {
|
||||
this->raw_state = state;
|
||||
|
||||
@@ -150,15 +150,40 @@ class Sensor : public EntityBase {
|
||||
/// Return whether this sensor has gotten a full state (that passed through all filters) yet.
|
||||
bool has_state() const;
|
||||
|
||||
/** Override this method to set the unique ID of this sensor.
|
||||
/** A unique ID for this sensor, empty for no unique id. See unique ID requirements:
|
||||
* https://developers.home-assistant.io/docs/en/entity_registry_index.html#unique-id-requirements
|
||||
*
|
||||
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
|
||||
* @return The unique id as a string.
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
void internal_send_state_to_frontend(float state);
|
||||
|
||||
protected:
|
||||
/** Override this to set the default unit of measurement.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual std::string unit_of_measurement(); // NOLINT
|
||||
|
||||
/** Override this to set the default accuracy in decimals.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual int8_t accuracy_decimals(); // NOLINT
|
||||
|
||||
/** Override this to set the default device class.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual std::string device_class(); // NOLINT
|
||||
|
||||
/** Override this to set the default state class.
|
||||
*
|
||||
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||
*/
|
||||
virtual StateClass state_class(); // NOLINT
|
||||
|
||||
CallbackManager<void(float)> raw_callback_; ///< Storage for raw state callbacks.
|
||||
CallbackManager<void(float)> callback_; ///< Storage for filtered state callbacks.
|
||||
|
||||
|
||||
@@ -234,8 +234,8 @@ bool SGP4xComponent::measure_raw_(uint16_t &voc_raw, uint16_t &nox_raw) {
|
||||
response_words = 2;
|
||||
}
|
||||
}
|
||||
uint16_t rhticks = llround((uint16_t) ((humidity * 65535) / 100));
|
||||
uint16_t tempticks = (uint16_t) (((temperature + 45) * 65535) / 175);
|
||||
uint16_t rhticks = llround((uint16_t)((humidity * 65535) / 100));
|
||||
uint16_t tempticks = (uint16_t)(((temperature + 45) * 65535) / 175);
|
||||
// first parameter are the relative humidity ticks
|
||||
data[0] = rhticks;
|
||||
// secomd parameter are the temperature ticks
|
||||
|
||||
@@ -19,7 +19,7 @@ void SHT4XComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up sht4x...");
|
||||
|
||||
if (this->duty_cycle_ > 0.0) {
|
||||
uint32_t heater_interval = (uint32_t) (this->heater_time_ / this->duty_cycle_);
|
||||
uint32_t heater_interval = (uint32_t)(this->heater_time_ / this->duty_cycle_);
|
||||
ESP_LOGD(TAG, "Heater interval: %i", heater_interval);
|
||||
|
||||
if (this->heater_power_ == SHT4X_HEATERPOWER_HIGH) {
|
||||
|
||||
@@ -20,9 +20,7 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) {
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
if (inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)) != nullptr)
|
||||
return std::string{buf};
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
else if (storage.ss_family == AF_INET6) {
|
||||
} else if (storage.ss_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *addr = reinterpret_cast<const struct sockaddr_in6 *>(&storage);
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
// Format IPv4-mapped IPv6 addresses as regular IPv4 addresses
|
||||
@@ -34,7 +32,6 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) {
|
||||
if (inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof(buf)) != nullptr)
|
||||
return std::string{buf};
|
||||
}
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -15,28 +15,19 @@
|
||||
/* Address families. */
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_INET 2
|
||||
#define AF_INET6 10
|
||||
#define PF_INET AF_INET
|
||||
#define PF_INET6 AF_INET6
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_TCP 6
|
||||
|
||||
#if LWIP_IPV6
|
||||
#define AF_INET6 10
|
||||
#define PF_INET6 AF_INET6
|
||||
|
||||
#define IPPROTO_IPV6 41
|
||||
#define IPPROTO_ICMPV6 58
|
||||
#endif
|
||||
|
||||
#define TCP_NODELAY 0x01
|
||||
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#ifdef O_NONBLOCK
|
||||
#undef O_NONBLOCK
|
||||
#endif
|
||||
#define O_NONBLOCK 1
|
||||
|
||||
#define SHUT_RD 0
|
||||
@@ -67,7 +58,6 @@ struct sockaddr_in {
|
||||
char sin_zero[SIN_ZERO_LEN];
|
||||
};
|
||||
|
||||
#if LWIP_IPV6
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr_in6 {
|
||||
uint8_t sin6_len; /* length of this structure */
|
||||
@@ -77,7 +67,6 @@ struct sockaddr_in6 {
|
||||
struct in6_addr sin6_addr; /* IPv6 address */
|
||||
uint32_t sin6_scope_id; /* Set of interfaces for scope */
|
||||
};
|
||||
#endif
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr {
|
||||
|
||||
@@ -14,34 +14,6 @@ std::unique_ptr<Socket> socket_ip(int type, int protocol) {
|
||||
#endif
|
||||
}
|
||||
|
||||
socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const char *ip_address, uint16_t port) {
|
||||
#if LWIP_IPV6
|
||||
if (addrlen < sizeof(sockaddr_in6)) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
auto *server = reinterpret_cast<sockaddr_in6 *>(addr);
|
||||
memset(server, 0, sizeof(sockaddr_in6));
|
||||
server->sin6_family = AF_INET6;
|
||||
server->sin6_port = htons(port);
|
||||
ip6_addr_t ip6;
|
||||
inet6_aton(ip_address, &ip6);
|
||||
memcpy(server->sin6_addr.un.u32_addr, ip6.addr, sizeof(ip6.addr));
|
||||
return sizeof(sockaddr_in6);
|
||||
#else
|
||||
if (addrlen < sizeof(sockaddr_in)) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
auto *server = reinterpret_cast<sockaddr_in *>(addr);
|
||||
memset(server, 0, sizeof(sockaddr_in));
|
||||
server->sin_family = AF_INET;
|
||||
server->sin_addr.s_addr = inet_addr(ip_address);
|
||||
server->sin_port = htons(port);
|
||||
return sizeof(sockaddr_in);
|
||||
#endif
|
||||
}
|
||||
|
||||
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port) {
|
||||
#if LWIP_IPV6
|
||||
if (addrlen < sizeof(sockaddr_in6)) {
|
||||
@@ -51,7 +23,7 @@ socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t po
|
||||
auto *server = reinterpret_cast<sockaddr_in6 *>(addr);
|
||||
memset(server, 0, sizeof(sockaddr_in6));
|
||||
server->sin6_family = AF_INET6;
|
||||
server->sin6_port = htons(port);
|
||||
server->sin6_port = port;
|
||||
server->sin6_addr = in6addr_any;
|
||||
return sizeof(sockaddr_in6);
|
||||
#else
|
||||
@@ -63,7 +35,7 @@ socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t po
|
||||
memset(server, 0, sizeof(sockaddr_in));
|
||||
server->sin_family = AF_INET;
|
||||
server->sin_addr.s_addr = ESPHOME_INADDR_ANY;
|
||||
server->sin_port = htons(port);
|
||||
server->sin_port = port;
|
||||
return sizeof(sockaddr_in);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -44,10 +44,7 @@ std::unique_ptr<Socket> socket(int domain, int type, int protocol);
|
||||
/// Create a socket in the newest available IP domain (IPv6 or IPv4) of the given type and protocol.
|
||||
std::unique_ptr<Socket> socket_ip(int type, int protocol);
|
||||
|
||||
/// Set a sockaddr to the specified address and port for the IP version used by socket_ip().
|
||||
socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const char *ip_address, uint16_t port);
|
||||
|
||||
/// Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
|
||||
/// Set a sockaddr to the any address for the IP version used by socket_ip().
|
||||
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port);
|
||||
|
||||
} // namespace socket
|
||||
|
||||
@@ -17,7 +17,6 @@ spi_ns = cg.esphome_ns.namespace("spi")
|
||||
SPIComponent = spi_ns.class_("SPIComponent", cg.Component)
|
||||
SPIDevice = spi_ns.class_("SPIDevice")
|
||||
MULTI_CONF = True
|
||||
CONF_FORCE_SW = "force_sw"
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
@@ -26,7 +25,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
|
||||
cv.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_FORCE_SW, default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN),
|
||||
@@ -41,7 +39,6 @@ async def to_code(config):
|
||||
|
||||
clk = await cg.gpio_pin_expression(config[CONF_CLK_PIN])
|
||||
cg.add(var.set_clk(clk))
|
||||
cg.add(var.set_force_sw(config[CONF_FORCE_SW]))
|
||||
if CONF_MISO_PIN in config:
|
||||
miso = await cg.gpio_pin_expression(config[CONF_MISO_PIN])
|
||||
cg.add(var.set_miso(miso))
|
||||
|
||||
@@ -25,7 +25,7 @@ void SPIComponent::setup() {
|
||||
this->clk_->digital_write(true);
|
||||
|
||||
#ifdef USE_SPI_ARDUINO_BACKEND
|
||||
bool use_hw_spi = !this->force_sw_;
|
||||
bool use_hw_spi = true;
|
||||
const bool has_miso = this->miso_ != nullptr;
|
||||
const bool has_mosi = this->mosi_ != nullptr;
|
||||
int8_t clk_pin = -1, miso_pin = -1, mosi_pin = -1;
|
||||
|
||||
@@ -74,7 +74,6 @@ class SPIComponent : public Component {
|
||||
void set_clk(GPIOPin *clk) { clk_ = clk; }
|
||||
void set_miso(GPIOPin *miso) { miso_ = miso; }
|
||||
void set_mosi(GPIOPin *mosi) { mosi_ = mosi; }
|
||||
void set_force_sw(bool force_sw) { force_sw_ = force_sw; }
|
||||
|
||||
void setup() override;
|
||||
|
||||
@@ -261,7 +260,6 @@ class SPIComponent : public Component {
|
||||
GPIOPin *miso_{nullptr};
|
||||
GPIOPin *mosi_{nullptr};
|
||||
GPIOPin *active_cs_{nullptr};
|
||||
bool force_sw_{false};
|
||||
#ifdef USE_SPI_ARDUINO_BACKEND
|
||||
SPIClass *hw_spi_{nullptr};
|
||||
#endif // USE_SPI_ARDUINO_BACKEND
|
||||
|
||||
@@ -330,7 +330,6 @@ SPRINKLER_VALVE_SCHEMA = cv.Schema(
|
||||
SPRINKLER_CONTROLLER_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(Sprinkler),
|
||||
cv.Optional(CONF_NAME): cv.string,
|
||||
cv.Optional(CONF_AUTO_ADVANCE_SWITCH): cv.maybe_simple_value(
|
||||
switch.switch_schema(
|
||||
SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG
|
||||
@@ -425,8 +424,7 @@ SPRINKLER_CONTROLLER_SCHEMA = cv.Schema(
|
||||
): cv.positive_time_period_seconds,
|
||||
cv.Required(CONF_VALVES): cv.ensure_list(SPRINKLER_VALVE_SCHEMA),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
).extend(cv.ENTITY_BASE_SCHEMA)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.ensure_list(SPRINKLER_CONTROLLER_SCHEMA),
|
||||
@@ -561,19 +559,16 @@ async def sprinkler_simple_action_to_code(config, action_id, template_arg, args)
|
||||
|
||||
async def to_code(config):
|
||||
for sprinkler_controller in config:
|
||||
var = cg.new_Pvariable(sprinkler_controller[CONF_ID])
|
||||
|
||||
if CONF_NAME in sprinkler_controller:
|
||||
cg.add(var.set_name(sprinkler_controller[CONF_NAME]))
|
||||
if len(sprinkler_controller[CONF_VALVES]) > 1:
|
||||
var = cg.new_Pvariable(
|
||||
sprinkler_controller[CONF_ID],
|
||||
sprinkler_controller[CONF_MAIN_SWITCH][CONF_NAME],
|
||||
)
|
||||
else:
|
||||
if len(sprinkler_controller[CONF_VALVES]) > 1:
|
||||
name = sprinkler_controller[CONF_MAIN_SWITCH][CONF_NAME]
|
||||
else:
|
||||
name = sprinkler_controller[CONF_VALVES][0][CONF_VALVE_SWITCH][
|
||||
CONF_NAME
|
||||
]
|
||||
cg.add(var.set_name(name))
|
||||
|
||||
var = cg.new_Pvariable(
|
||||
sprinkler_controller[CONF_ID],
|
||||
sprinkler_controller[CONF_VALVES][0][CONF_VALVE_SWITCH][CONF_NAME],
|
||||
)
|
||||
await cg.register_component(var, sprinkler_controller)
|
||||
|
||||
if len(sprinkler_controller[CONF_VALVES]) > 1:
|
||||
|
||||
@@ -138,7 +138,15 @@ float SprinklerControllerSwitch::get_setup_priority() const { return setup_prior
|
||||
Trigger<> *SprinklerControllerSwitch::get_turn_on_trigger() const { return this->turn_on_trigger_; }
|
||||
Trigger<> *SprinklerControllerSwitch::get_turn_off_trigger() const { return this->turn_off_trigger_; }
|
||||
|
||||
void SprinklerControllerSwitch::setup() { this->state = this->get_initial_state_with_restore_mode().value_or(false); }
|
||||
void SprinklerControllerSwitch::setup() {
|
||||
this->state = this->get_initial_state_with_restore_mode().value_or(false);
|
||||
|
||||
if (this->state) {
|
||||
this->turn_on();
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
}
|
||||
|
||||
void SprinklerControllerSwitch::dump_config() { LOG_SWITCH("", "Sprinkler Switch", this); }
|
||||
|
||||
@@ -370,11 +378,10 @@ SprinklerValveOperator *SprinklerValveRunRequest::valve_operator() { return this
|
||||
|
||||
SprinklerValveRunRequestOrigin SprinklerValveRunRequest::request_is_from() { return this->origin_; }
|
||||
|
||||
void Sprinkler::setup() {
|
||||
this->timer_.push_back({this->name_ + "sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)});
|
||||
this->timer_.push_back({this->name_ + "vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)});
|
||||
this->all_valves_off_(true);
|
||||
}
|
||||
Sprinkler::Sprinkler() {}
|
||||
Sprinkler::Sprinkler(const std::string &name) : EntityBase(name) {}
|
||||
|
||||
void Sprinkler::setup() { this->all_valves_off_(true); }
|
||||
|
||||
void Sprinkler::loop() {
|
||||
for (auto &p : this->pump_) {
|
||||
@@ -1211,6 +1218,8 @@ SprinklerSwitch *Sprinkler::valve_pump_switch_by_pump_index(size_t pump_index) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t Sprinkler::hash_base() { return 3129891955UL; }
|
||||
|
||||
bool Sprinkler::valve_is_enabled_(const size_t valve_number) {
|
||||
if (this->is_a_valid_valve(valve_number)) {
|
||||
if (this->valve_[valve_number].enable_switch != nullptr) {
|
||||
|
||||
@@ -201,14 +201,15 @@ class SprinklerValveRunRequest {
|
||||
SprinklerValveRunRequestOrigin origin_{USER};
|
||||
};
|
||||
|
||||
class Sprinkler : public Component {
|
||||
class Sprinkler : public Component, public EntityBase {
|
||||
public:
|
||||
Sprinkler();
|
||||
Sprinkler(const std::string &name);
|
||||
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_name(const std::string &name) { this->name_ = name; }
|
||||
|
||||
/// add a valve to the controller
|
||||
void add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControllerSwitch *enable_sw = nullptr);
|
||||
|
||||
@@ -422,6 +423,8 @@ class Sprinkler : public Component {
|
||||
SprinklerSwitch *valve_pump_switch_by_pump_index(size_t pump_index);
|
||||
|
||||
protected:
|
||||
uint32_t hash_base() override;
|
||||
|
||||
/// returns true if valve number is enabled
|
||||
bool valve_is_enabled_(size_t valve_number);
|
||||
|
||||
@@ -525,8 +528,6 @@ class Sprinkler : public Component {
|
||||
uint32_t start_delay_{0};
|
||||
uint32_t stop_delay_{0};
|
||||
|
||||
std::string name_;
|
||||
|
||||
/// Sprinkler controller state
|
||||
SprinklerState state_{IDLE};
|
||||
|
||||
@@ -573,7 +574,9 @@ class Sprinkler : public Component {
|
||||
std::vector<SprinklerValveOperator> valve_op_{2};
|
||||
|
||||
/// Valve control timers
|
||||
std::vector<SprinklerTimer> timer_{};
|
||||
std::vector<SprinklerTimer> timer_{
|
||||
{this->name_ + "sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)},
|
||||
{this->name_ + "vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)}};
|
||||
|
||||
/// Other Sprinkler instances we should be aware of (used to check if pumps are in use)
|
||||
std::vector<Sprinkler *> other_controllers_;
|
||||
|
||||
@@ -74,7 +74,7 @@ void ST7920::goto_xy_(uint16_t x, uint16_t y) {
|
||||
|
||||
void HOT ST7920::write_display_data() {
|
||||
uint8_t i, j, b;
|
||||
for (j = 0; j < (uint8_t) (this->get_height_internal() / 2); j++) {
|
||||
for (j = 0; j < (uint8_t)(this->get_height_internal() / 2); j++) {
|
||||
this->goto_xy_(0, j);
|
||||
this->enable();
|
||||
for (i = 0; i < 16; i++) { // 16 bytes from line #0+
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
from esphome import pins
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import light, output
|
||||
from esphome.const import CONF_OUTPUT, CONF_OUTPUT_ID, CONF_PIN
|
||||
from esphome.components import light
|
||||
from esphome.const import CONF_OUTPUT_ID, CONF_PIN
|
||||
from .. import status_led_ns
|
||||
|
||||
AUTO_LOAD = ["output"]
|
||||
|
||||
StatusLEDLightOutput = status_led_ns.class_(
|
||||
"StatusLEDLightOutput", light.LightOutput, cg.Component
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
light.BINARY_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(StatusLEDLightOutput),
|
||||
cv.Optional(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_OUTPUT): cv.use_id(output.BinaryOutput),
|
||||
}
|
||||
),
|
||||
cv.has_at_least_one_key(CONF_PIN, CONF_OUTPUT),
|
||||
CONFIG_SCHEMA = light.BINARY_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(StatusLEDLightOutput),
|
||||
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
||||
if CONF_PIN in config:
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
if CONF_OUTPUT in config:
|
||||
out = await cg.get_variable(config[CONF_OUTPUT])
|
||||
cg.add(var.set_output(out))
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
await cg.register_component(var, config)
|
||||
# cg.add(cg.App.register_component(var))
|
||||
await light.register_light(var, config)
|
||||
|
||||
@@ -15,10 +15,10 @@ void StatusLEDLightOutput::loop() {
|
||||
}
|
||||
|
||||
if ((new_state & STATUS_LED_ERROR) != 0u) {
|
||||
this->output_state_(millis() % 250u < 150u);
|
||||
this->pin_->digital_write(millis() % 250u < 150u);
|
||||
this->last_app_state_ = new_state;
|
||||
} else if ((new_state & STATUS_LED_WARNING) != 0u) {
|
||||
this->output_state_(millis() % 1500u < 250u);
|
||||
this->pin_->digital_write(millis() % 1500u < 250u);
|
||||
this->last_app_state_ = new_state;
|
||||
} else if (new_state != this->last_app_state_) {
|
||||
// if no error/warning -> restore light state or turn off
|
||||
@@ -26,16 +26,17 @@ void StatusLEDLightOutput::loop() {
|
||||
|
||||
if (lightstate_)
|
||||
lightstate_->current_values_as_binary(&state);
|
||||
ESP_LOGD(TAG, "Restoring light state %s", ONOFF(state));
|
||||
|
||||
this->output_state_(state);
|
||||
this->pin_->digital_write(state);
|
||||
this->last_app_state_ = new_state;
|
||||
|
||||
ESP_LOGD(TAG, "Restoring light state %s", ONOFF(state));
|
||||
}
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::setup_state(light::LightState *state) {
|
||||
lightstate_ = state;
|
||||
ESP_LOGD(TAG, "'%s': Setting initial state", state->get_name().c_str());
|
||||
ESP_LOGD(TAG, "'%s': Setting initital state", state->get_name().c_str());
|
||||
this->write_state(state);
|
||||
}
|
||||
|
||||
@@ -46,18 +47,16 @@ void StatusLEDLightOutput::write_state(light::LightState *state) {
|
||||
// if in warning/error, don't overwrite the status_led
|
||||
// once it is back to OK, the loop will restore the state
|
||||
if ((App.get_app_state() & (STATUS_LED_ERROR | STATUS_LED_WARNING)) == 0u) {
|
||||
this->pin_->digital_write(binary);
|
||||
ESP_LOGD(TAG, "'%s': Setting state %s", state->get_name().c_str(), ONOFF(binary));
|
||||
this->output_state_(binary);
|
||||
}
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Status LED...");
|
||||
|
||||
if (this->pin_ != nullptr) {
|
||||
this->pin_->setup();
|
||||
this->pin_->digital_write(false);
|
||||
}
|
||||
this->pin_->setup();
|
||||
this->pin_->digital_write(false);
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::dump_config() {
|
||||
@@ -65,12 +64,5 @@ void StatusLEDLightOutput::dump_config() {
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
}
|
||||
|
||||
void StatusLEDLightOutput::output_state_(bool state) {
|
||||
if (this->pin_ != nullptr)
|
||||
this->pin_->digital_write(state);
|
||||
if (this->output_ != nullptr)
|
||||
this->output_->set_state(state);
|
||||
}
|
||||
|
||||
} // namespace status_led
|
||||
} // namespace esphome
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
#include "esphome/components/output/binary_output.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace status_led {
|
||||
@@ -11,7 +10,6 @@ namespace status_led {
|
||||
class StatusLEDLightOutput : public light::LightOutput, public Component {
|
||||
public:
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
void set_output(output::BinaryOutput *output) { output_ = output; }
|
||||
|
||||
light::LightTraits get_traits() override {
|
||||
auto traits = light::LightTraits();
|
||||
@@ -33,11 +31,9 @@ class StatusLEDLightOutput : public light::LightOutput, public Component {
|
||||
float get_loop_priority() const override { return 50.0f; }
|
||||
|
||||
protected:
|
||||
GPIOPin *pin_{nullptr};
|
||||
output::BinaryOutput *output_{nullptr};
|
||||
GPIOPin *pin_;
|
||||
light::LightState *lightstate_{};
|
||||
uint32_t last_app_state_{0xFFFF};
|
||||
void output_state_(bool state);
|
||||
};
|
||||
|
||||
} // namespace status_led
|
||||
|
||||
@@ -269,7 +269,7 @@ struct SunAtLocation {
|
||||
num_t jd = julian_day(date) + added_d;
|
||||
|
||||
num_t eot = SunAtTime(jd).equation_of_time() * 240;
|
||||
time_t new_timestamp = (time_t) (date.timestamp + added_d * 86400 - eot);
|
||||
time_t new_timestamp = (time_t)(date.timestamp + added_d * 86400 - eot);
|
||||
return time::ESPTime::from_epoch_utc(new_timestamp);
|
||||
}
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user