homeassistant

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Home Assistant API Client

This package provides a client for the Home Assistant API, which is used to interact with the Home Assistant home automation system.

References:

Documentation

Overview

homeassistant implements an API client for Home Assistant API https://developers.home-assistant.io/docs/api/rest/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*client.Client
}

func New

func New(endPoint, apiKey string, opts ...client.ClientOpt) (*Client, error)

func (*Client) Call added in v1.0.3

func (c *Client) Call(service, entity string) ([]*State, error)

Call a service for an entity. Returns a list of states that have changed while the service was being executed. TODO: This is a placeholder implementation, and requires fields to be passed in the request

func (*Client) Domains added in v1.0.3

func (c *Client) Domains() ([]*Domain, error)

Domains returns all domains and their associated service objects

func (*Client) Events

func (c *Client) Events() ([]Event, error)

Events returns all the events and number of listeners

func (*Client) Health

func (c *Client) Health() (string, error)

ListModels returns all the models

func (*Client) Services added in v1.0.3

func (c *Client) Services(domain string) ([]*Service, error)

Return callable services for a domain

func (*Client) State added in v1.0.3

func (c *Client) State(EntityId string) (*State, error)

State returns a state for a specific entity

func (*Client) States

func (c *Client) States() ([]*State, error)

States returns all the entities and their state

type Domain added in v1.0.3

type Domain struct {
	Domain   string              `json:"domain"`
	Services map[string]*Service `json:"services,omitempty"`
}

func (Domain) String added in v1.0.3

func (v Domain) String() string

type Event

type Event struct {
	Event     string `json:"event"`
	Listeners uint   `json:"listener_count"`
}

type Field added in v1.0.3

type Field struct {
	Required bool                `json:"required,omitempty"`
	Example  any                 `json:"example,omitempty"`
	Selector map[string]Selector `json:"selector,omitempty"`
}

func (Field) String added in v1.0.3

func (v Field) String() string

type Selector added in v1.0.3

type Selector struct {
	Text              string `json:"text,omitempty"`
	Mode              string `json:"mode,omitempty"`
	Min               int    `json:"min,omitempty"`
	Max               int    `json:"max,omitempty"`
	UnitOfMeasurement string `json:"unit_of_measurement,omitempty"`
}

type Service added in v1.0.3

type Service struct {
	Call        string           `json:"call,omitempty"`
	Name        string           `json:"name,omitempty"`
	Description string           `json:"description,omitempty,wrap"`
	Fields      map[string]Field `json:"fields,omitempty,wrap"`
}

func (Service) String added in v1.0.3

func (v Service) String() string

type State

type State struct {
	Entity       string         `json:"entity_id"`
	LastChanged  time.Time      `json:"last_changed,omitempty"`
	LastReported time.Time      `json:"last_reported,omitempty"`
	LastUpdated  time.Time      `json:"last_updated,omitempty"`
	State        string         `json:"state"`
	Attributes   map[string]any `json:"attributes"`
	Context      struct {
		Id       string `json:"id,omitempty"`
		ParentId string `json:"parent_id,omitempty"`
		UserId   string `json:"user_id,omitempty"`
	} `json:"context"`
}

func (State) Class added in v1.0.3

func (s State) Class() string

Class determines how the state should be interpreted, or will return "" if it's unknown

func (State) Domain added in v1.0.3

func (s State) Domain() string

Domain is used to determine the services which can be called on the entity

func (State) Name

func (s State) Name() string

Name is the friendly name of the entity

func (State) String

func (s State) String() string

func (State) UnitOfMeasurement

func (s State) UnitOfMeasurement() string

UnitOfMeasurement provides the unit of measurement for the state, or "" if there is no unit of measurement

func (State) Value added in v1.0.3

func (s State) Value() string

Value is the current state of the entity, or empty if the state is unavailable

Jump to

Keyboard shortcuts

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