Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include power options for ip5306 to enable charging #57

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/ip5306/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ ip5306:
on_release:
then:
- lambda: ESP_LOGD("TEST", "still charging");
charger_active: # binary_sensor
id: charger_active
power_boost_on: false # default: false
power_boost_set: false # default: false
power_vin: false # default: false
power_btn: false # default: false
power_boost_keep_on: false # default: false
auto_boot_on_load: false # default: false
enable_power_btn: false # default: false
low_power_shutdown_time: false # default: 64
```
40 changes: 40 additions & 0 deletions components/ip5306/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
IP5306 = ip5306_ns.class_('IP5306', i2c.I2CDevice, cg.Component)

CONF_CHARGER_CONNECTED = "charger_connected"
CONF_CHARGER_ACTIVE = "charger_active"
CONF_CHARGE_FULL = "charge_full"
CONF_POWER_BOOST_ON = "power_boost_on"
CONF_POWER_BOOST_SET = "power_boost_set"
CONF_POWER_VIN = "power_vin"
CONF_POWER_BTN = "power_btn"
CONF_POWER_BOOST_KEEP_ON = "power_boost_keep_on"
CONF_AUTO_BOOT_ON_LOAD = "auto_boot_on_load"
CONF_ENABLE_POWER_BTN = "enable_power_btn"
CONF_LOW_POWER_SHUTDOWN_TIME = "low_power_shutdown_time"

CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend(
{
Expand All @@ -23,9 +32,35 @@
),
cv.Optional(CONF_CHARGER_CONNECTED): binary_sensor.binary_sensor_schema(),
cv.Optional(CONF_CHARGE_FULL): binary_sensor.binary_sensor_schema(),
cv.Optional(CONF_CHARGER_ACTIVE): binary_sensor.binary_sensor_schema(),
cv.Optional(CONF_POWER_BOOST_ON, default=True): cv.boolean,
cv.Optional(CONF_POWER_BOOST_SET, default=True): cv.boolean,
cv.Optional(CONF_POWER_VIN, default=True): cv.boolean,
cv.Optional(CONF_POWER_BTN, default=True): cv.boolean,
cv.Optional(CONF_POWER_BOOST_KEEP_ON, default=True): cv.boolean,
cv.Optional(CONF_AUTO_BOOT_ON_LOAD, default=False): cv.boolean,
cv.Optional(CONF_ENABLE_POWER_BTN, default=True): cv.boolean,
cv.Optional(CONF_LOW_POWER_SHUTDOWN_TIME, default=64): cv.uint8_t,
}
).extend(i2c.i2c_device_schema(0x75))

def keys_to_code(config, var, types):
for key in types:
if key in config:
conf = config[key]
cg.add(getattr(var, f"set_{key}")(conf))

IP5306_KEYS = {
CONF_POWER_BOOST_ON,
CONF_POWER_BOOST_SET,
CONF_POWER_VIN,
CONF_POWER_BTN,
CONF_POWER_BOOST_KEEP_ON,
CONF_AUTO_BOOT_ON_LOAD,
CONF_ENABLE_POWER_BTN,
CONF_LOW_POWER_SHUTDOWN_TIME
}

async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
Expand All @@ -39,7 +74,12 @@ async def to_code(config):
sens = await binary_sensor.new_binary_sensor(config[CONF_CHARGER_CONNECTED])
cg.add(var.set_charger_connected(sens))

if CONF_CHARGER_ACTIVE in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_CHARGER_ACTIVE])
cg.add(var.set_charger_active(sens))

if CONF_CHARGE_FULL in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_CHARGE_FULL])
cg.add(var.set_charge_full(sens))

keys_to_code(config, var, IP5306_KEYS)
Loading