From 292879a8a940ffa885c58af0c2e2db6bb6e30b1e Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 1 Aug 2025 21:19:47 -0500 Subject: [PATCH] docs: normalize & make basic corrections to documentation --- app.go | 27 ++++----- app_test.go | 4 +- cmd/generate/main.go | 4 +- entity_listener.go | 14 ++--- event_listener.go | 15 ++--- internal/connect/connection.go | 30 ++++------ internal/connect/listen.go | 8 +-- internal/http.go | 5 +- internal/misc.go | 5 +- internal/parse.go | 6 +- internal/services/alarm_control_panel.go | 28 +++------ internal/services/cover.go | 6 +- internal/services/event.go | 3 +- internal/services/home_assistant.go | 7 +-- internal/services/input_boolean.go | 3 + internal/services/input_button.go | 1 + internal/services/input_text.go | 1 + internal/services/light.go | 7 +-- internal/services/lock.go | 6 +- internal/services/media_player.go | 75 +++++++----------------- internal/services/scene.go | 6 +- internal/services/switch.go | 3 + internal/services/tts.go | 8 +-- internal/services/vacuum.go | 33 ++++------- interval.go | 22 +++---- schedule.go | 18 ++---- state.go | 6 +- types/app.go | 10 ++-- 28 files changed, 132 insertions(+), 229 deletions(-) diff --git a/app.go b/app.go index 809035a..8017431 100644 --- a/app.go +++ b/app.go @@ -42,16 +42,16 @@ type App struct { type Item types.Item -func (mi Item) Compare(other queue.Item) int { - if mi.Priority > other.(Item).Priority { +func (i Item) Compare(other queue.Item) int { + if i.Priority > other.(Item).Priority { return 1 - } else if mi.Priority == other.(Item).Priority { + } else if i.Priority == other.(Item).Priority { return 0 } return -1 } -// validateHomeZone verifies that the home zone entity exists and has latitude/longitude +// validateHomeZone verifies that the home zone entity exists and has latitude/longitude. func validateHomeZone(state State, entityID string) error { entity, err := state.Get(entityID) if err != nil { @@ -75,10 +75,7 @@ func validateHomeZone(state State, entityID string) error { return nil } -/* -NewApp establishes the websocket connection and returns an object -you can use to register schedules and listeners. -*/ +// NewApp establishes the WebSocket connection and returns an object you can use to register schedules and listeners. func NewApp(request types.NewAppRequest) (*App, error) { if (request.URL == "" && request.IpAddress == "") || request.HAAuthToken == "" { slog.Error("URL and HAAuthToken are required arguments in NewAppRequest") @@ -138,11 +135,9 @@ func (app *App) Cleanup() { } } -// Close performs a clean shutdown of the application. -// It cancels the context, closes the websocket connection, -// and ensures all background processes are properly terminated. +// Close performs a clean shutdown of the application. It cancels the context, closes the WebSocket connection, and ensures all background processes are properly terminated. func (app *App) Close() error { - // Close websocket connection if it exists + // Close WebSocket connection if it exists if app.conn != nil { deadline := time.Now().Add(10 * time.Second) err := app.conn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), deadline) @@ -151,15 +146,15 @@ func (app *App) Close() error { return err } - // Close the websocket connection + // Close the WebSocket connection err = app.conn.Conn.Close() if err != nil { - slog.Warn("Error closing websocket connection", "error", err) + slog.Warn("Error closing WebSocket connection", "error", err) return err } } - // Wait a short time for the websocket connection to close + // Wait a short time for the WebSocket connection to close time.Sleep(500 * time.Millisecond) // Cancel context to signal all goroutines to stop @@ -338,7 +333,7 @@ func (app *App) Start() { select { case msg, ok := <-elChan: if !ok { - slog.Info("Websocket channel closed, stopping main loop") + slog.Info("WebSocket channel closed, stopping main loop") return } if app.entityListenersId == msg.Id { diff --git a/app_test.go b/app_test.go index 0b42a9b..56ceda5 100644 --- a/app_test.go +++ b/app_test.go @@ -133,11 +133,11 @@ func TestAppWithNilFields(t *testing.T) { } func TestAppWithWebsocketConnection(t *testing.T) { - // Test app with websocket connection (mocked) + // Test app with WebSocket connection (mocked) app := &App{ ctx: context.Background(), ctxCancel: func() {}, - conn: nil, // In real test, this would be a mock websocket + conn: nil, // In real test, this would be a mock WebSocket } // Test that Close() handles nil connection gracefully diff --git a/cmd/generate/main.go b/cmd/generate/main.go index 5ae00d5..c5f0f56 100644 --- a/cmd/generate/main.go +++ b/cmd/generate/main.go @@ -67,7 +67,7 @@ func toCamelCase(s string) string { return result.String() } -// validateHomeZone verifies that the home zone entity exists and is valid +// validateHomeZone verifies that the home zone entity exists and is valid. func validateHomeZone(state ha.State, entityID string) error { entity, err := state.Get(entityID) if err != nil { @@ -93,7 +93,7 @@ func validateHomeZone(state ha.State, entityID string) error { return nil } -// generate creates the entities.go file with constants for all Home Assistant entities +// generate creates the entities.go file with constants for all Home Assistant entities. func generate(config Config) error { if config.HomeZoneEntityId == "" { config.HomeZoneEntityId = "zone.home" diff --git a/entity_listener.go b/entity_listener.go index 84dabd1..6a888cc 100644 --- a/entity_listener.go +++ b/entity_listener.go @@ -67,8 +67,6 @@ type msgState struct { Attributes map[string]any `json:"attributes"` } -/* Methods */ - func NewEntityListener() elBuilder1 { return elBuilder1{EntityListener{ lastRan: carbon.Now().StartOfCentury(), @@ -154,10 +152,8 @@ func (b elBuilder3) RunOnStartup() elBuilder3 { return b } -/* -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. -*/ +// EnabledWhen enables 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) @@ -171,10 +167,8 @@ func (b elBuilder3) EnabledWhen(entityId, state string, runOnNetworkError bool) return b } -/* -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. -*/ +// DisabledWhen disables 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) diff --git a/event_listener.go b/event_listener.go index 85f15fc..608b33c 100644 --- a/event_listener.go +++ b/event_listener.go @@ -34,8 +34,6 @@ type EventData struct { RawEventJSON []byte } -/* Methods */ - func NewEventListener() eventListenerBuilder1 { return eventListenerBuilder1{EventListener{ lastRan: carbon.Now().StartOfCentury(), @@ -96,10 +94,8 @@ func (b eventListenerBuilder3) ExceptionRange(start, end time.Time) eventListene return b } -/* -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. -*/ +// EnabledWhen enables 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 == "" { panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) @@ -113,10 +109,8 @@ func (b eventListenerBuilder3) EnabledWhen(entityId, state string, runOnNetworkE return b } -/* -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. -*/ +// DisabledWhen disables 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 == "" { panic(fmt.Sprintf("entityId is empty in eventListener EnabledWhen entityId='%s' state='%s' runOnNetworkError='%t'", entityId, state, runOnNetworkError)) @@ -140,7 +134,6 @@ type BaseEventMsg struct { } `json:"event"` } -/* Functions */ func callEventListeners(app *App, msg connect.ChannelMessage) { baseEventMsg := BaseEventMsg{} _ = json.Unmarshal(msg.Raw, &baseEventMsg) diff --git a/internal/connect/connection.go b/internal/connect/connection.go index 3b5a7e9..345f5d1 100644 --- a/internal/connect/connection.go +++ b/internal/connect/connection.go @@ -1,7 +1,3 @@ -// Package websocket is used to interact with the Home Assistant -// websocket API. All HA interaction is done via websocket -// except for cases explicitly called out in http package -// documentation. package connect import ( @@ -20,13 +16,13 @@ import ( var ErrInvalidToken = errors.New("invalid authentication token") -// HAConnection is a wrapper around a websocket connection that provides a mutex for thread safety. +// HAConnection is a wrapper around a WebSocket connection that provides a mutex for thread safety. type HAConnection struct { Conn *websocket.Conn // Note: this is not thread safe except for Close() and WriteControl() mutex sync.Mutex } -// WriteMessage writes a message to the websocket connection. +// WriteMessage writes a message to the WebSocket connection. func (w *HAConnection) WriteMessage(msg any) error { w.mutex.Lock() defer w.mutex.Unlock() @@ -34,7 +30,7 @@ func (w *HAConnection) WriteMessage(msg any) error { return w.Conn.WriteJSON(msg) } -// ReadMessageRaw reads a raw message from the websocket connection. +// ReadMessageRaw reads a raw message from the WebSocket connection. func ReadMessageRaw(conn *websocket.Conn) ([]byte, error) { _, msg, err := conn.ReadMessage() if err != nil { @@ -43,7 +39,7 @@ func ReadMessageRaw(conn *websocket.Conn) ([]byte, error) { return msg, nil } -// ReadMessage reads a message from the websocket connection and unmarshals it into the given type. +// ReadMessage reads a message from the WebSocket connection and unmarshals it into the given type. func ReadMessage[T any](conn *websocket.Conn) (T, error) { var result T _, msg, err := conn.ReadMessage() @@ -59,14 +55,14 @@ func ReadMessage[T any](conn *websocket.Conn) (T, error) { return result, nil } -// ConnectionFromUri creates a new websocket connection from the given base URL and authentication token. +// ConnectionFromUri creates a new WebSocket connection from the given base URL and authentication token. func ConnectionFromUri(baseUrl *url.URL, token string) (*HAConnection, context.Context, context.CancelFunc, error) { - // Build the websocket URL + // Build the WebSocket URL urlWebsockets := *baseUrl urlWebsockets.Path = "/api/websocket" scheme, err := internal.GetEquivalentWebsocketScheme(baseUrl.Scheme) if err != nil { - return nil, nil, nil, fmt.Errorf("failed to build websocket URL: %w", err) + return nil, nil, nil, fmt.Errorf("failed to build WebSocket URL: %w", err) } urlWebsockets.Scheme = scheme @@ -74,11 +70,11 @@ func ConnectionFromUri(baseUrl *url.URL, token string) (*HAConnection, context.C connCtx, connCtxCancel := context.WithTimeout(context.Background(), time.Second*3) defer connCtxCancel() // Always cancel the connection context when we're done - // Init websocket connection + // Init WebSocket connection dialer := websocket.DefaultDialer conn, _, err := dialer.DialContext(connCtx, urlWebsockets.String(), nil) if err != nil { - slog.Error("Failed to connect to websocket. Check URI\n", "url", urlWebsockets) + slog.Error("Failed to connect to WebSocket. Check URI\n", "url", urlWebsockets) return nil, nil, nil, err } @@ -87,7 +83,7 @@ func ConnectionFromUri(baseUrl *url.URL, token string) (*HAConnection, context.C MsgType string `json:"type"` }](conn) if err != nil { - slog.Error("Unknown error creating websocket client\n") + slog.Error("Unknown error creating WebSocket client\n") return nil, nil, nil, err } else if msg.MsgType != "auth_required" { slog.Error("Expected auth_required message, got", "msgType", msg.MsgType) @@ -97,7 +93,7 @@ func ConnectionFromUri(baseUrl *url.URL, token string) (*HAConnection, context.C // Send auth message err = SendAuthMessage(conn, connCtx, token) if err != nil { - slog.Error("Unknown error creating websocket client\n") + slog.Error("Unknown error creating WebSocket client\n") return nil, nil, nil, err } @@ -114,7 +110,7 @@ func ConnectionFromUri(baseUrl *url.URL, token string) (*HAConnection, context.C return &HAConnection{Conn: conn}, appCtx, appCtxCancel, nil } -// SendAuthMessage sends an auth message to the websocket connection. +// SendAuthMessage sends an auth message to the WebSocket connection. func SendAuthMessage(conn *websocket.Conn, ctx context.Context, token string) error { type AuthMessage struct { MsgType string `json:"type"` @@ -174,7 +170,7 @@ func SubscribeToEventType(eventType string, conn *HAConnection, ctx context.Cont err := conn.WriteMessage(e) // TODO: Handle errors better if err != nil { - wrappedErr := fmt.Errorf("error writing to websocket: %w", err) + wrappedErr := fmt.Errorf("error writing to WebSocket: %w", err) slog.Error(wrappedErr.Error()) panic(wrappedErr) } diff --git a/internal/connect/listen.go b/internal/connect/listen.go index b9c9bc0..b39a04c 100644 --- a/internal/connect/listen.go +++ b/internal/connect/listen.go @@ -7,7 +7,7 @@ import ( "github.com/gorilla/websocket" ) -// BaseMessage is the base message type for all messages sent by the websocket server. +// BaseMessage is the base message type for all messages sent by the WebSocket server. type BaseMessage struct { Type string `json:"type"` Id int64 `json:"id"` @@ -21,14 +21,14 @@ type ChannelMessage struct { Raw []byte } -// ListenWebsocket reads messages from the websocket connection and sends them to the channel. +// ListenWebsocket reads messages from the WebSocket connection and sends them to the channel. // It will close the channel if it encounters an error, or if the channel is full, and return. // It ignores errors in deserialization. func ListenWebsocket(conn *websocket.Conn, c chan ChannelMessage) { for { raw, err := ReadMessageRaw(conn) if err != nil { - slog.Error("Error reading from websocket", "err", err) + slog.Error("Error reading from WebSocket", "err", err) close(c) break } @@ -60,7 +60,7 @@ func ListenWebsocket(conn *websocket.Conn, c chan ChannelMessage) { // Message sent successfully default: // Channel is full or closed, break out of loop - slog.Warn("Websocket message channel is full or closed, stopping listener", + slog.Warn("WebSocket message channel is full or closed, stopping listener", "channel_capacity", cap(c), "channel_length", len(c)) close(c) diff --git a/internal/http.go b/internal/http.go index 0f6f794..c0990bb 100644 --- a/internal/http.go +++ b/internal/http.go @@ -1,6 +1,3 @@ -// http is used to interact with the home assistant -// REST API. Currently only used to retrieve state for -// a single entity_id package internal import ( @@ -44,7 +41,7 @@ func NewHttpClient(ctx context.Context, baseUrl *url.URL, token string) *HttpCli } } -// getRequest returns a new request +// getRequest returns a new request. func (c *HttpClient) getRequest() *resty.Request { return c.baseRequest.Clone(c.client.Context()) } diff --git a/internal/misc.go b/internal/misc.go index 5c664da..f2450c3 100644 --- a/internal/misc.go +++ b/internal/misc.go @@ -21,8 +21,7 @@ var ( id atomic.Int64 // default value is 0 ) -// NextId returns a unique integer (for the given process), often used for providing a uniquely identifiable -// id for a request. This function is thread-safe. +// NextId returns a unique integer (for the given process), often used for providing a uniquely identifiable ID for a request. This function is thread-safe. func NextId() int64 { return id.Add(1) } @@ -32,7 +31,7 @@ func GetFunctionName(i interface{}) string { return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() } -// GetEquivalentWebsocketScheme returns the equivalent websocket scheme for the given scheme. +// GetEquivalentWebsocketScheme returns the equivalent WebSocket scheme for the given scheme. // If the scheme is http or https, it returns ws or wss respectively. // If the scheme is ws or wss, it returns the same scheme. // If the scheme is not any of the above, it returns an error. diff --git a/internal/parse.go b/internal/parse.go index 0599a40..a2b8f07 100644 --- a/internal/parse.go +++ b/internal/parse.go @@ -8,11 +8,11 @@ import ( "github.com/dromara/carbon/v2" ) -// Parses a HH:MM string. +// ParseTime parses a HH:MM string. func ParseTime(s string) *carbon.Carbon { t, err := time.Parse("15:04", s) if err != nil { - parsingErr := fmt.Errorf("failed to parse time string \"%s\"; format must be HH:MM.: %w", s, err) + parsingErr := fmt.Errorf("failed to parse time string \"%s\"; format must be HH:MM: %w", s, err) slog.Error(parsingErr.Error()) panic(parsingErr) } @@ -22,7 +22,7 @@ func ParseTime(s string) *carbon.Carbon { func ParseDuration(s string) time.Duration { d, err := time.ParseDuration(s) if err != nil { - parsingErr := fmt.Errorf("couldn't parse string duration: \"%s\" see https://pkg.go.dev/time#ParseDuration for valid time units: %w", s, err) + parsingErr := fmt.Errorf("couldn't parse string duration: \"%s\"; see https://pkg.go.dev/time#ParseDuration for valid time units: %w", s, err) slog.Error(parsingErr.Error()) panic(parsingErr) } diff --git a/internal/services/alarm_control_panel.go b/internal/services/alarm_control_panel.go index dd5a1ff..a711f16 100644 --- a/internal/services/alarm_control_panel.go +++ b/internal/services/alarm_control_panel.go @@ -8,9 +8,7 @@ type AlarmControlPanel struct { conn *connect.HAConnection } -// Send the alarm the command for arm away. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for arm away. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) ArmAway(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -22,9 +20,7 @@ func (acp AlarmControlPanel) ArmAway(entityId string, serviceData ...map[string] return acp.conn.WriteMessage(req) } -// Send the alarm the command for arm away. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for arm away. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) ArmWithCustomBypass(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -36,9 +32,7 @@ func (acp AlarmControlPanel) ArmWithCustomBypass(entityId string, serviceData .. return acp.conn.WriteMessage(req) } -// Send the alarm the command for arm home. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for arm home. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) ArmHome(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -50,9 +44,7 @@ func (acp AlarmControlPanel) ArmHome(entityId string, serviceData ...map[string] return acp.conn.WriteMessage(req) } -// Send the alarm the command for arm night. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for arm night. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) ArmNight(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -64,9 +56,7 @@ func (acp AlarmControlPanel) ArmNight(entityId string, serviceData ...map[string return acp.conn.WriteMessage(req) } -// Send the alarm the command for arm vacation. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for arm vacation. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) ArmVacation(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -78,9 +68,7 @@ func (acp AlarmControlPanel) ArmVacation(entityId string, serviceData ...map[str return acp.conn.WriteMessage(req) } -// Send the alarm the command for disarm. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for disarm. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) Disarm(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" @@ -92,9 +80,7 @@ func (acp AlarmControlPanel) Disarm(entityId string, serviceData ...map[string]a return acp.conn.WriteMessage(req) } -// Send the alarm the command for trigger. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the alarm the command for trigger. Takes an entityId and an optional map that is translated into service_data. func (acp AlarmControlPanel) Trigger(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "alarm_control_panel" diff --git a/internal/services/cover.go b/internal/services/cover.go index 1881401..b1a2fca 100644 --- a/internal/services/cover.go +++ b/internal/services/cover.go @@ -44,8 +44,7 @@ func (c Cover) OpenTilt(entityId string) error { return c.conn.WriteMessage(req) } -// Move to specific position all or specified cover. Takes an entityId and an optional -// map that is translated into service_data. +// Move to specific position all or specified cover. Takes an entityId and an optional map that is translated into service_data. func (c Cover) SetPosition(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "cover" @@ -57,8 +56,7 @@ func (c Cover) SetPosition(entityId string, serviceData ...map[string]any) error return c.conn.WriteMessage(req) } -// Move to specific position all or specified cover tilt. Takes an entityId and an optional -// map that is translated into service_data. +// Move to specific position all or specified cover tilt. Takes an entityId and an optional map that is translated into service_data. func (c Cover) SetTiltPosition(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "cover" diff --git a/internal/services/event.go b/internal/services/event.go index 573b4aa..2d0143a 100644 --- a/internal/services/event.go +++ b/internal/services/event.go @@ -17,8 +17,7 @@ type FireEventRequest struct { EventData map[string]any `json:"event_data,omitempty"` } -// Fire an event. Takes an event type and an optional map that is sent -// as `event_data`. +// Fire an event. Takes an event type and an optional map that is sent as `event_data`. func (e Event) Fire(eventType string, eventData ...map[string]any) error { req := FireEventRequest{ Id: internal.NextId(), diff --git a/internal/services/home_assistant.go b/internal/services/home_assistant.go index 321ad0a..6893d9c 100644 --- a/internal/services/home_assistant.go +++ b/internal/services/home_assistant.go @@ -8,8 +8,7 @@ type HomeAssistant struct { conn *connect.HAConnection } -// TurnOn a Home Assistant entity. Takes an entityId and an optional -// map that is translated into service_data. +// TurnOn a Home Assistant entity. Takes an entityId and an optional map that is translated into service_data. func (ha *HomeAssistant) TurnOn(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "homeassistant" @@ -21,8 +20,7 @@ func (ha *HomeAssistant) TurnOn(entityId string, serviceData ...map[string]any) return ha.conn.WriteMessage(req) } -// Toggle a Home Assistant entity. Takes an entityId and an optional -// map that is translated into service_data. +// Toggle a Home Assistant entity. Takes an entityId and an optional map that is translated into service_data. func (ha *HomeAssistant) Toggle(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "homeassistant" @@ -34,6 +32,7 @@ func (ha *HomeAssistant) Toggle(entityId string, serviceData ...map[string]any) return ha.conn.WriteMessage(req) } +// TurnOff turns off a Home Assistant entity. func (ha *HomeAssistant) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "homeassistant" diff --git a/internal/services/input_boolean.go b/internal/services/input_boolean.go index b92a669..4f5031e 100644 --- a/internal/services/input_boolean.go +++ b/internal/services/input_boolean.go @@ -8,6 +8,7 @@ type InputBoolean struct { conn *connect.HAConnection } +// TurnOn turns on an input boolean entity. func (ib InputBoolean) TurnOn(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "input_boolean" @@ -16,6 +17,7 @@ func (ib InputBoolean) TurnOn(entityId string) error { return ib.conn.WriteMessage(req) } +// Toggle toggles an input boolean entity. func (ib InputBoolean) Toggle(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "input_boolean" @@ -24,6 +26,7 @@ func (ib InputBoolean) Toggle(entityId string) error { return ib.conn.WriteMessage(req) } +// TurnOff turns off an input boolean entity. func (ib InputBoolean) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "input_boolean" diff --git a/internal/services/input_button.go b/internal/services/input_button.go index 0756212..476af41 100644 --- a/internal/services/input_button.go +++ b/internal/services/input_button.go @@ -8,6 +8,7 @@ type InputButton struct { conn *connect.HAConnection } +// Press presses an input button entity. func (ib InputButton) Press(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "input_button" diff --git a/internal/services/input_text.go b/internal/services/input_text.go index 8563e16..6a68584 100644 --- a/internal/services/input_text.go +++ b/internal/services/input_text.go @@ -8,6 +8,7 @@ type InputText struct { conn *connect.HAConnection } +// Set sets the value of an input text entity. func (ib InputText) Set(entityId string, value string) error { req := NewBaseServiceRequest(entityId) req.Domain = "input_text" diff --git a/internal/services/light.go b/internal/services/light.go index 919f8b1..ef5e3c5 100644 --- a/internal/services/light.go +++ b/internal/services/light.go @@ -8,8 +8,7 @@ type Light struct { conn *connect.HAConnection } -// TurnOn a light entity. Takes an entityId and an optional -// map that is translated into service_data. +// TurnOn a light entity. Takes an entityId and an optional map that is translated into service_data. func (l Light) TurnOn(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "light" @@ -21,8 +20,7 @@ func (l Light) TurnOn(entityId string, serviceData ...map[string]any) error { return l.conn.WriteMessage(req) } -// Toggle a light entity. Takes an entityId and an optional -// map that is translated into service_data. +// Toggle a light entity. Takes an entityId and an optional map that is translated into service_data. func (l Light) Toggle(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "light" @@ -34,6 +32,7 @@ func (l Light) Toggle(entityId string, serviceData ...map[string]any) error { return l.conn.WriteMessage(req) } +// TurnOff turns off a light entity. func (l Light) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "light" diff --git a/internal/services/lock.go b/internal/services/lock.go index 247794b..4d4b92f 100644 --- a/internal/services/lock.go +++ b/internal/services/lock.go @@ -8,8 +8,7 @@ type Lock struct { conn *connect.HAConnection } -// Lock a lock entity. Takes an entityId and an optional -// map that is translated into service_data. +// Lock a lock entity. Takes an entityId and an optional map that is translated into service_data. func (l Lock) Lock(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "lock" @@ -21,8 +20,7 @@ func (l Lock) Lock(entityId string, serviceData ...map[string]any) error { return l.conn.WriteMessage(req) } -// Unlock a lock entity. Takes an entityId and an optional -// map that is translated into service_data. +// Unlock a lock entity. Takes an entityId and an optional map that is translated into service_data. func (l Lock) Unlock(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "lock" diff --git a/internal/services/media_player.go b/internal/services/media_player.go index 0a666e6..dcef2a3 100644 --- a/internal/services/media_player.go +++ b/internal/services/media_player.go @@ -8,8 +8,7 @@ type MediaPlayer struct { conn *connect.HAConnection } -// Send the media player the command to clear players playlist. -// Takes an entityId. +// Send the media player the command to clear players playlist. Takes an entityId. func (mp MediaPlayer) ClearPlaylist(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -18,9 +17,7 @@ func (mp MediaPlayer) ClearPlaylist(entityId string) error { return mp.conn.WriteMessage(req) } -// Group players together. Only works on platforms with support for player groups. -// Takes an entityId and an optional -// map that is translated into service_data. +// Group players together. Only works on platforms with support for player groups. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) Join(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -32,8 +29,7 @@ func (mp MediaPlayer) Join(entityId string, serviceData ...map[string]any) error return mp.conn.WriteMessage(req) } -// Send the media player the command for next track. -// Takes an entityId. +// Send the media player the command for next track. Takes an entityId. func (mp MediaPlayer) Next(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -42,8 +38,7 @@ func (mp MediaPlayer) Next(entityId string) error { return mp.conn.WriteMessage(req) } -// Send the media player the command for pause. -// Takes an entityId. +// Send the media player the command for pause. Takes an entityId. func (mp MediaPlayer) Pause(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -52,8 +47,7 @@ func (mp MediaPlayer) Pause(entityId string) error { return mp.conn.WriteMessage(req) } -// Send the media player the command for play. -// Takes an entityId. +// Send the media player the command for play. Takes an entityId. func (mp MediaPlayer) Play(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -62,8 +56,7 @@ func (mp MediaPlayer) Play(entityId string) error { return mp.conn.WriteMessage(req) } -// Toggle media player play/pause state. -// Takes an entityId. +// Toggle media player play/pause state. Takes an entityId. func (mp MediaPlayer) PlayPause(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -72,8 +65,7 @@ func (mp MediaPlayer) PlayPause(entityId string) error { return mp.conn.WriteMessage(req) } -// Send the media player the command for previous track. -// Takes an entityId. +// Send the media player the command for previous track. Takes an entityId. func (mp MediaPlayer) Previous(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -82,9 +74,7 @@ func (mp MediaPlayer) Previous(entityId string) error { return mp.conn.WriteMessage(req) } -// Send the media player the command to seek in current playing media. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the media player the command to seek in current playing media. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) Seek(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -96,8 +86,7 @@ func (mp MediaPlayer) Seek(entityId string, serviceData ...map[string]any) error return mp.conn.WriteMessage(req) } -// Send the media player the stop command. -// Takes an entityId. +// Send the media player the stop command. Takes an entityId. func (mp MediaPlayer) Stop(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -106,9 +95,7 @@ func (mp MediaPlayer) Stop(entityId string) error { return mp.conn.WriteMessage(req) } -// Send the media player the command for playing media. -// Takes an entityId and an optional -// map that is translated into service_data. +// Send the media player the command to play a media. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) PlayMedia(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -120,8 +107,7 @@ func (mp MediaPlayer) PlayMedia(entityId string, serviceData ...map[string]any) return mp.conn.WriteMessage(req) } -// Set repeat mode. Takes an entityId and an optional -// map that is translated into service_data. +// Set repeat mode. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) RepeatSet(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -133,9 +119,7 @@ func (mp MediaPlayer) RepeatSet(entityId string, serviceData ...map[string]any) return mp.conn.WriteMessage(req) } -// Send the media player the command to change sound mode. -// Takes an entityId and an optional -// map that is translated into service_data. +// Select a sound mode. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) SelectSoundMode(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -147,9 +131,7 @@ func (mp MediaPlayer) SelectSoundMode(entityId string, serviceData ...map[string return mp.conn.WriteMessage(req) } -// Send the media player the command to change input source. -// Takes an entityId and an optional -// map that is translated into service_data. +// Select a source. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) SelectSource(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -161,9 +143,7 @@ func (mp MediaPlayer) SelectSource(entityId string, serviceData ...map[string]an return mp.conn.WriteMessage(req) } -// Set shuffling state. -// Takes an entityId and an optional -// map that is translated into service_data. +// Toggle shuffle state. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) Shuffle(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -175,8 +155,7 @@ func (mp MediaPlayer) Shuffle(entityId string, serviceData ...map[string]any) er return mp.conn.WriteMessage(req) } -// Toggles a media player power state. -// Takes an entityId. +// Toggle a media player on/off. Takes an entityId. func (mp MediaPlayer) Toggle(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -185,8 +164,7 @@ func (mp MediaPlayer) Toggle(entityId string) error { return mp.conn.WriteMessage(req) } -// Turn a media player power off. -// Takes an entityId. +// Turn off a media player. Takes an entityId. func (mp MediaPlayer) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -195,8 +173,7 @@ func (mp MediaPlayer) TurnOff(entityId string) error { return mp.conn.WriteMessage(req) } -// Turn a media player power on. -// Takes an entityId. +// Turn on a media player. Takes an entityId. func (mp MediaPlayer) TurnOn(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -205,9 +182,7 @@ func (mp MediaPlayer) TurnOn(entityId string) error { return mp.conn.WriteMessage(req) } -// Unjoin the player from a group. Only works on -// platforms with support for player groups. -// Takes an entityId. +// Separate a player from a group. Only works on platforms with support for player groups. Takes an entityId. func (mp MediaPlayer) Unjoin(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -216,8 +191,7 @@ func (mp MediaPlayer) Unjoin(entityId string) error { return mp.conn.WriteMessage(req) } -// Turn a media player volume down. -// Takes an entityId. +// Send the media player the command for volume down. Takes an entityId. func (mp MediaPlayer) VolumeDown(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -226,9 +200,7 @@ func (mp MediaPlayer) VolumeDown(entityId string) error { return mp.conn.WriteMessage(req) } -// Mute a media player's volume. -// Takes an entityId and an optional -// map that is translated into service_data. +// Mute a media player. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) VolumeMute(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -240,9 +212,7 @@ func (mp MediaPlayer) VolumeMute(entityId string, serviceData ...map[string]any) return mp.conn.WriteMessage(req) } -// Set a media player's volume level. -// Takes an entityId and an optional -// map that is translated into service_data. +// Set volume level. Takes an entityId and an optional map that is translated into service_data. func (mp MediaPlayer) VolumeSet(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" @@ -254,8 +224,7 @@ func (mp MediaPlayer) VolumeSet(entityId string, serviceData ...map[string]any) return mp.conn.WriteMessage(req) } -// Turn a media player volume up. -// Takes an entityId. +// Send the media player the command for volume up. Takes an entityId. func (mp MediaPlayer) VolumeUp(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "media_player" diff --git a/internal/services/scene.go b/internal/services/scene.go index ea4ac43..d9131da 100644 --- a/internal/services/scene.go +++ b/internal/services/scene.go @@ -20,8 +20,7 @@ func (s Scene) Apply(serviceData ...map[string]any) error { return s.conn.WriteMessage(req) } -// Create a scene entity. Takes an entityId and an optional -// map that is translated into service_data. +// Create a scene entity. Takes an entityId and an optional map that is translated into service_data. func (s Scene) Create(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "scene" @@ -42,8 +41,7 @@ func (s Scene) Reload() error { return s.conn.WriteMessage(req) } -// TurnOn a scene entity. Takes an entityId and an optional -// map that is translated into service_data. +// TurnOn a scene entity. Takes an entityId and an optional map that is translated into service_data. func (s Scene) TurnOn(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "scene" diff --git a/internal/services/switch.go b/internal/services/switch.go index 67335f1..bef9107 100644 --- a/internal/services/switch.go +++ b/internal/services/switch.go @@ -8,6 +8,7 @@ type Switch struct { conn *connect.HAConnection } +// TurnOn turns on a switch entity. func (s Switch) TurnOn(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "switch" @@ -16,6 +17,7 @@ func (s Switch) TurnOn(entityId string) error { return s.conn.WriteMessage(req) } +// Toggle toggles a switch entity. func (s Switch) Toggle(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "switch" @@ -24,6 +26,7 @@ func (s Switch) Toggle(entityId string) error { return s.conn.WriteMessage(req) } +// TurnOff turns off a switch entity. func (s Switch) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "switch" diff --git a/internal/services/tts.go b/internal/services/tts.go index ca99071..9eebbac 100644 --- a/internal/services/tts.go +++ b/internal/services/tts.go @@ -17,9 +17,7 @@ func (tts TTS) ClearCache() error { return tts.conn.WriteMessage(req) } -// Say something using text-to-speech on a media player with cloud. -// Takes an entityId and an optional -// map that is translated into service_data. +// Say something using text-to-speech on a media player with cloud. Takes an entityId and an optional map that is translated into service_data. func (tts TTS) CloudSay(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "tts" @@ -31,9 +29,7 @@ func (tts TTS) CloudSay(entityId string, serviceData ...map[string]any) error { return tts.conn.WriteMessage(req) } -// Say something using text-to-speech on a media player with google_translate. -// Takes an entityId and an optional -// map that is translated into service_data. +// Say something using text-to-speech on a media player with google_translate. Takes an entityId and an optional map that is translated into service_data. func (tts TTS) GoogleTranslateSay(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "tts" diff --git a/internal/services/vacuum.go b/internal/services/vacuum.go index 8492eee..10f0427 100644 --- a/internal/services/vacuum.go +++ b/internal/services/vacuum.go @@ -8,8 +8,7 @@ type Vacuum struct { conn *connect.HAConnection } -// Tell the vacuum cleaner to do a spot clean-up. -// Takes an entityId. +// Tell the vacuum cleaner to do a spot clean-up. Takes an entityId. func (v Vacuum) CleanSpot(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -18,8 +17,7 @@ func (v Vacuum) CleanSpot(entityId string) error { return v.conn.WriteMessage(req) } -// Locate the vacuum cleaner robot. -// Takes an entityId. +// Locate the vacuum cleaner robot. Takes an entityId. func (v Vacuum) Locate(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -28,8 +26,7 @@ func (v Vacuum) Locate(entityId string) error { return v.conn.WriteMessage(req) } -// Pause the cleaning task. -// Takes an entityId. +// Pause the cleaning task. Takes an entityId. func (v Vacuum) Pause(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -38,8 +35,7 @@ func (v Vacuum) Pause(entityId string) error { return v.conn.WriteMessage(req) } -// Tell the vacuum cleaner to return to its dock. -// Takes an entityId. +// Tell the vacuum cleaner to return to its dock. Takes an entityId. func (v Vacuum) ReturnToBase(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -48,8 +44,7 @@ func (v Vacuum) ReturnToBase(entityId string) error { return v.conn.WriteMessage(req) } -// Send a raw command to the vacuum cleaner. Takes an entityId and an optional -// map that is translated into service_data. +// Send a raw command to the vacuum cleaner. Takes an entityId and an optional map that is translated into service_data. func (v Vacuum) SendCommand(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -61,8 +56,7 @@ func (v Vacuum) SendCommand(entityId string, serviceData ...map[string]any) erro return v.conn.WriteMessage(req) } -// Set the fan speed of the vacuum cleaner. Takes an entityId and an optional -// map that is translated into service_data. +// Set the fan speed of the vacuum cleaner. Takes an entityId and an optional map that is translated into service_data. func (v Vacuum) SetFanSpeed(entityId string, serviceData ...map[string]any) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -75,8 +69,7 @@ func (v Vacuum) SetFanSpeed(entityId string, serviceData ...map[string]any) erro return v.conn.WriteMessage(req) } -// Start or resume the cleaning task. -// Takes an entityId. +// Start or resume the cleaning task. Takes an entityId. func (v Vacuum) Start(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -85,8 +78,7 @@ func (v Vacuum) Start(entityId string) error { return v.conn.WriteMessage(req) } -// Start, pause, or resume the cleaning task. -// Takes an entityId. +// Start, pause, or resume the cleaning task. Takes an entityId. func (v Vacuum) StartPause(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -95,8 +87,7 @@ func (v Vacuum) StartPause(entityId string) error { return v.conn.WriteMessage(req) } -// Stop the current cleaning task. -// Takes an entityId. +// Stop the current cleaning task. Takes an entityId. func (v Vacuum) Stop(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -105,8 +96,7 @@ func (v Vacuum) Stop(entityId string) error { return v.conn.WriteMessage(req) } -// Stop the current cleaning task and return to home. -// Takes an entityId. +// Stop the current cleaning task and return to home. Takes an entityId. func (v Vacuum) TurnOff(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" @@ -115,8 +105,7 @@ func (v Vacuum) TurnOff(entityId string) error { return v.conn.WriteMessage(req) } -// Start a new cleaning task. -// Takes an entityId. +// Start a new cleaning task. Takes an entityId. func (v Vacuum) TurnOn(entityId string) error { req := NewBaseServiceRequest(entityId) req.Domain = "vacuum" diff --git a/interval.go b/interval.go index 23b29d4..4cb7d93 100644 --- a/interval.go +++ b/interval.go @@ -79,20 +79,20 @@ func (ib intervalBuilder) Call(callback IntervalCallback) intervalBuilderCall { return intervalBuilderCall(ib) } -// Takes a DurationString ("2h", "5m", etc) to set the frequency of the interval. +// Every takes a DurationString ("2h", "5m", etc.) to set the frequency of the interval. func (ib intervalBuilderCall) Every(s types.DurationString) intervalBuilderEnd { d := internal.ParseDuration(string(s)) ib.interval.frequency = d return intervalBuilderEnd(ib) } -// Takes a TimeString ("HH:MM") when this interval will start running for the day. +// StartingAt takes a TimeString ("HH:MM") when this interval will start running for the day. func (ib intervalBuilderEnd) StartingAt(s types.TimeString) intervalBuilderEnd { ib.interval.startTime = s return ib } -// Takes a TimeString ("HH:MM") when this interval will stop running for the day. +// EndingAt takes a TimeString ("HH:MM") when this interval will stop running for the day. func (ib intervalBuilderEnd) EndingAt(s types.TimeString) intervalBuilderEnd { ib.interval.endTime = s return ib @@ -111,10 +111,8 @@ func (ib intervalBuilderEnd) ExceptionRange(start, end time.Time) intervalBuilde return ib } -/* -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. -*/ +// 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) @@ -128,10 +126,8 @@ func (ib intervalBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkErr return ib } -/* -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. -*/ +// 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) @@ -188,10 +184,10 @@ func runIntervals(a *App) { } func (i Interval) maybeRunCallback(a *App) { - if c := CheckStartEndTime(i.startTime /* isStart = */, true); c.fail { + if c := CheckStartEndTime(i.startTime, true); c.fail { return } - if c := CheckStartEndTime(i.endTime /* isStart = */, false); c.fail { + if c := CheckStartEndTime(i.endTime, false); c.fail { return } if c := CheckExceptionDates(i.exceptionDates); c.fail { diff --git a/schedule.go b/schedule.go index 24f4a9e..26899e1 100644 --- a/schedule.go +++ b/schedule.go @@ -83,8 +83,7 @@ func (sb scheduleBuilderCall) At(s string) scheduleBuilderEnd { } // Sunrise takes an optional duration string that is passed to time.ParseDuration. -// Examples include "-1.5h", "30m", etc. See https://pkg.go.dev/time#ParseDuration -// for full list. +// Examples include "-1.5h", "30m", etc. See https://pkg.go.dev/time#ParseDuration for the full list. func (sb scheduleBuilderCall) Sunrise(offset ...types.DurationString) scheduleBuilderEnd { sb.schedule.isSunrise = true if len(offset) > 0 { @@ -94,8 +93,7 @@ func (sb scheduleBuilderCall) Sunrise(offset ...types.DurationString) scheduleBu } // Sunset takes an optional duration string that is passed to time.ParseDuration. -// Examples include "-1.5h", "30m", etc. See https://pkg.go.dev/time#ParseDuration -// for full list. +// Examples include "-1.5h", "30m", etc. See https://pkg.go.dev/time#ParseDuration for the full list. func (sb scheduleBuilderCall) Sunset(offset ...types.DurationString) scheduleBuilderEnd { sb.schedule.isSunset = true if len(offset) > 0 { @@ -114,10 +112,8 @@ func (sb scheduleBuilderEnd) OnlyOnDates(t time.Time, tl ...time.Time) scheduleB return sb } -/* -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. -*/ +// EnabledWhen enables 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) @@ -131,10 +127,8 @@ func (sb scheduleBuilderEnd) EnabledWhen(entityId, state string, runOnNetworkErr return sb } -/* -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. -*/ +// DisabledWhen disables 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 == "" { panic(fmt.Sprintf("entityId is empty in EnabledWhen entityId='%s' state='%s'", entityId, state)) diff --git a/state.go b/state.go index 793e4e3..d4b6510 100644 --- a/state.go +++ b/state.go @@ -81,7 +81,7 @@ func (s *StateImpl) Get(entityId string) (EntityState, error) { } // ListEntities returns a list of all entities in Home Assistant. -// see rest documentation for more details: https://developers.home-assistant.io/docs/api/rest/#actions +// See REST documentation for more details: https://developers.home-assistant.io/docs/api/rest/#actions func (s *StateImpl) ListEntities() ([]EntityState, error) { resp, err := s.httpClient.GetStates() if err != nil { @@ -101,7 +101,7 @@ func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) } func (s *StateImpl) BeforeSunrise(offset ...types.DurationString) bool { - sunrise := getSunriseSunset(s /* sunrise = */, true, carbon.Now(), offset...) + sunrise := getSunriseSunset(s, true, carbon.Now(), offset...) return carbon.Now().Lt(sunrise) } @@ -110,7 +110,7 @@ func (s *StateImpl) AfterSunrise(offset ...types.DurationString) bool { } func (s *StateImpl) BeforeSunset(offset ...types.DurationString) bool { - sunset := getSunriseSunset(s /* sunrise = */, false, carbon.Now(), offset...) + sunset := getSunriseSunset(s, false, carbon.Now(), offset...) return carbon.Now().Lt(sunset) } diff --git a/types/app.go b/types/app.go index 164e449..26c51c9 100644 --- a/types/app.go +++ b/types/app.go @@ -7,7 +7,7 @@ type NewAppRequest struct { // Optional // Deprecated: use URL instead - // IpAddress of your Home Assistant instance i.e. "localhost" + // IpAddress of your Home Assistant instance, e.g. "localhost" // or "192.168.86.59" etc. IpAddress string @@ -18,18 +18,18 @@ type NewAppRequest struct { // Required // Auth token generated in Home Assistant. Used - // to connect to the Websocket API. + // to connect to the WebSocket API. HAAuthToken string // Required - // EntityId of the zone representing your home e.g. "zone.home". + // EntityId of the zone representing your home, e.g. "zone.home". // Used to pull latitude/longitude from Home Assistant // to calculate sunset/sunrise times. HomeZoneEntityId string // Optional - // Whether to use secure connections for http and websockets. - // Setting this to `true` will use `https://` instead of `https://` + // Whether to use secure connections for HTTP and WebSockets. + // Setting this to `true` will use `https://` instead of `http://` // and `wss://` instead of `ws://`. Secure bool }