mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-25 15:18:29 +02:00
Add support for TM1638 Led and Key component (#3340)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import switch
|
||||
from esphome.const import CONF_LED
|
||||
from ..display import tm1638_ns, TM1638Component, CONF_TM1638_ID
|
||||
|
||||
TM1638SwitchLed = tm1638_ns.class_("TM1638SwitchLed", switch.Switch, cg.Component)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(TM1638SwitchLed),
|
||||
cv.GenerateID(CONF_TM1638_ID): cv.use_id(TM1638Component),
|
||||
cv.Required(CONF_LED): cv.int_range(min=0, max=7),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await switch.new_switch(config)
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_lednum(config[CONF_LED]))
|
||||
hub = await cg.get_variable(config[CONF_TM1638_ID])
|
||||
cg.add(var.set_tm1638(hub))
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "tm1638_switch_led.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tm1638 {
|
||||
|
||||
static const char *const TAG = "tm1638.led";
|
||||
|
||||
void TM1638SwitchLed::write_state(bool state) {
|
||||
tm1638_->set_led(led_, state);
|
||||
publish_state(state);
|
||||
}
|
||||
|
||||
void TM1638SwitchLed::dump_config() {
|
||||
LOG_SWITCH("", "TM1638 LED", this);
|
||||
ESP_LOGCONFIG(TAG, " LED: %d", led_);
|
||||
}
|
||||
|
||||
} // namespace tm1638
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../tm1638.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tm1638 {
|
||||
|
||||
class TM1638SwitchLed : public switch_::Switch, public Component {
|
||||
public:
|
||||
void dump_config() override;
|
||||
|
||||
void set_tm1638(TM1638Component *tm1638) { tm1638_ = tm1638; }
|
||||
void set_lednum(int led) { led_ = led; }
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
TM1638Component *tm1638_;
|
||||
int led_;
|
||||
};
|
||||
} // namespace tm1638
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user