From 70535f3467c11f97eb07abc522013e76663f3813 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 3 Feb 2025 19:11:55 +0100 Subject: [PATCH] add light component --- library.json | 2 +- src/ha.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 6ddcfee..d2c4995 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "ha-mqtt", - "version": "1.4.2", + "version": "1.5.0", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/ha.h b/src/ha.h index 3139cdb..3fd17a4 100644 --- a/src/ha.h +++ b/src/ha.h @@ -224,6 +224,20 @@ namespace Ha { } }; + struct Light : Component, StatefulCommand { + + Light(const char* name, const char* id, onMessage f = nullptr) : Component(id, name, "light"), StatefulCommand(this, f) {} + + void updateState(bool state) { + State::updateState(state ? "ON" : "OFF"); + } + + void buildConfig(JsonDocument& jsonDoc) override { + Component::buildConfig(jsonDoc); + StatefulCommand::buildConfig(jsonDoc); + } + }; + struct Number : Component, StatefulCommand { unsigned int min = 1; unsigned int max = 100;