summaryrefslogtreecommitdiff
path: root/src/rhctl/switch_control.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl/switch_control.go')
-rw-r--r--src/rhctl/switch_control.go29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 4211d9d..822c044 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -125,25 +125,38 @@ func handleServer(in <-chan ServerState, out chan<- ServerState) {
}
}
-func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
- rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
-
- // send out commands to switch and/or server to get missing infos
- if time.Since(ctrl.state.Switch.Changed) > (2 * time.Hour) { // TODO: hardcoded value
+func (ctrl *SwitchControl) checkMissingOrStaleStates(maxAge time.Duration) {
+ if time.Since(ctrl.state.Switch.AudioInputsChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateAudio, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.AudioSilenceChanged) > maxAge {
+ ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateSilence, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.GPIChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateGPIAll, nil, nil}
- ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateOC, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.RelayChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateRelay, nil, nil}
- ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateSilence, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.OCChanged) > maxAge {
+ ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateOC, nil, nil}
}
for _, server := range ctrl.servers {
s, exists := ctrl.state.Server[server.name]
- if !exists || time.Since(s.Changed) > (2*time.Hour) { // TODO: hardcoded value
+ if !exists || time.Since(s.Changed) > maxAge {
server.UpdateRequest <- true
}
}
+}
+
+func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
+ rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
+
+ // send out commands to switch and/or server to get missing infos
+ ctrl.checkMissingOrStaleStates(2 * time.Hour) // TODO: hardcoded value
+
if ctrl.state.Mood == MoodAwakening && time.Since(ctrl.startup) < (time.Minute) { // TODO: hardcoded value
// it's to early to take actions - let's learn i little bit more about current state
return