Skip to content

Commit 854c888

Browse files
authored
Merge pull request #18 from depili/source.Connected
Fix tally `SourceState.Connected`, and use it for the GPIO status pins. This allows the `--gpio-green-pin`, `--gpio-red-pin` options to be used for status output independently. Fixes #16, #17
2 parents 36c7388 + 733c263 commit 854c888

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

gpio/gpio.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ func (gpio *GPIO) updateTally(state tally.State) {
131131
if status, exists := state.Tally[id]; !exists {
132132
// missing tally state for pin
133133
} else {
134-
statusGreen = true
135-
136134
if status.Status.High() {
137135
log.Printf("GPIO:\ttally pin %v high: %v", pin, status)
138136

@@ -143,6 +141,12 @@ func (gpio *GPIO) updateTally(state tally.State) {
143141
pin.Set(pinState)
144142
}
145143

144+
for _, source := range state.Sources {
145+
if source.Connected {
146+
statusGreen = true
147+
}
148+
}
149+
146150
if len(state.Errors) > 0 {
147151
statusRed = true
148152
}

tally/source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (source Source) String() string {
5959
}
6060

6161
func (source Source) run(updateChan chan Source) {
62+
defer source.xmlClient.Close()
6263
for {
6364
if system, err := source.xmlClient.Read(); err == nil {
6465
source.system = system

tally/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (state *State) setSourceError(source Source, err error) {
128128
Discovery: source.discoveryPacket,
129129
FirstSeen: source.created,
130130
LastSeen: source.updated,
131-
Connected: (source.xmlClient != nil),
131+
Connected: (!source.closed && source.err == nil),
132132
Error: err,
133133
}
134134

0 commit comments

Comments
 (0)