File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -17,21 +17,29 @@ def prepare_response(response)
17
17
response . filter do
18
18
entity_ids . include? ( _1 [ "entity_id" ] ) ||
19
19
_1 . dig ( "attributes" , "device_class" ) == "battery" ||
20
- _1 [ "entity_id" ] . include? ( "binary_sensor .timeframe" )
20
+ _1 [ "entity_id" ] . include? ( "sensor .timeframe" )
21
21
end
22
22
end
23
23
24
24
def problems
25
25
data
26
- . select { _1 [ :entity_id ] . include? ( "binary_sensor.timeframe" ) && _1 [ :state ] == "on" }
27
- . map { _1 [ :entity_id ] }
28
- . map do |entity_id |
29
- _ , icon , raw_message = entity_id . split ( "0" )
30
-
31
- {
32
- icon : icon . tr ( "_" , "-" ) ,
33
- message : raw_message . tr ( "_" , " " ) . humanize
34
- }
26
+ . select { _1 [ :entity_id ] . include? ( "sensor.timeframe" ) }
27
+ . map do
28
+ if _1 [ :state ] == "on"
29
+ _ , icon , raw_message = _1 [ :entity_id ] . split ( "0" )
30
+
31
+ {
32
+ icon : icon . tr ( "_" , "-" ) ,
33
+ message : raw_message . tr ( "_" , " " ) . humanize
34
+ }
35
+ elsif ![ "on" , "off" , "" ] . include? ( _1 [ :state ] )
36
+ _ , icon , _ = _1 [ :entity_id ] . split ( "0" )
37
+
38
+ {
39
+ icon : icon . tr ( "_" , "-" ) ,
40
+ message : _1 [ :state ]
41
+ }
42
+ end
35
43
end
36
44
end
37
45
Original file line number Diff line number Diff line change @@ -370,4 +370,13 @@ def test_problems
370
370
assert_equal ( api . problems , [ { icon : "print" , message : "Printer ink low" } ] )
371
371
end
372
372
end
373
+
374
+ def test_problems_non_binary
375
+ data = [ { entity_id : "sensor.timeframe0print0printer_ink_low" , state : "Ink low" } ]
376
+
377
+ api = HomeAssistantApi . new ( { } )
378
+ api . stub :data , data do
379
+ assert_equal ( api . problems , [ { icon : "print" , message : "Ink low" } ] )
380
+ end
381
+ end
373
382
end
You can’t perform that action at this time.
0 commit comments