diff --git a/esphome/components/m5stack4relay/m5stack4relay.h b/esphome/components/m5stack4relay/m5stack4relay.h index ab9bd73d3f..8a34d82f5d 100644 --- a/esphome/components/m5stack4relay/m5stack4relay.h +++ b/esphome/components/m5stack4relay/m5stack4relay.h @@ -9,7 +9,6 @@ namespace m5stack4relay { static constexpr uint8_t UNIT_4RELAY_REG = 0X10; static constexpr uint8_t UNIT_4RELAY_RELAY_REG = 0X11; -enum class RelayBit : uint8_t { RELAY1 = 0, RELAY2 = 1, RELAY3 = 2, RELAY4 = 3 }; class M5Stack4Relay : public Component, public i2c::I2CDevice { public: diff --git a/esphome/components/m5stack4relay/switch/__init__.py b/esphome/components/m5stack4relay/switch/__init__.py index 10cbf4e75b..f0be5dd529 100644 --- a/esphome/components/m5stack4relay/switch/__init__.py +++ b/esphome/components/m5stack4relay/switch/__init__.py @@ -18,14 +18,6 @@ CONF_Relay_2 = 2 CONF_Relay_3 = 3 CONF_Relay_4 = 4 -RelayBit_ = m5stack4relay_ns.enum("RelayBit", is_class=True) - -SWITCH_MAP = { - CONF_Relay_1: RelayBit_.RELAY1, - CONF_Relay_2: RelayBit_.RELAY2, - CONF_Relay_3: RelayBit_.RELAY3, - CONF_Relay_4: RelayBit_.RELAY4, -} CONFIG_SCHEMA = ( @@ -34,11 +26,7 @@ CONFIG_SCHEMA = ( { cv.GenerateID(): cv.declare_id(M5StackSwitch), cv.GenerateID(CONF_M5STACK4RELAY_ID): cv.use_id(M5Stack4Relay), - cv.Required(CONF_CHANNEL): cv.enum(SWITCH_MAP), - cv.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_id(switch.Switch)), - cv.Optional( - CONF_INTERLOCK_WAIT_TIME, default="0ms" - ): cv.positive_time_period_milliseconds, + cv.Required(CONF_CHANNEL): cv.int_range(min=1, max=4), } ) .extend(cv.COMPONENT_SCHEMA) @@ -52,10 +40,3 @@ async def to_code(config): cg.add(var.set_channel(config[CONF_CHANNEL])) - if CONF_INTERLOCK in config: - interlock = [] - for it in config[CONF_INTERLOCK]: - lock = await cg.get_variable(it) - interlock.append(lock) - cg.add(var.set_interlock(interlock)) - cg.add(var.set_interlock_wait_time(config[CONF_INTERLOCK_WAIT_TIME])) diff --git a/esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp index 75eda61dee..e556699636 100644 --- a/esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp +++ b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp @@ -23,6 +23,7 @@ void M5Stack4RelaySwitch::setup() { void M5Stack4RelaySwitch::dump_config() { LOG_SWITCH("", "M5Stack4Relay Switch", this); +ESP_LOGCONFIG(TAG, " Channel: %u", this->channel_); if (!this->interlock_.empty()) { ESP_LOGCONFIG(TAG, " Interlocks:"); @@ -63,7 +64,7 @@ void M5Stack4RelaySwitch::write_state(bool state) { } // This will be called every time the user requests a state change. - this->parent_->relay_write(this->channel_, state); + this->parent_->relay_write(this->channel_ - 1, state); // Acknowledge new state by publishing it this->publish_state(state); diff --git a/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h index db96ecdfa6..2da2b22016 100644 --- a/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h +++ b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h @@ -16,7 +16,7 @@ class M5Stack4RelaySwitch : public Component, public switch_::Switch, public Par void dump_config() override; void write_state(bool state) override; - void set_channel(RelayBit channel) { this->channel_ = (uint8_t) channel; } + void set_channel(uint8_t channel) { this->channel_ = channel; } void set_interlock(const std::vector &interlock); void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }