From 14e36b00d3abc55bea6582fd0df63ece70030e93 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 22:28:22 +0200 Subject: [PATCH 01/14] implemented m5stack4relay --- .gitignore | 4 +- esphome/components/m5stack4relay/__init__.py | 30 ++++++++ .../m5stack4relay/m5stack4relay.cpp | 65 ++++++++++++++++ .../components/m5stack4relay/m5stack4relay.h | 32 ++++++++ .../m5stack4relay/switch/__init__.py | 63 ++++++++++++++++ .../switch/m5stack4relay_switch.cpp | 75 +++++++++++++++++++ .../switch/m5stack4relay_switch.h | 31 ++++++++ tests/test5.yaml | 27 +++++++ 8 files changed, 326 insertions(+), 1 deletion(-) create mode 100644 esphome/components/m5stack4relay/__init__.py create mode 100644 esphome/components/m5stack4relay/m5stack4relay.cpp create mode 100644 esphome/components/m5stack4relay/m5stack4relay.h create mode 100644 esphome/components/m5stack4relay/switch/__init__.py create mode 100644 esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp create mode 100644 esphome/components/m5stack4relay/switch/m5stack4relay_switch.h diff --git a/.gitignore b/.gitignore index 71b66b2499..bb69733547 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,6 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ \ No newline at end of file +.tests/ +/.vs/ESPHome_fork/v16 +/.vs diff --git a/esphome/components/m5stack4relay/__init__.py b/esphome/components/m5stack4relay/__init__.py new file mode 100644 index 0000000000..8ff8b29838 --- /dev/null +++ b/esphome/components/m5stack4relay/__init__.py @@ -0,0 +1,30 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import i2c +from esphome.const import CONF_ID + +CODEOWNERS = ["@KoenBreeman"] +DEPENDENCIES = ["i2c"] + +MULTI_CONF = True + +CONF_M5STACK4RELAY_ID = "m5stack4relay_id" + +m5stack4relay_ns = cg.esphome_ns.namespace("m5stack4relay") +M5Stack4Relay = m5stack4relay_ns.class_("M5Stack4Relay", cg.Component, i2c.I2CDevice) + +CONFIG_SCHEMA = ( + cv.Schema( + { + cv.GenerateID(): cv.declare_id(M5Stack4Relay), + } + ) + .extend(cv.COMPONENT_SCHEMA) + .extend(i2c.i2c_device_schema(0x26)) +) + + +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) diff --git a/esphome/components/m5stack4relay/m5stack4relay.cpp b/esphome/components/m5stack4relay/m5stack4relay.cpp new file mode 100644 index 0000000000..ee6d617692 --- /dev/null +++ b/esphome/components/m5stack4relay/m5stack4relay.cpp @@ -0,0 +1,65 @@ +#include "m5stack4relay.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace m5stack4relay { + +static const char *const TAG = "m5stack_4_relay"; + +void M5Stack4Relay::dump_config() { + ESP_LOGCONFIG(TAG, "M5Stack 4 Relays:"); + LOG_I2C_DEVICE(this); +} + +/*! @brief Setting the mode of the device, and turn off all relays. + * @param mode Async = 0, Sync = 1. */ +void M5Stack4Relay::init_(bool mode) { + this->write1_byte_(UNIT_4RELAY_REG, mode); + this->write1_byte_(UNIT_4RELAY_RELAY_REG, 0); +} + +/*! @brief Read a certain length of data to the specified register address. */ +uint8_t M5Stack4Relay::read1_byte_(uint8_t register_address) { + uint8_t data; + if (!this->read_byte(register_address, &data)) { + ESP_LOGW(TAG, "Read from relay failed!"); + this->status_set_warning(); + return uint8_t(0); + } + return data; +} + +/*! @brief Control the on/off of the specified relay. + * @param number Bit number of relay (0~3). + @param state OFF = 0, ON = 1 . */ +void M5Stack4Relay::relay_write(uint8_t number, bool state) { + uint8_t state_from_device = this->read1_byte_(UNIT_4RELAY_RELAY_REG); + if (state == 0) { + state_from_device &= ~(0x01 << number); + } else { + state_from_device |= (0x01 << number); + } + this->write1_byte_(UNIT_4RELAY_RELAY_REG, state_from_device); +} + +void M5Stack4Relay::setup() { + ESP_LOGCONFIG(TAG, "Setting up M5Stack_4_Relays..."); + uint8_t setupmode = 1; + this->init_(setupmode); +} + +/*! @brief Setting the mode of the device. + * @param mode Async = 0, Sync = 1. */ +void M5Stack4Relay::set_switch_mode(bool mode) { this->write1_byte_(UNIT_4RELAY_REG, mode); } + +/*! @brief Write a certain length of data to the specified register address. */ +void M5Stack4Relay::write1_byte_(uint8_t register_address, uint8_t data) { + if (!this->write_byte(register_address, data)) { + ESP_LOGW(TAG, "Write to relay failed!"); + this->status_set_warning(); + return; + } +} + +} // namespace m5stack4relay +} // namespace esphome diff --git a/esphome/components/m5stack4relay/m5stack4relay.h b/esphome/components/m5stack4relay/m5stack4relay.h new file mode 100644 index 0000000000..ab9bd73d3f --- /dev/null +++ b/esphome/components/m5stack4relay/m5stack4relay.h @@ -0,0 +1,32 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/i2c/i2c.h" + +namespace esphome { +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: + void set_switch_mode(bool mode); + + void relay_write(uint8_t number, bool state); + + protected: + void write1_byte_(uint8_t register_address, uint8_t data); + uint8_t read1_byte_(uint8_t register_address); + + void dump_config() override; + + void init_(bool mode); + + void setup() override; +}; + +} // namespace m5stack4relay +} // namespace esphome diff --git a/esphome/components/m5stack4relay/switch/__init__.py b/esphome/components/m5stack4relay/switch/__init__.py new file mode 100644 index 0000000000..0b50580b70 --- /dev/null +++ b/esphome/components/m5stack4relay/switch/__init__.py @@ -0,0 +1,63 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import i2c, switch +from esphome.const import CONF_CHANNEL, CONF_INTERLOCK # , CONF_ID, + +from .. import m5stack4relay_ns, M5Stack4Relay, CONF_M5STACK4RELAY_ID + +DEPENDENCIES = ["m5stack4relay"] + +M5StackSwitch = m5stack4relay_ns.class_( + "M5Stack4RelaySwitch", cg.Component, i2c.I2CDevice, switch.Switch +) + +CONF_INTERLOCK_WAIT_TIME = "interlock_wait_time" + +CONF_Relay_1 = "relay_1" +CONF_Relay_2 = "relay_2" +CONF_Relay_3 = "relay_3" +CONF_Relay_4 = "relay_4" + +CONF_INTERLOCK_WAIT_TIME = "interlock_wait_time" + +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 = ( + switch.switch_schema(M5StackSwitch) + .extend( + { + 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, + } + ) + .extend(cv.COMPONENT_SCHEMA) +) + + +async def to_code(config): + var = await switch.new_switch(config) + await cg.register_component(var, config) + await cg.register_parented(var, config[CONF_M5STACK4RELAY_ID]) + + 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 new file mode 100644 index 0000000000..75eda61dee --- /dev/null +++ b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.cpp @@ -0,0 +1,75 @@ +#include "esphome/core/log.h" +#include "m5stack4relay_switch.h" + +namespace esphome { +namespace m5stack4relay { + +static const char *const TAG = "switch.M5Stack_4_Relay"; + +float M5Stack4RelaySwitch::get_setup_priority() const { return setup_priority::HARDWARE; } + +void M5Stack4RelaySwitch::setup() { + ESP_LOGCONFIG(TAG, "Setting up M5Stack_4_relay Switch '%s'...", this->name_.c_str()); + + bool initial_state = this->get_initial_state_with_restore_mode().value_or(false); + + // write state before setup + if (initial_state) { + this->turn_on(); + } else { + this->turn_off(); + } +} + +void M5Stack4RelaySwitch::dump_config() { + LOG_SWITCH("", "M5Stack4Relay Switch", this); + + if (!this->interlock_.empty()) { + ESP_LOGCONFIG(TAG, " Interlocks:"); + for (auto *lock : this->interlock_) { + if (lock == this) + continue; + ESP_LOGCONFIG(TAG, " %s", lock->get_name().c_str()); + } + } +} + +void M5Stack4RelaySwitch::write_state(bool state) { + if (state != this->inverted_) { + // Turning ON, check interlocking + + bool found = false; + for (auto *lock : this->interlock_) { + if (lock == this) + continue; + + if (lock->state) { + lock->turn_off(); + found = true; + } + } + if (found && this->interlock_wait_time_ != 0) { + this->set_timeout("interlock", this->interlock_wait_time_, [this, state] { + // Don't write directly, call the function again + // (some other switch may have changed state while we were waiting) + this->write_state(state); + }); + return; + } + } else if (this->interlock_wait_time_ != 0) { + // If we are switched off during the interlock wait time, cancel any pending + // re-activations + this->cancel_timeout("interlock"); + } + + // This will be called every time the user requests a state change. + this->parent_->relay_write(this->channel_, state); + + // Acknowledge new state by publishing it + this->publish_state(state); +} + +void M5Stack4RelaySwitch::set_interlock(const std::vector &interlock) { this->interlock_ = interlock; } + +} // namespace m5stack4relay +} // namespace esphome diff --git a/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h new file mode 100644 index 0000000000..db96ecdfa6 --- /dev/null +++ b/esphome/components/m5stack4relay/switch/m5stack4relay_switch.h @@ -0,0 +1,31 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/switch/switch.h" + +#include "esphome/components/m5stack4relay/m5stack4relay.h" + +namespace esphome { +namespace m5stack4relay { + +class M5Stack4RelaySwitch : public Component, public switch_::Switch, public Parented { + public: + float get_setup_priority() const override; + + void setup() override; + void dump_config() override; + void write_state(bool state) override; + + void set_channel(RelayBit channel) { this->channel_ = (uint8_t) channel; } + + void set_interlock(const std::vector &interlock); + void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; } + + protected: + uint8_t channel_; + std::vector interlock_; + uint32_t interlock_wait_time_{0}; +}; + +} // namespace m5stack4relay +} // namespace esphome diff --git a/tests/test5.yaml b/tests/test5.yaml index 0d044ac241..1aa9cb7677 100644 --- a/tests/test5.yaml +++ b/tests/test5.yaml @@ -41,6 +41,9 @@ uart: i2c: frequency: 100khz +m5stack4relay: + id: M5stackrelay_ID1 + modbus: uart_id: uart_1 flow_control_pin: 5 @@ -560,6 +563,30 @@ switch: id: Led3 led: 3 name: TM1638Led3 + + - platform: m5stack4relay + id: m5stack4relay_1 + name: m5stack4relay1 + channel: relay_1 + m5stack4relay_id: M5stackrelay_ID1 + + - platform: m5stack4relay + id: m5stack4relay_2 + name: m5stack4relay2 + channel: relay_2 + m5stack4relay_id: M5stackrelay_ID1 + + - platform: m5stack4relay + id: m5stack4relay_3 + name: m5stack4relay3 + channel: relay_3 + m5stack4relay_id: M5stackrelay_ID1 + + - platform: m5stack4relay + id: m5stack4relay_4 + name: m5stack4relay4 + channel: relay_4 + m5stack4relay_id: M5stackrelay_ID1 display: - platform: tm1638 From 345b224dd1113667d19c4a79a6d28d806884ad78 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 22:34:56 +0200 Subject: [PATCH 02/14] Added codeowner --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index 3032e7dd88..653741f34d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -137,6 +137,7 @@ esphome/components/lilygo_t5_47/touchscreen/* @jesserockz esphome/components/lock/* @esphome/core esphome/components/logger/* @esphome/core esphome/components/ltr390/* @sjtrny +esphome/components/m5stack4relay/* @KoenBreeman esphome/components/matrix_keypad/* @ssieb esphome/components/max31865/* @DAVe3283 esphome/components/max44009/* @berfenger From 9ddce5cf85f030301af19e4984be12639b7feae2 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Sat, 6 May 2023 08:44:13 +1200 Subject: [PATCH 03/14] Restore .gitignore --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index bb69733547..71b66b2499 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,4 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ -/.vs/ESPHome_fork/v16 -/.vs +.tests/ \ No newline at end of file From a7ab389ab0a9b677bcd9600c62fd5a108d6930e8 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 23:05:26 +0200 Subject: [PATCH 04/14] Updated switch component to implement interlocking --- esphome/components/switch/switch.h | 20 ++++++++++++++++++++ tests/test5.yaml | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index 9daac4ee23..d711ccb1c0 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -75,6 +75,23 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { */ void set_inverted(bool inverted); + /** Sets interlocked switches. + * + * Set the switches which should be switched to off when this switch is turened on + * + * @param vector a single switch or vector of switches which should be switched to off. + */ + void set_interlock(const std::vector &interlock) { interlock_ = interlock; } + + /** Sets waiting time for interlocking switches. + * + * Sets the time between switching the interlocked switches off and switching the + * switch on. + * + * @param interlock_wait_time time microseconds to wait between switching. + */ + void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; } + /** Set callback for state changes. * * @param callback The void(bool) callback. @@ -120,6 +137,9 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { bool inverted_{false}; Deduplicator publish_dedup_; ESPPreferenceObject rtc_; + + std::vector interlock_; + uint32_t interlock_wait_time_{0}; }; #define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj)) diff --git a/tests/test5.yaml b/tests/test5.yaml index 1aa9cb7677..f0a5ffb0ce 100644 --- a/tests/test5.yaml +++ b/tests/test5.yaml @@ -563,7 +563,7 @@ switch: id: Led3 led: 3 name: TM1638Led3 - + - platform: m5stack4relay id: m5stack4relay_1 name: m5stack4relay1 From a2f73fe34d9fd3c2e6e0e42cf739ebe834433853 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 23:07:09 +0200 Subject: [PATCH 05/14] removed trailing spaces --- .gitignore | 3 ++- esphome/components/switch/switch.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 71b66b2499..b80791b4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ \ No newline at end of file +.tests/ +/.vs diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index d711ccb1c0..ae63868bae 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -82,10 +82,10 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { * @param vector a single switch or vector of switches which should be switched to off. */ void set_interlock(const std::vector &interlock) { interlock_ = interlock; } - + /** Sets waiting time for interlocking switches. * - * Sets the time between switching the interlocked switches off and switching the + * Sets the time between switching the interlocked switches off and switching the * switch on. * * @param interlock_wait_time time microseconds to wait between switching. From eaa88eedf008ead9fcad46efa8ef6efdfd625a4f Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 23:08:00 +0200 Subject: [PATCH 06/14] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index b80791b4eb..3eb2a5d542 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,3 @@ sdkconfig.* !sdkconfig.defaults .tests/ -/.vs From 19acda028a7f777193a31a54c06e7f4fc331a4fd Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 23:27:33 +0200 Subject: [PATCH 07/14] removed spaces in front of comments --- .gitignore | 2 ++ esphome/components/switch/switch.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3eb2a5d542..bb69733547 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ sdkconfig.* !sdkconfig.defaults .tests/ +/.vs/ESPHome_fork/v16 +/.vs diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index ae63868bae..45304f9be0 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -75,7 +75,7 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { */ void set_inverted(bool inverted); - /** Sets interlocked switches. + /** Sets interlocked switches. * * Set the switches which should be switched to off when this switch is turened on * @@ -83,7 +83,7 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { */ void set_interlock(const std::vector &interlock) { interlock_ = interlock; } - /** Sets waiting time for interlocking switches. + /** Sets waiting time for interlocking switches. * * Sets the time between switching the interlocked switches off and switching the * switch on. From 298893cb386e37471339bef6f198774895a5be4d Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Fri, 5 May 2023 23:28:50 +0200 Subject: [PATCH 08/14] Update .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index bb69733547..3eb2a5d542 100644 --- a/.gitignore +++ b/.gitignore @@ -130,5 +130,3 @@ sdkconfig.* !sdkconfig.defaults .tests/ -/.vs/ESPHome_fork/v16 -/.vs From 0d36fb3cab30f3350805d97fbe26dab374b29299 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Sat, 6 May 2023 16:22:21 +0200 Subject: [PATCH 09/14] restored switch.h --- esphome/components/switch/switch.h | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/esphome/components/switch/switch.h b/esphome/components/switch/switch.h index 45304f9be0..9daac4ee23 100644 --- a/esphome/components/switch/switch.h +++ b/esphome/components/switch/switch.h @@ -75,23 +75,6 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { */ void set_inverted(bool inverted); - /** Sets interlocked switches. - * - * Set the switches which should be switched to off when this switch is turened on - * - * @param vector a single switch or vector of switches which should be switched to off. - */ - void set_interlock(const std::vector &interlock) { interlock_ = interlock; } - - /** Sets waiting time for interlocking switches. - * - * Sets the time between switching the interlocked switches off and switching the - * switch on. - * - * @param interlock_wait_time time microseconds to wait between switching. - */ - void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; } - /** Set callback for state changes. * * @param callback The void(bool) callback. @@ -137,9 +120,6 @@ class Switch : public EntityBase, public EntityBase_DeviceClass { bool inverted_{false}; Deduplicator publish_dedup_; ESPPreferenceObject rtc_; - - std::vector interlock_; - uint32_t interlock_wait_time_{0}; }; #define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj)) From 229ecc30867cadbfae992549cb605c0f9333e15b Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Sat, 6 May 2023 16:24:51 +0200 Subject: [PATCH 10/14] restored .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3eb2a5d542..71b66b2499 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,4 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ +.tests/ \ No newline at end of file From 3f4b364c55d33a0a03f14b99cdaa7a1330309cbf Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Thu, 22 Jun 2023 20:51:44 +0200 Subject: [PATCH 11/14] Updated options of channel from string to integer --- .gitignore | 3 ++- esphome/components/m5stack4relay/switch/__init__.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 71b66b2499..b80791b4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ \ No newline at end of file +.tests/ +/.vs diff --git a/esphome/components/m5stack4relay/switch/__init__.py b/esphome/components/m5stack4relay/switch/__init__.py index 0b50580b70..d986baa2e2 100644 --- a/esphome/components/m5stack4relay/switch/__init__.py +++ b/esphome/components/m5stack4relay/switch/__init__.py @@ -13,10 +13,10 @@ M5StackSwitch = m5stack4relay_ns.class_( CONF_INTERLOCK_WAIT_TIME = "interlock_wait_time" -CONF_Relay_1 = "relay_1" -CONF_Relay_2 = "relay_2" -CONF_Relay_3 = "relay_3" -CONF_Relay_4 = "relay_4" +CONF_Relay_1 = 1 +CONF_Relay_2 = 2 +CONF_Relay_3 = 3 +CONF_Relay_4 = 4 CONF_INTERLOCK_WAIT_TIME = "interlock_wait_time" From 4d11a6c00524883565c46d289dfdd142527c6293 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Thu, 22 Jun 2023 21:01:14 +0200 Subject: [PATCH 12/14] restored .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b80791b4eb..71b66b2499 100644 --- a/.gitignore +++ b/.gitignore @@ -129,5 +129,4 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ -/.vs +.tests/ \ No newline at end of file From f214a6a637313a4e92e28e2d695e14b7124fc197 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Thu, 22 Jun 2023 21:18:37 +0200 Subject: [PATCH 13/14] updated test5.yaml --- .gitignore | 3 ++- tests/test5.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 71b66b2499..b80791b4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ \ No newline at end of file +.tests/ +/.vs diff --git a/tests/test5.yaml b/tests/test5.yaml index f0a5ffb0ce..9a149984ab 100644 --- a/tests/test5.yaml +++ b/tests/test5.yaml @@ -567,25 +567,25 @@ switch: - platform: m5stack4relay id: m5stack4relay_1 name: m5stack4relay1 - channel: relay_1 + channel: 1 m5stack4relay_id: M5stackrelay_ID1 - platform: m5stack4relay id: m5stack4relay_2 name: m5stack4relay2 - channel: relay_2 + channel: 2 m5stack4relay_id: M5stackrelay_ID1 - platform: m5stack4relay id: m5stack4relay_3 name: m5stack4relay3 - channel: relay_3 + channel: 3 m5stack4relay_id: M5stackrelay_ID1 - platform: m5stack4relay id: m5stack4relay_4 name: m5stack4relay4 - channel: relay_4 + channel: 4 m5stack4relay_id: M5stackrelay_ID1 display: From 74964694c3be4782ac13f21a56eaa47d1f4b78b3 Mon Sep 17 00:00:00 2001 From: KoenBreeman <121864590+KoenBreeman@users.noreply.github.com> Date: Thu, 22 Jun 2023 21:19:14 +0200 Subject: [PATCH 14/14] restored .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b80791b4eb..71b66b2499 100644 --- a/.gitignore +++ b/.gitignore @@ -129,5 +129,4 @@ tests/.esphome/ sdkconfig.* !sdkconfig.defaults -.tests/ -/.vs +.tests/ \ No newline at end of file