Fix clang-format and python lint

This commit is contained in:
Silvio 2021-08-14 23:12:52 +02:00
parent d59c40a32c
commit 2d10ad7bff
5 changed files with 22 additions and 34 deletions

View file

@ -7,7 +7,7 @@ CODEOWNERS = ["@s1lvi0"]
DEPENDENCIES = ["uart"] DEPENDENCIES = ["uart"]
AUTO_LOAD = ["sensor", "text_sensor", "binary_sensor"] AUTO_LOAD = ["sensor", "text_sensor", "binary_sensor"]
CONF_BSM_DALY_ID = "bms_daly_id" BSM_DALY_ID = "bms_daly_id"
daly_bms = cg.esphome_ns.namespace("daly_bms") daly_bms = cg.esphome_ns.namespace("daly_bms")
DalyBmsComponent = daly_bms.class_("DalyBmsComponent", uart.UARTDevice, cg.Component) DalyBmsComponent = daly_bms.class_("DalyBmsComponent", uart.UARTDevice, cg.Component)

View file

@ -2,7 +2,7 @@ import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import binary_sensor from esphome.components import binary_sensor
from esphome.const import CONF_ID from esphome.const import CONF_ID
from . import DalyBmsComponent, CONF_BSM_DALY_ID from . import DalyBmsComponent, BSM_DALY_ID
CONF_CHARGING_MOS_ENABLED = "charging_mos_enabled" CONF_CHARGING_MOS_ENABLED = "charging_mos_enabled"
CONF_DISCHARGING_MOS_ENABLED = "discharging_mos_enabled" CONF_DISCHARGING_MOS_ENABLED = "discharging_mos_enabled"
@ -15,20 +15,23 @@ TYPES = [
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(CONF_BSM_DALY_ID): cv.use_id(DalyBmsComponent), cv.GenerateID(BSM_DALY_ID): cv.use_id(DalyBmsComponent),
cv.Optional(CONF_CHARGING_MOS_ENABLED): binary_sensor.BINARY_SENSOR_SCHEMA.extend( cv.Optional(
CONF_CHARGING_MOS_ENABLED
): binary_sensor.BINARY_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor),
} }
), ),
cv.Optional(CONF_DISCHARGING_MOS_ENABLED): binary_sensor.BINARY_SENSOR_SCHEMA.extend( cv.Optional(
CONF_DISCHARGING_MOS_ENABLED
): binary_sensor.BINARY_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor),
} }
), ),
} }
) ).extend(cv.COMPONENT_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
) )
@ -41,6 +44,6 @@ async def setup_conf(config, key, hub):
async def to_code(config): async def to_code(config):
hub = await cg.get_variable(config[CONF_BSM_DALY_ID]) hub = await cg.get_variable(config[BSM_DALY_ID])
for key in TYPES: for key in TYPES:
await setup_conf(config, key, hub) await setup_conf(config, key, hub)

View file

@ -74,7 +74,6 @@ void DalyBmsComponent::decode_data(unsigned char *data, int length) {
data = start_flag_position; data = start_flag_position;
if (length >= 13 && data[1] == 0x01) { if (length >= 13 && data[1] == 0x01) {
unsigned char checksum; unsigned char checksum;
int sum = 0; int sum = 0;
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {

View file

@ -5,6 +5,8 @@ from esphome.const import (
CONF_VOLTAGE, CONF_VOLTAGE,
CONF_CURRENT, CONF_CURRENT,
CONF_BATTERY_LEVEL, CONF_BATTERY_LEVEL,
CONF_MAX_TEMPERATURE,
CONF_MIN_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
@ -23,19 +25,15 @@ from esphome.const import (
ICON_THERMOMETER, ICON_THERMOMETER,
ICON_GAUGE, ICON_GAUGE,
) )
from . import DalyBmsComponent, CONF_BSM_DALY_ID from . import DalyBmsComponent, BSM_DALY_ID
CONF_MAX_CELL_VOLTAGE = "max_cell_voltage" CONF_MAX_CELL_VOLTAGE = "max_cell_voltage"
CONF_MAX_CELL_VOLTAGE_NUMBER = "max_cell_voltage_number" CONF_MAX_CELL_VOLTAGE_NUMBER = "max_cell_voltage_number"
CONF_MIN_CELL_VOLTAGE = "min_cell_voltage" CONF_MIN_CELL_VOLTAGE = "min_cell_voltage"
CONF_MIN_CELL_VOLTAGE_NUMBER = "min_cell_voltage_number" CONF_MIN_CELL_VOLTAGE_NUMBER = "min_cell_voltage_number"
CONF_MAX_TEMPERATURE = "max_temperature"
CONF_MAX_TEMPERATURE_PROBE_NUMBER = "max_temperature_probe_number" CONF_MAX_TEMPERATURE_PROBE_NUMBER = "max_temperature_probe_number"
CONF_MIN_TEMPERATURE = "min_temperature"
CONF_MIN_TEMPERATURE_PROBE_NUMBER = "min_temperature_probe_number" CONF_MIN_TEMPERATURE_PROBE_NUMBER = "min_temperature_probe_number"
CONF_STATUS = "status"
CONF_CELLS_NUMBER = "cells_number" CONF_CELLS_NUMBER = "cells_number"
CONF_TEMPERATURE_PROBES_NUMBER = "temperature_probe_number"
CONF_REMAINING_CAPACITY = "remaining_capacity" CONF_REMAINING_CAPACITY = "remaining_capacity"
CONF_TEMPERATURE_1 = "temperature_1" CONF_TEMPERATURE_1 = "temperature_1"
@ -62,7 +60,6 @@ TYPES = [
CONF_MIN_TEMPERATURE, CONF_MIN_TEMPERATURE,
CONF_MIN_TEMPERATURE_PROBE_NUMBER, CONF_MIN_TEMPERATURE_PROBE_NUMBER,
CONF_CELLS_NUMBER, CONF_CELLS_NUMBER,
CONF_TEMPERATURE_PROBES_NUMBER,
CONF_REMAINING_CAPACITY, CONF_REMAINING_CAPACITY,
CONF_TEMPERATURE_1, CONF_TEMPERATURE_1,
CONF_TEMPERATURE_2, CONF_TEMPERATURE_2,
@ -71,7 +68,7 @@ TYPES = [
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(CONF_BSM_DALY_ID): cv.use_id(DalyBmsComponent), cv.GenerateID(BSM_DALY_ID): cv.use_id(DalyBmsComponent),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, UNIT_VOLT,
ICON_FLASH, ICON_FLASH,
@ -163,13 +160,6 @@ CONFIG_SCHEMA = cv.All(
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE, STATE_CLASS_NONE,
), ),
cv.Optional(CONF_TEMPERATURE_PROBES_NUMBER): sensor.sensor_schema(
UNIT_EMPTY,
ICON_COUNTER,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
),
cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema(
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_THERMOMETER, ICON_THERMOMETER,
@ -185,8 +175,7 @@ CONFIG_SCHEMA = cv.All(
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
), ),
} }
) ).extend(cv.COMPONENT_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
) )
@ -198,6 +187,6 @@ async def setup_conf(config, key, hub):
async def to_code(config): async def to_code(config):
hub = await cg.get_variable(config[CONF_BSM_DALY_ID]) hub = await cg.get_variable(config[BSM_DALY_ID])
for key in TYPES: for key in TYPES:
await setup_conf(config, key, hub) await setup_conf(config, key, hub)

View file

@ -1,10 +1,8 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import text_sensor from esphome.components import text_sensor
from esphome.const import CONF_ICON, CONF_ID from esphome.const import CONF_ICON, CONF_ID, CONF_STATUS
from . import DalyBmsComponent, CONF_BSM_DALY_ID from . import DalyBmsComponent, BSM_DALY_ID
CONF_STATUS = "status"
ICON_CAR_BATTERY = "mdi:car-battery" ICON_CAR_BATTERY = "mdi:car-battery"
@ -15,7 +13,7 @@ TYPES = [
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(CONF_BSM_DALY_ID): cv.use_id(DalyBmsComponent), cv.GenerateID(BSM_DALY_ID): cv.use_id(DalyBmsComponent),
cv.Optional(CONF_STATUS): text_sensor.TEXT_SENSOR_SCHEMA.extend( cv.Optional(CONF_STATUS): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{ {
cv.GenerateID(): cv.declare_id(text_sensor.TextSensor), cv.GenerateID(): cv.declare_id(text_sensor.TextSensor),
@ -23,8 +21,7 @@ CONFIG_SCHEMA = cv.All(
} }
), ),
} }
) ).extend(cv.COMPONENT_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
) )
@ -37,6 +34,6 @@ async def setup_conf(config, key, hub):
async def to_code(config): async def to_code(config):
hub = await cg.get_variable(config[CONF_BSM_DALY_ID]) hub = await cg.get_variable(config[BSM_DALY_ID])
for key in TYPES: for key in TYPES:
await setup_conf(config, key, hub) await setup_conf(config, key, hub)