Use platform consts (#5508)

This commit is contained in:
Jesse Hills
2023-10-10 10:54:15 +13:00
committed by GitHub
parent be7e167c63
commit 46be886ca6
14 changed files with 74 additions and 34 deletions
+7 -1
View File
@@ -2,13 +2,19 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.core import CORE, coroutine_with_priority
from esphome.const import (
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_BK72XX,
PLATFORM_RTL87XX,
)
CODEOWNERS = ["@OttoWinter"]
CONFIG_SCHEMA = cv.All(
cv.Schema({}),
cv.only_with_arduino,
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_RTL87XX]),
)
@@ -2,7 +2,13 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import web_server_base
from esphome.components.web_server_base import CONF_WEB_SERVER_BASE_ID
from esphome.const import CONF_ID
from esphome.const import (
CONF_ID,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_BK72XX,
PLATFORM_RTL87XX,
)
from esphome.core import coroutine_with_priority, CORE
AUTO_LOAD = ["web_server_base"]
@@ -21,7 +27,7 @@ CONFIG_SCHEMA = cv.All(
),
}
).extend(cv.COMPONENT_SCHEMA),
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_RTL87XX]),
)
+2 -1
View File
@@ -25,6 +25,7 @@ from esphome.const import (
KEY_NAME,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PLATFORM_ESP32,
TYPE_GIT,
TYPE_LOCAL,
__version__,
@@ -62,7 +63,7 @@ AUTO_LOAD = ["preferences"]
def set_core_data(config):
CORE.data[KEY_ESP32] = {}
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "esp32"
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_ESP32
conf = config[CONF_FRAMEWORK]
if conf[CONF_TYPE] == FRAMEWORK_ESP_IDF:
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "esp-idf"
+2 -1
View File
@@ -11,6 +11,7 @@ from esphome.const import (
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PLATFORM_ESP8266,
)
from esphome.core import CORE, coroutine_with_priority
import esphome.config_validation as cv
@@ -38,7 +39,7 @@ AUTO_LOAD = ["preferences"]
def set_core_data(config):
CORE.data[KEY_ESP8266] = {}
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "esp8266"
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_ESP8266
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "arduino"
CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version.parse(
config[CONF_FRAMEWORK][CONF_VERSION]
+2 -1
View File
@@ -3,6 +3,7 @@ from esphome.const import (
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PLATFORM_HOST,
)
from esphome.core import CORE
import esphome.config_validation as cv
@@ -20,7 +21,7 @@ AUTO_LOAD = ["network"]
def set_core_data(config):
CORE.data[KEY_HOST] = {}
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "host"
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_HOST
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "host"
CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version(1, 0, 0)
return config
+4 -1
View File
@@ -12,6 +12,9 @@ from esphome.const import (
CONF_SDA,
CONF_ADDRESS,
CONF_I2C_ID,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
)
from esphome.core import coroutine_with_priority, CORE
@@ -60,7 +63,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_SCAN, default=True): cv.boolean,
}
).extend(cv.COMPONENT_SCHEMA),
cv.only_on(["esp32", "esp8266", "rp2040"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]),
)
@@ -12,6 +12,8 @@ from esphome.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
KEY_CORE,
KEY_FRAMEWORK_VERSION,
PLATFORM_ESP32,
PLATFORM_RP2040,
)
from esphome.core import CORE
@@ -49,7 +51,7 @@ CONFIG_SCHEMA = cv.All(
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
).extend(cv.polling_component_schema("60s")),
cv.only_on(["esp32", "rp2040"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_RP2040]),
validate_config,
)
+4 -1
View File
@@ -43,6 +43,9 @@ from esphome.const import (
CONF_USE_ABBREVIATIONS,
CONF_USERNAME,
CONF_WILL_MESSAGE,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_BK72XX,
)
from esphome.core import coroutine_with_priority, CORE
from esphome.components.esp32 import add_idf_sdkconfig_option
@@ -250,7 +253,7 @@ CONFIG_SCHEMA = cv.All(
}
),
validate_config,
cv.only_on(["esp32", "esp8266", "bk72xx"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX]),
)
+2 -1
View File
@@ -14,6 +14,7 @@ from esphome.const import (
KEY_FRAMEWORK_VERSION,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PLATFORM_RP2040,
)
from esphome.core import CORE, coroutine_with_priority, EsphomeError
from esphome.helpers import mkdir_p, write_file, copy_file_if_changed
@@ -30,7 +31,7 @@ AUTO_LOAD = []
def set_core_data(config):
CORE.data[KEY_RP2040] = {}
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = "rp2040"
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_RP2040
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = "arduino"
CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = cv.Version.parse(
config[CONF_FRAMEWORK][CONF_VERSION]
+11 -8
View File
@@ -26,6 +26,9 @@ from esphome.const import (
KEY_TARGET_PLATFORM,
KEY_VARIANT,
CONF_DATA_RATE,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
)
from esphome.core import coroutine_with_priority, CORE
@@ -102,9 +105,9 @@ def get_target_variant():
# The returned value is a list of lists of names
def get_hw_interface_list():
target_platform = get_target_platform()
if target_platform == "esp8266":
if target_platform == PLATFORM_ESP8266:
return [["spi", "hspi"]]
if target_platform == "esp32":
if target_platform == PLATFORM_ESP32:
if get_target_variant() in [
VARIANT_ESP32C2,
VARIANT_ESP32C3,
@@ -113,7 +116,7 @@ def get_hw_interface_list():
]:
return [["spi", "spi2"]]
return [["spi", "spi2"], ["spi3"]]
if target_platform == "rp2040":
if target_platform == PLATFORM_RP2040:
return [["spi"], ["spi1"]]
return []
@@ -150,17 +153,17 @@ def validate_hw_pins(spi, index=-1):
sdi_pin_no = sdi_pin[CONF_NUMBER]
target_platform = get_target_platform()
if target_platform == "esp8266":
if target_platform == PLATFORM_ESP8266:
if clk_pin_no == 6:
return sdo_pin_no in (-1, 8) and sdi_pin_no in (-1, 7)
if clk_pin_no == 14:
return sdo_pin_no in (-1, 13) and sdi_pin_no in (-1, 12)
return False
if target_platform == "esp32":
if target_platform == PLATFORM_ESP32:
return clk_pin_no >= 0
if target_platform == "rp2040":
if target_platform == PLATFORM_RP2040:
pin_set = (
list(filter(lambda s: clk_pin_no in s[CONF_CLK_PIN], RP_SPI_PINSETS))[0]
if index == -1
@@ -236,7 +239,7 @@ def get_spi_interface(index):
return ["SPI2_HOST", "SPI3_HOST"][index]
# Arduino code follows
platform = get_target_platform()
if platform == "rp2040":
if platform == PLATFORM_RP2040:
return ["&SPI", "&SPI1"][index]
if index == 0:
return "&SPI"
@@ -261,7 +264,7 @@ SPI_SCHEMA = cv.All(
}
),
cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN),
cv.only_on(["esp32", "esp8266", "rp2040"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040]),
)
CONFIG_SCHEMA = cv.All(
+5 -1
View File
@@ -18,6 +18,10 @@ from esphome.const import (
CONF_LOG,
CONF_VERSION,
CONF_LOCAL,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_BK72XX,
PLATFORM_RTL87XX,
)
from esphome.core import CORE, coroutine_with_priority
@@ -90,7 +94,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_LOCAL): cv.boolean,
}
).extend(cv.COMPONENT_SCHEMA),
cv.only_on(["esp32", "esp8266", "bk72xx", "rtl87xx"]),
cv.only_on([PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_RTL87XX]),
default_url,
validate_local,
validate_ota,