From 472b2281d19a5378954ebe2297678f95745d9a43 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Oct 2026 13:46:00 -1000 Subject: [PATCH] [bq25186] Use Apply buttons --- esphome/components/bq25186/bq25186_button.h | 25 --------------------- esphome/components/bq25186/button.py | 11 ++++----- 2 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 esphome/components/bq25186/bq25186_button.h diff --git a/esphome/components/bq25186/bq25186_button.h b/esphome/components/bq25186/bq25186_button.h deleted file mode 100644 index e088166ac6c..00000000000 --- a/esphome/components/bq25186/bq25186_button.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "esphome/core/defines.h" -#ifdef USE_BUTTON - -#include "bq25186.h" -#include "esphome/components/button/button.h" - -namespace esphome::bq25186 { - -/// Writes one SHIP_RST field when pressed -class BQ25186Button final : public button::Button, public Parented { - public: - BQ25186Button(uint8_t mask, uint8_t value) : mask_(mask), value_(value) {} - - protected: - void press_action() override { this->parent_->write_ship_rst(this->mask_, this->value_); } - - const uint8_t mask_; - const uint8_t value_; -}; - -} // namespace esphome::bq25186 - -#endif // USE_BUTTON diff --git a/esphome/components/bq25186/button.py b/esphome/components/bq25186/button.py index 25527ff9a27..c2664e954a3 100644 --- a/esphome/components/bq25186/button.py +++ b/esphome/components/bq25186/button.py @@ -1,4 +1,3 @@ -import esphome.codegen as cg from esphome.components import button import esphome.config_validation as cv from esphome.const import ( @@ -10,11 +9,10 @@ from esphome.const import ( ) from esphome.types import ConfigType -from . import BQ25186_CHILD_SCHEMA, CONF_BQ25186_ID, bq25186_ns +from . import BQ25186_CHILD_SCHEMA, CONF_BQ25186_ID DEPENDENCIES = ["bq25186"] -BQ25186Button = bq25186_ns.class_("BQ25186Button", button.Button) # SHIP_RST: bit 7 is the software reset, bits 6:5 the shutdown, ship and hardware reset codes SOFTWARE_RESET_MASK = 0x80 @@ -33,7 +31,7 @@ CONFIG_SCHEMA = cv.All( BQ25186_CHILD_SCHEMA.extend( { cv.Optional(key): button.button_schema( - BQ25186Button, + button.ApplyButton, entity_category=ENTITY_CATEGORY_CONFIG, icon=icon, device_class=device_class, @@ -46,7 +44,6 @@ CONFIG_SCHEMA = cv.All( async def to_code(config: ConfigType) -> None: + buttons = button.sub_buttons(config, parent=config[CONF_BQ25186_ID]) for key, mask, value, _, _ in _BUTTONS: - if (conf := config.get(key)) is not None: - var = await button.new_button(conf, mask, value) - await cg.register_parented(var, config[CONF_BQ25186_ID]) + await buttons(key, None, apply=f"write_ship_rst({mask:#04x}, {value:#04x})")