mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge branch 'dev' into vornado-ir
This commit is contained in:
		| @@ -1,8 +1,5 @@ | ||||
| #include "cse7766.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include <cinttypes> | ||||
| #include <iomanip> | ||||
| #include <sstream> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace cse7766 { | ||||
| @@ -72,12 +69,8 @@ bool CSE7766Component::check_byte_() { | ||||
| void CSE7766Component::parse_data_() { | ||||
| #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE | ||||
|   { | ||||
|     std::stringstream ss; | ||||
|     ss << "Raw data:" << std::hex << std::uppercase << std::setfill('0'); | ||||
|     for (uint8_t i = 0; i < 23; i++) { | ||||
|       ss << ' ' << std::setw(2) << static_cast<unsigned>(this->raw_data_[i]); | ||||
|     } | ||||
|     ESP_LOGVV(TAG, "%s", ss.str().c_str()); | ||||
|     std::string s = format_hex_pretty(this->raw_data_, sizeof(this->raw_data_)); | ||||
|     ESP_LOGVV(TAG, "Raw data: %s", s.c_str()); | ||||
|   } | ||||
| #endif | ||||
|  | ||||
| @@ -211,21 +204,20 @@ void CSE7766Component::parse_data_() { | ||||
|  | ||||
| #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE | ||||
|   { | ||||
|     std::stringstream ss; | ||||
|     ss << "Parsed:"; | ||||
|     std::string buf = "Parsed:"; | ||||
|     if (have_voltage) { | ||||
|       ss << " V=" << voltage << "V"; | ||||
|       buf += str_sprintf(" V=%fV", voltage); | ||||
|     } | ||||
|     if (have_current) { | ||||
|       ss << " I=" << current * 1000.0f << "mA (~" << calculated_current * 1000.0f << "mA)"; | ||||
|       buf += str_sprintf(" I=%fmA (~%fmA)", current * 1000.0f, calculated_current * 1000.0f); | ||||
|     } | ||||
|     if (have_power) { | ||||
|       ss << " P=" << power << "W"; | ||||
|       buf += str_sprintf(" P=%fW", power); | ||||
|     } | ||||
|     if (energy != 0.0f) { | ||||
|       ss << " E=" << energy << "kWh (" << cf_pulses << ")"; | ||||
|       buf += str_sprintf(" E=%fkWh (%u)", energy, cf_pulses); | ||||
|     } | ||||
|     ESP_LOGVV(TAG, "%s", ss.str().c_str()); | ||||
|     ESP_LOGVV(TAG, "%s", buf.c_str()); | ||||
|   } | ||||
| #endif | ||||
| } | ||||
|   | ||||
| @@ -4,9 +4,6 @@ | ||||
| #include "esphome/core/log.h" | ||||
| #include "esphome/core/hal.h" | ||||
| #include <algorithm> | ||||
| #include <sstream> | ||||
| #include <iostream>  // std::cout, std::fixed | ||||
| #include <iomanip> | ||||
| namespace esphome { | ||||
| namespace graph { | ||||
|  | ||||
| @@ -231,9 +228,8 @@ void GraphLegend::init(Graph *g) { | ||||
|     ESP_LOGI(TAGL, "  %s %d %d", txtstr.c_str(), fw, fh); | ||||
|  | ||||
|     if (this->values_ != VALUE_POSITION_TYPE_NONE) { | ||||
|       std::stringstream ss; | ||||
|       ss << std::fixed << std::setprecision(trace->sensor_->get_accuracy_decimals()) << trace->sensor_->get_state(); | ||||
|       std::string valstr = ss.str(); | ||||
|       std::string valstr = | ||||
|           value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals()); | ||||
|       if (this->units_) { | ||||
|         valstr += trace->sensor_->get_unit_of_measurement(); | ||||
|       } | ||||
| @@ -368,9 +364,8 @@ void Graph::draw_legend(display::Display *buff, uint16_t x_offset, uint16_t y_of | ||||
|     if (legend_->values_ != VALUE_POSITION_TYPE_NONE) { | ||||
|       int xv = x + legend_->xv_; | ||||
|       int yv = y + legend_->yv_; | ||||
|       std::stringstream ss; | ||||
|       ss << std::fixed << std::setprecision(trace->sensor_->get_accuracy_decimals()) << trace->sensor_->get_state(); | ||||
|       std::string valstr = ss.str(); | ||||
|       std::string valstr = | ||||
|           value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals()); | ||||
|       if (legend_->units_) { | ||||
|         valstr += trace->sensor_->get_unit_of_measurement(); | ||||
|       } | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
|  | ||||
| #include "modbus_textsensor.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include <iomanip> | ||||
| #include <sstream> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace modbus_controller { | ||||
| @@ -12,20 +10,17 @@ static const char *const TAG = "modbus_controller.text_sensor"; | ||||
| void ModbusTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Modbus Controller Text Sensor", this); } | ||||
|  | ||||
| void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) { | ||||
|   std::ostringstream output; | ||||
|   std::string output_str{}; | ||||
|   uint8_t items_left = this->response_bytes; | ||||
|   uint8_t index = this->offset; | ||||
|   char buffer[5]; | ||||
|   while ((items_left > 0) && index < data.size()) { | ||||
|     uint8_t b = data[index]; | ||||
|     switch (this->encode_) { | ||||
|       case RawEncoding::HEXBYTES: | ||||
|         sprintf(buffer, "%02x", b); | ||||
|         output << buffer; | ||||
|         output_str += str_snprintf("%02x", 2, b); | ||||
|         break; | ||||
|       case RawEncoding::COMMA: | ||||
|         sprintf(buffer, index != this->offset ? ",%d" : "%d", b); | ||||
|         output << buffer; | ||||
|         output_str += str_sprintf(index != this->offset ? ",%d" : "%d", b); | ||||
|         break; | ||||
|       case RawEncoding::ANSI: | ||||
|         if (b < 0x20) | ||||
| @@ -33,25 +28,24 @@ void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) { | ||||
|       // FALLTHROUGH | ||||
|       // Anything else no encoding | ||||
|       default: | ||||
|         output << (char) b; | ||||
|         output_str += (char) b; | ||||
|         break; | ||||
|     } | ||||
|     items_left--; | ||||
|     index++; | ||||
|   } | ||||
|  | ||||
|   auto result = output.str(); | ||||
|   // Is there a lambda registered | ||||
|   // call it with the pre converted value and the raw data array | ||||
|   if (this->transform_func_.has_value()) { | ||||
|     // the lambda can parse the response itself | ||||
|     auto val = (*this->transform_func_)(this, result, data); | ||||
|     auto val = (*this->transform_func_)(this, output_str, data); | ||||
|     if (val.has_value()) { | ||||
|       ESP_LOGV(TAG, "Value overwritten by lambda"); | ||||
|       result = val.value(); | ||||
|       output_str = val.value(); | ||||
|     } | ||||
|   } | ||||
|   this->publish_state(result); | ||||
|   this->publish_state(output_str); | ||||
| } | ||||
|  | ||||
| }  // namespace modbus_controller | ||||
|   | ||||
| @@ -582,7 +582,7 @@ class EsphomeCore: | ||||
|  | ||||
|     @property | ||||
|     def config_dir(self): | ||||
|         return os.path.dirname(os.path.abspath(self.config_path)) | ||||
|         return os.path.abspath(os.path.dirname(self.config_path)) | ||||
|  | ||||
|     @property | ||||
|     def data_dir(self): | ||||
|   | ||||
| @@ -217,6 +217,8 @@ def preload_core_config(config, result) -> str: | ||||
|     target_platforms = [] | ||||
|  | ||||
|     for domain, _ in config.items(): | ||||
|         if domain.startswith("."): | ||||
|             continue | ||||
|         if _is_target_platform(domain): | ||||
|             target_platforms += [domain] | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ esptool==4.7.0 | ||||
| click==8.1.7 | ||||
| esphome-dashboard==20250212.0 | ||||
| aioesphomeapi==24.6.2 | ||||
| zeroconf==0.143.0 | ||||
| zeroconf==0.144.1 | ||||
| puremagic==1.27 | ||||
| ruamel.yaml==0.18.6 # dashboard_import | ||||
| glyphsets==1.0.0 | ||||
|   | ||||
| @@ -33,3 +33,73 @@ modbus_controller: | ||||
|         read_lambda: |- | ||||
|           return 42.3; | ||||
|     max_cmd_retries: 0 | ||||
|  | ||||
| binary_sensor: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_binary_sensor1 | ||||
|     name: Test Binary Sensor | ||||
|     register_type: read | ||||
|     address: 0x3200 | ||||
|     bitmask: 0x80 | ||||
|  | ||||
| number: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_number1 | ||||
|     name: Test Number | ||||
|     address: 0x9001 | ||||
|     value_type: U_WORD | ||||
|     multiply: 1.0 | ||||
|  | ||||
| output: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_output1 | ||||
|     address: 2048 | ||||
|     register_type: holding | ||||
|     value_type: U_WORD | ||||
|     multiply: 1000 | ||||
|  | ||||
| select: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_select1 | ||||
|     name: Test Select | ||||
|     address: 1000 | ||||
|     value_type: U_WORD | ||||
|     optionsmap: | ||||
|       "Zero": 0 | ||||
|       "One": 1 | ||||
|       "Two": 2 | ||||
|       "Three": 3 | ||||
|  | ||||
| sensor: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_sensor1 | ||||
|     name: Test Sensor | ||||
|     register_type: holding | ||||
|     address: 0x9001 | ||||
|     unit_of_measurement: "AH" | ||||
|     value_type: U_WORD | ||||
|  | ||||
| switch: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_switch1 | ||||
|     name: Test Switch | ||||
|     register_type: coil | ||||
|     address: 0x15 | ||||
|     bitmask: 1 | ||||
|  | ||||
| text_sensor: | ||||
|   - platform: modbus_controller | ||||
|     modbus_controller_id: modbus_controller1 | ||||
|     id: modbus_text_sensor1 | ||||
|     name: Test Text Sensor | ||||
|     register_type: holding | ||||
|     address: 0x9013 | ||||
|     register_count: 3 | ||||
|     raw_encode: HEXBYTES | ||||
|     response_size: 6 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user