client

package
v0.0.0-...-2c77352 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetServicesResult resultType = iota
	CallServiceResult
)
View Source
const API_ENDPOINT string = "/api/websocket"

Default Endpoint of Websocket

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Id       string  `json:"id"`
	ParentId *string `json:"parent_id"`
	UserId   string  `json:"user_id"`
}

type Event

type Event struct {
	EventType EventType              `json:"event_type"`
	TimeFired time.Time              `json:"time_fired"`
	Origin    string                 `json:"origin"`
	Data      map[string]interface{} `json:"data"`
	Context   Context                `json:"context"`
}

func (*Event) GetStateChangedEvent

func (evt *Event) GetStateChangedEvent() (*StateChangedEvent, error)

func (*Event) IsStateChangedEvent

func (evt *Event) IsStateChangedEvent() bool
Returns true, if the event is of type `state_changed` In  this case you can safely get the parsed event via

```

if event.IsStateChangedEvent() {
	changeEvent, err := event.GetStateChangedEvent()
}

```

type EventType

type EventType string

Custom type to express available event types

const (
	EVT_STATE_CHANGED EventType = "state_changed" // Event type: "state_changed"
)

type Field

type Field struct {
	Description string                 `json:"description"`
	Example     interface{}            `json:"example"`
	Required    bool                   `json:"required"`
	Selecttor   map[string]interface{} `json:"selector"`
}

type HassClient

type HassClient struct {
	// contains filtered or unexported fields
}

func CreateHassClient

func CreateHassClient(address string, token string) *HassClient

Create a new client with the given target address and authentication token. Use `client.connect()` afterwards to establish a connection.

func (*HassClient) CallService

func (client *HassClient) CallService(domain string, service string, params *map[string]string, callback func(ServerResult)) error

*

func (*HassClient) Connect

func (client *HassClient) Connect() error

Connects to the homeassistant instance and initiates authentication via token. If this method returns without error, you are ready to execute commands to send or subscribe to events.

func (*HassClient) Disconnect

func (client *HassClient) Disconnect()

func (*HassClient) GetServices

func (client *HassClient) GetServices(callback func([]*Service, error)) error

func (*HassClient) SubscribeEvent

func (client *HassClient) SubscribeEvent(eventType EventType, callback func(Event))

func (*HassClient) WithEncryption

func (client *HassClient) WithEncryption(enableWss bool) *HassClient

Use the builder method to set scheme to "wss" and use an encrypted method

type ServerResult

type ServerResult struct {
	Success bool                   `json:"success"`
	Result  map[string]interface{} `json:"result"`
}

type Service

type Service struct {
	Domain      string
	Name        string `json:"name"`
	Id          string
	Description string `json:"description"`
	Fields      map[string]Field
}

type State

type State struct {
	State       string                 `json:"state"`        // String representation of the current state of the entity. Example off.
	EntityId    string                 `json:"entity_id"`    // Entity ID. Format: <domain>.<object_id>. Example: light.kitchen.
	ObjectId    string                 `json:"object_id"`    // Object ID of entity. Example: kitchen.
	Domain      string                 `json:"domain"`       // Domain of the entity. Example: light.
	Name        string                 `json:"name"`         // Name of the entity. Based on friendly_name attribute with fall back to object ID. Example: Kitchen Ceiling.
	LastChanged string                 `json:"last_changed"` // Time the state changed in the state machine in UTC time. This is not updated when there are only updated attributes. Example: 2017-10-28 08:13:36.715874+00:00.
	LastUpdated string                 `json:"last_updated"` // Time the state was written to the state machine in UTC time. Note that writing the exact same state including attributes will not result in this field being updated. Example: 2017-10-28 08:13:36.715874+00:00.
	Attributes  map[string]interface{} `json:"attributes"`   // A dictionary with extra attributes related to the current state.
	Context     Context                `json:"context"`      // A dictionary with extra attributes related to the context of the state.
}

type StateChangedEvent

type StateChangedEvent struct {
	EntityId string `json:"entity_id"`
	OldState State  `json:"old_state"`
	NewState State  `json:"new_state"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL