mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 11:44:13 +01:00
ac0d921413
* 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>
114 lines
3.5 KiB
Python
114 lines
3.5 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome import pins
|
|
from esphome.const import (
|
|
CONF_ID,
|
|
CONF_INPUT,
|
|
CONF_NUMBER,
|
|
CONF_MODE,
|
|
CONF_INVERTED,
|
|
CONF_INTERRUPT,
|
|
CONF_OPEN_DRAIN_INTERRUPT,
|
|
CONF_OUTPUT,
|
|
CONF_PULLUP,
|
|
)
|
|
from esphome.core import coroutine
|
|
|
|
CODEOWNERS = ["@jesserockz"]
|
|
|
|
mcp23xxx_base_ns = cg.esphome_ns.namespace("mcp23xxx_base")
|
|
MCP23XXXBase = mcp23xxx_base_ns.class_("MCP23XXXBase", cg.Component)
|
|
MCP23XXXGPIOPin = mcp23xxx_base_ns.class_("MCP23XXXGPIOPin", cg.GPIOPin)
|
|
MCP23XXXGPIOMode = mcp23xxx_base_ns.enum("MCP23XXXGPIOMode")
|
|
MCP23XXXInterruptMode = mcp23xxx_base_ns.enum("MCP23XXXInterruptMode")
|
|
|
|
MCP23XXX_INTERRUPT_MODES = {
|
|
"NO_INTERRUPT": MCP23XXXInterruptMode.MCP23XXX_NO_INTERRUPT,
|
|
"CHANGE": MCP23XXXInterruptMode.MCP23XXX_CHANGE,
|
|
"RISING": MCP23XXXInterruptMode.MCP23XXX_RISING,
|
|
"FALLING": MCP23XXXInterruptMode.MCP23XXX_FALLING,
|
|
}
|
|
|
|
MCP23XXX_GPIO_MODES = {
|
|
"INPUT": MCP23XXXGPIOMode.MCP23XXX_INPUT,
|
|
"INPUT_PULLUP": MCP23XXXGPIOMode.MCP23XXX_INPUT_PULLUP,
|
|
"OUTPUT": MCP23XXXGPIOMode.MCP23XXX_OUTPUT,
|
|
}
|
|
|
|
MCP23XXX_CONFIG_SCHEMA = cv.Schema(
|
|
{
|
|
cv.Optional(CONF_OPEN_DRAIN_INTERRUPT, default=False): cv.boolean,
|
|
}
|
|
).extend(cv.COMPONENT_SCHEMA)
|
|
|
|
|
|
@coroutine
|
|
async def register_mcp23xxx(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
cg.add(var.set_open_drain_ints(config[CONF_OPEN_DRAIN_INTERRUPT]))
|
|
return var
|
|
|
|
|
|
def validate_mode(value):
|
|
if not (value[CONF_INPUT] or value[CONF_OUTPUT]):
|
|
raise cv.Invalid("Mode must be either input or output")
|
|
if value[CONF_INPUT] and value[CONF_OUTPUT]:
|
|
raise cv.Invalid("Mode must be either input or output")
|
|
if value[CONF_PULLUP] and not value[CONF_INPUT]:
|
|
raise cv.Invalid("Pullup only available with input")
|
|
return value
|
|
|
|
|
|
CONF_MCP23XXX = "mcp23xxx"
|
|
MCP23XXX_PIN_SCHEMA = cv.All(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(MCP23XXXGPIOPin),
|
|
cv.Required(CONF_MCP23XXX): cv.use_id(MCP23XXXBase),
|
|
cv.Required(CONF_NUMBER): cv.int_range(min=0, max=15),
|
|
cv.Optional(CONF_MODE, default={}): cv.All(
|
|
{
|
|
cv.Optional(CONF_INPUT, default=False): cv.boolean,
|
|
cv.Optional(CONF_PULLUP, default=False): cv.boolean,
|
|
cv.Optional(CONF_OUTPUT, default=False): cv.boolean,
|
|
},
|
|
validate_mode,
|
|
),
|
|
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
|
|
cv.Optional(CONF_INTERRUPT, default="NO_INTERRUPT"): cv.enum(
|
|
MCP23XXX_INTERRUPT_MODES, upper=True
|
|
),
|
|
}
|
|
)
|
|
|
|
|
|
@pins.PIN_SCHEMA_REGISTRY.register(CONF_MCP23XXX, MCP23XXX_PIN_SCHEMA)
|
|
async def mcp23xxx_pin_to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
parent = await cg.get_variable(config[CONF_MCP23XXX])
|
|
|
|
cg.add(var.set_parent(parent))
|
|
|
|
num = config[CONF_NUMBER]
|
|
cg.add(var.set_pin(num))
|
|
cg.add(var.set_inverted(config[CONF_INVERTED]))
|
|
cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
|
|
cg.add(var.set_interrupt_mode(config[CONF_INTERRUPT]))
|
|
return var
|
|
|
|
|
|
# BEGIN Removed pin schemas below to show error in configuration
|
|
# TODO remove in 2022.5.0
|
|
|
|
for id in ["mcp23008", "mcp23s08", "mcp23017", "mcp23s17"]:
|
|
invalid_schema = cv.invalid(
|
|
f"'{id}:' has been removed from the pin schema in 1.17.0, please use 'mcp23xxx:'"
|
|
)
|
|
|
|
# pylint: disable=cell-var-from-loop
|
|
@pins.PIN_SCHEMA_REGISTRY.register(id, invalid_schema)
|
|
def pin_to_code(config):
|
|
pass
|
|
|
|
|
|
# END Removed pin schemas
|