88from bsblan .models import DataType , EntityInfo
99
1010
11- def test_entity_info_invalid_time_conversion () -> None :
12- """Test EntityInfo with invalid time format."""
13- # Create EntityInfo with invalid time format
14- entity = EntityInfo (
15- name = "Invalid Time" ,
16- value = "24:61" , # Invalid time
17- unit = "" ,
18- desc = "" ,
19- data_type = DataType .TIME ,
20- )
11+ def test_entity_info_invalid_time_conversion (
12+ caplog : pytest .LogCaptureFixture ,
13+ ) -> None :
14+ """Test EntityInfo with invalid time format logs a warning."""
15+ with caplog .at_level (logging .WARNING ):
16+ entity = EntityInfo (
17+ name = "Invalid Time" ,
18+ value = "24:61" , # Invalid time
19+ unit = "" ,
20+ desc = "" ,
21+ data_type = DataType .TIME ,
22+ )
2123
22- # The value should remain as string since conversion failed
23- assert entity .value == "24:61"
24+ # The value should remain as string since conversion failed
25+ assert entity .value == "24:61"
26+ assert "Failed to convert value" in caplog .text
2427
2528
2629def test_entity_info_undefined_value_becomes_none () -> None :
@@ -35,19 +38,58 @@ def test_entity_info_undefined_value_becomes_none() -> None:
3538 assert entity .value is None
3639
3740
38- def test_entity_info_invalid_weekday_conversion () -> None :
39- """Test EntityInfo with invalid weekday format."""
40- # Create EntityInfo with invalid weekday format
41- entity = EntityInfo (
42- name = "Invalid Weekday" ,
43- value = "not-a-number" , # Invalid weekday
44- unit = "" ,
45- desc = "" ,
46- data_type = DataType .WEEKDAY ,
47- )
41+ def test_entity_info_invalid_weekday_conversion (
42+ caplog : pytest .LogCaptureFixture ,
43+ ) -> None :
44+ """Test EntityInfo with invalid weekday format logs a warning."""
45+ with caplog .at_level (logging .WARNING ):
46+ entity = EntityInfo (
47+ name = "Invalid Weekday" ,
48+ value = "not-a-number" , # Invalid weekday
49+ unit = "" ,
50+ desc = "" ,
51+ data_type = DataType .WEEKDAY ,
52+ )
4853
49- # The value should remain as string since conversion failed
50- assert entity .value == "not-a-number"
54+ # The value should remain as string since conversion failed
55+ assert entity .value == "not-a-number"
56+ assert "Failed to convert value" in caplog .text
57+
58+
59+ def test_entity_info_invalid_plain_number_conversion (
60+ caplog : pytest .LogCaptureFixture ,
61+ ) -> None :
62+ """Test non-temperature PLAIN_NUMBER conversion failure logs a warning."""
63+ with caplog .at_level (logging .WARNING ):
64+ entity = EntityInfo (
65+ name = "Invalid Number" ,
66+ value = "not-numeric" ,
67+ unit = "%" ,
68+ desc = "" ,
69+ data_type = DataType .PLAIN_NUMBER ,
70+ )
71+
72+ # The value should remain as string since conversion failed
73+ assert entity .value == "not-numeric"
74+ assert "Failed to convert value" in caplog .text
75+
76+
77+ def test_entity_info_invalid_enum_conversion (
78+ caplog : pytest .LogCaptureFixture ,
79+ ) -> None :
80+ """Test ENUM conversion failure logs a warning."""
81+ with caplog .at_level (logging .WARNING ):
82+ entity = EntityInfo (
83+ name = "Invalid Enum" ,
84+ value = "not-an-int" ,
85+ unit = "" ,
86+ desc = "Some description" ,
87+ data_type = DataType .ENUM ,
88+ )
89+
90+ # The value should remain as string since conversion failed
91+ assert entity .value == "not-an-int"
92+ assert "Failed to convert value" in caplog .text
5193
5294
5395def test_entity_info_general_conversion_error (caplog : pytest .LogCaptureFixture ) -> None :
0 commit comments