[core] Add type annotations to component Python (11/11) (#18348)

This commit is contained in:
Jesse Hills
2026-08-21 07:57:14 +12:00
committed by GitHub
parent c006e9804a
commit 12da2140cf
24 changed files with 62 additions and 29 deletions
+8 -1
View File
@@ -6,6 +6,8 @@ from esphome.components.file.image import image_schema, write_image
from esphome.components.image import Image_, validate_settings from esphome.components.image import Image_, validate_settings
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_REPEAT from esphome.const import CONF_ID, CONF_REPEAT
from esphome.core import ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType from esphome.types import ConfigType
CODEOWNERS = ["@syndlex"] CODEOWNERS = ["@syndlex"]
@@ -79,7 +81,12 @@ SET_FRAME_SCHEMA = cv.Schema(
@automation.register_action( @automation.register_action(
"animation.set_frame", SetFrameAction, SET_FRAME_SCHEMA, synchronous=True "animation.set_frame", SetFrameAction, SET_FRAME_SCHEMA, synchronous=True
) )
async def animation_action_to_code(config, action_id, template_arg, args): async def animation_action_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
paren = await cg.get_variable(config[CONF_ID]) paren = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren) var = cg.new_Pvariable(action_id, template_arg, paren)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import i2c from esphome.components import i2c
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
MULTI_CONF = True MULTI_CONF = True
@@ -57,7 +58,7 @@ CONFIG_SCHEMA = (
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import binary_sensor from esphome.components import binary_sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_DIRECTION, DEVICE_CLASS_MOVING from esphome.const import CONF_DIRECTION, DEVICE_CLASS_MOVING
from esphome.types import ConfigType
from . import APDS9960, CONF_APDS9960_ID from . import APDS9960, CONF_APDS9960_ID
@@ -19,7 +20,7 @@ CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_APDS9960_ID]) hub = await cg.get_variable(config[CONF_APDS9960_ID])
var = await binary_sensor.new_binary_sensor(config) var = await binary_sensor.new_binary_sensor(config)
func = getattr(hub, f"set_{config[CONF_DIRECTION]}_direction_binary_sensor") func = getattr(hub, f"set_{config[CONF_DIRECTION]}_direction_binary_sensor")
+2 -1
View File
@@ -7,6 +7,7 @@ from esphome.const import (
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
) )
from esphome.types import ConfigType
from . import APDS9960, CONF_APDS9960_ID from . import APDS9960, CONF_APDS9960_ID
@@ -27,7 +28,7 @@ CONFIG_SCHEMA = sensor.sensor_schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_APDS9960_ID]) hub = await cg.get_variable(config[CONF_APDS9960_ID])
var = await sensor.new_sensor(config) var = await sensor.new_sensor(config)
func = getattr(hub, f"set_{config[CONF_TYPE]}_sensor") func = getattr(hub, f"set_{config[CONF_TYPE]}_sensor")
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import i2c from esphome.components import i2c
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_INVERTED, CONF_RESOLUTION from esphome.const import CONF_ID, CONF_INVERTED, CONF_RESOLUTION
from esphome.types import ConfigType
CODEOWNERS = ["@ellull"] CODEOWNERS = ["@ellull"]
@@ -68,7 +69,7 @@ CONFIG_SCHEMA = cv.All(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import output from esphome.components import output
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns
@@ -16,7 +17,7 @@ CONFIG_SCHEMA = EMC2101_COMPONENT_SCHEMA.extend(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
paren = await cg.get_variable(config[CONF_EMC2101_ID]) paren = await cg.get_variable(config[CONF_EMC2101_ID])
var = cg.new_Pvariable(config[CONF_ID], paren) var = cg.new_Pvariable(config[CONF_ID], paren)
await output.register_output(var, config) await output.register_output(var, config)
@@ -13,6 +13,7 @@ from esphome.const import (
UNIT_PERCENT, UNIT_PERCENT,
UNIT_REVOLUTIONS_PER_MINUTE, UNIT_REVOLUTIONS_PER_MINUTE,
) )
from esphome.types import ConfigType
from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns from .. import CONF_EMC2101_ID, EMC2101_COMPONENT_SCHEMA, emc2101_ns
@@ -53,7 +54,7 @@ CONFIG_SCHEMA = EMC2101_COMPONENT_SCHEMA.extend(
).extend(cv.polling_component_schema("60s")) ).extend(cv.polling_component_schema("60s"))
async def to_code(config): async def to_code(config: ConfigType) -> None:
paren = await cg.get_variable(config[CONF_EMC2101_ID]) paren = await cg.get_variable(config[CONF_EMC2101_ID])
var = cg.new_Pvariable(config[CONF_ID], paren) var = cg.new_Pvariable(config[CONF_ID], paren)
await cg.register_component(var, config) await cg.register_component(var, config)
+6 -3
View File
@@ -29,6 +29,7 @@ from esphome.const import (
CONF_X_GRID, CONF_X_GRID,
CONF_Y_GRID, CONF_Y_GRID,
) )
from esphome.types import ConfigType
CODEOWNERS = ["@synco"] CODEOWNERS = ["@synco"]
@@ -115,7 +116,9 @@ GRAPH_SCHEMA = cv.Schema(
) )
def _relocate_fields_to_subfolder(config, subfolder, subschema): def _relocate_fields_to_subfolder(
config: ConfigType, subfolder: str, subschema: cv.Schema
) -> ConfigType:
fields = [k.schema for k in subschema.schema] fields = [k.schema for k in subschema.schema]
fields.remove(CONF_ID) fields.remove(CONF_ID)
if subfolder in config: if subfolder in config:
@@ -138,7 +141,7 @@ def _relocate_fields_to_subfolder(config, subfolder, subschema):
return config return config
def _relocate_trace(config): def _relocate_trace(config: ConfigType) -> ConfigType:
return _relocate_fields_to_subfolder(config, CONF_TRACES, GRAPH_TRACE_SCHEMA) return _relocate_fields_to_subfolder(config, CONF_TRACES, GRAPH_TRACE_SCHEMA)
@@ -148,7 +151,7 @@ CONFIG_SCHEMA = cv.All(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_duration(config[CONF_DURATION])) cg.add(var.set_duration(config[CONF_DURATION]))
cg.add(var.set_width(config[CONF_WIDTH])) cg.add(var.set_width(config[CONF_WIDTH]))
+2 -1
View File
@@ -4,6 +4,7 @@ import esphome.codegen as cg
from esphome.components import uart from esphome.components import uart
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@@ -41,7 +42,7 @@ CONFIG_SCHEMA = cv.All(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
@@ -16,6 +16,7 @@ from esphome.const import (
UNIT_PERCENT, UNIT_PERCENT,
UNIT_VOLT, UNIT_VOLT,
) )
from esphome.types import ConfigType
from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns
@@ -90,7 +91,7 @@ CONFIG_SCHEMA = PYLONTECH_COMPONENT_SCHEMA.extend(
).extend({cv.Optional(marker): schema for marker, schema in TYPES.items()}) ).extend({cv.Optional(marker): schema for marker, schema in TYPES.items()})
async def to_code(config): async def to_code(config: ConfigType) -> None:
paren = await cg.get_variable(config[CONF_PYLONTECH_ID]) paren = await cg.get_variable(config[CONF_PYLONTECH_ID])
bat = cg.new_Pvariable(config[CONF_ID], config[CONF_BATTERY]) bat = cg.new_Pvariable(config[CONF_ID], config[CONF_BATTERY])
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import text_sensor from esphome.components import text_sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns from .. import CONF_BATTERY, CONF_PYLONTECH_ID, PYLONTECH_COMPONENT_SCHEMA, pylontech_ns
@@ -24,7 +25,7 @@ CONFIG_SCHEMA = PYLONTECH_COMPONENT_SCHEMA.extend(
).extend({cv.Optional(marker): text_sensor.text_sensor_schema() for marker in MARKERS}) ).extend({cv.Optional(marker): text_sensor.text_sensor_schema() for marker in MARKERS})
async def to_code(config): async def to_code(config: ConfigType) -> None:
paren = await cg.get_variable(config[CONF_PYLONTECH_ID]) paren = await cg.get_variable(config[CONF_PYLONTECH_ID])
bat = cg.new_Pvariable(config[CONF_ID], config[CONF_BATTERY]) bat = cg.new_Pvariable(config[CONF_ID], config[CONF_BATTERY])
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import uart from esphome.components import uart
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_THROTTLE from esphome.const import CONF_ID, CONF_THROTTLE
from esphome.types import ConfigType
CODEOWNERS = ["@jasstrong"] CODEOWNERS = ["@jasstrong"]
DEPENDENCIES = ["uart"] DEPENDENCIES = ["uart"]
@@ -38,7 +39,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import binary_sensor from esphome.components import binary_sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_TARGET, DEVICE_CLASS_OCCUPANCY from esphome.const import CONF_TARGET, DEVICE_CLASS_OCCUPANCY
from esphome.types import ConfigType
from . import CONF_RD03D_ID, RD03DComponent from . import CONF_RD03D_ID, RD03DComponent
@@ -26,7 +27,7 @@ CONFIG_SCHEMA = cv.Schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_RD03D_ID]) hub = await cg.get_variable(config[CONF_RD03D_ID])
if target_config := config.get(CONF_TARGET): if target_config := config.get(CONF_TARGET):
+2 -1
View File
@@ -15,6 +15,7 @@ from esphome.const import (
UNIT_DEGREES, UNIT_DEGREES,
UNIT_MILLIMETER, UNIT_MILLIMETER,
) )
from esphome.types import ConfigType
from . import CONF_RD03D_ID, RD03DComponent from . import CONF_RD03D_ID, RD03DComponent
@@ -75,7 +76,7 @@ CONFIG_SCHEMA = cv.Schema(
).extend({cv.Optional(f"target_{i + 1}"): TARGET_SCHEMA for i in range(MAX_TARGETS)}) ).extend({cv.Optional(f"target_{i + 1}"): TARGET_SCHEMA for i in range(MAX_TARGETS)})
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_RD03D_ID]) hub = await cg.get_variable(config[CONF_RD03D_ID])
if target_count_config := config.get(CONF_TARGET_COUNT): if target_count_config := config.get(CONF_TARGET_COUNT):
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import uart from esphome.components import uart
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
CODEOWNERS = ["@Mat931"] CODEOWNERS = ["@Mat931"]
MULTI_CONF = True MULTI_CONF = True
@@ -24,7 +25,7 @@ CONFIG_SCHEMA = (
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
+2 -1
View File
@@ -13,6 +13,7 @@ from esphome.const import (
UNIT_VOLT, UNIT_VOLT,
UNIT_WATT, UNIT_WATT,
) )
from esphome.types import ConfigType
from . import CONF_SUN_GTIL2_ID, SunGTIL2Component from . import CONF_SUN_GTIL2_ID, SunGTIL2Component
@@ -73,7 +74,7 @@ CONFIG_SCHEMA = cv.All(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_SUN_GTIL2_ID]) hub = await cg.get_variable(config[CONF_SUN_GTIL2_ID])
if ac_voltage_config := config.get(CONF_AC_VOLTAGE): if ac_voltage_config := config.get(CONF_AC_VOLTAGE):
sens = await sensor.new_sensor(ac_voltage_config) sens = await sensor.new_sensor(ac_voltage_config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import text_sensor from esphome.components import text_sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_STATE from esphome.const import CONF_STATE
from esphome.types import ConfigType
from . import CONF_SUN_GTIL2_ID, SunGTIL2Component from . import CONF_SUN_GTIL2_ID, SunGTIL2Component
@@ -22,7 +23,7 @@ CONFIG_SCHEMA = cv.All(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_SUN_GTIL2_ID]) hub = await cg.get_variable(config[CONF_SUN_GTIL2_ID])
if state_config := config.get(CONF_STATE): if state_config := config.get(CONF_STATE):
sens = await text_sensor.new_text_sensor(state_config) sens = await text_sensor.new_text_sensor(state_config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import uart from esphome.components import uart
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
CODEOWNERS = ["@0hax"] CODEOWNERS = ["@0hax"]
MULTI_CONF = True MULTI_CONF = True
@@ -34,7 +35,7 @@ CONFIG_SCHEMA = (
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID], config[CONF_HISTORICAL_MODE]) var = cg.new_Pvariable(config[CONF_ID], config[CONF_HISTORICAL_MODE])
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
@@ -7,6 +7,7 @@ from esphome.const import (
STATE_CLASS_TOTAL_INCREASING, STATE_CLASS_TOTAL_INCREASING,
UNIT_WATT_HOURS, UNIT_WATT_HOURS,
) )
from esphome.types import ConfigType
from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns
@@ -22,7 +23,7 @@ CONFIG_SCHEMA = sensor.sensor_schema(
).extend(TELEINFO_LISTENER_SCHEMA) ).extend(TELEINFO_LISTENER_SCHEMA)
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG_NAME]) var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG_NAME])
await cg.register_component(var, config) await cg.register_component(var, config)
await sensor.register_sensor(var, config) await sensor.register_sensor(var, config)
@@ -1,6 +1,7 @@
import esphome.codegen as cg import esphome.codegen as cg
from esphome.components import text_sensor from esphome.components import text_sensor
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns from .. import CONF_TAG_NAME, CONF_TELEINFO_ID, TELEINFO_LISTENER_SCHEMA, teleinfo_ns
@@ -13,7 +14,7 @@ CONFIG_SCHEMA = text_sensor.text_sensor_schema(TeleInfoTextSensor).extend(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG_NAME]) var = cg.new_Pvariable(config[CONF_ID], config[CONF_TAG_NAME])
await cg.register_component(var, config) await cg.register_component(var, config)
await text_sensor.register_text_sensor(var, config) await text_sensor.register_text_sensor(var, config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import uart from esphome.components import uart
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID from esphome.const import CONF_ID
from esphome.types import ConfigType
CODEOWNERS = ["@ljungqvist"] CODEOWNERS = ["@ljungqvist"]
@@ -34,7 +35,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await uart.register_uart_device(var, config) await uart.register_uart_device(var, config)
+2 -1
View File
@@ -2,6 +2,7 @@ import esphome.codegen as cg
from esphome.components import binary_sensor from esphome.components import binary_sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import DEVICE_CLASS_PROBLEM, ENTITY_CATEGORY_DIAGNOSTIC from esphome.const import DEVICE_CLASS_PROBLEM, ENTITY_CATEGORY_DIAGNOSTIC
from esphome.types import ConfigType
from . import CONF_UFM01_ID, UFM01Component from . import CONF_UFM01_ID, UFM01Component
@@ -32,7 +33,7 @@ CONFIG_SCHEMA = {
} }
async def to_code(config): async def to_code(config: ConfigType) -> None:
ufm01_component = await cg.get_variable(config[CONF_UFM01_ID]) ufm01_component = await cg.get_variable(config[CONF_UFM01_ID])
if ufc_chip_error_config := config.get(CONF_UFC_CHIP_ERROR): if ufc_chip_error_config := config.get(CONF_UFC_CHIP_ERROR):
+2 -1
View File
@@ -13,6 +13,7 @@ from esphome.const import (
UNIT_CUBIC_METER_PER_HOUR, UNIT_CUBIC_METER_PER_HOUR,
UNIT_LITRE, UNIT_LITRE,
) )
from esphome.types import ConfigType
from . import CONF_UFM01_ID, UFM01Component from . import CONF_UFM01_ID, UFM01Component
@@ -47,7 +48,7 @@ CONFIG_SCHEMA = cv.Schema(
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
ufm01_component = await cg.get_variable(config[CONF_UFM01_ID]) ufm01_component = await cg.get_variable(config[CONF_UFM01_ID])
if CONF_ACCUMULATED_FLOW in config: if CONF_ACCUMULATED_FLOW in config:
+6 -4
View File
@@ -10,6 +10,8 @@ from esphome.const import (
CONF_NUMBER, CONF_NUMBER,
CONF_OUTPUT, CONF_OUTPUT,
) )
from esphome.cpp_generator import MockObj
from esphome.types import ConfigType
CONF_XL9535 = "xl9535" CONF_XL9535 = "xl9535"
@@ -29,13 +31,13 @@ CONFIG_SCHEMA = (
) )
async def to_code(config): async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
def validate_mode(mode): def validate_mode(mode: ConfigType) -> ConfigType:
if not (mode[CONF_INPUT] or mode[CONF_OUTPUT]) or ( if not (mode[CONF_INPUT] or mode[CONF_OUTPUT]) or (
mode[CONF_INPUT] and mode[CONF_OUTPUT] mode[CONF_INPUT] and mode[CONF_OUTPUT]
): ):
@@ -43,7 +45,7 @@ def validate_mode(mode):
return mode return mode
def validate_pin(pin): def validate_pin(pin: int) -> int:
if pin in (8, 9): if pin in (8, 9):
raise cv.Invalid(f"pin {pin} doesn't exist") raise cv.Invalid(f"pin {pin} doesn't exist")
return pin return pin
@@ -67,7 +69,7 @@ XL9535_PIN_SCHEMA = cv.All(
@pins.PIN_SCHEMA_REGISTRY.register(CONF_XL9535, XL9535_PIN_SCHEMA) @pins.PIN_SCHEMA_REGISTRY.register(CONF_XL9535, XL9535_PIN_SCHEMA)
async def xl9535_pin_to_code(config): async def xl9535_pin_to_code(config: ConfigType) -> MockObj:
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
parent = await cg.get_variable(config[CONF_XL9535]) parent = await cg.get_variable(config[CONF_XL9535])