Skip to content

Commit 432959b

Browse files
committed
add enable power btn and cleanup
1 parent b110300 commit 432959b

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

components/ip5306/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ ip5306:
2525
on_release:
2626
then:
2727
- lambda: ESP_LOGD("TEST", "still charging");
28+
charger_active: # binary_sensor
29+
id: charger_active
30+
power_boost_on: false # default: false
31+
power_boost_set: false # default: false
32+
power_vin: false # default: false
33+
power_btn: false # default: false
34+
power_boost_keep_on: false # default: false
35+
auto_boot_on_load: false # default: false
36+
enable_power_btn: false # default: false
37+
low_power_shutdown_time: false # default: 64
2838
```

components/ip5306/__init__.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@
1919
CONF_POWER_BTN = "power_btn"
2020
CONF_POWER_BOOST_KEEP_ON = "power_boost_keep_on"
2121
CONF_AUTO_BOOT_ON_LOAD = "auto_boot_on_load"
22+
CONF_ENABLE_POWER_BTN = "enable_power_btn"
2223
CONF_LOW_POWER_SHUTDOWN_TIME = "low_power_shutdown_time"
2324

24-
25-
async def ids_to_code(config, var, types):
26-
for key in types:
27-
if key in config:
28-
conf = await cg.get_variable(config[key])
29-
cg.add(getattr(var, f"set_{key}")(conf))
30-
3125
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend(
3226
{
3327
cv.GenerateID(): cv.declare_id(IP5306),
@@ -39,23 +33,31 @@ async def ids_to_code(config, var, types):
3933
cv.Optional(CONF_CHARGER_CONNECTED): binary_sensor.binary_sensor_schema(),
4034
cv.Optional(CONF_CHARGE_FULL): binary_sensor.binary_sensor_schema(),
4135
cv.Optional(CONF_CHARGER_ACTIVE): binary_sensor.binary_sensor_schema(),
42-
cv.Optional(CONF_POWER_BOOST_ON, default=True): binary_sensor.binary_sensor_schema(),
43-
cv.Optional(CONF_POWER_BOOST_SET, default=True): binary_sensor.binary_sensor_schema(),
44-
cv.Optional(CONF_POWER_VIN, default=True): binary_sensor.binary_sensor_schema(),
45-
cv.Optional(CONF_POWER_BTN, default=True): binary_sensor.binary_sensor_schema(),
46-
cv.Optional(CONF_POWER_BOOST_KEEP_ON, default=True): binary_sensor.binary_sensor_schema(),
47-
cv.Optional(CONF_AUTO_BOOT_ON_LOAD, default=False): binary_sensor.binary_sensor_schema(),
36+
cv.Optional(CONF_POWER_BOOST_ON, default=True): cv.boolean,
37+
cv.Optional(CONF_POWER_BOOST_SET, default=True): cv.boolean,
38+
cv.Optional(CONF_POWER_VIN, default=True): cv.boolean,
39+
cv.Optional(CONF_POWER_BTN, default=True): cv.boolean,
40+
cv.Optional(CONF_POWER_BOOST_KEEP_ON, default=True): cv.boolean,
41+
cv.Optional(CONF_AUTO_BOOT_ON_LOAD, default=False): cv.boolean,
42+
cv.Optional(CONF_ENABLE_POWER_BTN, default=True): cv.boolean,
4843
cv.Optional(CONF_LOW_POWER_SHUTDOWN_TIME, default=64): cv.uint8_t,
4944
}
5045
).extend(i2c.i2c_device_schema(0x75))
5146

52-
IP5306_TYPES = {
47+
def keys_to_code(config, var, types):
48+
for key in types:
49+
if key in config:
50+
conf = config[key]
51+
cg.add(getattr(var, f"set_{key}")(conf))
52+
53+
IP5306_KEYS = {
5354
CONF_POWER_BOOST_ON,
5455
CONF_POWER_BOOST_SET,
5556
CONF_POWER_VIN,
5657
CONF_POWER_BTN,
5758
CONF_POWER_BOOST_KEEP_ON,
5859
CONF_AUTO_BOOT_ON_LOAD,
60+
CONF_ENABLE_POWER_BTN,
5961
CONF_LOW_POWER_SHUTDOWN_TIME
6062
}
6163

@@ -80,4 +82,4 @@ async def to_code(config):
8082
sens = await binary_sensor.new_binary_sensor(config[CONF_CHARGE_FULL])
8183
cg.add(var.set_charge_full(sens))
8284

83-
await ids_to_code(config, var, IP5306_TYPES)
85+
keys_to_code(config, var, IP5306_KEYS)

components/ip5306/ip5306.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IP5306 : public i2c::I2CDevice, public Component {
2626
void set_power_btn(bool enabled) { this->powerBtn_ = enabled; }
2727
void set_power_boost_keep_on(bool enabled) { this->powerBoostKeepOn_ = enabled; }
2828
void set_auto_boot_on_load(bool enabled) { this->autoBootOnLoad_ = enabled; }
29+
void set_enable_power_btn(bool enabled) { this->enablePowerBtn_ = enabled; }
2930
void set_low_power_shutdown_time(int time) { this->lowPowerShutdownTime_ = time; }
3031

3132
protected:
@@ -55,6 +56,7 @@ class IP5306 : public i2c::I2CDevice, public Component {
5556
bool powerBtn_{false};
5657
bool powerBoostKeepOn_{false};
5758
bool autoBootOnLoad_{false};
59+
bool enablePowerBtn_{false};
5860
int lowPowerShutdownTime_{0};
5961
};
6062

0 commit comments

Comments
 (0)