1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-03 08:31:47 +00:00

Compare commits

..

41 Commits

Author SHA1 Message Date
Jesse Hills
b6e765daaa InterruptLock per core for rp2040 2023-03-21 14:13:25 +13:00
jerome992
cd57469e06 Fix negative sqrt root in ct_clamp_sensor.cpp (#2701) (#4236)
Co-authored-by: Jerome <jerome992@internet.lu>
2023-03-20 04:22:22 +00:00
Aaron S. Jackson
d98d6ff45f B/W support for GooDisplay GDEY029T94 (as used on Adafruit MagTag) (#4222)
* B/W support for GooDisplay GDEY029T94

* Fix python style ci

* linter recommendations

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-20 03:45:50 +00:00
Oxan van Leeuwen
14e38f0469 Upgrade clang-format to v13 (#4535)
* Upgrade clang-format to v13

* Apply clang-format-13 formatting changes

* Format

* Format bme_680

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-20 03:38:41 +00:00
Jesse Hills
f0f6d3f1cd Disallow uart0/1/2 as ids in config (#4446)
* Disallow uart0/1/2 as ids in config

* Update test files
2023-03-20 02:29:21 +00:00
Jesse Hills
0b383542da Split test3.yaml (#4591) 2023-03-19 22:39:02 +00:00
Michael Bisbjerg
b2cec10601 Fix outdated filter string in platformio_api (#4587) 2023-03-19 19:11:18 +00:00
Sybren A. Stüvel
48658d5a55 Add a simple 'skip_initial' filter (#4582)
* Add a simple 'skip' filter

This filter simply skips the first `send_first_at` values, then passes
everything as-is. This is quite useful when you know the first few sensor
readings should be ignored.

Example YAML:

```yaml
sensor:
  - platform: sgp30
    id: mysensor_sgp30
    eco2:
      id: mysensor_sgp30_co2
      name: "eCO₂"
      accuracy_decimals: 0
      filters:
        - skip:
            send_first_at: 41
```

* Rename the filter to `skip_initial` and simplify the schema

New usage:

```yaml
      filters:
        - skip_initial: 41
```

* Apply clang-format
2023-03-19 19:08:51 +00:00
Peter Halicky
5207ca1d52 Add support for ESP32 CAM resolutions for 3MP and 5MP sensors (OV5640 for example). Also support (almost) arbitrary camera clock, some cameras/ESP chips need slightly lower clock than 20MHz to avoid image corruption. (#4580) 2023-03-19 19:03:38 +00:00
Fabian
7196fb8e82 add define __str__ method (#4576)
Co-authored-by: Your Name <you@example.com>
2023-03-19 18:55:12 +00:00
dependabot[bot]
48ada2eebb Bump aioesphomeapi from 13.5.0 to 13.5.1 (#4572)
Bumps [aioesphomeapi](https://github.com/esphome/aioesphomeapi) from 13.5.0 to 13.5.1.
- [Release notes](https://github.com/esphome/aioesphomeapi/releases)
- [Commits](https://github.com/esphome/aioesphomeapi/compare/v13.5.0...v13.5.1)

---
updated-dependencies:
- dependency-name: aioesphomeapi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-19 18:54:18 +00:00
Nathaniel Wesley Filardo
0de5808ed2 climate: brown paper bag fix for on_configure (#4573)
I forgot this hunk in https://github.com/esphome/esphome/pull/4511 .
I'm sorry for the noise.
2023-03-19 18:54:00 +00:00
Kai Gerken
ebc544e4b4 Fix compile error on pzemdc.h (#4583) 2023-03-19 18:31:05 +00:00
Raph
a31fb3c987 Add option flip_x (#4555)
* Adding flip_x

* Adding flip_x

* Adding flip_x

* Adding flip_x

* Adding flip_x

* convert tab to space

* update format
2023-03-15 22:23:01 +00:00
Samuel Sieb
dfc7cd7f5d allow using a binary output for the status led (#4532)
* allow using a binary output for the status led

* lint

* output status as well

* simplify

---------

Co-authored-by: Samuel Sieb <samuel@sieb.net>
2023-03-15 22:21:35 +00:00
Witold Krecicki
a8bb2a42a1 Add an option to force SPI into software mode, useful when (#4556)
reusing pins for different purposes.
2023-03-15 22:21:25 +00:00
R Huish
3d4c0e6667 Added missing PM_1_0 and PM_10_0 for PMS5003T and PMS5003ST (#4560)
* Added missing PM_1_0 and PM_10_0 for PMS5003T

Added missing PM_1_0 and PM_10_0 for PMS5003T

* Revert "Added missing PM_1_0 and PM_10_0 for PMS5003T"

This reverts commit 86084f7c61.

* Added tests for PMS5003T

* Added missing PM_1_0 and PM_10_0 for PMS5003T PMS5003ST

* Added missing PM_1_0 and PM_10_0 for PMS5003T

* lint: Trailing whitespace fixed

* tab character removed

* Clang format suggested edit
2023-03-15 22:21:10 +00:00
Trent Houliston
25fb288016 Update the delta filter to take a percentage value as well as an absolute value (#4391) 2023-03-15 22:20:18 +00:00
Fabian
1b8b8cdd11 EntityBase: Icon string can stay in flash. (#4566)
* Icon string can stay in flash.

* Remove redundant const.

---------

Co-authored-by: Your Name <you@example.com>
2023-03-15 22:20:12 +00:00
NP v/d Spek
2f50e18eb5 fixing shrink and extend functions of the displaybuffer's Rect class (#4565)
* fixing rectangle's `shrink` and `extend`

* fixed the rect::shrink and rect::inside methods
and added rect:equal() method

* fixed internal clang issue again. When would is
this going to be fixed :(

* fixed internal clang issue again. When would is
this going to be fixed :(

* remove trailing space
2023-03-15 19:45:50 +00:00
Jesse Hills
215107e8ea Mark esp32_touch supported only on standard esp32 variant (#4562)
* Mark esp32_touch supported only on standard esp32 variant

* Add back default
2023-03-15 07:42:33 +00:00
Keith Burzinski
d3f2b93c42 Remove switch actions during config; bump setup priority (#4563) 2023-03-15 05:21:23 +00:00
Stroe Andrei Catalin
ee7102fcd1 Added response for Tuya RSSI command (#4549)
* Added wifi rssi util
Added tuya mcu response to wifi rssi command

* Cleanup

* PR Comments

* PR Comments
2023-03-14 00:54:35 +00:00
DAVe3283
a44e38300b Revert "Remove state class from uptime sensor (#4345)" (#4557)
This reverts commit 36c2e770bf.
Addresses esphome/issues#4193.
2023-03-14 00:52:19 +00:00
Eduardo Roldan
b00e20c29f pipsolar component. Correct the sscanf format for QPIG command parsing to set pv_input_voltage as float (not int) (#4165) 2023-03-13 22:46:46 +00:00
Jesse Hills
d642aeba0f Map gpio pins for touch on esp32-s2/s3 (#4552)
* Map gpio pins for touch on esp32-s2/s3

* fix value
2023-03-13 00:13:36 +00:00
NP v/d Spek
6a6aee510d On the ILI9xxx display's enable the psram on esp32 and allow big screen (#4551)
* enable the psram on esp32 and allow big screen

* update CODEOWNERS

* small update

* update CODEOWNERS again.

* Removed the M5STACK because it is a ESP32 device.

* i removed the wrong model

* update the error message.
2023-03-13 00:13:19 +00:00
Jesse Hills
ea17a92dbc Allow AUTO_LOAD to be a function (#4550) 2023-03-12 22:43:31 +00:00
Dorian Zedler
32a0a60480 Feat: add support for hex color in color component (#4493)
* Feat: add support for hex color in color component

* Chore: move hex color validator to color component

* Chore: add test

* Chore: fix formatting

* Chore: make linter happy

* Chore: make linter happy

* Fix: parse correct offsets

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

* Chore: use cv.Invalid

* Fix: remove # because it indicates a comment in yaml

* Fix: only allow hex if no other color value is set

* Fix: tests

* Fix: mutual exclusion of raw and hex colors

* Chore: format file

* Update __init__.py

---------

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-12 20:26:27 +00:00
Martin Murray
5a56644702 Add carbon dioxide device class to scd30 sensor schema. (#4547) 2023-03-12 20:16:48 +00:00
jakehdk
29113808ee Add support for new clones of mpu6050 responding with 0x70 address (#4546)
Co-authored-by: jakehdk <Jake@Jakobs-MacBook-Pro.local>
2023-03-12 20:14:00 +00:00
Jesse Hills
6471361715 Format test files (#4541) 2023-03-09 01:54:51 +00:00
Carlos Garcia Saura
01687a9d57 Correct BME680 gas calculation and heater_off (#4498)
* Fix missing data array

* Fix incorrect bit offset

* Correct variable types

* Do same conversions as in original library

* Correct clang-format

* Move out float conversion for clarity

* Added check for heater stability

* Correct clang format

* Allow reporting gas resistance when heater is disabled

* Correct clang format

* Better error reporting by @DAVe3283

* Correct signed operation, range switching error was positive all the time
2023-03-09 00:34:06 +00:00
Oxan van Leeuwen
801fbf44c5 Revert storing Font glyphs in manually-allocated memory (#4516)
This partially reverts commit 62459a8ae1.
2023-03-09 00:14:34 +00:00
Oxan van Leeuwen
ba1416cc0e Drop deprecated entity property base methods (#4539) 2023-03-09 00:08:45 +00:00
Oxan van Leeuwen
afc1c83af4 Mark unique_id() override as deprecated (#4538) 2023-03-09 00:06:20 +00:00
Oxan van Leeuwen
da056866ff Drop broken logging macros (#4534) 2023-03-09 00:03:33 +00:00
NP v/d Spek
336c2d34e6 Renaming and extending the ili9341 to the ili9xxx component (#4275)
* - Removed cleaning the screen twice.
  \Should be handled by  `DisplayBuffer::init_internal_();`
- Made ili9341::initalize() protected and renamed
  \ it to ili9341::initalize().
- ili9341::initalize() should only init the display
  \ and set the width and heigth.

* removed to much

* clang format fixes

* removing trailing underscors for
protected virtual methods

* removed the "override"  on display()

* clang fixes

* restored old changes

* Renamed the ili9341 platform to ili9xxx and added
multiple drivers as well. including PR #3848

* fixed most of the clang reported issues

* fixed reported issues

* last fixes

* Setting the right codeowners

* missing changes

* fixed naming Display() method.

* clang again

* clang fix

* fixes reported by @jesserockz & @gpambrozio

* a change to display.py removing an unneeded var

* re-introduce **backlight** option.

* update the ili9488 initialization

* update the ili9488 initialization and fix typo

* fixed typo

* add missing constants

* swap height and width back for the ili9488

* init fixes ili9488

* fixed lint issue
testing the init code

* oeps

* init fixes ili9488

* fixed wrong define

* fixed wrong define again

* removed some spaces

* revert to ili9341

* Remove parts that where used for
the switchplate

* lint fixes and removing unused function

* fix error and introducing 16bit color option

* fix error and introducing 16bit color option

* fix clang issue

* clang fix

* clang issue again

* is this what clang exprect

* clang fix

* clang fix

* try again

* let try again

* and again

* and the last clang fix

* remove the need of wifi

* update dimentions

* update ili8488 init code.

* update dimentions

* allow to change height and width

* dump color mode config

* fix

* fix

* modify logging

* referd back unrelated change

* code formatting commit and moving functions around

* add missing ;

* update code

* update code

* use the correct write_array for sending uint16_t

* fix panic loop

* fix panic loop

* - update the test file
- fixed sending display data

* clang fixes

* clang fixes

* clang fixes again

* remove .gitignore items

* remove .gitignore items

* make sure Update() can can not be called while
called

* clang correction

* adding a test yaml for the ili9341

* Update ili9341 example

* Make test ili9xxx/tests only local

* restore back old ili9341 driver code

* Add a new config for the M5Core

* fix clang request

* reverd to restore of the old ili9341
there is no proper way to say it is depricated.

* Remove the backlight/led pin from the config.
You need to use a proper light platform component

* Ili9488init changes (#88)

Fixed ILI9488 init settings, and adjusted pixel handling code to push pixels in 18 bit format.
This does not change the internal 16-bit representation.

* fixed some leftover clang issues from the merge.

* fixed the slang-tidy request.

* remove `backlight_pin` warning.

---------

Co-authored-by: JD Steffen <jdsteffen81@gmail.com>
2023-03-08 23:03:49 +00:00
Russell Cloran
f3a969d35c Add ESP32-S3 support in NeoPixelBus component (#4114)
* Add ESP32-S3 support in NeoPixelBus component

* Update NeoPixelBus version in platformio.ini
2023-03-08 22:35:40 +00:00
Jared Sanson
c12dd77c64 Fix ethernet clk_mode for GPIO0_OUT (#4307)
* Fix GPIO0_OUT definition for ethernet component

* Formatting

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-08 21:03:11 +00:00
Jesse Hills
4f138c600b Bump version to 2023.4.0-dev 2023-03-09 09:09:39 +13:00
103 changed files with 1355 additions and 952 deletions

View File

@@ -51,6 +51,6 @@
"files.associations": {
"**/.vscode/*.json": "jsonc"
},
"C_Cpp.clang_format_path": "/usr/bin/clang-format-11",
"C_Cpp.clang_format_path": "/usr/bin/clang-format-13",
}
}

View File

@@ -41,6 +41,10 @@ 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
@@ -129,7 +133,7 @@ jobs:
- name: Install clang tools
run: |
sudo apt-get install \
clang-format-11 \
clang-format-13 \
clang-tidy-11
if: matrix.id == 'clang-tidy' || matrix.id == 'clang-format'

View File

@@ -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-11=1:11.0.1-2 \
clang-format-13=1:13.0.1-6~deb11u1 \
clang-tidy-11=1:11.0.1-2 \
patch=2.7.6-7 \
software-properties-common=0.96.20.2-2.1 \

View File

@@ -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);

View File

@@ -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];

View File

@@ -41,16 +41,13 @@ 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_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
return "";
}
void BinarySensor::add_filter(Filter *filter) {
filter->parent_ = this;

View File

@@ -80,14 +80,6 @@ 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

View File

@@ -1,6 +1,6 @@
#include "bme680.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.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);

View File

@@ -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");

View File

@@ -324,6 +324,10 @@ async def setup_climate_core_(var, config):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_CONTROL, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
async def register_climate(var, config):
if not CORE.has_id(config[CONF_ID]):

View File

@@ -208,14 +208,10 @@ Cover::Cover() : Cover("") {}
std::string Cover::get_device_class() {
if (this->device_class_override_.has_value())
return *this->device_class_override_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
return "";
}
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();

View File

@@ -170,12 +170,6 @@ 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_{};

View File

@@ -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;
}

View File

@@ -33,7 +33,10 @@ 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 = std::sqrt(rms_ac_dc_squared - rms_dc * rms_dc);
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);
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);

View File

@@ -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();

View File

@@ -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];

View File

@@ -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);

View File

@@ -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);

View File

@@ -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); }

View File

@@ -12,8 +12,6 @@ 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)

View File

@@ -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_,

View File

@@ -45,10 +45,11 @@ 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_; }

View File

@@ -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);
}
}

View File

@@ -55,6 +55,22 @@ 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 = {
@@ -140,7 +156,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.one_of(20e6, 10e6)
cv.frequency, cv.Range(min=10e6, max=20e6)
),
}
),

View File

@@ -91,6 +91,30 @@ 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;
}
@@ -257,6 +281,30 @@ 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; }

View File

@@ -29,6 +29,14 @@ 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 {

View File

@@ -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;
}

View File

@@ -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; }

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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_);
}

View File

@@ -1,8 +1,8 @@
#include "ili9xxx_display.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.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));
}

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -52,25 +52,26 @@ 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

View File

@@ -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:

View File

@@ -7,6 +7,7 @@ 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"
@@ -67,6 +68,7 @@ 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"))
@@ -91,6 +93,7 @@ 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(

View File

@@ -261,13 +261,21 @@ 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
b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits
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
}
}
} else if (this->orientation_ == 1) {
b = pixels[col];
} else if (this->orientation_ == 2) {
for (uint8_t i = 0; i < 8; i++) {
b |= ((pixels[i] >> (7 - col)) & 1) << i;
if (this->flip_x_) {
b |= ((pixels[i] >> (7 - col)) & 1) << (7 - i);
} else {
b |= ((pixels[i] >> (7 - col)) & 1) << i;
}
}
} else {
b = pixels[7 - col];

View File

@@ -67,6 +67,7 @@ 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]);
@@ -108,6 +109,7 @@ 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_;

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -123,7 +123,8 @@ 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; }

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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++;

View File

@@ -264,13 +264,52 @@ 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 PM2.5 Concentration: %u µg/m^3, Temperature: %.1f°C, Humidity: %.1f%%", pm_2_5_concentration,
temperature, humidity);
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);
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)

View File

@@ -55,9 +55,9 @@ PMSX003_TYPES = {
}
SENSORS_TO_TYPE = {
CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_2_5: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_TEMPERATURE: [TYPE_PMS5003T, TYPE_PMS5003ST],
CONF_HUMIDITY: [TYPE_PMS5003T, TYPE_PMS5003ST],
CONF_FORMALDEHYDE: [TYPE_PMS5003ST, TYPE_PMS5003S],

View File

@@ -1,5 +1,6 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/modbus/modbus.h"

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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; }

View File

@@ -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();

View File

@@ -194,6 +194,7 @@ 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_(
@@ -365,6 +366,11 @@ 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(
@@ -466,9 +472,21 @@ async def lambda_filter_to_code(config, filter_id):
return cg.new_Pvariable(filter_id, lambda_)
@FILTER_REGISTRY.register("delta", DeltaFilter, cv.float_)
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)
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)

View File

@@ -74,6 +74,19 @@ 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) {}
@@ -315,19 +328,23 @@ optional<float> ThrottleFilter::new_value(float value) {
}
// DeltaFilter
DeltaFilter::DeltaFilter(float min_delta) : min_delta_(min_delta), last_value_(NAN) {}
DeltaFilter::DeltaFilter(float delta, bool percentage_mode)
: delta_(delta), current_delta_(delta), percentage_mode_(percentage_mode), 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_)) {
return this->last_value_ = value;
}
if (fabsf(value - this->last_value_) >= this->min_delta_) {
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_);
}
return this->last_value_ = value;
}
return {};

View File

@@ -102,6 +102,24 @@ 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>.
@@ -325,12 +343,14 @@ class HeartbeatFilter : public Filter, public Component {
class DeltaFilter : public Filter {
public:
explicit DeltaFilter(float min_delta);
explicit DeltaFilter(float delta, bool percentage_mode);
optional<float> new_value(float value) override;
protected:
float min_delta_;
float delta_;
float current_delta_;
bool percentage_mode_;
float last_value_{NAN};
};

View File

@@ -26,48 +26,32 @@ Sensor::Sensor() : Sensor("") {}
std::string Sensor::get_unit_of_measurement() {
if (this->unit_of_measurement_.has_value())
return *this->unit_of_measurement_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->unit_of_measurement();
#pragma GCC diagnostic pop
return "";
}
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_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->accuracy_decimals();
#pragma GCC diagnostic pop
return 0;
}
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_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->device_class();
#pragma GCC diagnostic pop
return "";
}
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_;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return this->state_class();
#pragma GCC diagnostic pop
return StateClass::STATE_CLASS_NONE;
}
StateClass Sensor::state_class() { return StateClass::STATE_CLASS_NONE; }
void Sensor::publish_state(float state) {
this->raw_state = state;

View File

@@ -150,40 +150,15 @@ class Sensor : public EntityBase {
/// Return whether this sensor has gotten a full state (that passed through all filters) yet.
bool has_state() const;
/** 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
/** Override this method to set the unique ID of this sensor.
*
* @return The unique id as a string.
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
*/
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.

View File

@@ -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

View File

@@ -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) {

View File

@@ -17,6 +17,7 @@ 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(
@@ -25,6 +26,7 @@ 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),
@@ -39,6 +41,7 @@ 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))

View File

@@ -25,7 +25,7 @@ void SPIComponent::setup() {
this->clk_->digital_write(true);
#ifdef USE_SPI_ARDUINO_BACKEND
bool use_hw_spi = true;
bool use_hw_spi = !this->force_sw_;
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;

View File

@@ -74,6 +74,7 @@ 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;
@@ -260,6 +261,7 @@ 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

View File

@@ -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+

View File

@@ -1,26 +1,35 @@
from esphome import pins
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import light
from esphome.const import CONF_OUTPUT_ID, CONF_PIN
from esphome.components import light, output
from esphome.const import CONF_OUTPUT, 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 = light.BINARY_LIGHT_SCHEMA.extend(
{
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(StatusLEDLightOutput),
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
}
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),
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
pin = await cg.gpio_pin_expression(config[CONF_PIN])
cg.add(var.set_pin(pin))
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))
await cg.register_component(var, config)
# cg.add(cg.App.register_component(var))
await light.register_light(var, config)

View File

@@ -15,10 +15,10 @@ void StatusLEDLightOutput::loop() {
}
if ((new_state & STATUS_LED_ERROR) != 0u) {
this->pin_->digital_write(millis() % 250u < 150u);
this->output_state_(millis() % 250u < 150u);
this->last_app_state_ = new_state;
} else if ((new_state & STATUS_LED_WARNING) != 0u) {
this->pin_->digital_write(millis() % 1500u < 250u);
this->output_state_(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,17 +26,16 @@ void StatusLEDLightOutput::loop() {
if (lightstate_)
lightstate_->current_values_as_binary(&state);
this->pin_->digital_write(state);
this->last_app_state_ = new_state;
ESP_LOGD(TAG, "Restoring light state %s", ONOFF(state));
this->output_state_(state);
this->last_app_state_ = new_state;
}
}
void StatusLEDLightOutput::setup_state(light::LightState *state) {
lightstate_ = state;
ESP_LOGD(TAG, "'%s': Setting initital state", state->get_name().c_str());
ESP_LOGD(TAG, "'%s': Setting initial state", state->get_name().c_str());
this->write_state(state);
}
@@ -47,16 +46,18 @@ 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...");
this->pin_->setup();
this->pin_->digital_write(false);
if (this->pin_ != nullptr) {
this->pin_->setup();
this->pin_->digital_write(false);
}
}
void StatusLEDLightOutput::dump_config() {
@@ -64,5 +65,12 @@ 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

View File

@@ -3,6 +3,7 @@
#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 {
@@ -10,6 +11,7 @@ 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();
@@ -31,9 +33,11 @@ class StatusLEDLightOutput : public light::LightOutput, public Component {
float get_loop_priority() const override { return 50.0f; }
protected:
GPIOPin *pin_;
GPIOPin *pin_{nullptr};
output::BinaryOutput *output_{nullptr};
light::LightState *lightstate_{};
uint32_t last_app_state_{0xFFFF};
void output_state_(bool state);
};
} // namespace status_led

View File

@@ -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);
}
};

View File

@@ -287,7 +287,7 @@ void TCS34725Component::update() {
}
// calculate register value from timing
uint8_t regval_atime = (uint8_t)(256.f - integration_time_next / 2.4f);
uint8_t regval_atime = (uint8_t) (256.f - integration_time_next / 2.4f);
ESP_LOGD(TAG, "Integration time: %.1fms, ideal: %.1fms regval_new %d Gain: %.f Clear channel raw: %d gain reg: %d",
this->integration_time_, integration_time_next, regval_atime, this->gain_, raw_c, this->gain_reg_);

View File

@@ -61,6 +61,10 @@ class TextSensor : public EntityBase {
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
/** Override this method to set the unique ID of this sensor.
*
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
*/
virtual std::string unique_id();
bool has_state();

View File

@@ -168,7 +168,7 @@ uint8_t TM1637Display::get_keys() {
// Bit | 7 6 5 4 3 2 1 0
// ------+------------------------
// To | 0 0 0 0 K2 S2 S1 S0
key_code = (uint8_t)((key_code & 0x80) >> 7 | (key_code & 0x40) >> 5 | (key_code & 0x20) >> 3 | (key_code & 0x08));
key_code = (uint8_t) ((key_code & 0x80) >> 7 | (key_code & 0x40) >> 5 | (key_code & 0x20) >> 3 | (key_code & 0x08));
}
return key_code;
}

View File

@@ -140,7 +140,7 @@ void TM1638Component::set_intensity(uint8_t brightness_level) {
this->send_command_(TM1638_REGISTER_FIXEDADDRESS);
if (brightness_level > 0) {
this->send_command_((uint8_t)(TM1638_REGISTER_DISPLAYON | intensity_));
this->send_command_((uint8_t) (TM1638_REGISTER_DISPLAYON | intensity_));
} else {
this->send_command_(TM1638_REGISTER_DISPLAYOFF);
}

View File

@@ -381,8 +381,8 @@ void Tuya::handle_datapoints_(const uint8_t *buffer, size_t len) {
}
void Tuya::send_raw_command_(TuyaCommand command) {
uint8_t len_hi = (uint8_t)(command.payload.size() >> 8);
uint8_t len_lo = (uint8_t)(command.payload.size() & 0xFF);
uint8_t len_hi = (uint8_t) (command.payload.size() >> 8);
uint8_t len_lo = (uint8_t) (command.payload.size() & 0xFF);
uint8_t version = 0;
this->last_command_timestamp_ = millis();

View File

@@ -12,7 +12,7 @@ static inline uint16_t get_u16(std::vector<uint8_t> &message, int start) {
}
static inline int16_t get_i16(std::vector<uint8_t> &message, int start) {
return (int16_t)((message[start + 1] << 8) + message[start]);
return (int16_t) ((message[start + 1] << 8) + message[start]);
}
void DeltaSolBSPlusSensor::dump_config() {

View File

@@ -88,7 +88,7 @@ void VL53L0XSensor::setup() {
this->timeout_start_us_ = micros();
while (reg(0x83).get() == 0x00) {
if (this->timeout_us_ > 0 && ((uint16_t)(micros() - this->timeout_start_us_) > this->timeout_us_)) {
if (this->timeout_us_ > 0 && ((uint16_t) (micros() - this->timeout_start_us_) > this->timeout_us_)) {
ESP_LOGE(TAG, "'%s' - setup timeout", this->name_.c_str());
this->mark_failed();
return;

View File

@@ -29,6 +29,7 @@ WaveshareEPaper2P7In = waveshare_epaper_ns.class_(
WaveshareEPaper2P9InB = waveshare_epaper_ns.class_(
"WaveshareEPaper2P9InB", WaveshareEPaper
)
GDEY029T94 = waveshare_epaper_ns.class_("GDEY029T94", WaveshareEPaper)
WaveshareEPaper4P2In = waveshare_epaper_ns.class_(
"WaveshareEPaper4P2In", WaveshareEPaper
)
@@ -73,6 +74,7 @@ MODELS = {
"2.13in-ttgo-b74": ("a", WaveshareEPaperTypeAModel.TTGO_EPAPER_2_13_IN_B74),
"2.90in": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
"2.90inv2": ("a", WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN_V2),
"gdey029t94": ("c", GDEY029T94),
"2.70in": ("b", WaveshareEPaper2P7In),
"2.90in-b": ("b", WaveshareEPaper2P9InB),
"4.20in": ("b", WaveshareEPaper4P2In),

View File

@@ -663,6 +663,90 @@ void WaveshareEPaper2P9InB::dump_config() {
LOG_UPDATE_INTERVAL(this);
}
// ========================================================
// Good Display 2.9in black/white/grey
// Datasheet:
// - https://v4.cecdn.yun300.cn/100001_1909185148/SSD1680.pdf
// - https://github.com/adafruit/Adafruit_EPD/blob/master/src/panels/ThinkInk_290_Grayscale4_T5.h
// ========================================================
void GDEY029T94::initialize() {
// from https://www.waveshare.com/w/upload/b/bb/2.9inch-e-paper-b-specification.pdf, page 37
// EPD hardware init start
this->reset_();
// COMMAND POWER SETTINGS
this->command(0x00);
this->data(0x03);
this->data(0x00);
this->data(0x2b);
this->data(0x2b);
this->data(0x03); /* for b/w */
// COMMAND BOOSTER SOFT START
this->command(0x06);
this->data(0x17);
this->data(0x17);
this->data(0x17);
// COMMAND POWER ON
this->command(0x04);
this->wait_until_idle_();
// Not sure what this does but it's in the Adafruit EPD library
this->command(0xFF);
this->wait_until_idle_();
// COMMAND PANEL SETTING
this->command(0x00);
// 128x296 resolution: 10
// LUT from OTP: 0
// B/W mode (doesn't work): 1
// scan-up: 1
// shift-right: 1
// booster ON: 1
// no soft reset: 1
this->data(0b10011111);
// COMMAND RESOLUTION SETTING
// set to 128x296 by COMMAND PANEL SETTING
// COMMAND VCOM AND DATA INTERVAL SETTING
// use defaults for white border and ESPHome image polarity
// EPD hardware init end
}
void HOT GDEY029T94::display() {
// COMMAND DATA START TRANSMISSION 2 (B/W only)
this->command(0x13);
delay(2);
this->start_data_();
for (size_t i = 0; i < this->get_buffer_length_(); i++) {
this->write_byte(this->buffer_[i]);
}
this->end_data_();
delay(2);
// COMMAND DISPLAY REFRESH
this->command(0x12);
delay(2);
this->wait_until_idle_();
// COMMAND POWER OFF
// NOTE: power off < deep sleep
this->command(0x02);
}
int GDEY029T94::get_width_internal() { return 128; }
int GDEY029T94::get_height_internal() { return 296; }
void GDEY029T94::dump_config() {
LOG_DISPLAY("", "Waveshare E-Paper (Good Display)", this);
ESP_LOGCONFIG(TAG, " Model: 2.9in Greyscale GDEY029T94");
LOG_PIN(" Reset Pin: ", this->reset_pin_);
LOG_PIN(" DC Pin: ", this->dc_pin_);
LOG_PIN(" Busy Pin: ", this->busy_pin_);
LOG_UPDATE_INTERVAL(this);
}
static const uint8_t LUT_VCOM_DC_4_2[] = {
0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00, 0x02, 0x00, 0x0A, 0x01,
0x00, 0x00, 0x01, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

View File

@@ -146,6 +146,26 @@ class WaveshareEPaper2P7In : public WaveshareEPaper {
int get_height_internal() override;
};
class GDEY029T94 : public WaveshareEPaper {
public:
void initialize() override;
void display() override;
void dump_config() override;
void deep_sleep() override {
// COMMAND DEEP SLEEP
this->command(0x07);
this->data(0xA5); // check byte
}
protected:
int get_width_internal() override;
int get_height_internal() override;
};
class WaveshareEPaper2P9InB : public WaveshareEPaper {
public:
void initialize() override;

View File

@@ -867,7 +867,7 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url
}
// Longest: HORIZONTAL
#define PSTR_LOCAL(mode_s) strncpy_P(__buf, (PGM_P)((mode_s)), 15)
#define PSTR_LOCAL(mode_s) strncpy_P(__buf, (PGM_P) ((mode_s)), 15)
std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_config) {
return json::build_json([obj, start_config](JsonObject root) {

View File

@@ -78,7 +78,7 @@ void WhirlpoolClimate::transmit_state() {
// Temperature
auto temp = (uint8_t) roundf(clamp(this->target_temperature, this->temperature_min_(), this->temperature_max_()));
remote_state[3] |= (uint8_t)(temp - this->temperature_min_()) << 4;
remote_state[3] |= (uint8_t) (temp - this->temperature_min_()) << 4;
// Fan speed
switch (this->fan_mode.value()) {

View File

@@ -239,12 +239,12 @@ bool decrypt_xiaomi_payload(std::vector<uint8_t> &raw, const uint8_t *bindkey, c
}
uint8_t mac_reverse[6] = {0};
mac_reverse[5] = (uint8_t)(address >> 40);
mac_reverse[4] = (uint8_t)(address >> 32);
mac_reverse[3] = (uint8_t)(address >> 24);
mac_reverse[2] = (uint8_t)(address >> 16);
mac_reverse[1] = (uint8_t)(address >> 8);
mac_reverse[0] = (uint8_t)(address >> 0);
mac_reverse[5] = (uint8_t) (address >> 40);
mac_reverse[4] = (uint8_t) (address >> 32);
mac_reverse[3] = (uint8_t) (address >> 24);
mac_reverse[2] = (uint8_t) (address >> 16);
mac_reverse[1] = (uint8_t) (address >> 8);
mac_reverse[0] = (uint8_t) (address >> 0);
XiaomiAESVector vector{.key = {0},
.plaintext = {0},

View File

@@ -104,8 +104,8 @@ void XPT2046Component::check_touch_() {
break;
}
touchpoint.x = (int16_t)((int) touchpoint.x * this->display_->get_width() / 0xfff);
touchpoint.y = (int16_t)((int) touchpoint.y * this->display_->get_height() / 0xfff);
touchpoint.x = (int16_t) ((int) touchpoint.x * this->display_->get_width() / 0xfff);
touchpoint.y = (int16_t) ((int) touchpoint.y * this->display_->get_height() / 0xfff);
if (!this->touched || (now - this->last_pos_ms_) >= this->report_millis_) {
ESP_LOGV(TAG, "Touching at [%03X, %03X] => [%3d, %3d]", this->x_raw, this->y_raw, touchpoint.x, touchpoint.y);
@@ -185,7 +185,7 @@ int16_t XPT2046Component::normalize(int16_t val, int16_t min_val, int16_t max_va
} else if (val >= max_val) {
ret = 0xfff;
} else {
ret = (int16_t)((int) 0xfff * (val - min_val) / (max_val - min_val));
ret = (int16_t) ((int) 0xfff * (val - min_val) / (max_val - min_val));
}
return ret;

View File

@@ -211,6 +211,9 @@ RESERVED_IDS = [
"open",
"setup",
"loop",
"uart0",
"uart1",
"uart2",
]
@@ -1097,7 +1100,7 @@ def possibly_negative_percentage(value):
if isinstance(value, str):
try:
if value.endswith("%"):
has_percent_sign = False
has_percent_sign = True
value = float(value[:-1].rstrip()) / 100.0
else:
value = float(value)

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2023.3.0"
__version__ = "2023.4.0-dev"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"

View File

@@ -409,6 +409,9 @@ class Define:
return self.as_tuple == other.as_tuple
return NotImplemented
def __str__(self):
return f"{self.name}={self.value}"
class Library:
def __init__(self, name, version, repository=None):

View File

@@ -23,8 +23,13 @@ bool EntityBase::is_disabled_by_default() const { return this->disabled_by_defau
void EntityBase::set_disabled_by_default(bool disabled_by_default) { this->disabled_by_default_ = disabled_by_default; }
// Entity Icon
const std::string &EntityBase::get_icon() const { return this->icon_; }
void EntityBase::set_icon(const std::string &name) { this->icon_ = name; }
std::string EntityBase::get_icon() const {
if (this->icon_c_str_ == nullptr) {
return "";
}
return this->icon_c_str_;
}
void EntityBase::set_icon(const char *icon) { this->icon_c_str_ = icon; }
// Entity Category
EntityCategory EntityBase::get_entity_category() const { return this->entity_category_; }

View File

@@ -42,8 +42,8 @@ class EntityBase {
void set_entity_category(EntityCategory entity_category);
// Get/set this entity's icon
const std::string &get_icon() const;
void set_icon(const std::string &name);
std::string get_icon() const;
void set_icon(const char *icon);
protected:
/// The hash_base() function has been deprecated. It is kept in this
@@ -53,7 +53,7 @@ class EntityBase {
std::string name_;
std::string object_id_;
std::string icon_;
const char *icon_c_str_{nullptr};
uint32_t object_id_hash_;
bool internal_{false};
bool disabled_by_default_{false};

View File

@@ -415,8 +415,23 @@ IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(state_); }
IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); }
#elif defined(USE_RP2040)
IRAM_ATTR InterruptLock::InterruptLock() { state_ = save_and_disable_interrupts(); }
IRAM_ATTR InterruptLock::~InterruptLock() { restore_interrupts(state_); }
IRAM_ATTR InterruptLock::InterruptLock() {
auto core = get_core_num();
if (this->stack_top_[core] == STACK_SIZE) {
panic("InterruptLock stack overflow");
}
uint8_t stack_top = this->stack_top_[core]++;
state_stack_[core][stack_top] = save_and_disable_interrupts();
}
IRAM_ATTR InterruptLock::~InterruptLock() {
auto core = get_core_num();
if (!this->stack_top_[core]) {
return; // No state to restore
}
uint8_t stack_top = --this->stack_top_[core];
uint32_t state = this->state_stack_[core][stack_top];
restore_interrupts(state);
}
#endif
uint8_t HighFrequencyLoopRequester::num_requests = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

View File

@@ -583,8 +583,12 @@ class InterruptLock {
~InterruptLock();
protected:
#if defined(USE_ESP8266) || defined(USE_RP2040)
#if defined(USE_ESP8266)
uint32_t state_;
#elif defined(USE_RP2040)
static const uint8_t STACK_SIZE = 15;
uint8_t stack_top_[2] = {0, 0};
uint32_t state_stack_[2][STACK_SIZE];
#endif
};

View File

@@ -167,7 +167,7 @@ struct LogString;
#include <pgmspace.h>
#if USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 5, 0)
#define LOG_STR_ARG(s) ((PGM_P)(s))
#define LOG_STR_ARG(s) ((PGM_P) (s))
#else
// Pre-Arduino 2.5, we can't pass a PSTR() to printf(). Emulate support by copying the message to a
// local buffer first. String length is limited to 63 characters.
@@ -176,7 +176,7 @@ struct LogString;
({ \
char __buf[64]; \
__buf[63] = '\0'; \
strncpy_P(__buf, (PGM_P)(s), 63); \
strncpy_P(__buf, (PGM_P) (s), 63); \
__buf; \
})
#endif

View File

@@ -47,7 +47,7 @@ FILTER_PLATFORMIO_LINES = [
r"CONFIGURATION: https://docs.platformio.org/.*",
r"DEBUG: Current.*",
r"LDF Modes:.*",
r"LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf.*",
r"LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf.*",
f"Looking for {IGNORE_LIB_WARNINGS} library in registry",
f"Warning! Library `.*'{IGNORE_LIB_WARNINGS}.*` has not been found in PlatformIO Registry.",
f"You can ignore this message, if `.*{IGNORE_LIB_WARNINGS}.*` is a built-in library.*",

View File

@@ -10,7 +10,7 @@ platformio==6.1.6 # When updating platformio, also update Dockerfile
esptool==4.5.1
click==8.1.3
esphome-dashboard==20230214.0
aioesphomeapi==13.5.0
aioesphomeapi==13.5.1
zeroconf==0.47.3
# esp-idf requires this, but doesn't bundle it by default

View File

@@ -17,7 +17,7 @@ def run_format(args, queue, lock, failed_files):
"""Takes filenames out of queue and runs clang-format on them."""
while True:
path = queue.get()
invocation = ["clang-format-11"]
invocation = ["clang-format-13"]
if args.inplace:
invocation.append("-i")
else:
@@ -59,14 +59,14 @@ def main():
args = parser.parse_args()
try:
get_output("clang-format-11", "-version")
get_output("clang-format-13", "-version")
except:
print(
"""
Oops. It looks like clang-format is not installed.
Please check you can run "clang-format-11 -version" in your terminal and install
clang-format (v11) if necessary.
Please check you can run "clang-format-13 -version" in your terminal and install
clang-format (v13) if necessary.
Note you can also upload your code as a pull request on GitHub and see the CI check
output to apply clang-format.

View File

@@ -161,13 +161,13 @@ mqtt:
id: ${roomname}_lights
relative_brightness: 5%
- uart.write:
id: uart0
id: uart_0
data: Hello World
- uart.write:
id: uart0
id: uart_0
data: [0x00, 0x20, 0x30]
- uart.write:
id: uart0
id: uart_0
data: !lambda |-
return {};
on_connect:
@@ -199,7 +199,7 @@ uart:
number: GPIO23
inverted: true
baud_rate: 115200
id: uart0
id: uart_0
parity: NONE
data_bits: 8
stop_bits: 1
@@ -325,7 +325,7 @@ mcp23s17:
sensor:
- platform: internal_temperature
name: "Internal Temperature"
name: Internal Temperature
- platform: ble_client
type: characteristic
ble_client_id: ble_foo
@@ -392,6 +392,7 @@ sensor:
- heartbeat: 5s
- debounce: 0.1s
- delta: 5.0
- delta: 1%
- or:
- throttle: 1s
- delta: 5.0
@@ -789,7 +790,7 @@ sensor:
reference_resistance: 430 Ω
rtd_nominal_resistance: 100 Ω
- platform: mhz19
uart_id: uart0
uart_id: uart_0
co2:
name: MH-Z19 CO2 Value
temperature:
@@ -929,7 +930,7 @@ sensor:
name: Pulse Width
pin: GPIO12
- platform: sm300d2
uart_id: uart0
uart_id: uart_0
co2:
name: SM300D2 CO2 Value
formaldehyde:
@@ -1121,7 +1122,7 @@ sensor:
root["key"] = id(the_sensor).state;
root["greeting"] = "Hello World";
- platform: sds011
uart_id: uart0
uart_id: uart_0
pm_2_5:
name: SDS011 PM2.5
pm_10_0:
@@ -2093,7 +2094,7 @@ climate:
on_state:
logger.log: State changed!
id: midea_unit
uart_id: uart0
uart_id: uart_0
name: Midea Climate
transmitter_id:
period: 1s
@@ -2418,15 +2419,15 @@ switch:
id: my_switch
state: !lambda "return false;"
- platform: uart
uart_id: uart0
uart_id: uart_0
name: UART String Output
data: DataToSend
- platform: uart
uart_id: uart0
uart_id: uart_0
name: UART Bytes Output
data: [0xDE, 0xAD, 0xBE, 0xEF]
- platform: uart
uart_id: uart0
uart_id: uart_0
name: UART Recurring Output
data: [0xDE, 0xAD, 0xBE, 0xEF]
send_every: 1s
@@ -2774,7 +2775,7 @@ pn532_i2c:
i2c_id: i2c_bus
rdm6300:
uart_id: uart0
uart_id: uart_0
rc522_spi:
cs_pin: GPIO23
@@ -2803,7 +2804,7 @@ mcp4728:
i2c_id: i2c_bus
gps:
uart_id: uart0
uart_id: uart_0
time:
- platform: sntp
@@ -3123,7 +3124,7 @@ canbus:
teleinfo:
id: myteleinfo
uart_id: uart0
uart_id: uart_0
update_interval: 60s
historical_mode: true
@@ -3241,25 +3242,25 @@ lcd_menu:
lambda: 'ESP_LOGI("lcd_menu", "root leave");'
items:
- type: back
text: 'Back'
text: Back
- type: label
- type: menu
text: 'Submenu 1'
text: Submenu 1
items:
- type: back
text: 'Back'
text: Back
- type: menu
text: 'Submenu 21'
text: Submenu 21
items:
- type: back
text: 'Back'
text: Back
- type: command
text: 'Show Main'
text: Show Main
on_value:
then:
- display_menu.show_main:
- type: select
text: 'Enum Item'
text: Enum Item
immediate_edit: true
select: test_select
on_enter:
@@ -3272,7 +3273,7 @@ lcd_menu:
then:
lambda: 'ESP_LOGI("lcd_menu", "select value: %s, %s", it->get_text().c_str(), it->get_value_text().c_str());'
- type: number
text: 'Number'
text: Number
number: test_number
on_enter:
then:
@@ -3284,15 +3285,15 @@ lcd_menu:
then:
lambda: 'ESP_LOGI("lcd_menu", "number value: %s, %s", it->get_text().c_str(), it->get_value_text().c_str());'
- type: command
text: 'Hide'
text: Hide
on_value:
then:
- display_menu.hide:
- type: switch
text: 'Switch'
text: Switch
switch: my_switch
on_text: 'Bright'
off_text: 'Dark'
on_text: Bright
off_text: Dark
immediate_edit: false
on_value:
then:

View File

@@ -399,7 +399,7 @@ sensor:
time:
- platform: homeassistant
on_time:
- at: '16:00:00'
- at: "16:00:00"
then:
- logger.log: It's 16:00
@@ -518,7 +518,6 @@ ble_client:
- mac_address: 01:02:03:04:05:06
id: radon_eye_ble_id
airthings_ble:
radon_eye_ble:
@@ -535,7 +534,7 @@ bluetooth_proxy:
xiaomi_rtcgq02lm:
- id: motion_rtcgq02lm
mac_address: 01:02:03:04:05:06
bindkey: '48403ebe2d385db8d0c187f81e62cb64'
bindkey: "48403ebe2d385db8d0c187f81e62cb64"
status_led:
pin: GPIO2

600
tests/test3.1.yaml Normal file
View File

@@ -0,0 +1,600 @@
---
esphome:
name: $device_name
comment: $device_comment
build_path: build/test3.1
includes:
- custom.h
esp8266:
board: d1_mini
substitutions:
device_name: test3-1
device_comment: test3-1 device
min_sub: "0.03"
max_sub: "12.0%"
api:
wifi:
ssid: "MySSID"
password: "password1"
i2c:
sda: 4
scl: 5
scan: false
spi:
clk_pin: GPIO12
mosi_pin: GPIO13
miso_pin: GPIO14
ota:
logger:
sensor:
- platform: apds9960
type: proximity
name: APDS9960 Proximity
- platform: vl53l0x
name: VL53L0x Distance
address: 0x29
update_interval: 60s
enable_pin: GPIO13
timeout: 200us
- platform: apds9960
type: clear
name: APDS9960 Clear
- platform: apds9960
type: red
name: APDS9960 Red
- platform: apds9960
type: green
name: APDS9960 Green
- platform: apds9960
type: blue
name: APDS9960 Blue
- platform: aht10
temperature:
name: Temperature
humidity:
name: Humidity
- platform: am2320
temperature:
name: Temperature
humidity:
name: Humidity
- platform: adc
pin: VCC
id: my_sensor
filters:
- offset: 5.0
- multiply: 2.0
- filter_out: NAN
- sliding_window_moving_average:
- exponential_moving_average:
- quantile:
window_size: 5
send_every: 5
send_first_at: 3
quantile: .8
- lambda: "return 0;"
- delta: 100
- throttle: 100ms
- debounce: 500s
- calibrate_linear:
- 0 -> 0
- 100 -> 100
- calibrate_polynomial:
degree: 3
datapoints:
- 0 -> 0
- 100 -> 200
- 400 -> 500
- -50 -> -1000
- -100 -> -10000
- platform: cd74hc4067
id: cd74hc4067_0
number: 0
sensor: my_sensor
- platform: resistance
sensor: my_sensor
configuration: DOWNSTREAM
resistor: 10kΩ
reference_voltage: 3.3V
name: Resistance
id: resist
- platform: ntc
sensor: resist
name: NTC Sensor
calibration:
b_constant: 3950
reference_resistance: 10k
reference_temperature: 25°C
- platform: ntc
sensor: resist
name: NTC Sensor2
calibration:
- 10.0kOhm -> 25°C
- 27.219kOhm -> 0°C
- 14.674kOhm -> 15°C
- platform: ct_clamp
sensor: my_sensor
name: CT Clamp
sample_duration: 500ms
update_interval: 5s
- platform: tcs34725
red_channel:
name: Red Channel
green_channel:
name: Green Channel
blue_channel:
name: Blue Channel
clear_channel:
name: Clear Channel
illuminance:
name: Illuminance
color_temperature:
name: Color Temperature
integration_time: 614ms
gain: 60x
- platform: custom
lambda: |-
auto s = new CustomSensor();
App.register_component(s);
return {s};
sensors:
- id: custom_sensor
name: Custom Sensor
- platform: ade7953
irq_pin: GPIO16
voltage:
name: ADE7953 Voltage
id: ade7953_voltage
current_a:
name: ADE7953 Current A
id: ade7953_current_a
current_b:
name: ADE7953 Current B
id: ade7953_current_b
active_power_a:
name: ADE7953 Active Power A
id: ade7953_active_power_a
active_power_b:
name: ADE7953 Active Power B
id: ade7953_active_power_b
- platform: tmp102
name: TMP102 Temperature
- platform: hm3301
pm_1_0:
name: PM1.0
pm_2_5:
name: PM2.5
pm_10_0:
name: PM10.0
aqi:
name: AQI
calculation_type: AQI
- platform: ezo
id: ph_ezo
address: 99
unit_of_measurement: pH
- platform: tof10120
name: Distance sensor
update_interval: 5s
- platform: mlx90393
oversampling: 1
filter: 0
gain: 3X
x_axis:
name: mlxxaxis
y_axis:
name: mlxyaxis
z_axis:
name: mlxzaxis
resolution: 17BIT
temperature:
name: mlxtemp
oversampling: 2
- platform: adc128s102
id: adc128s102_channel_0
channel: 0
apds9960:
address: 0x20
update_interval: 60s
mpr121:
id: mpr121_first
address: 0x5A
binary_sensor:
- platform: apds9960
direction: up
name: APDS9960 Up
device_class: motion
filters:
- invert
- delayed_on: 20ms
- delayed_off: 20ms
- lambda: "return false;"
on_state:
- logger.log: New state
id: my_binary_sensor
- platform: apds9960
direction: down
name: APDS9960 Down
- platform: apds9960
direction: left
name: APDS9960 Left
- platform: apds9960
direction: right
name: APDS9960 Right
- platform: mpr121
id: touchkey0
channel: 0
name: touchkey0
- platform: mpr121
channel: 1
name: touchkey1
id: bin1
- platform: mpr121
channel: 2
name: touchkey2
id: bin2
- platform: mpr121
channel: 3
name: touchkey3
id: bin3
on_press:
then:
- switch.toggle: mpr121_toggle
- platform: ttp229_lsf
channel: 1
name: TTP229 LSF Test
- platform: ttp229_bsf
channel: 1
name: TTP229 BSF Test
- platform: custom
lambda: |-
auto s = new CustomBinarySensor();
App.register_component(s);
return {s};
binary_sensors:
- id: custom_binary_sensor
name: Custom Binary Sensor
- platform: template
id: cover_toggle
on_press:
then:
- cover.toggle: time_based_cover
- cover.toggle: endstop_cover
- cover.toggle: current_based_cover
globals:
- id: my_global_string
type: std::string
initial_value: '""'
text_sensor:
- platform: custom
lambda: |-
auto s = new CustomTextSensor();
App.register_component(s);
return {s};
text_sensors:
- id: custom_text_sensor
name: Custom Text Sensor
sm2135:
data_pin: GPIO12
clock_pin: GPIO14
switch:
- platform: template
name: mpr121_toggle
id: mpr121_toggle
optimistic: true
- platform: gpio
id: gpio_switch1
pin:
mcp23xxx: mcp23017_hub
number: 0
mode: OUTPUT
interlock: &interlock [gpio_switch1, gpio_switch2, gpio_switch3]
- platform: gpio
id: gpio_switch2
pin:
mcp23xxx: mcp23008_hub
number: 0
mode: OUTPUT
interlock: *interlock
- platform: gpio
id: gpio_switch3
pin: GPIO1
interlock: *interlock
- platform: custom
lambda: |-
auto s = new CustomSwitch();
return {s};
switches:
- id: custom_switch
name: Custom Switch
on_turn_on:
- http_request.get:
url: https://esphome.io
headers:
Content-Type: application/json
verify_ssl: false
- http_request.post:
url: https://esphome.io
verify_ssl: false
json:
key: !lambda |-
return id(custom_text_sensor).state;
greeting: Hello World
- http_request.send:
method: PUT
url: https://esphome.io
headers:
Content-Type: application/json
body: Some data
verify_ssl: false
custom_component:
lambda: |-
auto s = new CustomComponent();
s->set_update_interval(15000);
return {s};
stepper:
- platform: uln2003
id: my_stepper
pin_a: GPIO12
pin_b: GPIO13
pin_c: GPIO14
pin_d: GPIO15
sleep_when_done: false
step_mode: HALF_STEP
max_speed: 250 steps/s
acceleration: inf
deceleration: inf
- platform: a4988
id: my_stepper2
step_pin: GPIO1
dir_pin: GPIO2
max_speed: 0.1 steps/s
acceleration: 10 steps/s^2
deceleration: 10 steps/s^2
interval:
interval: 5s
then:
- logger.log: Interval Run
- stepper.set_target:
id: my_stepper2
target: 500
- stepper.set_target:
id: my_stepper
target: !lambda "return 0;"
- stepper.report_position:
id: my_stepper2
position: 0
- stepper.report_position:
id: my_stepper
position: !lambda "return 50/100.0;"
cover:
- platform: endstop
name: Endstop Cover
id: endstop_cover
stop_action:
- switch.turn_on: gpio_switch1
open_endstop: my_binary_sensor
open_action:
- switch.turn_on: gpio_switch1
open_duration: 5min
close_endstop: my_binary_sensor
close_action:
- switch.turn_on: gpio_switch2
- output.set_level:
id: out
level: 50%
- output.esp8266_pwm.set_frequency:
id: out
frequency: 500.0Hz
- output.esp8266_pwm.set_frequency:
id: out
frequency: !lambda "return 500.0;"
- servo.write:
id: my_servo
level: -100%
- servo.write:
id: my_servo
level: !lambda "return -1.0;"
- delay: 2s
- servo.detach: my_servo
close_duration: 4.5min
max_duration: 10min
- platform: time_based
name: Time Based Cover
id: time_based_cover
stop_action:
- switch.turn_on: gpio_switch1
open_action:
- switch.turn_on: gpio_switch1
open_duration: 5min
close_action:
- switch.turn_on: gpio_switch2
close_duration: 4.5min
- platform: current_based
name: Current Based Cover
id: current_based_cover
open_sensor: ade7953_current_a
open_moving_current_threshold: 0.5
open_obstacle_current_threshold: 0.8
open_duration: 12s
open_action:
- switch.turn_on: gpio_switch1
close_sensor: ade7953_current_b
close_moving_current_threshold: 0.5
close_obstacle_current_threshold: 0.8
close_duration: 10s
close_action:
- switch.turn_on: gpio_switch2
stop_action:
- switch.turn_off: gpio_switch1
- switch.turn_off: gpio_switch2
obstacle_rollback: 30%
start_sensing_delay: 0.8s
malfunction_detection: true
malfunction_action:
then:
- logger.log: Malfunction Detected
- platform: template
name: Template Cover with Tilt
tilt_lambda: "return 0.5;"
tilt_action:
- output.set_level:
id: out
level: !lambda "return tilt;"
position_action:
- output.set_level:
id: out
level: !lambda "return pos;"
output:
- platform: esp8266_pwm
id: out
pin: D3
frequency: 50Hz
- platform: esp8266_pwm
id: out2
pin: D4
- platform: custom
type: binary
lambda: |-
auto s = new CustomBinaryOutput();
App.register_component(s);
return {s};
outputs:
- id: custom_binary
- platform: sigma_delta_output
id: sddac
update_interval: 60s
pin: D4
turn_on_action:
then:
- logger.log: "Turned on"
turn_off_action:
then:
- logger.log: "Turned off"
state_change_action:
then:
- logger.log:
format: "Changed state: %d"
args: ["state"]
- platform: custom
type: float
lambda: |-
auto s = new CustomFloatOutput();
App.register_component(s);
return {s};
outputs:
- id: custom_float
- platform: slow_pwm
pin: GPIO5
id: my_slow_pwm
period: 15s
restart_cycle_on_state_change: false
- platform: sm2135
id: sm2135_0
channel: 0
- platform: sm2135
id: sm2135_1
channel: 1
- platform: sm2135
id: sm2135_2
channel: 2
- platform: sm2135
id: sm2135_3
channel: 3
- platform: sm2135
id: sm2135_4
channel: 4
mcp23017:
id: mcp23017_hub
mcp23008:
id: mcp23008_hub
light:
- platform: hbridge
name: Icicle Lights
pin_a: out
pin_b: out2
servo:
id: my_servo
output: out
restore: true
min_level: $min_sub
max_level: $max_sub
ttp229_lsf:
ttp229_bsf:
sdo_pin: D2
scl_pin: D1
display:
- platform: max7219digit
cs_pin: GPIO15
num_chips: 4
rotate_chip: 0
intensity: 10
scroll_mode: STOP
id: my_matrix
lambda: |-
it.printdigit("hello");
http_request:
useragent: esphome/device
timeout: 10s
button:
- platform: output
id: output_button
output: out
duration: 100ms
- platform: wake_on_lan
target_mac_address: 12:34:56:78:90:ab
name: wol_test_1
id: wol_1
- platform: factory_reset
name: Restart Button (Factory Default Settings)
cd74hc4067:
pin_s0: GPIO12
pin_s1: GPIO13
pin_s2: GPIO14
pin_s3: GPIO15
adc128s102:
cs_pin: GPIO12

File diff suppressed because it is too large Load Diff

View File

@@ -644,7 +644,6 @@ touchscreen:
format: Touch at (%d, %d)
args: [touch.x, touch.y]
- platform: lilygo_t5_47
id: lilygo_touchscreen
interrupt_pin: GPIO36

Some files were not shown because too many files have changed in this diff Show More