[ds1307] Use register_apply_action for ds1307.write_time and ds1307.read_time (#19638)

This commit is contained in:
J. Nick Koston
2026-09-25 14:09:26 -04:00
committed by GitHub
parent 63796e74bb
commit 2157ff5b4b
4 changed files with 15 additions and 18 deletions
-9
View File
@@ -55,13 +55,4 @@ class DS1307Component final : public time::RealTimeClock, public i2c::I2CDevice
} ds1307_;
};
template<typename... Ts> class WriteAction final : public Action<Ts...>, public Parented<DS1307Component> {
public:
void play(const Ts &...x) override { this->parent_->write_time(); }
};
template<typename... Ts> class ReadAction final : public Action<Ts...>, public Parented<DS1307Component> {
public:
void play(const Ts &...x) override { this->parent_->read_time(); }
};
} // namespace esphome::ds1307
+4 -9
View File
@@ -9,8 +9,6 @@ CODEOWNERS = ["@badbadc0ffee"]
DEPENDENCIES = ["i2c"]
ds1307_ns = cg.esphome_ns.namespace("ds1307")
DS1307Component = ds1307_ns.class_("DS1307Component", time.RealTimeClock, i2c.I2CDevice)
WriteAction = ds1307_ns.class_("WriteAction", automation.Action)
ReadAction = ds1307_ns.class_("ReadAction", automation.Action)
CONFIG_SCHEMA = time.TIME_SCHEMA.extend(
@@ -20,27 +18,24 @@ CONFIG_SCHEMA = time.TIME_SCHEMA.extend(
).extend(i2c.i2c_device_schema(0x68))
automation.register_parented_action(
automation.register_apply_action(
"ds1307.write_time",
WriteAction,
cv.Schema(
{
cv.GenerateID(): cv.use_id(DS1307Component),
}
),
synchronous=True,
automation.ApplyCall("write_time()"),
)
automation.register_parented_action(
automation.register_apply_action(
"ds1307.read_time",
ReadAction,
automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(DS1307Component),
}
),
synchronous=True,
automation.ApplyCall("read_time()"),
)
@@ -0,0 +1,7 @@
button:
- platform: template
name: DS1307 Actions
on_press:
- ds1307.write_time:
id: ds1307_time
- ds1307.read_time: ds1307_time
@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
ds1307: !include common.yaml
actions: !include common-actions.yaml