mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 03:16:37 +00:00
[mk2pvrouter] Add text_sensor platform (#19720)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
499ce56c2b
commit
04a53264b4
@@ -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
|
||||
Reference in New Issue
Block a user