mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 12:06:26 +01:00
updated components and test according to remark jesserocks
This commit is contained in:
parent
f7a8c8be46
commit
181fc3ec26
@ -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]))
|
||||
|
@ -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_) {
|
||||
|
@ -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<Switch *> &interlock);
|
||||
void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
|
||||
|
27
tests/components/seeedmultichannelrelay/common.yaml
Normal file
27
tests/components/seeedmultichannelrelay/common.yaml
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user