diff --git a/esphome/components/seeedmultichannelrelay/switch/__init__.py b/esphome/components/seeedmultichannelrelay/switch/__init__.py index a52b7c86d3..aab0c1106b 100644 --- a/esphome/components/seeedmultichannelrelay/switch/__init__.py +++ b/esphome/components/seeedmultichannelrelay/switch/__init__.py @@ -1,7 +1,7 @@ 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 +from esphome.const import CONF_CHANNEL from .. import ( seeedmultichannelrelay_ns, @@ -28,18 +28,6 @@ CONF_Relay_8 = 8 RelayBit_ = seeedmultichannelrelay_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, - CONF_Relay_5: RelayBit_.RELAY5, - CONF_Relay_6: RelayBit_.RELAY6, - CONF_Relay_7: RelayBit_.RELAY7, - CONF_Relay_8: RelayBit_.RELAY8, -} - - CONFIG_SCHEMA = ( switch.switch_schema(SeeedMultiChannelRelaySwitch) .extend( @@ -48,11 +36,7 @@ CONFIG_SCHEMA = ( cv.GenerateID(CONF_SEEEDMULTICHANNELRELAY_ID): cv.use_id( SeeedMultiChannelRelay ), - 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=8), } ) .extend(cv.COMPONENT_SCHEMA) @@ -66,10 +50,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/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.cpp b/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.cpp index 51e2168b95..884972fa97 100644 --- a/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.cpp +++ b/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.cpp @@ -23,7 +23,7 @@ void SeeedMultiChannelRelaySwitch::setup() { void SeeedMultiChannelRelaySwitch::dump_config() { LOG_SWITCH("", "SeeedMultiChannelRelay Switch", this); - + ESP_LOGCONFIG(TAG, " Channel: %u", this->channel_); if (!this->interlock_.empty()) { ESP_LOGCONFIG(TAG, " Interlocks:"); for (auto *lock : this->interlock_) { diff --git a/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.h b/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.h index 0111055f32..2a9ccc64aa 100644 --- a/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.h +++ b/esphome/components/seeedmultichannelrelay/switch/seeedmultichannelrelay_switch.h @@ -16,7 +16,7 @@ class SeeedMultiChannelRelaySwitch : public Component, public switch_::Switch, p 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; } diff --git a/tests/components/seeedmultichannelrelay/common.yaml b/tests/components/seeedmultichannelrelay/common.yaml new file mode 100644 index 0000000000..24e015c249 --- /dev/null +++ b/tests/components/seeedmultichannelrelay/common.yaml @@ -0,0 +1,27 @@ +i2c: + - id: i2c_seeedmultichannelrelay + scl: ${scl_pin} + sda: ${sda_pin} + +seeedmultichannelrelay: + id: SeeedMultiChannelRelay_ID + change_address_to: 0x01 + +switch: + - platform: seeedmultichannelrelay + id: seeedmultichannelrelay_1 + name: seeedmultichannelrelay1 + channel: 1 + seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID + + - platform: seeedmultichannelrelay + id: seeedmultichannelrelay_2 + name: seeedmultichannelrelay2 + channel: 2 + seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID + + - platform: seeedmultichannelrelay + id: seeedmultichannelrelay_8 + name: seeedmultichannelrelay8 + channel: 8 + seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID diff --git a/tests/components/seeedmultichannelrelay/test.esp32-ard.yaml b/tests/components/seeedmultichannelrelay/test.esp32-ard.yaml index 81006ccc2c..a9de1c622f 100644 --- a/tests/components/seeedmultichannelrelay/test.esp32-ard.yaml +++ b/tests/components/seeedmultichannelrelay/test.esp32-ard.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 16 - sda: 17 +substitutions: + scl_pin: "16" + sda_pin: "17" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml diff --git a/tests/components/seeedmultichannelrelay/test.esp32-c3-ard.yaml b/tests/components/seeedmultichannelrelay/test.esp32-c3-ard.yaml index 9242a15c73..738a01ddbc 100644 --- a/tests/components/seeedmultichannelrelay/test.esp32-c3-ard.yaml +++ b/tests/components/seeedmultichannelrelay/test.esp32-c3-ard.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 5 - sda: 4 +substitutions: + scl_pin: "5" + sda_pin: "4" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml diff --git a/tests/components/seeedmultichannelrelay/test.esp32-c3-idf.yaml b/tests/components/seeedmultichannelrelay/test.esp32-c3-idf.yaml index 9242a15c73..738a01ddbc 100644 --- a/tests/components/seeedmultichannelrelay/test.esp32-c3-idf.yaml +++ b/tests/components/seeedmultichannelrelay/test.esp32-c3-idf.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 5 - sda: 4 +substitutions: + scl_pin: "5" + sda_pin: "4" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml diff --git a/tests/components/seeedmultichannelrelay/test.esp32-idf.yaml b/tests/components/seeedmultichannelrelay/test.esp32-idf.yaml index 81006ccc2c..a9de1c622f 100644 --- a/tests/components/seeedmultichannelrelay/test.esp32-idf.yaml +++ b/tests/components/seeedmultichannelrelay/test.esp32-idf.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 16 - sda: 17 +substitutions: + scl_pin: "16" + sda_pin: "17" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml diff --git a/tests/components/seeedmultichannelrelay/test.esp8266-ard.yaml b/tests/components/seeedmultichannelrelay/test.esp8266-ard.yaml index 9242a15c73..738a01ddbc 100644 --- a/tests/components/seeedmultichannelrelay/test.esp8266-ard.yaml +++ b/tests/components/seeedmultichannelrelay/test.esp8266-ard.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 5 - sda: 4 +substitutions: + scl_pin: "5" + sda_pin: "4" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml diff --git a/tests/components/seeedmultichannelrelay/test.rp2040-ard.yaml b/tests/components/seeedmultichannelrelay/test.rp2040-ard.yaml index 9242a15c73..738a01ddbc 100644 --- a/tests/components/seeedmultichannelrelay/test.rp2040-ard.yaml +++ b/tests/components/seeedmultichannelrelay/test.rp2040-ard.yaml @@ -1,27 +1,5 @@ -i2c: - - id: i2c_seeedmultichannelrelay - scl: 5 - sda: 4 +substitutions: + scl_pin: "5" + sda_pin: "4" -seeedmultichannelrelay: - id: SeeedMultiChannelRelay_ID - change_address_to: 0x01 - -switch: - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_1 - name: seeedmultichannelrelay1 - channel: 1 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_2 - name: seeedmultichannelrelay2 - channel: 2 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID - - - platform: seeedmultichannelrelay - id: seeedmultichannelrelay_8 - name: seeedmultichannelrelay8 - channel: 8 - seeedmultichannelrelay_id: SeeedMultiChannelRelay_ID +<<: !include common.yaml