[mk2pvrouter] Add text_sensor platform (#19720)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Frédéric Metrich
2026-09-26 15:37:31 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 499ce56c2b
commit 04a53264b4
5 changed files with 92 additions and 0 deletions
+12
View File
@@ -66,3 +66,15 @@ binary_sensor:
name: Relay 2 Binary
tag: R2
mk2pvrouter_id: test_mk2pvrouter
text_sensor:
- platform: mk2pvrouter
name: S per MC
tag: S_MC
mk2pvrouter_id: test_mk2pvrouter
# Test another text tag
- platform: mk2pvrouter
name: Status
tag: STATUS
mk2pvrouter_id: test_mk2pvrouter
@@ -0,0 +1,21 @@
#include <gtest/gtest.h>
#include "esphome/components/mk2pvrouter/text_sensor/mk2pvrouter_text_sensor.h"
namespace esphome::mk2pvrouter::testing {
TEST(Mk2PVRouterTextSensorTest, PublishesValueVerbatim) {
Mk2PVRouterTextSensor sensor("S_MC");
sensor.publish_val("-1234");
ASSERT_TRUE(sensor.has_state());
EXPECT_EQ(sensor.get_state(), "-1234");
}
TEST(Mk2PVRouterTextSensorTest, ShorterValueReplacesPreviousOne) {
Mk2PVRouterTextSensor sensor("S_MC");
sensor.publish_val("-1234");
sensor.publish_val("5");
EXPECT_EQ(sensor.get_state(), "5");
}
} // namespace esphome::mk2pvrouter::testing