mirror of
https://github.com/esphome/esphome.git
synced 2026-10-21 05:26:46 +00:00
[seeed_mr24hpc1] Use Apply switches
This commit is contained in:
@@ -4,18 +4,14 @@ import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_SWITCH, ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns
|
||||
|
||||
UnderlyingOpenFuncSwitch = mr24hpc1_ns.class_(
|
||||
"UnderlyOpenFunctionSwitch", switch.Switch
|
||||
)
|
||||
from .. import CONF_MR24HPC1_ID, MR24HPC1Component
|
||||
|
||||
CONF_UNDERLYING_OPEN_FUNCTION = "underlying_open_function"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component),
|
||||
cv.Optional(CONF_UNDERLYING_OPEN_FUNCTION): switch.switch_schema(
|
||||
UnderlyingOpenFuncSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon="mdi:electric-switch",
|
||||
@@ -27,5 +23,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_MR24HPC1_ID])
|
||||
switches = switch.sub_switches(config, parent=hub)
|
||||
await switches(
|
||||
CONF_UNDERLYING_OPEN_FUNCTION, hub.set_underlying_open_function_switch
|
||||
CONF_UNDERLYING_OPEN_FUNCTION,
|
||||
hub.set_underlying_open_function_switch,
|
||||
apply="set_underlying_open_function(state)",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "underlyFuc_switch.h"
|
||||
|
||||
namespace esphome::seeed_mr24hpc1 {
|
||||
|
||||
void UnderlyOpenFunctionSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_underlying_open_function(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::seeed_mr24hpc1
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../seeed_mr24hpc1.h"
|
||||
|
||||
namespace esphome::seeed_mr24hpc1 {
|
||||
|
||||
class UnderlyOpenFunctionSwitch final : public switch_::Switch, public Parented<MR24HPC1Component> {
|
||||
public:
|
||||
UnderlyOpenFunctionSwitch() = default;
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::seeed_mr24hpc1
|
||||
Reference in New Issue
Block a user