mirror of
https://github.com/esphome/esphome.git
synced 2025-02-08 06:00:56 +00:00
* Add support for Daly Smart BMS * Fix clang-format and python lint * Fix const declaration * Add code owner * Fix malloc with std::vector * Fix with suggestions * Revert "Fix with suggestions" This reverts commit bc618f20cf83e3df903fdbbca8d2529d946264b0. * Fix last commit * Fix Python Lint * Fix typo * Use std::vector instead pointer and fix loop * Fix typo * Add test configuration to test3.yaml * Fix test3.yaml * Fix uart in test3.yaml
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import binary_sensor
|
|
from esphome.const import CONF_ID
|
|
from . import DalyBmsComponent, CONF_BMS_DALY_ID
|
|
|
|
CONF_CHARGING_MOS_ENABLED = "charging_mos_enabled"
|
|
CONF_DISCHARGING_MOS_ENABLED = "discharging_mos_enabled"
|
|
|
|
TYPES = [
|
|
CONF_CHARGING_MOS_ENABLED,
|
|
CONF_DISCHARGING_MOS_ENABLED,
|
|
]
|
|
|
|
CONFIG_SCHEMA = cv.All(
|
|
cv.Schema(
|
|
{
|
|
cv.GenerateID(CONF_BMS_DALY_ID): cv.use_id(DalyBmsComponent),
|
|
cv.Optional(
|
|
CONF_CHARGING_MOS_ENABLED
|
|
): binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor),
|
|
}
|
|
),
|
|
cv.Optional(
|
|
CONF_DISCHARGING_MOS_ENABLED
|
|
): binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor),
|
|
}
|
|
),
|
|
}
|
|
).extend(cv.COMPONENT_SCHEMA)
|
|
)
|
|
|
|
|
|
async def setup_conf(config, key, hub):
|
|
if key in config:
|
|
conf = config[key]
|
|
sens = cg.new_Pvariable(conf[CONF_ID])
|
|
await binary_sensor.register_binary_sensor(sens, conf)
|
|
cg.add(getattr(hub, f"set_{key}_binary_sensor")(sens))
|
|
|
|
|
|
async def to_code(config):
|
|
hub = await cg.get_variable(config[CONF_BMS_DALY_ID])
|
|
for key in TYPES:
|
|
await setup_conf(config, key, hub)
|