mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-07 09:15:15 -06:00
refactor all automation types to take a list
This commit is contained in:
@@ -160,12 +160,12 @@ func (b elBuilder3) EnabledWhen(entityId, state string, runOnNetworkError bool)
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if b.entityListener.disabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
b.entityListener.enabledEntity = entityId
|
b.entityListener.enabledEntities = append(b.entityListener.enabledEntities, i)
|
||||||
b.entityListener.enabledEntityState = state
|
|
||||||
b.entityListener.enabledEntityRunOnError = runOnNetworkError
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,12 +177,12 @@ func (b elBuilder3) DisabledWhen(entityId, state string, runOnNetworkError bool)
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if b.entityListener.enabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
b.entityListener.disabledEntity = entityId
|
b.entityListener.disabledEntities = append(b.entityListener.disabledEntities, i)
|
||||||
b.entityListener.disabledEntityState = state
|
|
||||||
b.entityListener.disabledEntityRunOnError = runOnNetworkError
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,10 +233,10 @@ func callEntityListeners(app *App, msgBytes []byte) {
|
|||||||
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
|
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c := checkEnabledEntity(app.state, l.enabledEntity, l.enabledEntityState, l.enabledEntityRunOnError); c.fail {
|
if c := checkEnabledEntity(app.state, l.enabledEntities); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c := checkDisabledEntity(app.state, l.disabledEntity, l.disabledEntityState, l.disabledEntityRunOnError); c.fail {
|
if c := checkDisabledEntity(app.state, l.disabledEntities); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,12 +102,12 @@ func (b eventListenerBuilder3) EnabledWhen(entityId, state string, runOnNetworkE
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError))
|
panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError))
|
||||||
}
|
}
|
||||||
if b.eventListener.disabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
b.eventListener.enabledEntity = entityId
|
b.eventListener.enabledEntities = append(b.eventListener.enabledEntities, i)
|
||||||
b.eventListener.enabledEntityState = state
|
|
||||||
b.eventListener.enabledEntityRunOnError = runOnNetworkError
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,12 +119,12 @@ func (b eventListenerBuilder3) DisabledWhen(entityId, state string, runOnNetwork
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError))
|
panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError))
|
||||||
}
|
}
|
||||||
if b.eventListener.enabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
b.eventListener.disabledEntity = entityId
|
b.eventListener.disabledEntities = append(b.eventListener.disabledEntities, i)
|
||||||
b.eventListener.disabledEntityState = state
|
|
||||||
b.eventListener.disabledEntityRunOnError = runOnNetworkError
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,10 +162,10 @@ func callEventListeners(app *App, msg ws.ChanMsg) {
|
|||||||
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
|
if c := checkExceptionRanges(l.exceptionRanges); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c := checkEnabledEntity(app.state, l.enabledEntity, l.enabledEntityState, l.enabledEntityRunOnError); c.fail {
|
if c := checkEnabledEntity(app.state, l.enabledEntities); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c := checkDisabledEntity(app.state, l.disabledEntity, l.disabledEntityState, l.disabledEntityRunOnError); c.fail {
|
if c := checkDisabledEntity(app.state, l.disabledEntities); c.fail {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
interval.go
24
interval.go
@@ -114,12 +114,12 @@ func (ib intervalBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkErr
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if ib.interval.disabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
ib.interval.enabledEntity = entityId
|
ib.interval.enabledEntities = append(ib.interval.enabledEntities, i)
|
||||||
ib.interval.enabledEntityState = state
|
|
||||||
ib.interval.enabledEntityRunOnError = runOnNetworkError
|
|
||||||
return ib
|
return ib
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,12 +131,12 @@ func (ib intervalBuilderEnd) DisabledWhen(entityId, state string, runOnNetworkEr
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if ib.interval.enabledEntity != "" {
|
i := internal.EnabledDisabledInfo{
|
||||||
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))
|
Entity: entityId,
|
||||||
|
State: state,
|
||||||
|
RunOnError: runOnNetworkError,
|
||||||
}
|
}
|
||||||
ib.interval.disabledEntity = entityId
|
ib.interval.disabledEntities = append(ib.interval.disabledEntities, i)
|
||||||
ib.interval.disabledEntityState = state
|
|
||||||
ib.interval.disabledEntityRunOnError = runOnNetworkError
|
|
||||||
return ib
|
return ib
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,10 +180,10 @@ func (i Interval) maybeRunCallback(a *App) {
|
|||||||
if c := checkExceptionRanges(i.exceptionRanges); c.fail {
|
if c := checkExceptionRanges(i.exceptionRanges); c.fail {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c := checkEnabledEntity(a.state, i.enabledEntity, i.enabledEntityState, i.enabledEntityRunOnError); c.fail {
|
if c := checkEnabledEntity(a.state, i.enabledEntities); c.fail {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c := checkDisabledEntity(a.state, i.disabledEntity, i.disabledEntityState, i.disabledEntityRunOnError); c.fail {
|
if c := checkDisabledEntity(a.state, i.disabledEntities); c.fail {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go i.callback(a.service, a.state)
|
go i.callback(a.service, a.state)
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ func (sb scheduleBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkErr
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if len(sb.schedule.disabledEntities) != 0 {
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
i := internal.EnabledDisabledInfo{
|
i := internal.EnabledDisabledInfo{
|
||||||
Entity: entityId,
|
Entity: entityId,
|
||||||
State: state,
|
State: state,
|
||||||
@@ -141,9 +138,6 @@ func (sb scheduleBuilderEnd) DisabledWhen(entityId, state string, runOnNetworkEr
|
|||||||
if entityId == "" {
|
if entityId == "" {
|
||||||
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state))
|
||||||
}
|
}
|
||||||
if len(sb.schedule.enabledEntities) != 0 {
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
i := internal.EnabledDisabledInfo{
|
i := internal.EnabledDisabledInfo{
|
||||||
Entity: entityId,
|
Entity: entityId,
|
||||||
State: state,
|
State: state,
|
||||||
|
|||||||
Reference in New Issue
Block a user