From 93bc9a4a5d57e82310850a376e1ddd37d10bbb28 Mon Sep 17 00:00:00 2001 From: uncarvedblock <1+uncarvedblock@git.franklin57.com> Date: Sat, 31 Oct 2026 13:01:01 -0400 Subject: [PATCH] Add components/es8388/select/__init__.py --- components/es8388/select/__init__.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 components/es8388/select/__init__.py diff --git a/components/es8388/select/__init__.py b/components/es8388/select/__init__.py new file mode 100644 index 0000000..55da85c --- /dev/null +++ b/components/es8388/select/__init__.py @@ -0,0 +1,42 @@ +import esphome.codegen as cg +from esphome.components import select +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_CONFIG, ICON_CHIP # noqa: F401 +from esphome.types import ConfigType + +from ..audio_dac import CONF_ES8388_ID, ES8388, es8388_ns + +CONF_DAC_OUTPUT = "dac_output" +CONF_ADC_INPUT_MIC = "adc_input_mic" + +DacOutputSelect = es8388_ns.class_("DacOutputSelect", select.Select) +ADCInputMicSelect = es8388_ns.class_("ADCInputMicSelect", select.Select) + +CONFIG_SCHEMA = cv.All( + { + cv.GenerateID(CONF_ES8388_ID): cv.use_id(ES8388), + cv.Optional(CONF_DAC_OUTPUT): select.select_schema( + DacOutputSelect, + entity_category=ENTITY_CATEGORY_CONFIG, + icon=ICON_CHIP, + ), + cv.Optional(CONF_ADC_INPUT_MIC): select.select_schema( + ADCInputMicSelect, + entity_category=ENTITY_CATEGORY_CONFIG, + icon=ICON_CHIP, + ), + } +) + + +async def to_code(config: ConfigType) -> None: + hub = await cg.get_variable(config[CONF_ES8388_ID]) + selects = select.sub_selects(config, parent=hub) + await selects( + CONF_DAC_OUTPUT, hub.set_dac_output_select, options=["LINE1", "LINE2", "BOTH"] + ) + await selects( + CONF_ADC_INPUT_MIC, + hub.set_adc_input_mic_select, + options=["LINE1", "LINE2", "DIFFERENCE"], + ) \ No newline at end of file