Documentation ¶
Index ¶
Constants ¶
View Source
const API_ENDPOINT string = "/api/websocket"
Default Endpoint of Websocket
View Source
const (
GetServicesResult resultType = iota
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 HassClient ¶
type HassClient struct {
// contains filtered or unexported fields
}
func CreateHassClient ¶
func CreateHassClient(address string, token string, options ...string) *HassClient
Create a new client with the given target address and authentication token. Use `client.connect()` afterwards to establish a connection.
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))
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 ¶
Click to show internal directories.
Click to hide internal directories.