-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt_evlog.hap
94 lines (84 loc) · 2.3 KB
/
mqtt_evlog.hap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# MQTT Event Log HomeVision - Ron Boston
# Version 1.0
# $Revision: 1.3 $
# $Date: 2021/10/31 19:23:49 $
# This plug-in sends Event Log info to Home Assistant via MQTT.
# It uses the netio_evlog plug-in's netio and netioaction procs
# to process and get the log info.
# MQTT payloads for HA are max 256 characters, so the 20-line log view
# is broken into 4 separate MQTT messages.
hvImport debug
hvImport netioaction
hvImport netio
hvImport mqttComm
set version {$Id: mqtt_evlog.hap,v 1.3 2021/10/31 19:23:49 ron Exp $}
debug "$version" blue
hvPublic hvLog
proc hvLog {topic payload {retain 0}} {
debug "hvLog: topic:$topic,msg:$payload;" blue
lassign [split $topic "/"] cmnd top state
if {$top ne "HVLog"} return
if {$state eq "update"} {
netioaction evlog mode all
netioaction evlog update
sendlog
} elseif {$state eq "get"} {
switch $payload {
"" {
}
first {
netioaction evlog first
}
last {
netioaction evlog last
}
prev {
netioaction evlog prev
}
next {
netioaction evlog next
}
default {
return
}
}
sendlog
}
}
hvPublic mqttReady
proc mqttReady {status} {
debug "mqttReady: $status" green
if {[dict get $status state] eq "connected"} {
subscribe
} else {
}
}
proc subscribe {} {
mqttComm sub cmnd/HVLog/get hvLog
mqttComm sub cmnd/HVLog/update hvLog
}
proc sendlog {} {
debug "sendlog"
after cancel sendlog
if {[catch {netio evlog lines} rc]} {
debug "netio fail: $rc" red
}
unset -nocomplain rc0 rc1 rc2 rc3
set rc [lsearch -inline -not $rc {}]
set lrc [split $rc "\n"]
if {[string match -nocase "*Event log being read*" [lindex $lrc 0]]} {
after 10000 sendlog
debug "waiting" red
}
# debug "l:[llength $lrc];$lrc" red
for {set j 0} {$j < 4} {incr j} {
for {set i 0} {$i < 5} {incr i} {
append rc$j [lindex $lrc [expr {$i+$j*5}]] "\n"
}
}
mqttComm pub stat/HVLog/part1 $rc0
mqttComm pub stat/HVLog/part2 $rc1
mqttComm pub stat/HVLog/part3 $rc2
mqttComm pub stat/HVLog/part4 $rc3
}
subscribe