diff --git a/components/ifan/fan.py b/components/ifan/fan.py index c602ebd0..087b053c 100644 --- a/components/ifan/fan.py +++ b/components/ifan/fan.py @@ -1,6 +1,6 @@ import esphome.codegen as cg import esphome.config_validation as cv -from esphome.components import fan,uart +from esphome.components import fan, uart from esphome import automation from esphome.automation import maybe_simple_id @@ -8,7 +8,7 @@ CONF_OUTPUT_ID, CONF_ID, ) -from esphome.core import coroutine_with_priority +from esphome.core import coroutine_with_priority DEPENDENCIES = ['uart'] @@ -19,36 +19,38 @@ IFan = ifan_ns.class_("IFan", cg.Component, fan.Fan, uart.UARTDevice) CycleSpeedAction = ifan_ns.class_("CycleSpeedAction", automation.Action) -CONFIG_SCHEMA = fan.FAN_SCHEMA.extend( - { - cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(IFan), +# Fixed CONFIG_SCHEMA with proper dictionary syntax +CONFIG_SCHEMA = ( + fan.fan_schema(IFan) + .extend({ cv.Optional(BUZZER_ENABLE, default=True): cv.boolean, cv.Optional(REMOTE_ENABLE, default=True): cv.boolean, - } -).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA) + }) + .extend(cv.COMPONENT_SCHEMA) + .extend(uart.UART_DEVICE_SCHEMA) +) + FAN_ACTION_SCHEMA = maybe_simple_id( { cv.Required(CONF_ID): cv.use_id(IFan), } ) + @automation.register_action("ifan.cycle_speed", CycleSpeedAction, FAN_ACTION_SCHEMA) async def fan_cycle_speed_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) @coroutine_with_priority(100.0) - async def to_code(config): cg.add_define("USE_FAN") - var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) + var = await fan.new_fan(config) cg.add(var.set_buzzer_enable(config[BUZZER_ENABLE])) cg.add(var.set_remote_enable(config[REMOTE_ENABLE])) + + # Register UART device if remote is enabled if REMOTE_ENABLE in config: - #await cg.register_component(var, config) await uart.register_uart_device(var, config) - await cg.register_component(var, config) - - await fan.register_fan(var, config) - - cg.add_global(ifan_ns.using) \ No newline at end of file + await cg.register_component(var, config) + cg.add_global(ifan_ns.using) diff --git a/components/ifan/ifan.cpp b/components/ifan/ifan.cpp index 7baa3374..884c18e1 100644 --- a/components/ifan/ifan.cpp +++ b/components/ifan/ifan.cpp @@ -80,7 +80,7 @@ void IFan::set_low() { beep(); } void IFan::set_med() { - digitalWrite(relay_1, LOW); + digitalWrite(relay_1, HIGH); digitalWrite(relay_2, HIGH); digitalWrite(relay_3, LOW); beep(2); diff --git a/components/ifan04/__init__.py b/components/ifan04/__init__.py index e0971498..ae744506 100644 --- a/components/ifan04/__init__.py +++ b/components/ifan04/__init__.py @@ -6,7 +6,6 @@ DEPENDENCIES = ['uart'] - ifan04_ns = cg.esphome_ns.namespace('ifan04') IFan04 = ifan04_ns.class_('IFan04', cg.Component, uart.UARTDevice) @@ -14,14 +13,14 @@ CONF_ON_LIGHT = "on_light" CONF_ON_BUZZER = "on_buzzer" +# Reverted to the original working schema - cv.COMPONENT_SCHEMA without fan.fan_schema CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(IFan04), + cv.GenerateID(): cv.declare_id(IFan04), # Add the ID field cv.Optional(CONF_ON_FAN): automation.validate_automation(single=True), cv.Optional(CONF_ON_LIGHT): automation.validate_automation(single=True), cv.Optional(CONF_ON_BUZZER): automation.validate_automation(single=True), }).extend(uart.UART_DEVICE_SCHEMA) - async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) @@ -39,4 +38,3 @@ async def to_code(config): await automation.build_automation( var.get_buzzer_trigger(), [], config[CONF_ON_BUZZER] ) -