Merge branch 'dev' into nrf52_core

This commit is contained in:
tomaszduda23 2024-08-16 09:24:09 +02:00 committed by GitHub
commit c13a5b9eb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 139 additions and 10 deletions

View file

@ -169,6 +169,7 @@ esphome/components/he60r/* @clydebarrow
esphome/components/heatpumpir/* @rob-deutsch esphome/components/heatpumpir/* @rob-deutsch
esphome/components/hitachi_ac424/* @sourabhjaiswal esphome/components/hitachi_ac424/* @sourabhjaiswal
esphome/components/hm3301/* @freekode esphome/components/hm3301/* @freekode
esphome/components/hmac_md5/* @dwmw2
esphome/components/homeassistant/* @OttoWinter @esphome/core esphome/components/homeassistant/* @OttoWinter @esphome/core
esphome/components/homeassistant/number/* @landonr esphome/components/homeassistant/number/* @landonr
esphome/components/homeassistant/switch/* @Links2004 esphome/components/homeassistant/switch/* @Links2004

View file

@ -0,0 +1,2 @@
AUTO_LOAD = ["md5"]
CODEOWNERS = ["@dwmw2"]

View file

@ -0,0 +1,56 @@
#include <cstdio>
#include <cstring>
#include "hmac_md5.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace hmac_md5 {
void HmacMD5::init(const uint8_t *key, size_t len) {
uint8_t ipad[64], opad[64];
memset(ipad, 0, sizeof(ipad));
if (len > 64) {
md5::MD5Digest keymd5;
keymd5.init();
keymd5.add(key, len);
keymd5.calculate();
keymd5.get_bytes(ipad);
} else {
memcpy(ipad, key, len);
}
memcpy(opad, ipad, sizeof(opad));
for (int i = 0; i < 64; i++) {
ipad[i] ^= 0x36;
opad[i] ^= 0x5c;
}
this->ihash_.init();
this->ihash_.add(ipad, sizeof(ipad));
this->ohash_.init();
this->ohash_.add(opad, sizeof(opad));
}
void HmacMD5::add(const uint8_t *data, size_t len) { this->ihash_.add(data, len); }
void HmacMD5::calculate() {
uint8_t ibytes[16];
this->ihash_.calculate();
this->ihash_.get_bytes(ibytes);
this->ohash_.add(ibytes, sizeof(ibytes));
this->ohash_.calculate();
}
void HmacMD5::get_bytes(uint8_t *output) { this->ohash_.get_bytes(output); }
void HmacMD5::get_hex(char *output) { this->ohash_.get_hex(output); }
bool HmacMD5::equals_bytes(const uint8_t *expected) { return this->ohash_.equals_bytes(expected); }
bool HmacMD5::equals_hex(const char *expected) { return this->ohash_.equals_hex(expected); }
} // namespace hmac_md5
} // namespace esphome

View file

@ -0,0 +1,48 @@
#pragma once
#include "esphome/core/defines.h"
#include "esphome/components/md5/md5.h"
#include <string>
namespace esphome {
namespace hmac_md5 {
class HmacMD5 {
public:
HmacMD5() = default;
~HmacMD5() = default;
/// Initialize a new MD5 digest computation.
void init(const uint8_t *key, size_t len);
void init(const char *key, size_t len) { this->init((const uint8_t *) key, len); }
void init(const std::string &key) { this->init(key.c_str(), key.length()); }
/// Add bytes of data for the digest.
void add(const uint8_t *data, size_t len);
void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
/// Compute the digest, based on the provided data.
void calculate();
/// Retrieve the HMAC-MD5 digest as bytes.
/// The output must be able to hold 16 bytes or more.
void get_bytes(uint8_t *output);
/// Retrieve the HMAC-MD5 digest as hex characters.
/// The output must be able to hold 32 bytes or more.
void get_hex(char *output);
/// Compare the digest against a provided byte-encoded digest (16 bytes).
bool equals_bytes(const uint8_t *expected);
/// Compare the digest against a provided hex-encoded digest (32 bytes).
bool equals_hex(const char *expected);
protected:
md5::MD5Digest ihash_;
md5::MD5Digest ohash_;
};
} // namespace hmac_md5
} // namespace esphome

View file

@ -41,29 +41,29 @@ class ESPColorCorrection {
if (this->max_brightness_.red == 0 || this->local_brightness_ == 0) if (this->max_brightness_.red == 0 || this->local_brightness_ == 0)
return 0; return 0;
uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL; uint16_t uncorrected = this->gamma_reverse_table_[red] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_; uint16_t res = ((uncorrected / this->max_brightness_.red) * 255UL) / this->local_brightness_;
return res; return (uint8_t) std::min(res, uint16_t(255));
} }
inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE { inline uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.green == 0 || this->local_brightness_ == 0) if (this->max_brightness_.green == 0 || this->local_brightness_ == 0)
return 0; return 0;
uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL; uint16_t uncorrected = this->gamma_reverse_table_[green] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_; uint16_t res = ((uncorrected / this->max_brightness_.green) * 255UL) / this->local_brightness_;
return res; return (uint8_t) std::min(res, uint16_t(255));
} }
inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE { inline uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0) if (this->max_brightness_.blue == 0 || this->local_brightness_ == 0)
return 0; return 0;
uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL; uint16_t uncorrected = this->gamma_reverse_table_[blue] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_; uint16_t res = ((uncorrected / this->max_brightness_.blue) * 255UL) / this->local_brightness_;
return res; return (uint8_t) std::min(res, uint16_t(255));
} }
inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE { inline uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE {
if (this->max_brightness_.white == 0 || this->local_brightness_ == 0) if (this->max_brightness_.white == 0 || this->local_brightness_ == 0)
return 0; return 0;
uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL; uint16_t uncorrected = this->gamma_reverse_table_[white] * 255UL;
uint8_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_; uint16_t res = ((uncorrected / this->max_brightness_.white) * 255UL) / this->local_brightness_;
return res; return (uint8_t) std::min(res, uint16_t(255));
} }
protected: protected:

View file

@ -24,7 +24,11 @@ CONFIG_SCHEMA = cv.Schema(
esp32=False, esp32=False,
rp2040=False, rp2040=False,
): cv.All( ): cv.All(
cv.boolean, cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]) cv.boolean,
cv.Any(
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]),
cv.boolean_false,
),
), ),
cv.Optional(CONF_MIN_IPV6_ADDR_COUNT, default=0): cv.positive_int, cv.Optional(CONF_MIN_IPV6_ADDR_COUNT, default=0): cv.positive_int,
} }

View file

@ -371,6 +371,20 @@ def boolean(value):
) )
def boolean_false(value):
"""Validate the given config option to be a boolean, set to False.
This option allows a bunch of different ways of expressing boolean values:
- instance of boolean
- 'true'/'false'
- 'yes'/'no'
- 'enable'/disable
"""
if boolean(value):
raise Invalid("Expected boolean value to be false")
return False
@schema_extractor_list @schema_extractor_list
def ensure_list(*validators): def ensure_list(*validators):
"""Validate this configuration option to be a list. """Validate this configuration option to be a list.
@ -1857,7 +1871,7 @@ def maybe_simple_value(*validators, **kwargs):
if value == SCHEMA_EXTRACT: if value == SCHEMA_EXTRACT:
return (validator, key) return (validator, key)
if isinstance(value, dict) and key in value: if isinstance(value, dict):
return validator(value) return validator(value)
return validator({key: value}) return validator({key: value})

View file

@ -0,0 +1,4 @@
substitutions:
network_enable_ipv6: "false"
<<: !include common.yaml