python formatting

This commit is contained in:
Gábor Poczkodi 2024-10-17 18:37:08 +02:00
parent 14cf0b0fcb
commit 706c61bb6e
5 changed files with 336 additions and 300 deletions

View file

@ -5,9 +5,6 @@ from esphome.components import i2c, sensor, binary_sensor, text_sensor
from esphome.const import (
CONF_ID,
CONF_FREQUENCY,
UNIT_DECIBEL,
UNIT_EMPTY,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
ICON_CHIP,
ENTITY_CATEGORY_DIAGNOSTIC,
@ -59,7 +56,7 @@ CONF_MUTE = "mute"
CONF_MONO = "mono"
CONF_PRE_EMPHASIS = "pre_emphasis"
# tuner
CONF_FREQUENCY = "frequency"
# CONF_FREQUENCY = "frequency"
CONF_DEVIATION = "deviation"
CONF_POWER = "power"
CONF_ANTCAP = "antcap"
@ -74,10 +71,10 @@ CONF_MODE = "mode"
CONF_CLOCK_EDGE = "clock_edge"
# pilot
CONF_ENABLE = "enable"
CONF_FREQUENCY = "frequency"
# CONF_FREQUENCY = "frequency"
CONF_DEVIATION = "deviation"
# refclk
CONF_FREQUENCY = "frequency"
# CONF_FREQUENCY = "frequency"
CONF_SOURCE = "source"
CONF_PRESCALER = "prescaler"
# compressor
@ -104,9 +101,9 @@ CONF_DEVIATION = "deviation"
CONF_STATION = "station"
CONF_TEXT = "text"
# output
CONF_GPIO1="gpio1"
CONF_GPIO2="gpio2"
CONF_GPIO3="gpio3"
CONF_GPIO1 = "gpio1"
CONF_GPIO2 = "gpio2"
CONF_GPIO3 = "gpio3"
# sensor
CONF_CHIP_ID = "chip_id"
CONF_READ_FREQUENCY = "frequency"
@ -141,10 +138,10 @@ PRE_EMPHASIS = {
LineAttenuation = si4713_ns.enum("LineAttenuation", True)
LINE_ATTENUATION = {
"396kOhm": LineAttenuation.LIATTEN_396KOHM,
"100kOhm": LineAttenuation.LIATTEN_100KOHM,
"74kOhm": LineAttenuation.LIATTEN_74KOHM,
"60kOhm": LineAttenuation.LIATTEN_60KOHM,
"396kOhm": LineAttenuation.LIATTEN_396KOHM,
"100kOhm": LineAttenuation.LIATTEN_100KOHM,
"74kOhm": LineAttenuation.LIATTEN_74KOHM,
"60kOhm": LineAttenuation.LIATTEN_60KOHM,
}
SampleBits = si4713_ns.enum("SampleBits", True)
@ -212,6 +209,139 @@ ACOMP_PRESET = {
"Custom": AcompPreset.ACOMP_CUSTOM,
}
TUNER_SCHEMA = cv.Schema(
{
cv.Optional(CONF_FREQUENCY, default=87.50): cv.float_range(76, 108), # MHz
cv.Optional(CONF_DEVIATION, default=68.25): cv.float_range(0, 90), # kHz
cv.Optional(CONF_POWER, default=115): cv.int_range(88, 115),
cv.Optional(CONF_ANTCAP, default=0): cv.int_range(0, 191),
}
)
ANALOG_SCHEMA = cv.Schema(
{
cv.Optional(CONF_LEVEL, default=636): cv.int_range(0, 1023),
cv.Optional(CONF_ATTENUATION, default=636): cv.enum(LINE_ATTENUATION),
}
)
DIGITAL_SCHEMA = cv.Schema(
{
cv.Optional(CONF_SAMPLE_RATE, default=44100): cv.int_range(32000, 48000), # Hz
cv.Optional(CONF_SAMPLE_BITS, default="16"): cv.enum(SAMPLE_BITS),
cv.Optional(CONF_CHANNELS, default="Stereo"): cv.enum(SAMPLE_CHANNELS),
cv.Optional(CONF_MODE, default="Default"): cv.enum(DIGITAL_MODE),
cv.Optional(CONF_CLOCK_EDGE, default="Rising"): cv.enum(DIGITAL_CLOCK_EDGE),
}
)
PILOT_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE, default="True"): cv.boolean,
cv.Optional(CONF_FREQUENCY, default=19): cv.float_range(0, 19), # kHz
cv.Optional(CONF_DEVIATION, default=6.75): cv.float_range(0, 90), # kHz
}
)
REFCLK_SCHEMA = cv.Schema(
{
cv.Optional(CONF_FREQUENCY, default=32768): cv.int_range(31130, 34406), # Hz
cv.Optional(CONF_SOURCE, default="RCLK"): cv.enum(REFCLK_SOURCE),
cv.Optional(CONF_PRESCALER, default=1): cv.int_range(0, 4095),
}
)
COMPRESSOR_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE, default="False"): cv.boolean,
cv.Optional(CONF_THRESHOLD, default=-40): cv.int_range(-40, 0),
cv.Optional(CONF_ATTACK, default="0.5"): cv.enum(ACOMP_ATTACK),
cv.Optional(CONF_RELEASE, default="1000"): cv.enum(ACOMP_RELEASE),
cv.Optional(CONF_GAIN, default=15): cv.int_range(0, 20),
cv.Optional(CONF_PRESET, default="Custom"): cv.enum(ACOMP_PRESET),
}
)
LIMITER_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE, default="True"): cv.boolean,
cv.Optional(CONF_RELEASE_TIME, default=5): cv.float_range(0.25, 102.4),
}
)
ASQ_SCHEMA = cv.Schema(
{
cv.Optional(CONF_IALL, default="False"): cv.boolean,
cv.Optional(CONF_IALH, default="False"): cv.boolean,
cv.Optional(CONF_OVERMOD, default="False"): cv.boolean,
cv.Optional(CONF_LEVEL_LOW, default=-50): cv.float_range(-70, 0),
cv.Optional(CONF_DURATION_LOW, default=10000): cv.int_range(0, 65535),
cv.Optional(CONF_LEVEL_HIGH, default=-20): cv.float_range(-70, 0),
cv.Optional(CONF_DURATION_HIGH, default=5000): cv.int_range(0, 65535),
}
)
RDS_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE, default=False): cv.boolean,
cv.Optional(CONF_DEVIATION, default=2.0): cv.float_range(0, 7.5), # kHz
cv.Optional(CONF_STATION): cv.string,
cv.Optional(CONF_TEXT): cv.string,
}
)
SENSOR_SCHEMA = cv.Schema(
{
cv.Optional(CONF_CHIP_ID): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
icon=ICON_CHIP,
),
cv.Optional(CONF_READ_FREQUENCY): sensor.sensor_schema(
unit_of_measurement=UNIT_MEGA_HERTZ,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
accuracy_decimals=2,
# icon=ICON_,
),
cv.Optional(CONF_READ_POWER): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MICRO_VOLT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_READ_ANTCAP): sensor.sensor_schema(
unit_of_measurement=UNIT_PICO_FARAD,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_READ_NOISE_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MICRO_VOLT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_IALL): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_IALH): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_OVERMOD): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_INLEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_FS,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
}
)
CONFIG_SCHEMA = (
cv.Schema(
{
@ -221,130 +351,16 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_MUTE, default=False): cv.boolean,
cv.Optional(CONF_MONO, default=False): cv.boolean,
cv.Optional(CONF_PRE_EMPHASIS, default="75us"): cv.enum(PRE_EMPHASIS),
cv.Optional(CONF_SECTION_TUNER): cv.Schema(
{
cv.Optional(CONF_FREQUENCY, default=87.50): cv.float_range(76, 108), # MHz
cv.Optional(CONF_DEVIATION, default=68.25): cv.float_range(0, 90), # kHz
cv.Optional(CONF_POWER, default=115): cv.int_range(88, 115),
cv.Optional(CONF_ANTCAP, default=0): cv.int_range(0, 191),
}
),
cv.Optional(CONF_SECTION_ANALOG): cv.Schema(
{
cv.Optional(CONF_LEVEL, default=636): cv.int_range(0, 1023),
cv.Optional(CONF_ATTENUATION, default=636): cv.enum(LINE_ATTENUATION),
}
),
cv.Optional(CONF_SECTION_DIGITAL): cv.Schema(
{
cv.Optional(CONF_SAMPLE_RATE, default=44100): cv.int_range(32000, 48000), # Hz
cv.Optional(CONF_SAMPLE_BITS, default="16"): cv.enum(SAMPLE_BITS),
cv.Optional(CONF_CHANNELS, default="Stereo"): cv.enum(SAMPLE_CHANNELS),
cv.Optional(CONF_MODE, default="Default"): cv.enum(DIGITAL_MODE),
cv.Optional(CONF_CLOCK_EDGE, default="Rising"): cv.enum(DIGITAL_CLOCK_EDGE),
}
),
cv.Optional(CONF_SECTION_PILOT): cv.Schema(
{
cv.Optional(CONF_ENABLE, default="True"): cv.boolean,
cv.Optional(CONF_FREQUENCY, default=19): cv.float_range(0, 19), # kHz
cv.Optional(CONF_DEVIATION, default=6.75): cv.float_range(0, 90), # kHz
}
),
cv.Optional(CONF_SECTION_REFCLK): cv.Schema(
{
cv.Optional(CONF_FREQUENCY, default=32768): cv.int_range(31130, 34406), # Hz
cv.Optional(CONF_SOURCE, default="RCLK"): cv.enum(REFCLK_SOURCE),
cv.Optional(CONF_PRESCALER, default=1): cv.int_range(0, 4095),
}
),
cv.Optional(CONF_SECTION_COMPRESSOR): cv.Schema(
{
cv.Optional(CONF_ENABLE, default="False"): cv.boolean,
cv.Optional(CONF_THRESHOLD, default=-40): cv.int_range(-40, 0),
cv.Optional(CONF_ATTACK, default='0.5'): cv.enum(ACOMP_ATTACK),
cv.Optional(CONF_RELEASE, default="1000"): cv.enum(ACOMP_RELEASE),
cv.Optional(CONF_GAIN, default=15): cv.int_range(0, 20),
cv.Optional(CONF_PRESET, default="Custom"): cv.enum(ACOMP_PRESET),
}
),
cv.Optional(CONF_SECTION_LIMITER): cv.Schema(
{
cv.Optional(CONF_ENABLE, default="True"): cv.boolean,
cv.Optional(CONF_RELEASE_TIME, default=5): cv.float_range(0.25, 102.4),
}
),
cv.Optional(CONF_SECTION_ASQ): cv.Schema(
{
cv.Optional(CONF_IALL, default="False"): cv.boolean,
cv.Optional(CONF_IALH, default="False"): cv.boolean,
cv.Optional(CONF_OVERMOD, default="False"): cv.boolean,
cv.Optional(CONF_LEVEL_LOW, default=-50): cv.float_range(-70, 0),
cv.Optional(CONF_DURATION_LOW, default=10000): cv.int_range(0, 65535),
cv.Optional(CONF_LEVEL_HIGH, default=-20): cv.float_range(-70, 0),
cv.Optional(CONF_DURATION_HIGH, default=5000): cv.int_range(0, 65535),
}
),
cv.Optional(CONF_SECTION_RDS): cv.Schema(
{
cv.Optional(CONF_ENABLE, default=False): cv.boolean,
cv.Optional(CONF_DEVIATION, default=2.0): cv.float_range(0, 7.5), # kHz
cv.Optional(CONF_STATION): cv.string,
cv.Optional(CONF_TEXT): cv.string,
}
),
cv.Optional(CONF_SECTION_SENSOR): cv.Schema(
{
cv.Optional(CONF_CHIP_ID): text_sensor.text_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
icon=ICON_CHIP,
),
cv.Optional(CONF_READ_FREQUENCY): sensor.sensor_schema(
unit_of_measurement=UNIT_MEGA_HERTZ,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
accuracy_decimals=2,
# icon=ICON_,
),
cv.Optional(CONF_READ_POWER): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MICRO_VOLT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_READ_ANTCAP): sensor.sensor_schema(
unit_of_measurement=UNIT_PICO_FARAD,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_READ_NOISE_LEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MICRO_VOLT,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
cv.Optional(CONF_IALL): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_IALH): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_OVERMOD): binary_sensor.binary_sensor_schema(
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
# icon=ICON_,
),
cv.Optional(CONF_INLEVEL): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_FS,
# entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
# icon=ICON_,
),
}
),
cv.Optional(CONF_SECTION_TUNER): TUNER_SCHEMA,
cv.Optional(CONF_SECTION_ANALOG): ANALOG_SCHEMA,
cv.Optional(CONF_SECTION_DIGITAL): DIGITAL_SCHEMA,
cv.Optional(CONF_SECTION_PILOT): PILOT_SCHEMA,
cv.Optional(CONF_SECTION_REFCLK): REFCLK_SCHEMA,
cv.Optional(CONF_SECTION_COMPRESSOR): COMPRESSOR_SCHEMA,
cv.Optional(CONF_SECTION_LIMITER): LIMITER_SCHEMA,
cv.Optional(CONF_SECTION_ASQ): ASQ_SCHEMA,
cv.Optional(CONF_SECTION_RDS): RDS_SCHEMA,
cv.Optional(CONF_SECTION_SENSOR): SENSOR_SCHEMA,
}
)
.extend(cv.polling_component_schema("60s"))
@ -355,13 +371,17 @@ CONFIG_SCHEMA = (
FREQUENCY_SCHEMA = automation.maybe_simple_id(
{
cv.GenerateID(): cv.use_id(Si4713Component),
cv.Required(CONF_FREQUENCY): cv.templatable(cv.float_range(min = 76, max = 108)),
cv.Required(CONF_FREQUENCY): cv.templatable(cv.float_range(min=76, max=108)),
}
)
@automation.register_action("si4713.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA)
@automation.register_action("si4713.measure_frequency", MeasureFrequencyAction, FREQUENCY_SCHEMA)
@automation.register_action(
"si4713.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA
)
@automation.register_action(
"si4713.measure_frequency", MeasureFrequencyAction, FREQUENCY_SCHEMA
)
async def tune_frequency_action_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
@ -451,11 +471,17 @@ async def to_code(config):
await set_var(rds_config, CONF_TEXT, var.set_rds_text)
if sensor_config := config.get(CONF_SECTION_SENSOR):
await new_text_sensor(sensor_config, CONF_CHIP_ID, var.set_chip_id_text_sensor)
await new_sensor(sensor_config, CONF_READ_FREQUENCY, var.set_read_frequency_sensor)
await new_sensor(
sensor_config, CONF_READ_FREQUENCY, var.set_read_frequency_sensor
)
await new_sensor(sensor_config, CONF_READ_POWER, var.set_read_power_sensor)
await new_sensor(sensor_config, CONF_READ_ANTCAP, var.set_read_antcap_sensor)
await new_sensor(sensor_config, CONF_READ_NOISE_LEVEL, var.set_read_noise_level_sensor)
await new_sensor(
sensor_config, CONF_READ_NOISE_LEVEL, var.set_read_noise_level_sensor
)
await new_binary_sensor(sensor_config, CONF_IALL, var.set_iall_binary_sensor)
await new_binary_sensor(sensor_config, CONF_IALH, var.set_ialh_binary_sensor)
await new_binary_sensor(sensor_config, CONF_OVERMOD, var.set_overmod_binary_sensor)
await new_binary_sensor(
sensor_config, CONF_OVERMOD, var.set_overmod_binary_sensor
)
await new_sensor(sensor_config, CONF_INLEVEL, var.set_inlevel_sensor)

View file

@ -219,7 +219,7 @@ CONFIG_SCHEMA = cv.Schema(
)
async def new_number(parent, config, id, setter, min_value, max_value, step, *args, **kwargs):
async def new_number(p, config, id, setter, min_value, max_value, step, *args, **kwargs):
if c := config.get(id):
if CONF_MODE in kwargs:
if CONF_MODE not in c or c[CONF_MODE] == number.NumberMode.NUMBER_MODE_AUTO:
@ -227,37 +227,37 @@ async def new_number(parent, config, id, setter, min_value, max_value, step, *ar
n = await number.new_number(
c, *args, min_value=min_value, max_value=max_value, step=step
)
await cg.register_parented(n, parent)
await cg.register_parented(n, p)
cg.add(setter(n))
return n
async def to_code(config):
parent = await cg.get_variable(config[CONF_SI4713_ID])
p = await cg.get_variable(config[CONF_SI4713_ID])
if tuner_config := config.get(CONF_SECTION_TUNER):
await new_number(parent, tuner_config, CONF_FREQUENCY, parent.set_frequency_number, 76, 108, 0.05)
await new_number(parent, tuner_config, CONF_DEVIATION, parent.set_audio_deviation_number, 0, 90, 0.01)
await new_number(parent, tuner_config, CONF_POWER, parent.set_power_number, 88, 120, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
await new_number(parent, tuner_config, CONF_ANTCAP, parent.set_antcap_number, 0, 191, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
await new_number(p, tuner_config, CONF_FREQUENCY, p.set_frequency_number, 76, 108, 0.05)
await new_number(p, tuner_config, CONF_DEVIATION, p.set_audio_deviation_number, 0, 90, 0.01)
await new_number(p, tuner_config, CONF_POWER, p.set_power_number, 88, 120, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
await new_number(p, tuner_config, CONF_ANTCAP, p.set_antcap_number, 0, 191, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
if analog_config := config.get(CONF_SECTION_ANALOG):
await new_number(parent, analog_config, CONF_LEVEL, parent.set_analog_level_number, 0, 1023, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
await new_number(p, analog_config, CONF_LEVEL, p.set_analog_level_number, 0, 1023, 1, mode = number.NumberMode.NUMBER_MODE_SLIDER)
if digital_config := config.get(CONF_SECTION_DIGITAL):
await new_number(parent, digital_config, CONF_SAMPLE_RATE, parent.set_digital_sample_rate_number, 32000, 48000, 1)
await new_number(p, digital_config, CONF_SAMPLE_RATE, p.set_digital_sample_rate_number, 32000, 48000, 1)
if pilot_config := config.get(CONF_SECTION_PILOT):
await new_number(parent, pilot_config, CONF_FREQUENCY, parent.set_pilot_frequency_number, 0, 19, 0.001)
await new_number(parent, pilot_config, CONF_DEVIATION, parent.set_pilot_deviation_number, 0, 90, 0.001)
await new_number(p, pilot_config, CONF_FREQUENCY, p.set_pilot_frequency_number, 0, 19, 0.001)
await new_number(p, pilot_config, CONF_DEVIATION, p.set_pilot_deviation_number, 0, 90, 0.001)
if refclk_config := config.get(CONF_SECTION_REFCLK):
await new_number(parent, refclk_config, CONF_FREQUENCY, parent.set_refclk_frequency_number, 31130, 34406, 1)
await new_number(parent, refclk_config, CONF_PRESCALER, parent.set_refclk_prescaler_number, 0, 4095, 1)
await new_number(p, refclk_config, CONF_FREQUENCY, p.set_refclk_frequency_number, 31130, 34406, 1)
await new_number(p, refclk_config, CONF_PRESCALER, p.set_refclk_prescaler_number, 0, 4095, 1)
if compressor_config := config.get(CONF_SECTION_COMPRESSOR):
await new_number(parent, compressor_config, CONF_THRESHOLD, parent.set_acomp_threshold_number, -40, 0, 1)
await new_number(parent, compressor_config, CONF_GAIN, parent.set_acomp_gain_number, 0, 20, 1)
await new_number(p, compressor_config, CONF_THRESHOLD, p.set_acomp_threshold_number, -40, 0, 1)
await new_number(p, compressor_config, CONF_GAIN, p.set_acomp_gain_number, 0, 20, 1)
if limiter_config := config.get(CONF_SECTION_LIMITER):
await new_number(parent, limiter_config, CONF_RELEASE_TIME, parent.set_limiter_release_time_number, 0.25, 102.4, 0.01, mode = number.NumberMode.NUMBER_MODE_SLIDER)
await new_number(p, limiter_config, CONF_RELEASE_TIME, p.set_limiter_release_time_number, 0.25, 102.4, 0.01, mode = number.NumberMode.NUMBER_MODE_SLIDER)
if asq_config := config.get(CONF_SECTION_ASQ):
await new_number(parent, asq_config, CONF_LEVEL_LOW, parent.set_asq_level_low_number, -70, 0, 1)
await new_number(parent, asq_config, CONF_DURATION_LOW, parent.set_asq_duration_low_number, 0, 65535, 1)
await new_number(parent, asq_config, CONF_LEVEL_HIGH, parent.set_asq_level_high_number, -70, 0, 1)
await new_number(parent, asq_config, CONF_DURATION_HIGH, parent.set_asq_duration_high_number, 0, 65535, 1)
await new_number(p, asq_config, CONF_LEVEL_LOW, p.set_asq_level_low_number, -70, 0, 1)
await new_number(p, asq_config, CONF_DURATION_LOW, p.set_asq_duration_low_number, 0, 65535, 1)
await new_number(p, asq_config, CONF_LEVEL_HIGH, p.set_asq_level_high_number, -70, 0, 1)
await new_number(p, asq_config, CONF_DURATION_HIGH, p.set_asq_duration_high_number, 0, 65535, 1)
if rds_config := config.get(CONF_SECTION_RDS):
await new_number(parent, rds_config, CONF_DEVIATION, parent.set_rds_deviation_number, 0, 7.5, 0.01)
await new_number(p, rds_config, CONF_DEVIATION, p.set_rds_deviation_number, 0, 7.5, 0.01)

View file

@ -122,27 +122,27 @@ CONFIG_SCHEMA = cv.Schema(
)
async def new_select(parent, config, id, setter, options):
async def new_select(p, config, id, setter, options):
if c := config.get(id):
s = await select.new_select(c, options=list(options.keys()))
await cg.register_parented(s, parent)
await cg.register_parented(s, p)
cg.add(setter(s))
return s
async def to_code(config):
parent = await cg.get_variable(config[CONF_SI4713_ID])
await new_select(parent, config, CONF_PRE_EMPHASIS, parent.set_pre_emphasis_select, PRE_EMPHASIS)
p = await cg.get_variable(config[CONF_SI4713_ID])
await new_select(p, config, CONF_PRE_EMPHASIS, p.set_pre_emphasis_select, PRE_EMPHASIS)
if analog_config := config.get(CONF_SECTION_ANALOG):
await new_select(parent, analog_config, CONF_ATTENUATION, parent.set_analog_attenuation_select, LINE_ATTENUATION)
await new_select(p, analog_config, CONF_ATTENUATION, p.set_analog_attenuation_select, LINE_ATTENUATION)
if digital_config := config.get(CONF_SECTION_DIGITAL):
await new_select(parent, digital_config, CONF_SAMPLE_BITS, parent.set_digital_sample_bits_select, SAMPLE_BITS)
await new_select(parent, digital_config, CONF_CHANNELS, parent.set_digital_channels_select, SAMPLE_CHANNELS)
await new_select(parent, digital_config, CONF_MODE, parent.set_digital_mode_select, DIGITAL_MODE)
await new_select(parent, digital_config, CONF_CLOCK_EDGE, parent.set_digital_clock_edge_select, DIGITAL_CLOCK_EDGE)
await new_select(p, digital_config, CONF_SAMPLE_BITS, p.set_digital_sample_bits_select, SAMPLE_BITS)
await new_select(p, digital_config, CONF_CHANNELS, p.set_digital_channels_select, SAMPLE_CHANNELS)
await new_select(p, digital_config, CONF_MODE, p.set_digital_mode_select, DIGITAL_MODE)
await new_select(p, digital_config, CONF_CLOCK_EDGE, p.set_digital_clock_edge_select, DIGITAL_CLOCK_EDGE)
if refclk_config := config.get(CONF_SECTION_REFCLK):
await new_select(parent, refclk_config, CONF_SOURCE, parent.set_refclk_source_select, REFCLK_SOURCE)
await new_select(p, refclk_config, CONF_SOURCE, p.set_refclk_source_select, REFCLK_SOURCE)
if compressor_config := config.get(CONF_SECTION_COMPRESSOR):
await new_select(parent, compressor_config, CONF_ATTACK, parent.set_acomp_attack_select, ACOMP_ATTACK)
await new_select(parent, compressor_config, CONF_RELEASE, parent.set_acomp_release_select, ACOMP_RELEASE)
await new_select(parent, compressor_config, CONF_PRESET, parent.set_acomp_preset_select, ACOMP_PRESET)
await new_select(p, compressor_config, CONF_ATTACK, p.set_acomp_attack_select, ACOMP_ATTACK)
await new_select(p, compressor_config, CONF_RELEASE, p.set_acomp_release_select, ACOMP_RELEASE)
await new_select(p, compressor_config, CONF_PRESET, p.set_acomp_preset_select, ACOMP_PRESET)

View file

@ -43,6 +43,96 @@ RdsEnable = si4713_ns.class_("RdsEnable", switch.Switch)
RDSEnableSwitch = si4713_ns.class_("RDSEnableSwitch", switch.Switch)
GPIOSwitch = si4713_ns.class_("GPIOSwitch", switch.Switch)
PILOT_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
PilotEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
)
COMPRESSOR_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
AcompEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
)
LIMITER_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
LimiterEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
)
ASQ_SCHEMA = cv.Schema(
{
cv.Optional(CONF_OVERMOD): switch.switch_schema(
AsqOvermodEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
cv.Optional(CONF_IALL): switch.switch_schema(
AsqIallEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
cv.Optional(CONF_IALH): switch.switch_schema(
AsqIalhEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
}
)
RDS_SCHEMA = cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
RDSEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
}
)
OUTPUT_SCHEMA = cv.Schema(
{
cv.Optional(CONF_GPIO1): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
cv.Optional(CONF_GPIO2): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
cv.Optional(CONF_GPIO3): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
}
)
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_SI4713_ID): cv.use_id(Si4713Component),
@ -58,122 +148,44 @@ CONFIG_SCHEMA = cv.Schema(
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_EAR_HEARING,
),
cv.Optional(CONF_SECTION_PILOT): cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
PilotEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
),
cv.Optional(CONF_SECTION_COMPRESSOR): cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
AcompEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
),
cv.Optional(CONF_SECTION_LIMITER): cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
LimiterEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_SINE_WAVE,
),
}
),
cv.Optional(CONF_SECTION_ASQ): cv.Schema(
{
cv.Optional(CONF_OVERMOD): switch.switch_schema(
AsqOvermodEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
cv.Optional(CONF_IALL): switch.switch_schema(
AsqIallEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
cv.Optional(CONF_IALH): switch.switch_schema(
AsqIalhEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=ICON_,
),
}
),
cv.Optional(CONF_SECTION_RDS): cv.Schema(
{
cv.Optional(CONF_ENABLE): switch.switch_schema(
RDSEnableSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
}
),
cv.Optional(CONF_SECTION_OUTPUT): cv.Schema(
{
cv.Optional(CONF_GPIO1): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
cv.Optional(CONF_GPIO2): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
cv.Optional(CONF_GPIO3): switch.switch_schema(
GPIOSwitch,
device_class=DEVICE_CLASS_SWITCH,
entity_category=ENTITY_CATEGORY_CONFIG,
# icon=,
),
}
)
cv.Optional(CONF_SECTION_PILOT): PILOT_SCHEMA,
cv.Optional(CONF_SECTION_COMPRESSOR): COMPRESSOR_SCHEMA,
cv.Optional(CONF_SECTION_LIMITER): LIMITER_SCHEMA,
cv.Optional(CONF_SECTION_ASQ): ASQ_SCHEMA,
cv.Optional(CONF_SECTION_RDS): RDS_SCHEMA,
cv.Optional(CONF_SECTION_OUTPUT): OUTPUT_SCHEMA,
}
)
async def new_switch(parent, config, id, setter):
async def new_switch(p, config, id, setter):
if c := config.get(id):
s = await switch.new_switch(c)
await cg.register_parented(s, parent)
await cg.register_parented(s, p)
cg.add(setter(s))
return s
async def to_code(config):
parent = await cg.get_variable(config[CONF_SI4713_ID])
await new_switch(parent, config, CONF_MUTE, parent.set_mute_switch)
await new_switch(parent, config, CONF_MONO, parent.set_mono_switch)
p = await cg.get_variable(config[CONF_SI4713_ID])
await new_switch(p, config, CONF_MUTE, p.set_mute_switch)
await new_switch(p, config, CONF_MONO, p.set_mono_switch)
if pilot_config := config.get(CONF_SECTION_PILOT):
await new_switch(parent, pilot_config, CONF_ENABLE, parent.set_pilot_enable_switch)
await new_switch(p, pilot_config, CONF_ENABLE, p.set_pilot_enable_switch)
if compressor_config := config.get(CONF_SECTION_COMPRESSOR):
await new_switch(parent, compressor_config, CONF_ENABLE, parent.set_acomp_enable_switch)
await new_switch(p, compressor_config, CONF_ENABLE, p.set_acomp_enable_switch)
if limiter_config := config.get(CONF_SECTION_LIMITER):
await new_switch(parent, limiter_config, CONF_ENABLE, parent.set_limiter_enable_switch)
await new_switch(p, limiter_config, CONF_ENABLE, p.set_limiter_enable_switch)
if asq_config := config.get(CONF_SECTION_ASQ):
await new_switch(parent, asq_config, CONF_IALL, parent.set_asq_iall_enable_switch)
await new_switch(parent, asq_config, CONF_IALH, parent.set_asq_ialh_enable_switch)
await new_switch(parent, asq_config, CONF_OVERMOD, parent.set_asq_overmod_enable_switch)
await new_switch(p, asq_config, CONF_IALL, p.set_asq_iall_enable_switch)
await new_switch(p, asq_config, CONF_IALH, p.set_asq_ialh_enable_switch)
await new_switch(p, asq_config, CONF_OVERMOD, p.set_asq_overmod_enable_switch)
if rds_config := config.get(CONF_SECTION_RDS):
await new_switch(parent, rds_config, CONF_ENABLE, parent.set_rds_enable_switch)
await new_switch(p, rds_config, CONF_ENABLE, p.set_rds_enable_switch)
if output_config := config.get(CONF_SECTION_OUTPUT):
gpio1 = await new_switch(parent, output_config, CONF_GPIO1, parent.set_gpio1_switch)
gpio2 = await new_switch(parent, output_config, CONF_GPIO2, parent.set_gpio2_switch)
gpio3 = await new_switch(parent, output_config, CONF_GPIO3, parent.set_gpio3_switch)
gpio1 = await new_switch(p, output_config, CONF_GPIO1, p.set_gpio1_switch)
gpio2 = await new_switch(p, output_config, CONF_GPIO2, p.set_gpio2_switch)
gpio3 = await new_switch(p, output_config, CONF_GPIO3, p.set_gpio3_switch)
cg.add(gpio1.set_pin(1))
cg.add(gpio2.set_pin(2))
cg.add(gpio3.set_pin(3))

View file

@ -121,41 +121,39 @@ async def new_text(
return var
CONFIG_SCHEMA = cv.Schema(
RDS_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_SI4713_ID): cv.use_id(Si4713Component),
cv.Optional(CONF_SECTION_RDS): cv.Schema(
{
cv.Optional(CONF_STATION): text_schema(
RDSStationText,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
cv.Optional(CONF_TEXT): text_schema(
RDSTextText,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
}
cv.Optional(CONF_STATION): text_schema(
RDSStationText,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
cv.Optional(CONF_TEXT): text_schema(
RDSTextText,
entity_category=ENTITY_CATEGORY_CONFIG,
icon=ICON_FORMAT_TEXT,
),
}
)
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_SI4713_ID): cv.use_id(Si4713Component),
cv.Optional(CONF_SECTION_RDS): RDS_SCHEMA,
}
)
async def new_text_simple(parent, config, id, setter, min_length, max_length, *args):
async def new_text_simple(p, config, id, setter, min_length, max_length, *args):
if c := config.get(id):
t = await new_text(c, *args, min_length=min_length, max_length=max_length)
await cg.register_parented(t, parent)
await cg.register_parented(t, p)
cg.add(setter(t))
return t
async def to_code(config):
parent = await cg.get_variable(config[CONF_SI4713_ID])
p = await cg.get_variable(config[CONF_SI4713_ID])
if rds_config := config.get(CONF_SECTION_RDS):
await new_text_simple(
parent, rds_config, CONF_STATION, parent.set_rds_station_text, 0, si4713_ns.RDS_STATION_MAX
)
await new_text_simple(
parent, rds_config, CONF_TEXT, parent.set_rds_text_text, 0, si4713_ns.RDS_TEXT_MAX
)
await new_text_simple(p, rds_config, CONF_STATION, p.set_rds_station_text, 0, 8)
await new_text_simple(p, rds_config, CONF_TEXT, p.set_rds_text_text, 0, 64)