1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 03:12:20 +01:00

Create Protobuf Plugin for automatically generating native API stubs (#633)

* Create Protobuf Plugin for automatically generating native API stubs

* Format

* Delete api.proto

* Cleanup, use no_delay conditionally

* Updates

* Update

* Lint

* Lint

* Fixes

* Camera

* CustomAPIDevice

* Fix negative VarInt, Add User-defined services arrays

* Home Assistant Event

* Fixes

* Update custom_api_device.h
This commit is contained in:
Otto Winter
2019-06-18 19:31:22 +02:00
committed by GitHub
parent fc465d6d93
commit 369d175694
47 changed files with 7183 additions and 3110 deletions

View File

@@ -41,3 +41,32 @@ class CustomFloatOutput : public FloatOutput, public Component {
protected:
void write_state(float state) override { ESP_LOGD("custom_output", "Setting %f", state); }
};
class CustomNativeAPI : public Component, public CustomAPIDevice {
public:
void setup() override {
register_service(&CustomNativeAPI::on_hello_world, "hello_world");
register_service(&CustomNativeAPI::on_start_dryer, "start_dryer", {"value"});
register_service(&CustomNativeAPI::on_many_values, "many_values", {"bool", "int", "float", "str1", "str2"});
subscribe_homeassistant_state(&CustomNativeAPI::on_light_state, "light.my_light");
}
void on_hello_world() { ESP_LOGD("custom_api", "Hello World from native API service!"); }
void on_start_dryer(int value) { ESP_LOGD("custom_api", "Value is %d", value); }
void on_many_values(bool a_bool, int a_int, float a_float, std::string str1, std::string str2) {
ESP_LOGD("custom_api", "Bool: %s", ONOFF(a_bool));
ESP_LOGD("custom_api", "Int: %d", a_int);
ESP_LOGD("custom_api", "Float: %f", a_float);
ESP_LOGD("custom_api", "String1: %s", str1.c_str());
ESP_LOGD("custom_api", "String2: %s", str2.c_str());
ESP_LOGD("custom_api", "Connected: %s", YESNO(is_connected()));
call_homeassistant_service("light.turn_on", {
{"entity_id", "light.my_light"},
{"brightness", "127"},
});
// no args
call_homeassistant_service("homeassistant.restart");
}
void on_light_state(std::string state) { ESP_LOGD("custom_api", "Got state %s", state.c_str()); }
};

View File

@@ -40,6 +40,24 @@ api:
- stepper.set_target:
id: my_stepper2
target: !lambda 'return int_;'
- service: array_types
variables:
bool_arr: bool[]
int_arr: int[]
float_arr: float[]
string_arr: string[]
then:
- logger.log:
format: 'Bool: %s (%u), Int: %d (%u), Float: %f (%u), String: %s (%u)'
args:
- YESNO(bool_arr[0])
- bool_arr.size()
- int_arr[0]
- int_arr.size()
- float_arr[0]
- float_arr.size()
- string_arr[0].c_str()
- string_arr.size()
wifi:
ssid: 'MySSID'