mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
dalybms: support changing the address (#3676)
This commit is contained in:
parent
98aa3d51ed
commit
ba7737e9f8
3 changed files with 12 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.const import CONF_ID, CONF_ADDRESS
|
||||
|
||||
CODEOWNERS = ["@s1lvi0"]
|
||||
DEPENDENCIES = ["uart"]
|
||||
|
@ -15,7 +15,12 @@ DalyBmsComponent = daly_bms.class_(
|
|||
)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema({cv.GenerateID(): cv.declare_id(DalyBmsComponent)})
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(DalyBmsComponent),
|
||||
cv.Optional(CONF_ADDRESS, default=0x80): cv.positive_int,
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
.extend(cv.polling_component_schema("30s"))
|
||||
)
|
||||
|
@ -25,3 +30,4 @@ async def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||
|
|
|
@ -50,7 +50,7 @@ void DalyBmsComponent::request_data_(uint8_t data_id) {
|
|||
uint8_t request_message[DALY_FRAME_SIZE];
|
||||
|
||||
request_message[0] = 0xA5; // Start Flag
|
||||
request_message[1] = 0x80; // Communication Module Address
|
||||
request_message[1] = addr_; // Communication Module Address
|
||||
request_message[2] = data_id; // Data ID
|
||||
request_message[3] = 0x08; // Data Length (Fixed)
|
||||
request_message[4] = 0x00; // Empty Data
|
||||
|
|
|
@ -69,11 +69,14 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice {
|
|||
void update() override;
|
||||
|
||||
float get_setup_priority() const override;
|
||||
void set_address(uint8_t address) { this->addr_ = address; }
|
||||
|
||||
protected:
|
||||
void request_data_(uint8_t data_id);
|
||||
void decode_data_(std::vector<uint8_t> data);
|
||||
|
||||
uint8_t addr_;
|
||||
|
||||
sensor::Sensor *voltage_sensor_{nullptr};
|
||||
sensor::Sensor *current_sensor_{nullptr};
|
||||
sensor::Sensor *battery_level_sensor_{nullptr};
|
||||
|
|
Loading…
Reference in a new issue