mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 03:12:20 +01:00
🏗 Merge C++ into python codebase (#504)
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
This commit is contained in:
28
tests/livingroom32.cpp
Normal file
28
tests/livingroom32.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <esphome.h>
|
||||
|
||||
using namespace esphome;
|
||||
|
||||
void setup() {
|
||||
App.set_name("livingroom32");
|
||||
App.init_log();
|
||||
|
||||
App.init_wifi("YOUR_SSID", "YOUR_PASSWORD");
|
||||
App.init_mqtt("MQTT_HOST", "USERNAME", "PASSWORD");
|
||||
App.init_ota()->start_safe_mode();
|
||||
|
||||
// LEDC is only available on ESP32! for the ESP8266, take a look at App.make_esp8266_pwm_output().
|
||||
auto *red = App.make_ledc_output(32); // on pin 32
|
||||
auto *green = App.make_ledc_output(33);
|
||||
auto *blue = App.make_ledc_output(34);
|
||||
App.make_rgb_light("Livingroom Light", red, green, blue);
|
||||
|
||||
App.make_dht_sensor("Livingroom Temperature", "Livingroom Humidity", 12);
|
||||
App.make_status_binary_sensor("Livingroom Node Status");
|
||||
App.make_restart_switch("Livingroom Restart");
|
||||
|
||||
App.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
App.loop();
|
||||
}
|
34
tests/livingroom8266.cpp
Normal file
34
tests/livingroom8266.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <esphome/core/application.h>
|
||||
#include <esphome/components/logger/logger.h>
|
||||
#include <esphome/components/wifi/wifi_component.h>
|
||||
#include <esphome/components/ota/ota_component.h>
|
||||
#include <esphome/components/gpio/switch/gpio_switch.h>
|
||||
|
||||
using namespace esphome;
|
||||
|
||||
void setup() {
|
||||
App.pre_setup("livingroom", __DATE__ " " __TIME__);
|
||||
auto *log = new logger::Logger(115200, 512, logger::UART_SELECTION_UART0);
|
||||
log->pre_setup();
|
||||
App.register_component(log);
|
||||
|
||||
auto *wifi = new wifi::WiFiComponent();
|
||||
App.register_component(wifi);
|
||||
wifi::WiFiAP ap;
|
||||
ap.set_ssid("Test SSID");
|
||||
ap.set_password("password1");
|
||||
wifi->add_sta(ap);
|
||||
|
||||
auto *ota = new ota::OTAComponent(8266);
|
||||
ota->start_safe_mode();
|
||||
|
||||
auto *gpio = new gpio::GPIOSwitch("GPIO Switch", new GPIOPin(8, OUTPUT));
|
||||
App.register_component(gpio);
|
||||
App.register_switch(gpio);
|
||||
|
||||
App.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
App.loop();
|
||||
}
|
195
tests/test1.yaml
195
tests/test1.yaml
@@ -2,12 +2,6 @@ esphome:
|
||||
name: test1
|
||||
platform: ESP32
|
||||
board: nodemcu-32s
|
||||
# Use this for testing while developing:
|
||||
# Note the travis check for esphome PRs will fail until the
|
||||
# esphome-core PR has been merged.
|
||||
# esphome_core_version:
|
||||
# local: ~/path/to/esphome-core
|
||||
use_custom_code: false
|
||||
on_boot:
|
||||
priority: 150.0
|
||||
then:
|
||||
@@ -709,18 +703,6 @@ output:
|
||||
- platform: my9231
|
||||
id: my_5
|
||||
channel: 5
|
||||
- platform: copy
|
||||
id: my_copy1
|
||||
outputs:
|
||||
- my_1
|
||||
- my_2
|
||||
- my_3
|
||||
- platform: copy
|
||||
id: my_copy2
|
||||
type: binary
|
||||
outputs:
|
||||
- id22
|
||||
- id2
|
||||
|
||||
light:
|
||||
- platform: binary
|
||||
@@ -874,6 +856,7 @@ light:
|
||||
|
||||
remote_transmitter:
|
||||
- pin: 32
|
||||
carrier_duty_percent: 100%
|
||||
|
||||
switch:
|
||||
- platform: gpio
|
||||
@@ -883,92 +866,94 @@ switch:
|
||||
inverted: True
|
||||
command_topic: custom_command_topic
|
||||
restore_mode: ALWAYS_OFF
|
||||
- platform: remote_transmitter
|
||||
name: "JVC Off"
|
||||
jvc:
|
||||
data: 0x10EF
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
nec:
|
||||
address: 0x4242
|
||||
command: 0x8484
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
lg:
|
||||
data: 4294967295
|
||||
nbits: 28
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
samsung:
|
||||
data: 0xABCDEF
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
sony:
|
||||
data: 0xABCDEF
|
||||
nbits: 12
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
panasonic:
|
||||
address: 0x4004
|
||||
command: 0x1000BCD
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
rc_switch_raw:
|
||||
code: '001010011001111101011011'
|
||||
protocol: 1
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
rc_switch_type_a:
|
||||
group: '11001'
|
||||
device: '01000'
|
||||
state: True
|
||||
protocol:
|
||||
pulse_length: 175
|
||||
sync: [1, 31]
|
||||
zero: [1, 3]
|
||||
one: [3, 1]
|
||||
inverted: False
|
||||
repeat: 25
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
rc_switch_type_b:
|
||||
address: 4
|
||||
channel: 2
|
||||
state: True
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
rc_switch_type_c:
|
||||
family: 'a'
|
||||
group: 1
|
||||
device: 2
|
||||
state: True
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
- platform: template
|
||||
name: JVC Off
|
||||
id: living_room_lights_on
|
||||
rc_switch_type_d:
|
||||
group: 'a'
|
||||
device: 2
|
||||
state: True
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
rc5:
|
||||
address: 0x00
|
||||
command: 0x0B
|
||||
- platform: remote_transmitter
|
||||
name: "Panasonic TV Off"
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_jvc:
|
||||
data: 0x10EF
|
||||
- platform: template
|
||||
name: NEC
|
||||
id: living_room_lights_off
|
||||
raw:
|
||||
carrier_frequency: 35kHz
|
||||
data:
|
||||
- 1000
|
||||
- -1000
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_nec:
|
||||
address: 0x4242
|
||||
command: 0x8484
|
||||
- platform: template
|
||||
name: LG
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_lg:
|
||||
data: 4294967295
|
||||
nbits: 28
|
||||
- platform: template
|
||||
name: Samsung
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_samsung:
|
||||
data: 0xABCDEF
|
||||
- platform: template
|
||||
name: Sony
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_sony:
|
||||
data: 0xABCDEF
|
||||
nbits: 12
|
||||
- platform: template
|
||||
name: Panasonic
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_panasonic:
|
||||
address: 0x4004
|
||||
command: 0x1000BCD
|
||||
- platform: template
|
||||
name: RC Switch Raw
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc_switch_raw:
|
||||
code: '001010011001111101011011'
|
||||
protocol: 1
|
||||
- platform: template
|
||||
name: RC Switch Type A
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc_switch_type_a:
|
||||
group: '11001'
|
||||
device: '01000'
|
||||
state: True
|
||||
protocol:
|
||||
pulse_length: 175
|
||||
sync: [1, 31]
|
||||
zero: [1, 3]
|
||||
one: [3, 1]
|
||||
inverted: False
|
||||
- platform: template
|
||||
name: RC Switch Type B
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc_switch_type_b:
|
||||
address: 4
|
||||
channel: 2
|
||||
state: True
|
||||
- platform: template
|
||||
name: RC Switch Type C
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc_switch_type_c:
|
||||
family: 'a'
|
||||
group: 1
|
||||
device: 2
|
||||
state: True
|
||||
- platform: template
|
||||
name: RC Switch Type D
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc_switch_type_d:
|
||||
group: 'a'
|
||||
device: 2
|
||||
state: True
|
||||
- platform: template
|
||||
name: RC5
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_rc5:
|
||||
address: 0x00
|
||||
command: 0x0B
|
||||
- platform: template
|
||||
name: RC5
|
||||
turn_on_action:
|
||||
remote_transmitter.transmit_raw:
|
||||
code: [1000, -1000]
|
||||
- platform: template
|
||||
name: Living Room Lights
|
||||
id: livingroom_lights
|
||||
@@ -1061,8 +1046,8 @@ interval:
|
||||
then:
|
||||
- display.page.show: !lambda |-
|
||||
if (true) return id(page1); else return id(page2);
|
||||
- display.page.show_next: display
|
||||
- display.page.show_previous: display
|
||||
- display.page.show_next: display1
|
||||
- display.page.show_previous: display1
|
||||
|
||||
display:
|
||||
- platform: lcd_gpio
|
||||
@@ -1094,7 +1079,7 @@ display:
|
||||
model: "SSD1306 128x64"
|
||||
reset_pin: GPIO23
|
||||
address: 0x3C
|
||||
id: display
|
||||
id: display1
|
||||
pages:
|
||||
- id: page1
|
||||
lambda: |-
|
||||
|
@@ -2,11 +2,6 @@ esphome:
|
||||
name: $devicename
|
||||
platform: ESP32
|
||||
board: nodemcu-32s
|
||||
# Use this for testing while developing:
|
||||
# Note the travis check for esphome PRs will fail until the
|
||||
# esphome-core PR has been merged.
|
||||
# esphome_core_version:
|
||||
# local: ~/path/to/esphome-core
|
||||
build_path: build/test2
|
||||
|
||||
substitutions:
|
||||
@@ -142,7 +137,7 @@ esp32_touch:
|
||||
setup_mode: True
|
||||
|
||||
binary_sensor:
|
||||
- platform: esp32_ble_tracker
|
||||
- platform: ble_presence
|
||||
mac_address: AC:37:43:77:5F:4C
|
||||
name: "ESP32 BLE Tracker Google Home Mini"
|
||||
- platform: esp32_touch
|
||||
@@ -201,6 +196,8 @@ text_sensor:
|
||||
variables:
|
||||
my_variable: |-
|
||||
return id(version_sensor).state;
|
||||
my_variable_str: |-
|
||||
return "Hello World";
|
||||
- platform: template
|
||||
name: "Template Text Sensor"
|
||||
lambda: |-
|
||||
|
@@ -2,11 +2,6 @@ esphome:
|
||||
name: $devicename
|
||||
platform: ESP8266
|
||||
board: esp07
|
||||
# Use this for testing while developing:
|
||||
# Note the travis check for esphome PRs will fail until the
|
||||
# esphome-core PR has been merged.
|
||||
# esphome_core_version:
|
||||
# local: ~/path/to/esphome-core
|
||||
build_path: build/test3
|
||||
|
||||
substitutions:
|
||||
@@ -44,39 +39,6 @@ deep_sleep:
|
||||
sleep_duration: 50s
|
||||
|
||||
sensor:
|
||||
- platform: pmsx003
|
||||
type: PMSX003
|
||||
pm_1_0:
|
||||
name: "PM 1.0 Concentration"
|
||||
pm_2_5:
|
||||
name: "PM 2.5 Concentration"
|
||||
pm_10_0:
|
||||
name: "PM 10.0 Concentration"
|
||||
- platform: pmsx003
|
||||
type: PMS5003T
|
||||
pm_2_5:
|
||||
name: "PM 2.5 Concentration"
|
||||
temperature:
|
||||
name: "PMS Temperature"
|
||||
humidity:
|
||||
name: "PMS Humidity"
|
||||
- platform: pmsx003
|
||||
type: PMS5003ST
|
||||
pm_2_5:
|
||||
name: "PM 2.5 Concentration"
|
||||
temperature:
|
||||
name: "PMS Temperature"
|
||||
humidity:
|
||||
name: "PMS Humidity"
|
||||
formaldehyde:
|
||||
name: "PMS Formaldehyde Concentration"
|
||||
- platform: cse7766
|
||||
voltage:
|
||||
name: "CSE7766 Voltage"
|
||||
current:
|
||||
name: "CSE7766 Current"
|
||||
power:
|
||||
name: "CSE776 Power"
|
||||
- platform: apds9960
|
||||
type: proximity
|
||||
name: APDS9960 Proximity
|
||||
|
Reference in New Issue
Block a user