-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #16
- Loading branch information
Showing
19 changed files
with
2,493 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import esphome.codegen as cg | ||
from esphome.components import jk_balancer_modbus | ||
import esphome.config_validation as cv | ||
from esphome.const import CONF_ID | ||
|
||
AUTO_LOAD = ["jk_balancer_modbus", "binary_sensor", "sensor", "switch", "text_sensor"] | ||
CODEOWNERS = ["@syssi"] | ||
MULTI_CONF = True | ||
|
||
CONF_JK_BALANCER_ID = "jk_balancer_id" | ||
|
||
jk_balancer_ns = cg.esphome_ns.namespace("jk_balancer") | ||
JkBalancer = jk_balancer_ns.class_( | ||
"JkBalancer", cg.PollingComponent, jk_balancer_modbus.JkBalancerModbusDevice | ||
) | ||
|
||
JK_BALANCER_COMPONENT_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(CONF_JK_BALANCER_ID): cv.use_id(JkBalancer), | ||
} | ||
) | ||
|
||
CONFIG_SCHEMA = ( | ||
cv.Schema( | ||
{ | ||
cv.GenerateID(): cv.declare_id(JkBalancer), | ||
} | ||
) | ||
.extend(cv.polling_component_schema("5s")) | ||
.extend(jk_balancer_modbus.jk_balancer_modbus_device_schema(0x01)) | ||
) | ||
|
||
|
||
async def to_code(config): | ||
var = cg.new_Pvariable(config[CONF_ID]) | ||
await cg.register_component(var, config) | ||
await jk_balancer_modbus.register_jk_balancer_modbus_device(var, config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import esphome.codegen as cg | ||
from esphome.components import binary_sensor | ||
import esphome.config_validation as cv | ||
from esphome.const import CONF_ID, DEVICE_CLASS_CONNECTIVITY, ENTITY_CATEGORY_DIAGNOSTIC | ||
|
||
from . import CONF_JK_BALANCER_ID, JK_BALANCER_COMPONENT_SCHEMA | ||
from .const import CONF_CHARGING, CONF_DISCHARGING | ||
|
||
DEPENDENCIES = ["jk_balancer"] | ||
|
||
CODEOWNERS = ["@syssi"] | ||
|
||
CONF_CHARGING_SWITCH = ( | ||
"charging_switch" # @DEPRECATED and superseded by switch.charging | ||
) | ||
CONF_DISCHARGING_SWITCH = ( | ||
"discharging_switch" # @DEPRECATED and superseded by switch.discharging | ||
) | ||
CONF_BALANCING = "balancing" | ||
CONF_BALANCING_SWITCH = "balancing_switch" | ||
CONF_DEDICATED_CHARGER_SWITCH = "dedicated_charger_switch" | ||
CONF_ONLINE_STATUS = "online_status" | ||
|
||
ICON_CHARGING = "mdi:battery-charging" | ||
ICON_CHARGING_SWITCH = "mdi:battery-charging" | ||
ICON_DISCHARGING = "mdi:power-plug" | ||
ICON_DISCHARGING_SWITCH = "mdi:power-plug" | ||
ICON_BALANCING = "mdi:battery-heart-variant" | ||
ICON_BALANCING_SWITCH = "mdi:battery-heart-variant" | ||
ICON_DEDICATED_CHARGER_SWITCH = "mdi:battery-charging" | ||
|
||
BINARY_SENSORS = [ | ||
CONF_CHARGING, | ||
CONF_CHARGING_SWITCH, | ||
CONF_DISCHARGING, | ||
CONF_DISCHARGING_SWITCH, | ||
CONF_BALANCING, | ||
CONF_BALANCING_SWITCH, | ||
CONF_DEDICATED_CHARGER_SWITCH, | ||
CONF_ONLINE_STATUS, | ||
] | ||
|
||
CONFIG_SCHEMA = JK_BALANCER_COMPONENT_SCHEMA.extend( | ||
{ | ||
cv.Optional(CONF_CHARGING): binary_sensor.binary_sensor_schema( | ||
icon=ICON_CHARGING | ||
), | ||
cv.Optional(CONF_CHARGING_SWITCH): binary_sensor.binary_sensor_schema( | ||
icon=ICON_CHARGING_SWITCH | ||
), | ||
cv.Optional(CONF_DISCHARGING): binary_sensor.binary_sensor_schema( | ||
icon=ICON_DISCHARGING | ||
), | ||
cv.Optional(CONF_DISCHARGING_SWITCH): binary_sensor.binary_sensor_schema( | ||
icon=ICON_DISCHARGING_SWITCH | ||
), | ||
cv.Optional(CONF_BALANCING): binary_sensor.binary_sensor_schema( | ||
icon=ICON_BALANCING | ||
), | ||
cv.Optional(CONF_BALANCING_SWITCH): binary_sensor.binary_sensor_schema( | ||
icon=ICON_BALANCING_SWITCH | ||
), | ||
cv.Optional(CONF_DEDICATED_CHARGER_SWITCH): binary_sensor.binary_sensor_schema( | ||
icon=ICON_DEDICATED_CHARGER_SWITCH | ||
), | ||
cv.Optional(CONF_ONLINE_STATUS): binary_sensor.binary_sensor_schema( | ||
device_class=DEVICE_CLASS_CONNECTIVITY, | ||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, | ||
), | ||
} | ||
) | ||
|
||
|
||
async def to_code(config): | ||
hub = await cg.get_variable(config[CONF_JK_BALANCER_ID]) | ||
for key in BINARY_SENSORS: | ||
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Constants for the jk bms component.""" | ||
|
||
CONF_BALANCER = "balancer" | ||
CONF_CHARGING = "charging" | ||
CONF_DISCHARGING = "discharging" |
Oops, something went wrong.