def validate_color_temperature(value): try: val = cv.float_with_unit('Color Temperature', 'mireds')(value) except vol.Invalid: val = 1000000.0 / cv.float_with_unit('Color Temperature', 'K')(value) if val < 0: raise vol.Invalid("Color temperature cannot be negative") return val
unit_of_measurement=UNIT_LUX, icon=ICON_BRIGHTNESS_6, accuracy_decimals=4, device_class=DEVICE_CLASS_ILLUMINANCE, state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_INTEGRATION_TIME, default="100ms"): validate_integration_time, cv.Optional(CONF_NAME, default="TLS2591"): cv.string, cv.Optional(CONF_GAIN, default="AUTO"): cv.enum(GAINS, upper=True), cv.Optional(CONF_POWER_SAVE_MODE, default=True): cv.boolean, cv.Optional(CONF_DEVICE_FACTOR, default=53.0): cv.float_with_unit("device_factor", "", True), cv.Optional(CONF_GLASS_ATTENUATION_FACTOR, default=7.7): cv.float_with_unit("glass_attenuation_factor", "", True), }).extend(cv.polling_component_schema("60s")).extend( i2c.i2c_device_schema(0x29))) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) if CONF_FULL_SPECTRUM in config: conf = config[CONF_FULL_SPECTRUM] sens = await sensor.new_sensor(conf) cg.add(var.set_full_spectrum_sensor(sens))
cv.Required(CONF_NUMBER): validate_gpio_pin, cv.Optional(CONF_MODE, default={}): cv.Schema({ cv.Optional(CONF_INPUT, default=False): cv.boolean, cv.Optional(CONF_OUTPUT, default=False): cv.boolean, cv.Optional(CONF_OPEN_DRAIN, default=False): cv.boolean, cv.Optional(CONF_PULLUP, default=False): cv.boolean, cv.Optional(CONF_PULLDOWN, default=False): cv.boolean, }), cv.Optional(CONF_INVERTED, default=False): cv.boolean, cv.SplitDefault(CONF_DRIVE_STRENGTH, esp32_idf="20mA"): cv.All( cv.only_with_esp_idf, cv.float_with_unit("current", "mA", optional_unit=True), cv.enum(DRIVE_STRENGTHS), ), }, validate_supports, ) @pins.PIN_SCHEMA_REGISTRY.register("esp32", ESP32_PIN_SCHEMA) async def esp32_pin_to_code(config): var = cg.new_Pvariable(config[CONF_ID]) num = config[CONF_NUMBER] if CORE.using_esp_idf: cg.add(var.set_pin(getattr(gpio_num_t, f"GPIO_NUM_{num}"))) else: cg.add(var.set_pin(num))
raise cv.Invalid("The gains can't be zero") max_energy = (0.25 * 0.25 / 3600 / (2 ** -4)) / (voltage_gain * current_gain) min_energy = (0.25 * 0.25 / 3600 / (2 ** 18)) / (voltage_gain * current_gain) mech_min_energy = (0.25 * 0.25 / 3600 / 7.8) / (voltage_gain * current_gain) if pulse_energy < min_energy or pulse_energy > max_energy: raise cv.Invalid( "For given current&voltage gains, the pulse energy must be between " f"{min_energy} Wh and {max_energy} Wh and in mechanical counter mode " f"between {mech_min_energy} Wh and {max_energy} Wh" ) return config validate_energy = cv.float_with_unit("energy", "(Wh|WH|wh)?", optional_unit=True) CONFIG_SCHEMA = cv.All( cv.Schema( { cv.GenerateID(): cv.declare_id(CS5460AComponent), cv.Optional(CONF_SAMPLES, default=4000): cv.int_range(min=1, max=0xFFFFFF), cv.Optional(CONF_PHASE_OFFSET, default=0): cv.int_range(min=-64, max=63), cv.Optional(CONF_PGA_GAIN, default="10X"): cv.enum( PGA_GAIN_OPTIONS, upper=True ), cv.Optional(CONF_CURRENT_GAIN, default=0.001): cv.negative_one_to_one_float, cv.Optional(CONF_VOLTAGE_GAIN, default=0.001): cv.zero_to_one_float, cv.Optional(CONF_CURRENT_HPF, default=True): cv.boolean, cv.Optional(CONF_VOLTAGE_HPF, default=True): cv.boolean, cv.Optional(CONF_PULSE_ENERGY, default=10.0): validate_energy,
accuracy_decimals=1, device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( unit_of_measurement=UNIT_PERCENT, accuracy_decimals=1, device_class=DEVICE_CLASS_HUMIDITY, state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean, cv.Optional(CONF_ALTITUDE_COMPENSATION): cv.All( cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"), cv.int_range(min=0, max=0xFFFF, max_included=False), ), cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION, default=0): cv.pressure, cv.Optional(CONF_TEMPERATURE_OFFSET): cv.temperature, }).extend(cv.polling_component_schema("60s")).extend( i2c.i2c_device_schema(0x61))) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config)
), cv.Optional(CONF_CALCULATED_LUX): sensor.sensor_schema( UNIT_LUX, ICON_BRIGHTNESS_6, 4, DEVICE_CLASS_ILLUMINANCE, STATE_CLASS_MEASUREMENT, ), cv.Optional( CONF_INTEGRATION_TIME, default="100ms" ): validate_integration_time, cv.Optional(CONF_NAME, default="TLS2591"): cv.string, cv.Optional(CONF_GAIN, default="MEDIUM"): cv.enum(GAINS, upper=True), cv.Optional(CONF_POWER_SAVE_MODE, default=True): cv.boolean, cv.Optional(CONF_DEVICE_FACTOR, default=53.0): cv.float_with_unit( "device_factor", "", True ), cv.Optional(CONF_GLASS_ATTENUATION_FACTOR, default=7.7): cv.float_with_unit( "glass_attenuation_factor", "", True ), } ) .extend(cv.polling_component_schema("60s")) .extend(i2c.i2c_device_schema(0x29)) ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config)