feat(ups-hid): UPS and Battery test initial implementation

Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
bullshit committed 2025-08-18 16:55:00 +02:00
1 parent 0c1e24b525
commit ecf606593d
13 files changed
+790 -43

No files matched your search

+36 -5
View File
@@ -9,6 +9,7 @@ DEPENDENCIES = ["ups_hid"]
UpsHidButton = ups_hid_ns.class_("UpsHidButton", button.Button, cg.Component)
CONF_BEEPER_ACTION = "beeper_action"
CONF_TEST_ACTION = "test_action"
BEEPER_ACTIONS = {
"enable": "enable",
@@ -17,10 +18,35 @@ BEEPER_ACTIONS = {
"test": "test"
}
CONFIG_SCHEMA = button.button_schema(UpsHidButton).extend({
cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
cv.Required(CONF_BEEPER_ACTION): cv.enum(BEEPER_ACTIONS, lower=True),
}).extend(cv.COMPONENT_SCHEMA)
TEST_ACTIONS = {
"battery_quick": "battery_quick",
"battery_deep": "battery_deep",
"battery_stop": "battery_stop",
"ups_test": "ups_test",
"ups_stop": "ups_stop"
}
# Support either beeper_action or test_action, but not both
def validate_button_config(config):
beeper_action = config.get(CONF_BEEPER_ACTION)
test_action = config.get(CONF_TEST_ACTION)
if beeper_action is not None and test_action is not None:
raise cv.Invalid("Cannot specify both 'beeper_action' and 'test_action' on the same button")
if beeper_action is None and test_action is None:
raise cv.Invalid("Must specify either 'beeper_action' or 'test_action'")
return config
CONFIG_SCHEMA = cv.All(
button.button_schema(UpsHidButton).extend({
cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
cv.Optional(CONF_BEEPER_ACTION): cv.enum(BEEPER_ACTIONS, lower=True),
cv.Optional(CONF_TEST_ACTION): cv.enum(TEST_ACTIONS, lower=True),
}).extend(cv.COMPONENT_SCHEMA),
validate_button_config,
)
async def to_code(config):
@@ -29,4 +55,9 @@ async def to_code(config):
parent = await cg.get_variable(config[CONF_UPS_HID_ID])
cg.add(var.set_ups_hid_parent(parent))
cg.add(var.set_beeper_action(config[CONF_BEEPER_ACTION]))
# Set action based on which type was configured
if CONF_BEEPER_ACTION in config:
cg.add(var.set_beeper_action(config[CONF_BEEPER_ACTION]))
elif CONF_TEST_ACTION in config:
cg.add(var.set_test_action(config[CONF_TEST_ACTION]))