Add Actions

This commit is contained in:
Václav Španinger 2024-12-31 08:18:35 +01:00
parent 204f48f596
commit 97450423d3
4 changed files with 18 additions and 1 deletions

View File

@ -42,6 +42,7 @@ Notes:
* https://github.com/esphome/esphome/blob/dev/esphome/components/dht/sensor.py#L34
* https://github.com/mulcmu/esphome-marlin-uart
* https://github.com/oxan/esphome-stream-server/blob/master/components/stream_server/stream_server.cpp
* https://github.com/esphome/esphome/blob/dev/esphome/components/api/__init__.py
Full COnfiguration:
```yaml

View File

@ -31,6 +31,11 @@ CONFIG_SCHEMA = cv.All(
.extend(uart.UART_DEVICE_SCHEMA),
)
@automation.register_action("marlin2.set_bed_temperature", SetTemperatureAction, SWITCH_ACTION_SCHEMA)
async def marlin2_set_bed_temperature_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)

View File

@ -48,8 +48,17 @@ namespace esphome {
flush();
set_printer_state("IDLE");
register_service(&Marlin2::set_bed_setpoint, "set_bed_setpoint", {"temp_degC"});
register_service(&Marlin2::set_extruder_setpoint, "set_extruder_setpoint", {"temp_degC"});
}
void Marlin2::set_bed_setpoint() {
}
void Marlin2::set_extruder_setpoint() {
}
void Marlin2::update() {
while (available()) {
char c = read();
@ -271,7 +280,7 @@ namespace esphome {
*current = round(((d)*24*60*60) + ((h)*60*60) + ((m)*60) + (s));
if(progress != 0.0 && progress != 100.0) {
*remaining = (((100 * *current) / progress) -*current);
*remaining = (((100 * *current) / round(progress)) - *current);
}
return 1;

View File

@ -24,6 +24,8 @@ class Marlin2 : public PollingComponent, public uart::UARTDevice {
void add_text_sensor(const std::string& sName, text_sensor::TextSensor *tSens);
text_sensor::TextSensor* find_text_sensor(std::string key);
#endif
void set_bed_setpoint();
void set_extruder_setpoint();
float get_setup_priority() const override { return setup_priority::LATE; }
void setup() override;