Documentation
¶
Overview ¶
Package ha provides a Go library for creating Home Assistant automations and schedules. This file contains the scheduling system that allows you to create daily schedules with various conditions and callbacks.
Index ¶
- Constants
- Variables
- func NewDailySchedule() scheduleBuilder
- func NewEntityListener() elBuilder1
- func NewEventListener() eventListenerBuilder1
- func NewInterval() intervalBuilder
- type App
- func (app *App) Cleanup()deprecated
- func (app *App) Close() error
- func (app *App) RegisterEntityListeners(etls ...EntityListener)
- func (app *App) RegisterEventListeners(evls ...EventListener)
- func (app *App) RegisterIntervals(intervals ...Interval)
- func (app *App) RegisterSchedules(schedules ...DailySchedule)
- func (app *App) Services() *Service
- func (app *App) Start()
- func (app *App) State() StateReader
- type BaseEventMsg
- type ConditionCheck
- func CheckAllowlistDates(clock internal.Clock, eList []time.Time) ConditionCheck
- func CheckDisabledEntity(s StateReader, infos []internal.EnabledDisabledInfo) ConditionCheck
- func CheckEnabledEntity(s StateReader, infos []internal.EnabledDisabledInfo) ConditionCheck
- func CheckExceptionDates(clock internal.Clock, eList []time.Time) ConditionCheck
- func CheckExceptionRanges(clock internal.Clock, eList []types.TimeRange) ConditionCheck
- func CheckStartEndTime(clock internal.Clock, s types.TimeString, isStart bool) ConditionCheck
- func CheckStatesMatch(listenerState, s string) ConditionCheck
- func CheckThrottle(clock internal.Clock, throttle time.Duration, lastRan *carbon.Carbon) ConditionCheck
- func CheckWithinTimeRange(clock internal.Clock, startTime, endTime string) ConditionCheck
- type DailySchedule
- type EntityData
- type EntityListener
- type EntityListenerCallback
- type EntityState
- type EventData
- type EventListener
- type EventListenerCallback
- type Interval
- type IntervalCallback
- type Item
- type ScheduleCallback
- type Service
- type StateReader
Constants ¶
const Version = internal.Version
Version is the go-ha release this build corresponds to. It is also sent as the User-Agent on every REST call.
Variables ¶
var ErrInvalidArgs = errors.New("invalid arguments provided")
Functions ¶
func NewDailySchedule ¶
func NewDailySchedule() scheduleBuilder
NewDailySchedule creates a new schedule builder with default values. Use the fluent API to configure the schedule:
NewDailySchedule().Call(myFunction).At("15:30").Build()
func NewEntityListener ¶
func NewEntityListener() elBuilder1
func NewEventListener ¶
func NewEventListener() eventListenerBuilder1
func NewInterval ¶
func NewInterval() intervalBuilder
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func NewApp ¶
func NewApp(request types.NewAppRequest) (*App, error)
NewApp establishes the WebSocket connection and returns an object you can use to register schedules and listeners.
func (*App) Close ¶
Close performs a clean shutdown: it stops the background goroutines, closes the connection, and waits for both to finish.
func (*App) RegisterEntityListeners ¶
func (app *App) RegisterEntityListeners(etls ...EntityListener)
func (*App) RegisterEventListeners ¶
func (app *App) RegisterEventListeners(evls ...EventListener)
func (*App) RegisterIntervals ¶
func (*App) RegisterSchedules ¶
func (app *App) RegisterSchedules(schedules ...DailySchedule)
func (*App) State ¶ added in v0.8.0
func (app *App) State() StateReader
type BaseEventMsg ¶
type BaseEventMsg struct {
Event struct {
EventType string `json:"event_type"`
} `json:"event"`
}
type ConditionCheck ¶ added in v0.7.1
type ConditionCheck struct {
// contains filtered or unexported fields
}
func CheckAllowlistDates ¶ added in v0.7.1
func CheckAllowlistDates(clock internal.Clock, eList []time.Time) ConditionCheck
func CheckDisabledEntity ¶ added in v0.7.1
func CheckDisabledEntity(s StateReader, infos []internal.EnabledDisabledInfo) ConditionCheck
func CheckEnabledEntity ¶ added in v0.7.1
func CheckEnabledEntity(s StateReader, infos []internal.EnabledDisabledInfo) ConditionCheck
func CheckExceptionDates ¶ added in v0.7.1
func CheckExceptionDates(clock internal.Clock, eList []time.Time) ConditionCheck
func CheckExceptionRanges ¶ added in v0.7.1
func CheckExceptionRanges(clock internal.Clock, eList []types.TimeRange) ConditionCheck
func CheckStartEndTime ¶ added in v0.7.1
func CheckStartEndTime(clock internal.Clock, s types.TimeString, isStart bool) ConditionCheck
func CheckStatesMatch ¶ added in v0.7.1
func CheckStatesMatch(listenerState, s string) ConditionCheck
func CheckThrottle ¶ added in v0.7.1
func CheckWithinTimeRange ¶ added in v0.7.1
func CheckWithinTimeRange(clock internal.Clock, startTime, endTime string) ConditionCheck
type DailySchedule ¶
type DailySchedule struct {
// contains filtered or unexported fields
}
DailySchedule represents a recurring daily schedule with various conditions. It can be configured to run at specific times, sunrise/sunset, or based on entity states and date restrictions.
func (DailySchedule) Hash ¶
func (s DailySchedule) Hash() string
Hash returns a unique string identifier for this schedule based on when it fires and the callback function.
func (DailySchedule) String ¶
func (s DailySchedule) String() string
String returns a human-readable representation of the schedule.
type EntityData ¶
type EntityListener ¶
type EntityListener struct {
// contains filtered or unexported fields
}
type EntityListenerCallback ¶
type EntityListenerCallback func(*Service, StateReader, EntityData)
type EntityState ¶
type EventListener ¶
type EventListener struct {
// contains filtered or unexported fields
}
type EventListenerCallback ¶
type EventListenerCallback func(*Service, StateReader, EventData)
type IntervalCallback ¶
type IntervalCallback func(*Service, StateReader)
type ScheduleCallback ¶
type ScheduleCallback func(*Service, StateReader)
ScheduleCallback is a function type that gets called when a schedule triggers. It receives the service instance and current state as parameters.
type Service ¶
type Service struct {
AdaptiveLighting *services.AdaptiveLighting
AlarmControlPanel *services.AlarmControlPanel
Climate *services.Climate
Cover *services.Cover
HomeAssistant *services.HomeAssistant
Light *services.Light
Lock *services.Lock
MediaPlayer *services.MediaPlayer
Switch *services.Switch
InputBoolean *services.InputBoolean
InputButton *services.InputButton
InputText *services.InputText
InputDatetime *services.InputDatetime
InputNumber *services.InputNumber
Event *services.Event
Notify *services.Notify
Number *services.Number
Scene *services.Scene
Script *services.Script
Timer *services.Timer
TTS *services.TTS
Vacuum *services.Vacuum
ZWaveJS *services.ZWaveJS
}
type StateReader ¶ added in v0.8.0
type StateReader interface {
AfterSunrise(...types.DurationString) bool
BeforeSunrise(...types.DurationString) bool
AfterSunset(...types.DurationString) bool
BeforeSunset(...types.DurationString) bool
ListEntities() ([]EntityState, error)
Get(entityId string) (EntityState, error)
Equals(entityId, state string) (bool, error)
}