Skip to content

Commit

Permalink
Add an automation Action for processing data.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfleming committed Sep 2, 2023
1 parent 5dace28 commit dfca65a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion FULL_CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ interval:
on_response:
then:
- delay: 3s
- lambda: id(solar).process_data(response.data);
- sunpower_solar.process: response.data
```

This final section configures an `interval` component so that ESPHome
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ interval:
on_response:
then:
- delay: 3s
- lambda: id(solar).process_data(response.data);
- sunpower_solar.process: response.data
```

This final section configures an `interval` component so that ESPHome
Expand Down
24 changes: 24 additions & 0 deletions components/sunpower_solar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from esphome import automation
from esphome.automation import LambdaAction
from esphome.core import Lambda
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import (
Expand Down Expand Up @@ -133,3 +136,24 @@ async def to_code(config):
cg.add(pvs.set_production_meter(pm))
cg.add(pm.set_serial(production[CONF_SERIAL]))
cg.add(var.add_device(pm))


CONF_SUNPOWER_SOLAR_PROCESS = "sunpower_solar.process"
SUNPOWER_SOLAR_PROCESS_ACTION_SCHEMA = cv.maybe_simple_value(
{
cv.GenerateID(): cv.use_id(SunpowerSolar),
cv.Required(CONF_DATA): cv.lambda_,
},
key=CONF_DATA,
)


@automation.register_action(
CONF_SUNPOWER_SOLAR_PROCESS, LambdaAction, SUNPOWER_SOLAR_PROCESS_ACTION_SCHEMA
)
async def sunpower_solar_process_action_to_code(config, action_id, template_arg, args):
solar_ = await cg.get_variable(config[CONF_ID])
data_ = cg.RawExpression(str(config[CONF_DATA]))
text = str(cg.statement(solar_.process_data(data_)))
lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
return cg.new_Pvariable(action_id, template_arg, lambda_)
2 changes: 1 addition & 1 deletion examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ interval:
on_response:
then:
- delay: 3s
- lambda: id(solar).process_data(response.data);
- sunpower_solar.process: response.data
2 changes: 1 addition & 1 deletion examples/minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ interval:
on_response:
then:
- delay: 3s
- lambda: id(solar).process_data(response.data);
- sunpower_solar.process: response.data

0 comments on commit dfca65a

Please sign in to comment.