refactor all automation types to take a list

This commit is contained in:
Sam Lewis
2023-10-22 18:07:42 -04:00
parent 3ec6608714
commit 824d6c12d1
4 changed files with 36 additions and 42 deletions

View File

@@ -160,12 +160,12 @@ func (b elBuilder3) EnabledWhen(entityId, state string, runOnNetworkError bool)
if entityId == "" {
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
}
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))
i := internal.EnabledDisabledInfo{
Entity: entityId,
State: state,
RunOnError: runOnNetworkError,
}
b.entityListener.enabledEntity = entityId
b.entityListener.enabledEntityState = state
b.entityListener.enabledEntityRunOnError = runOnNetworkError
b.entityListener.enabledEntities = append(b.entityListener.enabledEntities, i)
return b
}
@@ -177,12 +177,12 @@ func (b elBuilder3) DisabledWhen(entityId, state string, runOnNetworkError bool)
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))
i := internal.EnabledDisabledInfo{
Entity: entityId,
State: state,
RunOnError: runOnNetworkError,
}
b.entityListener.disabledEntity = entityId
b.entityListener.disabledEntityState = state
b.entityListener.disabledEntityRunOnError = runOnNetworkError
b.entityListener.disabledEntities = append(b.entityListener.disabledEntities, i)
return b
}
@@ -233,10 +233,10 @@ func callEntityListeners(app *App, msgBytes []byte) {
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
continue
}
if c := checkEnabledEntity(app.state, l.enabledEntity, l.enabledEntityState, l.enabledEntityRunOnError); c.fail {
if c := checkEnabledEntity(app.state, l.enabledEntities); c.fail {
continue
}
if c := checkDisabledEntity(app.state, l.disabledEntity, l.disabledEntityState, l.disabledEntityRunOnError); c.fail {
if c := checkDisabledEntity(app.state, l.disabledEntities); c.fail {
continue
}