-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING] Convert switch entities into binary sensors (#51)
It looks like the serial interface is read-only. The switch entity doesn't fit here anymore. Please update your configuration from ``` switch: - platform: jk_bms charging: name: "${name} charging" discharging: name: "${name} discharging" balancing: name: "${name} balancing" dedicated_charger: name: "${name} dedicated charger" ``` to ``` binary_sensor: - platform: jk_bms charging: name: "${name} charging" discharging: name: "${name} discharging" balancing: name: "${name} balancing" dedicated_charger: name: "${name} dedicated charger" ```
- Loading branch information
Showing
10 changed files
with
126 additions
and
163 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,67 @@ | ||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import binary_sensor | ||
from esphome.const import CONF_ICON, CONF_ID | ||
|
||
from . import CONF_JK_BMS_ID, JkBms | ||
|
||
DEPENDENCIES = ["jk_bms"] | ||
|
||
CODEOWNERS = ["@syssi"] | ||
|
||
CONF_CHARGING = "charging" | ||
CONF_DISCHARGING = "discharging" | ||
CONF_BALANCING = "balancing" | ||
CONF_DEDICATED_CHARGER = "dedicated_charger" | ||
|
||
ICON_CHARGING = "mdi:battery-charging" | ||
ICON_DISCHARGING = "mdi:power-plug" | ||
ICON_BALANCING = "mdi:battery-heart-variant" | ||
ICON_DEDICATED_CHARGER = "mdi:battery-charging" | ||
|
||
BINARY_SENSORS = [ | ||
CONF_CHARGING, | ||
CONF_DISCHARGING, | ||
CONF_BALANCING, | ||
CONF_DEDICATED_CHARGER, | ||
] | ||
|
||
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(CONF_JK_BMS_ID): cv.use_id(JkBms), | ||
cv.Optional(CONF_CHARGING): binary_sensor.BINARY_SENSOR_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), | ||
cv.Optional(CONF_ICON, default=ICON_CHARGING): cv.icon, | ||
} | ||
), | ||
cv.Optional(CONF_DISCHARGING): binary_sensor.BINARY_SENSOR_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), | ||
cv.Optional(CONF_ICON, default=ICON_DISCHARGING): cv.icon, | ||
} | ||
), | ||
cv.Optional(CONF_BALANCING): binary_sensor.BINARY_SENSOR_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), | ||
cv.Optional(CONF_ICON, default=ICON_BALANCING): cv.icon, | ||
} | ||
), | ||
cv.Optional(CONF_DEDICATED_CHARGER): binary_sensor.BINARY_SENSOR_SCHEMA.extend( | ||
{ | ||
cv.GenerateID(): cv.declare_id(binary_sensor.BinarySensor), | ||
cv.Optional(CONF_ICON, default=ICON_DEDICATED_CHARGER): cv.icon, | ||
} | ||
), | ||
} | ||
) | ||
|
||
|
||
def to_code(config): | ||
hub = yield cg.get_variable(config[CONF_JK_BMS_ID]) | ||
for key in BINARY_SENSORS: | ||
if key in config: | ||
conf = config[key] | ||
sens = cg.new_Pvariable(conf[CONF_ID]) | ||
yield 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.