From 3cb96800f9a0b112c5ef2a9ee469760dffa96034 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Sun, 8 Oct 2023 19:29:28 -0400 Subject: [PATCH] allow empty string for state --- entitylistener.go | 10 +++++----- eventListener.go | 10 +++++----- interval.go | 10 +++++----- schedule.go | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/entitylistener.go b/entitylistener.go index cc116c8..e6dd49d 100644 --- a/entitylistener.go +++ b/entitylistener.go @@ -161,10 +161,10 @@ Enable this listener only when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the listener runs if {runOnNetworkError} is true. */ func (b elBuilder3) EnabledWhen(entityId, state string, runOnNetworkError bool) elBuilder3 { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } - if b.entityListener.enabledEntity != "" { + if b.entityListener.disabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting EnabledWhen on an entity listener with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) } b.entityListener.enabledEntity = entityId @@ -178,8 +178,8 @@ Disable this listener when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the listener runs if {runOnNetworkError} is true. */ func (b elBuilder3) DisabledWhen(entityId, state string, runOnNetworkError bool) elBuilder3 { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } if b.entityListener.enabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting DisabledWhen on an entity listener with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) diff --git a/eventListener.go b/eventListener.go index 8c1be47..007e413 100644 --- a/eventListener.go +++ b/eventListener.go @@ -103,10 +103,10 @@ Enable this listener only when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the listener runs if {runOnNetworkError} is true. */ func (b eventListenerBuilder3) EnabledWhen(entityId, state string, runOnNetworkError bool) eventListenerBuilder3 { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) } - if b.eventListener.enabledEntity != "" { + if b.eventListener.disabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting EnabledWhen entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) } b.eventListener.enabledEntity = entityId @@ -120,8 +120,8 @@ Disable this listener when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the listener runs if {runOnNetworkError} is true. */ func (b eventListenerBuilder3) DisabledWhen(entityId, state string, runOnNetworkError bool) eventListenerBuilder3 { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) } if b.eventListener.enabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting DisabledWhen entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) diff --git a/interval.go b/interval.go index 4eda603..0d207eb 100644 --- a/interval.go +++ b/interval.go @@ -115,10 +115,10 @@ Enable this interval only when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the interval runs if {runOnNetworkError} is true. */ func (ib intervalBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkError bool) intervalBuilderEnd { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } - if ib.interval.enabledEntity != "" { + if ib.interval.disabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting EnabledWhen on an entity listener with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) } ib.interval.enabledEntity = entityId @@ -132,8 +132,8 @@ Disable this interval when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the interval runs if {runOnNetworkError} is true. */ func (ib intervalBuilderEnd) DisabledWhen(entityId, state string, runOnNetworkError bool) intervalBuilderEnd { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } if ib.interval.enabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting DisabledWhen on an entity listener with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) diff --git a/schedule.go b/schedule.go index 0b00974..c7d8e01 100644 --- a/schedule.go +++ b/schedule.go @@ -122,10 +122,10 @@ Enable this schedule only when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the schedule runs if {runOnNetworkError} is true. */ func (sb scheduleBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkError bool) scheduleBuilderEnd { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } - if sb.schedule.enabledEntity != "" { + if sb.schedule.disabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting EnabledWhen on a schedule with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError)) } sb.schedule.enabledEntity = entityId @@ -139,8 +139,8 @@ Disable this schedule when the current state of {entityId} matches {state}. If there is a network error while retrieving state, the schedule runs if {runOnNetworkError} is true. */ func (sb scheduleBuilderEnd) DisabledWhen(entityId, state string, runOnNetworkError bool) scheduleBuilderEnd { - if entityId == "" || state == "" { - panic(fmt.Sprintf("Either entityId or state is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) + if entityId == "" { + panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) } if sb.schedule.enabledEntity != "" { panic(fmt.Sprintf("You can't use EnabledWhen and DisabledWhen together. Error occurred while setting DisabledWhen on a schedule with params entityId=%s state=%s runOnNetworkError=%t", entityId, state, runOnNetworkError))