mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +00:00
ESP-IDF support and generic target platforms (#2303)
* Socket refactor and SSL * esp-idf temp * Fixes * Echo component and noise * Add noise API transport support * Updates * ESP-IDF * Complete * Fixes * Fixes * Versions update * New i2c APIs * Complete i2c refactor * SPI migration * Revert ESP Preferences migration, too complex for now * OTA support * Remove echo again * Remove ssl again * GPIOFlags updates * Rename esphal and ICACHE_RAM_ATTR * Make ESP32 arduino compilable again * Fix GPIO flags * Complete pin registry refactor and fixes * Fixes to make test1 compile * Remove sdkconfig file * Ignore sdkconfig file * Fixes in reviewing * Make test2 compile * Make test4 compile * Make test5 compile * Run clang-format * Fix lint errors * Use esp-idf APIs instead of btStart * Another round of fixes * Start implementing ESP8266 * Make test3 compile * Guard esp8266 code * Lint * Reformat * Fixes * Fixes v2 * more fixes * ESP-IDF tidy target * Convert ARDUINO_ARCH_ESPxx * Update WiFiSignalSensor * Update time ifdefs * OTA needs millis from hal * RestartSwitch needs delay from hal * ESP-IDF Uart * Fix OTA blank password * Allow setting sdkconfig * Fix idf partitions and allow setting sdkconfig from yaml * Re-add read/write compat APIs and fix esp8266 uart * Fix esp8266 store log strings in flash * Fix ESP32 arduino preferences not initialized * Update ifdefs * Change how sdkconfig change is detected * Add checks to ci-custom and fix them * Run clang-format * Add esp-idf clang-tidy target and fix errors * Fixes from clang-tidy idf round 2 * Fixes from compiling tests with esp-idf * Run clang-format * Switch test5.yaml to esp-idf * Implement ESP8266 Preferences * Lint * Re-do PIO package version selection a bit * Fix arduinoespressif32 package version * Fix unit tests * Lint * Lint fixes * Fix readv/writev not defined * Fix graphing component * Re-add all old options from core/config.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -30,7 +30,7 @@ def test_binary_sensor_sets_mandatory_fields(generate_main):
|
||||
|
||||
# Then
|
||||
assert 'bs_1->set_name("test bs1");' in main_cpp
|
||||
assert "bs_1->set_pin(new GPIOPin" in main_cpp
|
||||
assert "bs_1->set_pin(" in main_cpp
|
||||
|
||||
|
||||
def test_binary_sensor_config_value_internal_set(generate_main):
|
||||
|
||||
@@ -27,12 +27,6 @@ void setup() {
|
||||
auto *ota = new ota::OTAComponent(); // NOLINT
|
||||
ota->set_port(8266);
|
||||
|
||||
auto *gpio = new gpio::GPIOSwitch(); // NOLINT
|
||||
gpio->set_name("GPIO Switch");
|
||||
gpio->set_pin(new GPIOPin(8, OUTPUT, false)); // NOLINT
|
||||
App.register_component(gpio);
|
||||
App.register_switch(gpio);
|
||||
|
||||
App.setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ wifi:
|
||||
password: ''
|
||||
channel: 14
|
||||
bssid: 'A1:63:95:47:D3:1D'
|
||||
enable_mdns: true
|
||||
manual_ip:
|
||||
static_ip: 192.168.178.230
|
||||
gateway: 192.168.178.1
|
||||
@@ -82,6 +81,9 @@ wifi:
|
||||
reboot_timeout: 120s
|
||||
power_save_mode: light
|
||||
|
||||
mdns:
|
||||
disabled: false
|
||||
|
||||
http_request:
|
||||
useragent: esphome/device
|
||||
timeout: 10s
|
||||
@@ -170,6 +172,7 @@ i2c:
|
||||
scan: True
|
||||
frequency: 100kHz
|
||||
setup_priority: -100
|
||||
id: i2c_bus
|
||||
|
||||
spi:
|
||||
clk_pin: GPIO21
|
||||
@@ -177,15 +180,18 @@ spi:
|
||||
miso_pin: GPIO23
|
||||
|
||||
uart:
|
||||
- tx_pin: GPIO22
|
||||
rx_pin: GPIO23
|
||||
- tx_pin:
|
||||
number: GPIO22
|
||||
inverted: yes
|
||||
rx_pin:
|
||||
number: GPIO23
|
||||
inverted: yes
|
||||
baud_rate: 115200
|
||||
id: uart0
|
||||
parity: NONE
|
||||
data_bits: 8
|
||||
stop_bits: 1
|
||||
rx_buffer_size: 512
|
||||
invert: false
|
||||
|
||||
- id: adalight_uart
|
||||
tx_pin: GPIO25
|
||||
@@ -246,6 +252,7 @@ deep_sleep:
|
||||
|
||||
ads1115:
|
||||
address: 0x48
|
||||
i2c_id: i2c_bus
|
||||
|
||||
dallas:
|
||||
pin: GPIO23
|
||||
@@ -436,6 +443,7 @@ sensor:
|
||||
availability:
|
||||
state_topic: livingroom/custom_state_topic
|
||||
measurement_duration: 31
|
||||
i2c_id: i2c_bus
|
||||
- platform: bme280
|
||||
temperature:
|
||||
name: 'Outside Temperature'
|
||||
@@ -449,6 +457,7 @@ sensor:
|
||||
address: 0x77
|
||||
iir_filter: 16x
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: bme680
|
||||
temperature:
|
||||
name: 'Outside Temperature'
|
||||
@@ -464,6 +473,7 @@ sensor:
|
||||
temperature: 320
|
||||
duration: 150ms
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: bmp085
|
||||
temperature:
|
||||
name: 'Outside Temperature'
|
||||
@@ -473,6 +483,7 @@ sensor:
|
||||
- lambda: >-
|
||||
return x / powf(1.0 - (x / 44330.0), 5.255);
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: bmp280
|
||||
temperature:
|
||||
name: 'Outside Temperature'
|
||||
@@ -482,6 +493,7 @@ sensor:
|
||||
address: 0x77
|
||||
update_interval: 15s
|
||||
iir_filter: 16x
|
||||
i2c_id: i2c_bus
|
||||
- platform: dallas
|
||||
address: 0x1C0000031EDD2A28
|
||||
name: 'Living Room Temperature'
|
||||
@@ -503,6 +515,7 @@ sensor:
|
||||
humidity:
|
||||
name: 'Living Room Humidity 4'
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: duty_cycle
|
||||
pin: GPIO25
|
||||
name: Duty Cycle Sensor
|
||||
@@ -515,6 +528,7 @@ sensor:
|
||||
humidity:
|
||||
name: 'Living Room Pressure 5'
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: hlw8012
|
||||
sel_pin: 5
|
||||
cf_pin: 14
|
||||
@@ -560,6 +574,7 @@ sensor:
|
||||
range: 130uT
|
||||
oversampling: 8x
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: qmc5883l
|
||||
address: 0x0D
|
||||
field_strength_x:
|
||||
@@ -573,6 +588,7 @@ sensor:
|
||||
range: 800uT
|
||||
oversampling: 256x
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: hx711
|
||||
name: 'HX711 Value'
|
||||
dout_pin: GPIO23
|
||||
@@ -593,6 +609,7 @@ sensor:
|
||||
max_voltage: 32.0V
|
||||
max_current: 3.2A
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: ina226
|
||||
address: 0x40
|
||||
shunt_resistance: 0.1 ohm
|
||||
@@ -606,6 +623,7 @@ sensor:
|
||||
name: 'INA226 Shunt Voltage'
|
||||
max_current: 3.2A
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: ina3221
|
||||
address: 0x40
|
||||
channel_1:
|
||||
@@ -619,12 +637,14 @@ sensor:
|
||||
shunt_voltage:
|
||||
name: 'INA3221 Channel 1 Shunt Voltage'
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: htu21d
|
||||
temperature:
|
||||
name: 'Living Room Temperature 6'
|
||||
humidity:
|
||||
name: 'Living Room Humidity 6'
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: max6675
|
||||
name: 'Living Room Temperature'
|
||||
cs_pin: GPIO23
|
||||
@@ -670,6 +690,7 @@ sensor:
|
||||
name: 'MPU6050 Gyro z'
|
||||
temperature:
|
||||
name: 'MPU6050 Temperature'
|
||||
i2c_id: i2c_bus
|
||||
- platform: ms5611
|
||||
temperature:
|
||||
name: 'Outside Temperature'
|
||||
@@ -677,6 +698,7 @@ sensor:
|
||||
name: 'Outside Pressure'
|
||||
address: 0x77
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: pmsa003i
|
||||
pm_1_0:
|
||||
name: "PMSA003i PM1.0"
|
||||
@@ -698,6 +720,7 @@ sensor:
|
||||
name: "PMSA003i PMC <10µm"
|
||||
address: 0x12
|
||||
standard_units: True
|
||||
i2c_id: i2c_bus
|
||||
- platform: pulse_counter
|
||||
name: 'Pulse Counter'
|
||||
pin: GPIO12
|
||||
@@ -768,10 +791,12 @@ sensor:
|
||||
humidity:
|
||||
name: 'Living Room Humidity 8'
|
||||
address: 0x44
|
||||
i2c_id: i2c_bus
|
||||
update_interval: 15s
|
||||
- platform: sts3x
|
||||
name: 'Living Room Temperature 9'
|
||||
address: 0x4A
|
||||
i2c_id: i2c_bus
|
||||
- platform: scd30
|
||||
co2:
|
||||
name: 'Living Room CO2 9'
|
||||
@@ -785,6 +810,7 @@ sensor:
|
||||
altitude_compensation: 10m
|
||||
ambient_pressure_compensation: 961mBar
|
||||
temperature_offset: 4.2C
|
||||
i2c_id: i2c_bus
|
||||
- platform: sgp30
|
||||
eco2:
|
||||
name: 'Workshop eCO2'
|
||||
@@ -794,6 +820,7 @@ sensor:
|
||||
accuracy_decimals: 1
|
||||
address: 0x58
|
||||
update_interval: 5s
|
||||
i2c_id: i2c_bus
|
||||
- platform: sps30
|
||||
pm_1_0:
|
||||
name: 'Workshop PM <1µm Weight concentration'
|
||||
@@ -824,6 +851,7 @@ sensor:
|
||||
id: 'workshop_PMC_10_0'
|
||||
address: 0x69
|
||||
update_interval: 10s
|
||||
i2c_id: i2c_bus
|
||||
- platform: sht4x
|
||||
temperature:
|
||||
name: 'SHT4X Temperature'
|
||||
@@ -831,6 +859,7 @@ sensor:
|
||||
name: 'SHT4X Humidity'
|
||||
address: 0x44
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: shtcx
|
||||
temperature:
|
||||
name: 'Living Room Temperature 10'
|
||||
@@ -838,6 +867,7 @@ sensor:
|
||||
name: 'Living Room Humidity 10'
|
||||
address: 0x70
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: template
|
||||
name: 'Template Sensor'
|
||||
state_class: measurement
|
||||
@@ -863,6 +893,7 @@ sensor:
|
||||
is_cs_package: true
|
||||
integration_time: 402ms
|
||||
gain: 16x
|
||||
i2c_id: i2c_bus
|
||||
- platform: tsl2591
|
||||
id: this_little_light_of_mine
|
||||
address: 0x29
|
||||
@@ -882,6 +913,7 @@ sensor:
|
||||
calculated_lux:
|
||||
name: "tsl2591 calculated_lux"
|
||||
id: tsl2591_cl
|
||||
i2c_id: i2c_bus
|
||||
- platform: ultrasonic
|
||||
trigger_pin: GPIO25
|
||||
echo_pin:
|
||||
@@ -921,6 +953,7 @@ sensor:
|
||||
name: CCS811 TVOC
|
||||
update_interval: 30s
|
||||
baseline: 0x4242
|
||||
i2c_id: i2c_bus
|
||||
- platform: tx20
|
||||
wind_speed:
|
||||
name: 'Windspeed'
|
||||
@@ -946,6 +979,7 @@ sensor:
|
||||
- platform: tmp117
|
||||
name: 'TMP117 Temperature'
|
||||
update_interval: 5s
|
||||
i2c_id: i2c_bus
|
||||
- platform: hm3301
|
||||
pm_1_0:
|
||||
name: 'PM1.0'
|
||||
@@ -956,6 +990,7 @@ sensor:
|
||||
aqi:
|
||||
name: 'AQI'
|
||||
calculation_type: 'CAQI'
|
||||
i2c_id: i2c_bus
|
||||
- platform: teleinfo
|
||||
tag_name: "HCHC"
|
||||
name: "hchc"
|
||||
@@ -965,15 +1000,18 @@ sensor:
|
||||
- platform: mcp9808
|
||||
name: 'MCP9808 Temperature'
|
||||
update_interval: 15s
|
||||
i2c_id: i2c_bus
|
||||
- platform: ezo
|
||||
id: ph_ezo
|
||||
address: 99
|
||||
unit_of_measurement: 'pH'
|
||||
i2c_id: i2c_bus
|
||||
- platform: sdp3x
|
||||
name: "HVAC Filter Pressure drop"
|
||||
id: filter_pressure
|
||||
update_interval: 5s
|
||||
accuracy_decimals: 3
|
||||
i2c_id: i2c_bus
|
||||
- platform: cs5460a
|
||||
id: cs5460a1
|
||||
current:
|
||||
@@ -1216,14 +1254,18 @@ binary_sensor:
|
||||
pca9685:
|
||||
frequency: 500
|
||||
address: 0x0
|
||||
i2c_id: i2c_bus
|
||||
|
||||
tlc59208f:
|
||||
- address: 0x20
|
||||
id: tlc59208f_1
|
||||
i2c_id: i2c_bus
|
||||
- address: 0x22
|
||||
id: tlc59208f_2
|
||||
i2c_id: i2c_bus
|
||||
- address: 0x24
|
||||
id: tlc59208f_3
|
||||
i2c_id: i2c_bus
|
||||
|
||||
my9231:
|
||||
data_pin: GPIO12
|
||||
@@ -1363,6 +1405,7 @@ output:
|
||||
id: dac_output
|
||||
- platform: mcp4725
|
||||
id: mcp4725_dac_output
|
||||
i2c_id: i2c_bus
|
||||
|
||||
e131:
|
||||
|
||||
@@ -1992,6 +2035,7 @@ display:
|
||||
address: 0x3F
|
||||
lambda: |-
|
||||
it.print("Hello World!");
|
||||
i2c_id: i2c_bus
|
||||
- platform: max7219
|
||||
cs_pin: GPIO23
|
||||
num_chips: 1
|
||||
@@ -2039,6 +2083,7 @@ display:
|
||||
then:
|
||||
lambda: |-
|
||||
ESP_LOGD("display", "1 -> 2");
|
||||
i2c_id: i2c_bus
|
||||
- platform: ssd1306_spi
|
||||
model: 'SSD1306 128x64'
|
||||
cs_pin: GPIO23
|
||||
@@ -2073,6 +2118,7 @@ display:
|
||||
- id: page13272
|
||||
lambda: |-
|
||||
// Nothing
|
||||
i2c_id: i2c_bus
|
||||
- platform: ssd1327_spi
|
||||
model: 'SSD1327 128x128'
|
||||
cs_pin: GPIO23
|
||||
@@ -2151,6 +2197,7 @@ pn532_spi:
|
||||
payload: !lambda 'return x;'
|
||||
|
||||
pn532_i2c:
|
||||
i2c_id: i2c_bus
|
||||
|
||||
rdm6300:
|
||||
uart_id: uart0
|
||||
@@ -2167,11 +2214,13 @@ rc522_i2c:
|
||||
on_tag:
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Found tag %s", x.c_str());
|
||||
i2c_id: i2c_bus
|
||||
|
||||
- update_interval: 1s
|
||||
on_tag:
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Found tag %s", x.c_str());
|
||||
i2c_id: i2c_bus
|
||||
|
||||
gps:
|
||||
uart_id: uart0
|
||||
@@ -2198,6 +2247,7 @@ time:
|
||||
on_time:
|
||||
seconds: 0
|
||||
then: ds1307.read_time
|
||||
i2c_id: i2c_bus
|
||||
|
||||
cover:
|
||||
- platform: template
|
||||
@@ -2225,31 +2275,35 @@ debug:
|
||||
tca9548a:
|
||||
- address: 0x70
|
||||
id: multiplex0
|
||||
scan: True
|
||||
channels:
|
||||
- bus_id: multiplex0_chan0
|
||||
channel: 0
|
||||
i2c_id: i2c_bus
|
||||
- address: 0x71
|
||||
id: multiplex1
|
||||
scan: True
|
||||
multiplexer:
|
||||
id: multiplex0
|
||||
channel: 0
|
||||
i2c_id: multiplex0_chan0
|
||||
|
||||
pcf8574:
|
||||
- id: 'pcf8574_hub'
|
||||
address: 0x21
|
||||
pcf8575: False
|
||||
i2c_id: i2c_bus
|
||||
|
||||
mcp23017:
|
||||
- id: 'mcp23017_hub'
|
||||
open_drain_interrupt: 'true'
|
||||
i2c_id: i2c_bus
|
||||
|
||||
mcp23008:
|
||||
- id: 'mcp23008_hub'
|
||||
address: 0x22
|
||||
open_drain_interrupt: 'true'
|
||||
i2c_id: i2c_bus
|
||||
|
||||
mcp23016:
|
||||
- id: 'mcp23016_hub'
|
||||
address: 0x23
|
||||
i2c_id: i2c_bus
|
||||
|
||||
stepper:
|
||||
- platform: a4988
|
||||
|
||||
@@ -14,13 +14,15 @@ ethernet:
|
||||
clk_mode: GPIO0_IN
|
||||
phy_addr: 0
|
||||
power_pin: GPIO25
|
||||
enable_mdns: false
|
||||
manual_ip:
|
||||
static_ip: 192.168.178.56
|
||||
gateway: 192.168.178.1
|
||||
subnet: 255.255.255.0
|
||||
domain: .local
|
||||
|
||||
mdns:
|
||||
disabled: true
|
||||
|
||||
api:
|
||||
|
||||
i2c:
|
||||
@@ -360,7 +362,7 @@ esp32_ble_tracker:
|
||||
ble_client:
|
||||
- mac_address: 01:02:03:04:05:06
|
||||
id: airthings01
|
||||
|
||||
|
||||
airthings_ble:
|
||||
|
||||
#esp32_ble_beacon:
|
||||
|
||||
@@ -259,7 +259,7 @@ ota:
|
||||
logger:
|
||||
hardware_uart: UART1
|
||||
level: DEBUG
|
||||
esp8266_store_log_strings_in_flash: false
|
||||
esp8266_store_log_strings_in_flash: true
|
||||
|
||||
web_server:
|
||||
|
||||
|
||||
@@ -379,7 +379,7 @@ display:
|
||||
it.rectangle(3, 3, it.get_width()-6, it.get_height()-6, red);
|
||||
rotation: 0°
|
||||
update_interval: 16ms
|
||||
|
||||
|
||||
- platform: waveshare_epaper
|
||||
cs_pin: GPIO23
|
||||
dc_pin: GPIO23
|
||||
@@ -407,6 +407,23 @@ display:
|
||||
full_update_every: 30
|
||||
lambda: |-
|
||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||
- platform: inkplate6
|
||||
id: inkplate_display
|
||||
greyscale: false
|
||||
partial_updating: false
|
||||
update_interval: 60s
|
||||
|
||||
ckv_pin: GPIO1
|
||||
sph_pin: GPIO1
|
||||
gmod_pin: GPIO1
|
||||
gpio0_enable_pin: GPIO1
|
||||
oe_pin: GPIO1
|
||||
spv_pin: GPIO1
|
||||
powerup_pin: GPIO1
|
||||
wakeup_pin: GPIO1
|
||||
vcom_pin: GPIO1
|
||||
|
||||
|
||||
|
||||
text_sensor:
|
||||
- platform: pipsolar
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
esphome:
|
||||
name: test5
|
||||
platform: ESP32
|
||||
board: nodemcu-32s
|
||||
build_path: build/test5
|
||||
project:
|
||||
name: esphome.test5_project
|
||||
version: "1.0.0"
|
||||
|
||||
esp32:
|
||||
board: nodemcu-32s
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
wifi:
|
||||
networks:
|
||||
- ssid: 'MySSID'
|
||||
@@ -151,20 +154,3 @@ sensor:
|
||||
uart_id: uart2
|
||||
co2:
|
||||
name: CO2 Sensor
|
||||
|
||||
display:
|
||||
- platform: inkplate6
|
||||
id: inkplate_display
|
||||
greyscale: false
|
||||
partial_updating: false
|
||||
update_interval: 60s
|
||||
|
||||
ckv_pin: GPIO1
|
||||
sph_pin: GPIO1
|
||||
gmod_pin: GPIO1
|
||||
gpio0_enable_pin: GPIO1
|
||||
oe_pin: GPIO1
|
||||
spv_pin: GPIO1
|
||||
powerup_pin: GPIO1
|
||||
wakeup_pin: GPIO1
|
||||
vcom_pin: GPIO1
|
||||
|
||||
@@ -531,13 +531,13 @@ class TestEsphomeCore:
|
||||
assert target.address == "4.3.2.1"
|
||||
|
||||
def test_is_esp32(self, target):
|
||||
target.esp_platform = "ESP32"
|
||||
target.data[const.KEY_CORE] = {const.KEY_TARGET_PLATFORM: "esp32"}
|
||||
|
||||
assert target.is_esp32 is True
|
||||
assert target.is_esp8266 is False
|
||||
|
||||
def test_is_esp8266(self, target):
|
||||
target.esp_platform = "ESP8266"
|
||||
target.data[const.KEY_CORE] = {const.KEY_TARGET_PLATFORM: "esp8266"}
|
||||
|
||||
assert target.is_esp32 is False
|
||||
assert target.is_esp8266 is True
|
||||
|
||||
@@ -3,7 +3,6 @@ from mock import Mock
|
||||
|
||||
from esphome import cpp_helpers as ch
|
||||
from esphome import const
|
||||
from esphome.cpp_generator import MockObj
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -13,15 +12,6 @@ async def test_gpio_pin_expression__conf_is_none(monkeypatch):
|
||||
assert actual is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gpio_pin_expression__new_pin(monkeypatch):
|
||||
actual = await ch.gpio_pin_expression(
|
||||
{const.CONF_NUMBER: 42, const.CONF_MODE: "input", const.CONF_INVERTED: False}
|
||||
)
|
||||
|
||||
assert isinstance(actual, MockObj)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_component(monkeypatch):
|
||||
var = Mock(base="foo.bar")
|
||||
|
||||
@@ -1,346 +0,0 @@
|
||||
"""
|
||||
Please Note:
|
||||
|
||||
These tests cover the process of identifying information about pins, they do not
|
||||
check if the definition of MCUs and pins is correct.
|
||||
|
||||
"""
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.config_validation import Invalid
|
||||
from esphome.core import EsphomeCore
|
||||
from esphome import boards, pins
|
||||
|
||||
|
||||
MOCK_ESP8266_BOARD_ID = "_mock_esp8266"
|
||||
MOCK_ESP8266_PINS = {"X0": 16, "X1": 5, "X2": 4, "LED": 2}
|
||||
MOCK_ESP8266_BOARD_ALIAS_ID = "_mock_esp8266_alias"
|
||||
MOCK_ESP8266_FLASH_SIZE = boards.FLASH_SIZE_2_MB
|
||||
|
||||
MOCK_ESP32_BOARD_ID = "_mock_esp32"
|
||||
MOCK_ESP32_PINS = {"Y0": 12, "Y1": 8, "Y2": 3, "LED": 9, "A0": 8}
|
||||
MOCK_ESP32_BOARD_ALIAS_ID = "_mock_esp32_alias"
|
||||
|
||||
UNKNOWN_PLATFORM = "STM32"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_mcu(monkeypatch):
|
||||
"""
|
||||
Add a mock MCU into the lists as a stable fixture
|
||||
"""
|
||||
boards.ESP8266_BOARD_PINS[MOCK_ESP8266_BOARD_ID] = MOCK_ESP8266_PINS
|
||||
boards.ESP8266_FLASH_SIZES[MOCK_ESP8266_BOARD_ID] = MOCK_ESP8266_FLASH_SIZE
|
||||
boards.ESP8266_BOARD_PINS[MOCK_ESP8266_BOARD_ALIAS_ID] = MOCK_ESP8266_BOARD_ID
|
||||
boards.ESP8266_FLASH_SIZES[MOCK_ESP8266_BOARD_ALIAS_ID] = MOCK_ESP8266_FLASH_SIZE
|
||||
boards.ESP32_BOARD_PINS[MOCK_ESP32_BOARD_ID] = MOCK_ESP32_PINS
|
||||
boards.ESP32_BOARD_PINS[MOCK_ESP32_BOARD_ALIAS_ID] = MOCK_ESP32_BOARD_ID
|
||||
yield
|
||||
del boards.ESP8266_BOARD_PINS[MOCK_ESP8266_BOARD_ID]
|
||||
del boards.ESP8266_FLASH_SIZES[MOCK_ESP8266_BOARD_ID]
|
||||
del boards.ESP8266_BOARD_PINS[MOCK_ESP8266_BOARD_ALIAS_ID]
|
||||
del boards.ESP8266_FLASH_SIZES[MOCK_ESP8266_BOARD_ALIAS_ID]
|
||||
del boards.ESP32_BOARD_PINS[MOCK_ESP32_BOARD_ID]
|
||||
del boards.ESP32_BOARD_PINS[MOCK_ESP32_BOARD_ALIAS_ID]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def core(monkeypatch, mock_mcu):
|
||||
core = EsphomeCore()
|
||||
monkeypatch.setattr(pins, "CORE", core)
|
||||
return core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def core_esp8266(core):
|
||||
core.esp_platform = "ESP8266"
|
||||
core.board = MOCK_ESP8266_BOARD_ID
|
||||
return core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def core_esp32(core):
|
||||
core.esp_platform = "ESP32"
|
||||
core.board = MOCK_ESP32_BOARD_ID
|
||||
return core
|
||||
|
||||
|
||||
class Test_lookup_pin:
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
("X1", 5),
|
||||
("MOSI", 13),
|
||||
),
|
||||
)
|
||||
def test_valid_esp8266_pin(self, core_esp8266, value, expected):
|
||||
actual = pins._lookup_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
def test_valid_esp8266_pin_alias(self, core_esp8266):
|
||||
core_esp8266.board = MOCK_ESP8266_BOARD_ALIAS_ID
|
||||
|
||||
actual = pins._lookup_pin("X2")
|
||||
|
||||
assert actual == 4
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
("Y1", 8),
|
||||
("A0", 8),
|
||||
("MOSI", 23),
|
||||
),
|
||||
)
|
||||
def test_valid_esp32_pin(self, core_esp32, value, expected):
|
||||
actual = pins._lookup_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
def test_valid_32_pin_alias(self, core_esp32):
|
||||
core_esp32.board = MOCK_ESP32_BOARD_ALIAS_ID
|
||||
|
||||
actual = pins._lookup_pin("Y2")
|
||||
|
||||
assert actual == 3
|
||||
|
||||
def test_invalid_pin(self, core_esp8266):
|
||||
with pytest.raises(
|
||||
Invalid, match="Cannot resolve pin name 'X42' for board _mock_esp8266."
|
||||
):
|
||||
pins._lookup_pin("X42")
|
||||
|
||||
def test_unsupported_platform(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins._lookup_pin("TX")
|
||||
|
||||
|
||||
class Test_translate_pin:
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
(2, 2),
|
||||
("3", 3),
|
||||
("GPIO4", 4),
|
||||
("TX", 1),
|
||||
("Y0", 12),
|
||||
),
|
||||
)
|
||||
def test_valid_values(self, core_esp32, value, expected):
|
||||
actual = pins._translate_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize("value", ({}, None))
|
||||
def test_invalid_values(self, core_esp32, value):
|
||||
with pytest.raises(Invalid, match="This variable only supports"):
|
||||
pins._translate_pin(value)
|
||||
|
||||
|
||||
class Test_validate_gpio_pin:
|
||||
def test_esp32_valid(self, core_esp32):
|
||||
actual = pins.validate_gpio_pin("GPIO22")
|
||||
|
||||
assert actual == 22
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, match",
|
||||
(
|
||||
(-1, "ESP32: Invalid pin number: -1"),
|
||||
(40, "ESP32: Invalid pin number: 40"),
|
||||
(6, "This pin cannot be used on ESP32s and"),
|
||||
(7, "This pin cannot be used on ESP32s and"),
|
||||
(8, "This pin cannot be used on ESP32s and"),
|
||||
(11, "This pin cannot be used on ESP32s and"),
|
||||
(20, "The pin GPIO20 is not usable on ESP32s"),
|
||||
(24, "The pin GPIO24 is not usable on ESP32s"),
|
||||
(28, "The pin GPIO28 is not usable on ESP32s"),
|
||||
(29, "The pin GPIO29 is not usable on ESP32s"),
|
||||
(30, "The pin GPIO30 is not usable on ESP32s"),
|
||||
(31, "The pin GPIO31 is not usable on ESP32s"),
|
||||
),
|
||||
)
|
||||
def test_esp32_invalid_pin(self, core_esp32, value, match):
|
||||
with pytest.raises(Invalid, match=match):
|
||||
pins.validate_gpio_pin(value)
|
||||
|
||||
@pytest.mark.parametrize("value", (9, 10))
|
||||
def test_esp32_warning(self, core_esp32, caplog, value):
|
||||
caplog.at_level(logging.WARNING)
|
||||
pins.validate_gpio_pin(value)
|
||||
|
||||
assert len(caplog.messages) == 1
|
||||
assert caplog.messages[0].endswith("flash interface in QUAD IO flash mode.")
|
||||
|
||||
def test_esp8266_valid(self, core_esp8266):
|
||||
actual = pins.validate_gpio_pin("GPIO12")
|
||||
|
||||
assert actual == 12
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, match",
|
||||
(
|
||||
(-1, "ESP8266: Invalid pin number: -1"),
|
||||
(18, "ESP8266: Invalid pin number: 18"),
|
||||
(6, "This pin cannot be used on ESP8266s and"),
|
||||
(7, "This pin cannot be used on ESP8266s and"),
|
||||
(8, "This pin cannot be used on ESP8266s and"),
|
||||
(11, "This pin cannot be used on ESP8266s and"),
|
||||
),
|
||||
)
|
||||
def test_esp8266_invalid_pin(self, core_esp8266, value, match):
|
||||
with pytest.raises(Invalid, match=match):
|
||||
pins.validate_gpio_pin(value)
|
||||
|
||||
@pytest.mark.parametrize("value", (9, 10))
|
||||
def test_esp8266_warning(self, core_esp8266, caplog, value):
|
||||
caplog.at_level(logging.WARNING)
|
||||
pins.validate_gpio_pin(value)
|
||||
|
||||
assert len(caplog.messages) == 1
|
||||
assert caplog.messages[0].endswith("flash interface in QUAD IO flash mode.")
|
||||
|
||||
def test_unknown_device(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins.validate_gpio_pin("0")
|
||||
|
||||
|
||||
class Test_input_pin:
|
||||
@pytest.mark.parametrize("value, expected", (("X0", 16),))
|
||||
def test_valid_esp8266_values(self, core_esp8266, value, expected):
|
||||
actual = pins.input_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
("Y0", 12),
|
||||
(17, 17),
|
||||
),
|
||||
)
|
||||
def test_valid_esp32_values(self, core_esp32, value, expected):
|
||||
actual = pins.input_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize("value", (17,))
|
||||
def test_invalid_esp8266_values(self, core_esp8266, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.input_pin(value)
|
||||
|
||||
def test_unknown_platform(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins.input_pin(2)
|
||||
|
||||
|
||||
class Test_input_pullup_pin:
|
||||
@pytest.mark.parametrize("value, expected", (("X0", 16),))
|
||||
def test_valid_esp8266_values(self, core_esp8266, value, expected):
|
||||
actual = pins.input_pullup_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
("Y0", 12),
|
||||
(17, 17),
|
||||
),
|
||||
)
|
||||
def test_valid_esp32_values(self, core_esp32, value, expected):
|
||||
actual = pins.input_pullup_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize("value", (0,))
|
||||
def test_invalid_esp8266_values(self, core_esp8266, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.input_pullup_pin(value)
|
||||
|
||||
def test_unknown_platform(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins.input_pullup_pin(2)
|
||||
|
||||
|
||||
class Test_output_pin:
|
||||
@pytest.mark.parametrize("value, expected", (("X0", 16),))
|
||||
def test_valid_esp8266_values(self, core_esp8266, value, expected):
|
||||
actual = pins.output_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
("Y0", 12),
|
||||
(17, 17),
|
||||
),
|
||||
)
|
||||
def test_valid_esp32_values(self, core_esp32, value, expected):
|
||||
actual = pins.output_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize("value", (17,))
|
||||
def test_invalid_esp8266_values(self, core_esp8266, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.output_pin(value)
|
||||
|
||||
@pytest.mark.parametrize("value", range(34, 40))
|
||||
def test_invalid_esp32_values(self, core_esp32, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.output_pin(value)
|
||||
|
||||
def test_unknown_platform(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins.output_pin(2)
|
||||
|
||||
|
||||
class Test_analog_pin:
|
||||
@pytest.mark.parametrize("value, expected", ((17, 17),))
|
||||
def test_valid_esp8266_values(self, core_esp8266, value, expected):
|
||||
actual = pins.analog_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, expected",
|
||||
(
|
||||
(32, 32),
|
||||
(39, 39),
|
||||
),
|
||||
)
|
||||
def test_valid_esp32_values(self, core_esp32, value, expected):
|
||||
actual = pins.analog_pin(value)
|
||||
|
||||
assert actual == expected
|
||||
|
||||
@pytest.mark.parametrize("value", ("X0",))
|
||||
def test_invalid_esp8266_values(self, core_esp8266, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.analog_pin(value)
|
||||
|
||||
@pytest.mark.parametrize("value", ("Y0",))
|
||||
def test_invalid_esp32_values(self, core_esp32, value):
|
||||
with pytest.raises(Invalid):
|
||||
pins.analog_pin(value)
|
||||
|
||||
def test_unknown_platform(self, core):
|
||||
core.esp_platform = UNKNOWN_PLATFORM
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
pins.analog_pin(2)
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import esphome.wizard as wz
|
||||
import pytest
|
||||
from esphome.boards import ESP8266_BOARD_PINS
|
||||
from esphome.components.esp8266.boards import ESP8266_BOARD_PINS
|
||||
from mock import MagicMock
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user