mirror of
https://github.com/esphome/esphome.git
synced 2024-12-11 14:49:20 +01:00
Apply suggestions from code review
Accepted changes Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
c7503a44bd
commit
7226e89d8d
@ -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:
|
||||
|
@ -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]))
|
||||
|
@ -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);
|
||||
|
@ -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<Switch *> &interlock);
|
||||
void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
|
||||
|
Loading…
Reference in New Issue
Block a user