From 159d47a4c1b073b319515b9480479131fe3a9f32 Mon Sep 17 00:00:00 2001 From: Alec <30310787+alec-pinson@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:07:44 +0000 Subject: [PATCH] Fix `alert.disable` action not working (#14) --- cmd/terrarium-bot/alert.go | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/cmd/terrarium-bot/alert.go b/cmd/terrarium-bot/alert.go index 47a55fa..a24de4b 100644 --- a/cmd/terrarium-bot/alert.go +++ b/cmd/terrarium-bot/alert.go @@ -29,28 +29,30 @@ func (a *Alert) monitor() { // maybe add a sleep here for startup, dont want alerts straight away s := GetSensor(a.Sensor) for { - value := s.GetValue() - if !isSunset() && !isSunrise() && value != 0 { - // don't alert between sunset/sunrise or if value is 0 - if isDayTime() { - // day time - if value > a.When.Day.Above { - a.Failing("%v%s/%v%s", value, s.Unit, a.When.Day.Above, s.Unit) - } else if value < a.When.Day.Below { - a.Failing("%v%s/%v%s", value, s.Unit, a.When.Day.Below, s.Unit) + if !a.isDisabled() { + value := s.GetValue() + if !isSunset() && !isSunrise() && value != 0 { + // don't alert between sunset/sunrise or if value is 0 + if isDayTime() { + // day time + if value > a.When.Day.Above { + a.Failing("%v%s/%v%s", value, s.Unit, a.When.Day.Above, s.Unit) + } else if value < a.When.Day.Below { + a.Failing("%v%s/%v%s", value, s.Unit, a.When.Day.Below, s.Unit) + } else { + // clear alerts + a.Clear() + } } else { - // clear alerts - a.Clear() - } - } else { - // night time - if value > a.When.Night.Above { - a.Failing("%v%s/%v%s", value, s.Unit, a.When.Night.Above, s.Unit) - } else if value < a.When.Night.Below { - a.Failing("%v%s/%v%s", value, s.Unit, a.When.Night.Below, s.Unit) - } else { - // clear alerts - a.Clear() + // night time + if value > a.When.Night.Above { + a.Failing("%v%s/%v%s", value, s.Unit, a.When.Night.Above, s.Unit) + } else if value < a.When.Night.Below { + a.Failing("%v%s/%v%s", value, s.Unit, a.When.Night.Below, s.Unit) + } else { + // clear alerts + a.Clear() + } } } }