1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-02 08:01:50 +00:00

Compare commits

...

23 Commits

Author SHA1 Message Date
Jesse Hills
c0523590b4 Merge pull request #3154 from esphome/bump-2022.1.3
2022.1.3
2022-02-03 07:17:52 +13:00
Jesse Hills
c7f091ab10 Bump version to 2022.1.3 2022-02-02 22:16:24 +13:00
Jesse Hills
7479e0aada Fix backwards string case helpers (#3126) 2022-02-02 22:16:16 +13:00
Jesse Hills
5bbee1a1fe Merge pull request #3111 from esphome/bump-2022.1.2
2022.1.2
2022-01-25 09:36:20 +13:00
Jesse Hills
bdb9546ca3 Bump version to 2022.1.2 2022-01-25 09:11:20 +13:00
Plácido Revilla
46af4cad6e Set the wrapped single light in light partition to internal (#3092) 2022-01-25 09:11:19 +13:00
Martin
76a238912b [modbus_controller] fix incorrect start address for number write (#3073) 2022-01-25 09:11:19 +13:00
Jesse Hills
909a526967 Merge pull request #3075 from esphome/bump-2022.1.1
2022.1.1
2022-01-20 09:08:57 +13:00
Jesse Hills
cd6f4fb93f Bump version to 2022.1.1 2022-01-20 08:34:18 +13:00
Jesse Hills
c19458696e Add *.py.script files to distributions (#3074) 2022-01-20 08:34:18 +13:00
Jesse Hills
318b930e9f Merge pull request #3070 from esphome/bump-2022.1.0
2022.1.0
2022-01-19 19:43:54 +13:00
Jesse Hills
9296a078a7 Bump version to 2022.1.0 2022-01-19 16:08:27 +13:00
Jesse Hills
5dc776e55f Merge pull request #3068 from esphome/bump-2022.1.0b4
2022.1.0b4
2022-01-19 07:40:37 +13:00
Jesse Hills
72d60f30f7 Bump version to 2022.1.0b4 2022-01-18 15:49:31 +13:00
Oxan van Leeuwen
869743a742 Fail hard if no random bytes available for encryption (#3067) 2022-01-18 15:49:31 +13:00
Martin
7b03e07908 [modbus_controller] add missing skip_updates (#3063) 2022-01-18 15:49:31 +13:00
Paulus Schoutsen
348f880e15 bump dashboard to 20220116.0 (#3061) 2022-01-18 15:49:31 +13:00
Jesse Hills
ead597d0fb Merge pull request #3060 from esphome/bump-2022.1.0b3
2022.1.0b3
2022-01-17 13:13:40 +13:00
Jesse Hills
afbf989715 Bump version to 2022.1.0b3 2022-01-17 12:40:07 +13:00
Jesse Hills
01b62a16c3 Add number setting to web_server/rest_api (#3055) 2022-01-17 12:40:07 +13:00
Oxan van Leeuwen
c5eba04517 Remove deprecated attribute from virtual entity methods (#3056) 2022-01-17 12:40:07 +13:00
Oxan van Leeuwen
282313ab52 Rename post_build scripts to fix codeowners script (#3057) 2022-01-17 12:40:07 +13:00
Ohad Lutzky
d274545e77 Disable caching for binary download (#3054) 2022-01-17 12:40:07 +13:00
20 changed files with 91 additions and 36 deletions

View File

@@ -4,4 +4,5 @@ include requirements.txt
include esphome/dashboard/templates/*.html
recursive-include esphome/dashboard/static *.ico *.js *.css *.woff* LICENSE
recursive-include esphome *.cpp *.h *.tcc
recursive-include esphome *.py.script
recursive-include esphome LICENSE.txt

View File

@@ -1,6 +1,7 @@
#include "api_frame_helper.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "proto.h"
#include <cstring>
@@ -721,7 +722,12 @@ APIError APINoiseFrameHelper::shutdown(int how) {
}
extern "C" {
// declare how noise generates random bytes (here with a good HWRNG based on the RF system)
void noise_rand_bytes(void *output, size_t len) { esphome::random_bytes(reinterpret_cast<uint8_t *>(output), len); }
void noise_rand_bytes(void *output, size_t len) {
if (!esphome::random_bytes(reinterpret_cast<uint8_t *>(output), len)) {
ESP_LOGE(TAG, "Failed to acquire random bytes, rebooting!");
arch_restart();
}
}
}
#endif // USE_API_NOISE

View File

@@ -74,8 +74,10 @@ class BinarySensor : public EntityBase {
// ========== OVERRIDE METHODS ==========
// (You'll only need this when creating your own custom binary sensor)
/// Get the default device class for this sensor, or empty string for no default.
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
/** 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:

View File

@@ -169,7 +169,11 @@ class Cover : public EntityBase {
friend CoverCall;
virtual void control(const CoverCall &call) = 0;
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
/** 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_();

View File

@@ -235,7 +235,7 @@ float DallasTemperatureSensor::get_temp_c() {
return temp / 128.0f;
}
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + str_upper_case(format_hex(this->address_)); }
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + str_lower_case(format_hex(this->address_)); }
} // namespace dallas
} // namespace esphome

View File

@@ -417,7 +417,7 @@ def copy_files():
)
dir = os.path.dirname(__file__)
post_build_file = os.path.join(dir, "post_build.py")
post_build_file = os.path.join(dir, "post_build.py.script")
copy_file_if_changed(
post_build_file,
CORE.relative_build_path("post_build.py"),

View File

@@ -220,7 +220,7 @@ async def to_code(config):
def copy_files():
dir = os.path.dirname(__file__)
post_build_file = os.path.join(dir, "post_build.py")
post_build_file = os.path.join(dir, "post_build.py.script")
copy_file_if_changed(
post_build_file,
CORE.relative_build_path("post_build.py"),

View File

@@ -57,9 +57,11 @@ void ModbusNumber::control(float value) {
// Create and send the write command
ModbusCommandItem write_cmd;
if (this->register_count == 1 && !this->use_write_multiple_) {
write_cmd = ModbusCommandItem::create_write_single_command(parent_, this->start_address + this->offset, data[0]);
// since offset is in bytes and a register is 16 bits we get the start by adding offset/2
write_cmd =
ModbusCommandItem::create_write_single_command(parent_, this->start_address + this->offset / 2, data[0]);
} else {
write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset / 2,
this->register_count, data);
}
// publish new value

View File

@@ -18,6 +18,7 @@ from ..const import (
CONF_FORCE_NEW_RANGE,
CONF_MODBUS_CONTROLLER_ID,
CONF_REGISTER_TYPE,
CONF_SKIP_UPDATES,
CONF_USE_WRITE_MULTIPLE,
CONF_WRITE_LAMBDA,
)
@@ -53,6 +54,7 @@ async def to_code(config):
config[CONF_ADDRESS],
byte_offset,
config[CONF_BITMASK],
config[CONF_SKIP_UPDATES],
config[CONF_FORCE_NEW_RANGE],
)
await cg.register_component(var, config)

View File

@@ -10,14 +10,14 @@ namespace modbus_controller {
class ModbusSwitch : public Component, public switch_::Switch, public SensorItem {
public:
ModbusSwitch(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask,
bool force_new_range)
uint8_t skip_updates, bool force_new_range)
: Component(), switch_::Switch() {
this->register_type = register_type;
this->start_address = start_address;
this->offset = offset;
this->bitmask = bitmask;
this->sensor_value_type = SensorValueType::BIT;
this->skip_updates = 0;
this->skip_updates = skip_updates;
this->register_count = 1;
if (register_type == ModbusRegisterType::HOLDING || register_type == ModbusRegisterType::COIL) {
this->start_address += offset;

View File

@@ -104,7 +104,6 @@ async def to_code(config):
)
light_state = cg.new_Pvariable(conf[CONF_LIGHT_ID], "", wrapper)
await cg.register_component(light_state, conf)
cg.add(cg.App.register_light(light_state))
segments.append(AddressableSegment(light_state, 0, 1, False))
else:

View File

@@ -150,20 +150,28 @@ class Sensor : public EntityBase {
void internal_send_state_to_frontend(float state);
protected:
/// Override this to set the default unit of measurement.
ESPDEPRECATED("unit_of_measurement() is deprecated, set property during config validation instead.", "2022.01")
/** 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.
ESPDEPRECATED("accuracy_decimals() is deprecated, set property during config validation instead.", "2022.01")
/** 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.
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
/** 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.
ESPDEPRECATED("state_class() is deprecated, set property during config validation instead.", "2022.01")
/** 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
uint32_t hash_base() override;

View File

@@ -236,7 +236,18 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
#ifdef USE_NUMBER
for (auto *obj : App.get_numbers())
if (this->include_internal_ || !obj->is_internal())
write_row(stream, obj, "number", "");
write_row(stream, obj, "number", "", [](AsyncResponseStream &stream, EntityBase *obj) {
number::Number *number = (number::Number *) obj;
stream.print(R"(<input type="number" min=")");
stream.print(number->traits.get_min_value());
stream.print(R"(" max=")");
stream.print(number->traits.get_max_value());
stream.print(R"(" step=")");
stream.print(number->traits.get_step());
stream.print(R"(" value=")");
stream.print(number->state);
stream.print(R"("/>)");
});
#endif
#ifdef USE_SELECT
@@ -652,8 +663,29 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM
for (auto *obj : App.get_numbers()) {
if (obj->get_object_id() != match.id)
continue;
std::string data = this->number_json(obj, obj->state);
request->send(200, "text/json", data.c_str());
if (request->method() == HTTP_GET) {
std::string data = this->number_json(obj, obj->state);
request->send(200, "text/json", data.c_str());
return;
}
if (match.method != "set") {
request->send(404);
return;
}
auto call = obj->make_call();
if (request->hasParam("value")) {
String value = request->getParam("value")->value();
optional<float> value_f = parse_number<float>(value.c_str());
if (value_f.has_value())
call.set_value(*value_f);
}
this->defer([call]() mutable { call.perform(); });
request->send(200);
return;
}
request->send(404);
@@ -661,9 +693,8 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM
std::string WebServer::number_json(number::Number *obj, float value) {
return json::build_json([obj, value](JsonObject root) {
root["id"] = "number-" + obj->get_object_id();
char buffer[64];
snprintf(buffer, sizeof(buffer), "%f", value);
root["state"] = buffer;
std::string state = str_sprintf("%f", value);
root["state"] = state;
root["value"] = value;
});
}
@@ -769,7 +800,7 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
#endif
#ifdef USE_NUMBER
if (request->method() == HTTP_GET && match.domain == "number")
if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.domain == "number")
return true;
#endif

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2022.1.0b2"
__version__ = "2022.1.3"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"

View File

@@ -287,13 +287,12 @@ uint32_t random_uint32() {
#endif
}
float random_float() { return static_cast<float>(random_uint32()) / static_cast<float>(UINT32_MAX); }
void random_bytes(uint8_t *data, size_t len) {
bool random_bytes(uint8_t *data, size_t len) {
#ifdef USE_ESP32
esp_fill_random(data, len);
return true;
#elif defined(USE_ESP8266)
if (os_get_random(data, len) != 0) {
ESP_LOGE(TAG, "Failed to generate random bytes!");
}
return os_get_random(data, len) == 0;
#else
#error "No random source available for this configuration."
#endif
@@ -317,8 +316,8 @@ template<int (*fn)(int)> std::string str_ctype_transform(const std::string &str)
std::transform(str.begin(), str.end(), result.begin(), [](unsigned char ch) { return fn(ch); });
return result;
}
std::string str_lower_case(const std::string &str) { return str_ctype_transform<std::toupper>(str); }
std::string str_upper_case(const std::string &str) { return str_ctype_transform<std::tolower>(str); }
std::string str_lower_case(const std::string &str) { return str_ctype_transform<std::tolower>(str); }
std::string str_upper_case(const std::string &str) { return str_ctype_transform<std::toupper>(str); }
std::string str_snake_case(const std::string &str) {
std::string result;
result.resize(str.length());

View File

@@ -311,7 +311,7 @@ uint32_t random_uint32();
/// Return a random float between 0 and 1.
float random_float();
/// Generate \p len number of random bytes.
void random_bytes(uint8_t *data, size_t len);
bool random_bytes(uint8_t *data, size_t len);
///@}

View File

@@ -445,6 +445,7 @@ class DownloadBinaryRequestHandler(BaseHandler):
self.set_header("Content-Type", "application/octet-stream")
self.set_header("Content-Disposition", f'attachment; filename="{filename}"')
self.set_header("Cache-Control", "no-cache")
if not Path(path).is_file():
self.send_error(404)
return

View File

@@ -9,7 +9,7 @@ pyserial==3.5
platformio==5.2.4 # When updating platformio, also update Dockerfile
esptool==3.2
click==8.0.3
esphome-dashboard==20220113.2
esphome-dashboard==20220116.0
aioesphomeapi==10.6.0
zeroconf==0.37.0