formatting

This commit is contained in:
Gábor Poczkodi 2024-10-18 05:43:02 +02:00
parent c908cfc9cd
commit 2c148246fb
2 changed files with 34 additions and 6 deletions

View file

@ -364,12 +364,14 @@ CONFIG_SCHEMA = (
FREQUENCY_SCHEMA = automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(KT0803Component),
cv.Required(CONF_FREQUENCY): cv.float_range(min = 70, max = 108),
cv.Required(CONF_FREQUENCY): cv.float_range(min=70, max=108),
}
)
@automation.register_action("kt0803.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA)
@automation.register_action(
"kt0803.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA
)
async def tune_frequency_action_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
@ -378,7 +380,7 @@ async def tune_frequency_action_to_code(config, action_id, template_arg, args):
cg.add(var.set_frequency(template_))
return var
async def set_var(config, id, setter):
if c := config.get(id):
cg.add(setter(c))

View file

@ -25,6 +25,34 @@ namespace kt0803 {
void set_##name##_text(text::Text *text) { this->name##_text_ = text; }
#endif
#define SUB_NUMBER_EX(name) \
SUB_NUMBER(name) \
void publish_##name() { this->publish(this->name##_number_, (float) this->get_##name()); }
#define SUB_SWITCH_EX(name) \
SUB_SWITCH(name) \
void publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); }
#define SUB_SELECT_EX(name) \
SUB_SELECT(name) \
void publish_##name() { this->publish_select(this->name##_select_, (size_t) this->get_##name()); }
#define SUB_TEXT_EX(name) \
SUB_TEXT(name) \
void publish_##name() { this->publish(this->name##_text_, this->get_##name()); }
#define SUB_SENSOR_EX(name) \
SUB_SENSOR(name) \
void publish_##name() { this->publish(this->name##_sensor_, (float) this->get_##name()); }
#define SUB_BINARY_SENSOR_EX(name) \
SUB_BINARY_SENSOR(name) \
void publish_##name() { this->publish(this->name##_binary_sensor_, this->get_##name()); }
#define SUB_TEXT_SENSOR_EX(name) \
SUB_TEXT_SENSOR(name) \
void publish_##name() { this->publish(this->name##_text_sensor_, this->get_##name()); }
class KT0803Component : public PollingComponent, public i2c::I2CDevice {
ChipId chip_id_; // no way to detect it
bool reset_;
@ -200,9 +228,7 @@ class KT0803Component : public PollingComponent, public i2c::I2CDevice {
template<typename... Ts> class SetFrequencyAction : public Action<Ts...>, public Parented<KT0803Component> {
TEMPLATABLE_VALUE(float, frequency)
void play(Ts... x) override {
this->parent_->set_frequency(this->frequency_.value(x...));
}
void play(Ts... x) override { this->parent_->set_frequency(this->frequency_.value(x...)); }
};
} // namespace kt0803