Skip to content

Latest commit

 

History

History
1360 lines (960 loc) · 26.2 KB

api.md

File metadata and controls

1360 lines (960 loc) · 26.2 KB

api

-- import "."

Usage

const (
	Number  ServiceFieldType = "number"
	String                   = "string"
	Boolean                  = "boolean"
	Values                   = "values"
)
var MessageHandlers = map[string]Message{}
var ServiceNotFound = errors.New("not found")

func RegisterMessageType

func RegisterMessageType(typ ...Message)

type Action

type Action interface {
	KeyFieldName() string
}

type AndCondition

type AndCondition struct {
	Conditions []Condition `json:"conditions"`
}

func (*AndCondition) ConditionKey

func (*AndCondition) ConditionKey() string

type AuthInvalidMessage

type AuthInvalidMessage struct {
	Message string `json:"message"`
}

func (AuthInvalidMessage) Type

func (AuthInvalidMessage) Type() string

type AuthMessage

type AuthMessage struct {
	AccessToken string `json:"access_token,omitempty"`
	ApiPassword string `json:"api_password,omitempty"`
}

func (AuthMessage) Type

func (AuthMessage) Type() string

type AuthOkMessage

type AuthOkMessage struct{}

func (AuthOkMessage) Type

func (AuthOkMessage) Type() string

type AuthRequiredMessage

type AuthRequiredMessage struct{}

func (AuthRequiredMessage) Type

func (AuthRequiredMessage) Type() string

type Automation

type Automation struct {
	Action    AutomationAction      `json:"action"`
	Alias     string                `json:"alias"`
	Condition []AutomationCondition `json:"condition,omitempty"`
	Id        AutomationId          `json:"id"`
	Trigger   []AutomationTrigger   `json:"trigger"`
}

type AutomationAction

type AutomationAction struct {
	Action
}

func (*AutomationAction) MarshalJSON

func (a *AutomationAction) MarshalJSON() ([]byte, error)

func (*AutomationAction) UnmarshalJSON

func (a *AutomationAction) UnmarshalJSON(data []byte) error

type AutomationCondition

type AutomationCondition struct{ Condition }

func (AutomationCondition) MarshalJSON

func (a AutomationCondition) MarshalJSON() ([]byte, error)

func (*AutomationCondition) UnmarshalJSON

func (a *AutomationCondition) UnmarshalJSON(data []byte) error

type AutomationId

type AutomationId string

type AutomationListEntry

type AutomationListEntry struct {
	FriendlyName  string       `json:"friendly_name"`
	Id            AutomationId `json:"id"`
	LastTriggered time.Time    `json:"last_triggered"`
}

type AutomationTrigger

type AutomationTrigger struct {
	Trigger
}

func (AutomationTrigger) MarshalJSON

func (a AutomationTrigger) MarshalJSON() ([]byte, error)

func (*AutomationTrigger) UnmarshalJSON

func (a *AutomationTrigger) UnmarshalJSON(data []byte) error

type Client

type Client struct {
	Token  string
	Server string
}

Client is the object used to interface with a homeassistant server. It should not be copied after being created.

func (*Client) Delete

func (c *Client) Delete(path string, body interface{}) (interface{}, error)

Delete renders body as JSON and posts it to the given path.

func (*Client) Exchange

func (c *Client) Exchange(send Message) (Message, error)

Exchange exchanges the 'send' Message for a response. It is safe for use by multiple goroutines.

func (*Client) Get

func (c *Client) Get(path string, parameters map[string]interface{}) (interface{}, error)

func (*Client) GetAutomation

func (c *Client) GetAutomation(id AutomationId) (*Automation, error)

func (*Client) GetConfig

func (c *Client) GetConfig() (*Config, error)

func (*Client) GetDevice

func (c *Client) GetDevice(id string) (*Device, error)

func (*Client) GetEntity

func (c *Client) GetEntity(id string) (*Entity, error)

func (*Client) GetFlow

func (c *Client) GetFlow(id ConfigFlowId) (*ConfigFlow, error)

GetFlow returns the in-progress-but-not-started flow with the given ID.

func (*Client) GetOptionsFlow

func (c *Client) GetOptionsFlow(id ConfigFlowId) (*ConfigFlow, error)

GetOptionsFlow gets the current status of the options flow with the given ID.

func (*Client) GetService

func (c *Client) GetService(domain, service string) (*Service, error)

GetService returns the service with the given domain and service. If the service can't be retrieved, the returned service will be nil and the error will be non-nil. If the service does not exist but no other error occurs, an error wrapping ServiceNotFound will be returned.

func (*Client) GetSystemOptions

func (c *Client) GetSystemOptions(entryId EntryId) (*SystemOptions, error)

func (*Client) ListAutomations

func (c *Client) ListAutomations() ([]AutomationListEntry, error)

func (*Client) ListConfigEntries

func (c *Client) ListConfigEntries() ([]*ConfigEntry, error)

ListConfigEntries lists known config entries. A config entry is basically a top-level device category; examples are zwave or wemo.

func (*Client) ListConfigFlowProgress

func (c *Client) ListConfigFlowProgress() ([]ConfigFlowProgress, error)

func (*Client) ListDevices

func (c *Client) ListDevices() ([]*Device, error)

func (*Client) ListEntities

func (c *Client) ListEntities() ([]Entity, error)

func (*Client) ListFlowHandlers

func (c *Client) ListFlowHandlers() ([]string, error)

func (*Client) ListServices

func (c *Client) ListServices() ([]Service, error)

func (*Client) ListStates

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

func (*Client) Post

func (c *Client) Post(path string, body interface{}) (interface{}, error)

Post renders body as JSON and posts it to the given path.

func (*Client) Raw

func (c *Client) Raw(method string, path string, parameters map[string]interface{}, body io.Reader) (interface{}, error)

Raw is as RawJSON, above, except the body is expected to already be an io.Reader.

func (*Client) RawJSON

func (c *Client) RawJSON(method string, path string, parameters map[string]interface{}, body interface{}) (interface{}, error)

RawJSON sends a request using the given method (e.g., GET, POST, DELETE) to the given nominal path. Parameters describe URL parameters that are added to the URL, and may be nil. body is an object that's converted to JSON and supplied as the request body. No request body is supplied if body is nil.

Returns the generally JSON-decoded response object, or error, if something happens. (Including, e.g., non-2XX responses or a body that isn't parseable JSON).

func (*Client) RawRESTDelete

func (c *Client) RawRESTDelete(path string, parameters map[string]interface{}) (interface{}, error)

RawRESTDelete requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. Note that the returned interface will be generically typed (e.g., maps & slices). See RawRESTRequestAs.

func (*Client) RawRESTDeleteAs

func (c *Client) RawRESTDeleteAs(path string, parameters map[string]interface{}, prototype interface{}) (interface{}, error)

RawRESTDeleteAs requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. The returned interface will be the same type as the given prototype. If conversion cannot be achieved, an error will be returned.

func (*Client) RawRESTGet

func (c *Client) RawRESTGet(path string, parameters map[string]interface{}) (interface{}, error)

RawRESTGet requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. Note that the returned interface will be generically typed (e.g., maps & slices). See RawRESTRequestAs.

func (*Client) RawRESTGetAs

func (c *Client) RawRESTGetAs(path string, parameters map[string]interface{}, prototype interface{}) (interface{}, error)

RawRESTGetAs requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. The returned interface will be the same type as the given prototype. If conversion cannot be achieved, an error will be returned.

func (*Client) RawRESTPost

func (c *Client) RawRESTPost(path string, parameters map[string]interface{}) (interface{}, error)

RawRESTPost requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. Note that the returned interface will be generically typed (e.g., maps & slices). See RawRESTRequestAs.

func (*Client) RawRESTPostAs

func (c *Client) RawRESTPostAs(path string, parameters map[string]interface{}, prototype interface{}) (interface{}, error)

RawRESTPostAs requests the given path via the REST API and returns the JSON-decoded request body if everything goes well. If anything else happens (failure communicating, rejected request, etc.) the result will be nil and the error will be non-nil. The returned interface will be the same type as the given prototype. If conversion cannot be achieved, an error will be returned.

func (*Client) RawWebsocketRequest

func (c *Client) RawWebsocketRequest(message Message) (interface{}, error)

RawWebsocketRequest exchanges the given message and returns the Result.Result if everything goes well. If anything else happens (failure communicating, rejected request, etc) the result will be nil and the error wll be non-nil. Note that the returned interface will be generically typed (e.g., maps & slices). See RawWebsocketRequestAs.

func (*Client) RawWebsocketRequestAs

func (c *Client) RawWebsocketRequestAs(message Message, prototype interface{}) (interface{}, error)

RawWebsocketRequest exchanges the given message and returns the Result.Result if everything goes well. If anything else happens (failure communicating, rejected request, etc) the result will be nil and the error wll be non-nil. The returned interface will be the same type as the given prototype. If conversion cannot be achieved, an error will be returned.

func (*Client) SetEntityName

func (c *Client) SetEntityName(id string, name string) error

func (*Client) SetFlow

func (c *Client) SetFlow(id ConfigFlowId, payload map[string]interface{}) (result string, err error)

SetFlow sets the configuration for the given FlowId to the given payload, and returns the result ID. I've observed result ID to refer to an Entry, but I guess it could refer to a second-stage config flow?

If anything goes wrong, result will be the zero value and err will be non-nil.

func (*Client) StartOptionsFlow

func (c *Client) StartOptionsFlow(entryId EntryId) (*ConfigFlow, error)

StartOptionsFlow initiates a options flow with the given handler, usually (always?) a ConfigEntry id. The new flow is returned. The UI calls DELETE if a thus-created flow is not used. It's not clear to me what happens if you don't do this.

type Condition

type Condition interface {
	ConditionKey() string
}

type Config

type Config struct {
	Components            []string          `json:"components"`
	ConfigDir             string            `json:"config_dir"`
	ConfigSource          string            `json:"config_source"`
	Elevation             int               `json:"elevation"`
	Latitude              float64           `json:"latitude"`
	LocationName          string            `json:"location_name"`
	Longitude             float64           `json:"longitude"`
	TimeZone              string            `json:"time_zone"`
	UnitSystem            map[string]string `json:"unit_system"`
	Version               string            `json:"version"`
	WhitelistExternalDirs []string          `json:"whitelist_external_dirs"`
}

type ConfigEntry

type ConfigEntry struct {
	EntryId         EntryId `json:"entry_id"`
	Domain          string  `json:"domain"`
	Title           string  `json:"title"`
	Source          string  `json:"source"`
	State           string  `json:"state"`
	ConnectionClass string  `json:"connection_class"`
	SupportsOptions bool    `json:"supports_options"`
}

https://github.com/home-assistant/core/blob/master/homeassistant/components/config/config_entries.py#L79

func (*ConfigEntry) GetSystemOptions

func (c *ConfigEntry) GetSystemOptions() (*SystemOptions, error)

type ConfigFlow

type ConfigFlow struct {
	DataSchema              []ConfigFlowDataSchema `json:"data_schema"`
	DescriptionPlaceholders interface{}            `json:"description_placeholders"`
	Errors                  map[string]string      `json:"errors"`
	FlowId                  ConfigFlowId           `json:"flow_id"`
	Handler                 string                 `json:"handler"`
	StepId                  string                 `json:"step_id"`
	Type                    string                 `json:"type"`

	// These fields appear in the response to SetFlow, maybe based on `Type`?
	Description string `json:"description,omitempty"`
	Result      string `json:"result,omitempty"`
	Title       string `json:"title,omitempty"`
}

type ConfigFlowDataSchema

type ConfigFlowDataSchema struct {
	Name     string `json:"name"`
	Required bool   `json:"required"`
	Type     string `json:"type"`
}

type ConfigFlowId

type ConfigFlowId string

type ConfigFlowProgress

type ConfigFlowProgress struct {
	Context ConfigFlowProgressContext `json:"context"`
	FlowId  ConfigFlowId              `json:"flow_id"`
	Handler string                    `json:"handler"`
}

type ConfigFlowProgressContext

type ConfigFlowProgressContext struct {
	Source string `json:"source"`
}

type DelayAction

type DelayAction struct {
	Delay int `json:"delay"`
}

func (*DelayAction) KeyFieldName

func (*DelayAction) KeyFieldName() string

type Device

type Device struct {
	ID            string      `json:"id"`
	AreaId        *string     `json:"area_id"`
	ConfigEntries []string    `json:"config_entries"`
	Connections   [][2]string `json:"connections"`
	Manufacturer  *string     `json:"manufacturer"`
	Model         *string     `json:"model"`
	Name          *string     `json:"name"`
	NameByUser    *string     `json:"name_by_user"`
	SwVersion     *string     `json:"sw_version"`
	ViaDeviceId   *string     `json:"via_device_id"`
}

type DeviceAction

type DeviceAction struct {
	DeviceId string `json:"device_id"`
	Domain   string `json:"domain"`
	EntityId string `json:"entity_id"`
}

func (*DeviceAction) KeyFieldName

func (*DeviceAction) KeyFieldName() string

type DeviceListMessage

type DeviceListMessage struct{}

func (DeviceListMessage) Type

func (DeviceListMessage) Type() string

type DeviceTrigger

type DeviceTrigger struct {
	DeviceId string `json:"device_id"`
	Domain   string `json:"domain"`
	EntityId string `json:"entity_id"`
	Type     string `json:"type,omitempty"`
	Subtype  string `json:"subtype,omitempty"`
	Event    string `json:"event,omitempty"`
}

func (*DeviceTrigger) Platform

func (*DeviceTrigger) Platform() string

type Entity

type Entity struct {
	ConfigEntryId string `json:"config_entry_id,omitempty"`
	DeviceId      string `json:"device_id,omitempty"`
	DisabledBy    string `json:"disabled_by,omitempty"`
	EntityId      string `json:"entity_id,omitempty"`
	Platform      string `json:"platform,omitempty"`
	Name          string `json:"name,omitempty"`
}

type EntityGetMessage

type EntityGetMessage struct {
	EntityId string `json:"entity_id"`
}

func (EntityGetMessage) Type

func (EntityGetMessage) Type() string

type EntityList

type EntityList struct{}

type EntityListMessage

type EntityListMessage struct{}

func (EntityListMessage) Type

func (EntityListMessage) Type() string

type EntityRename

type EntityRename struct {
	EntityId string `json:"entity_id"`
	Name     string `json:"name"`
}

func (EntityRename) Type

func (EntityRename) Type() string

type EntryId

type EntryId string

type EventAction

type EventAction struct {
	Event             string                 `json:"event"`
	EventData         map[string]interface{} `json:"event_data,omitempty"`
	EventDataTemplate map[string]interface{} `json:"event_data_template,omitempty"`
}

func (*EventAction) KeyFieldName

func (*EventAction) KeyFieldName() string

type EventTrigger

type EventTrigger struct {
	EventType string      `json:"event_type"`
	EventData interface{} `json:"event_data"`
}

func (*EventTrigger) Platform

func (*EventTrigger) Platform() string

type GeoLocationTrigger

type GeoLocationTrigger struct {
	Source string `json:"source"`
	Zone   string `json:"zone"`
	Event  string `json:"event"`
}

func (*GeoLocationTrigger) Platform

func (*GeoLocationTrigger) Platform() string

type GetConfigMessage

type GetConfigMessage struct{}

func (GetConfigMessage) Type

func (GetConfigMessage) Type() string

type HassTrigger

type HassTrigger struct {
	Event string `json:"event"`
}

func (*HassTrigger) Platform

func (*HassTrigger) Platform() string

type ListConfigFlowProgressMessage

type ListConfigFlowProgressMessage struct{}

func (ListConfigFlowProgressMessage) Type

func (ListConfigFlowProgressMessage) Type() string

type ListStatesMessage

type ListStatesMessage struct{}

func (ListStatesMessage) Type

func (g ListStatesMessage) Type() string

type ListSystemOptionsMessage

type ListSystemOptionsMessage struct {
	EntryId EntryId `json:"entry_id"`
}

func (ListSystemOptionsMessage) Type

func (ListSystemOptionsMessage) Type() string

type Message

type Message interface {
	Type() string
}

func MessageFromJSON

func MessageFromJSON(data []byte) (Message, error)

MessageFromJSON returns one of the various ___Message structs described above, or an error if we can't do so.

type MqttTrigger

type MqttTrigger struct {
	Topic   string `json:"topic"`
	Payload string `json:"payload,omitempty"`
}

func (*MqttTrigger) Platform

func (*MqttTrigger) Platform() string

type NotCondition

type NotCondition struct {
	Conditions []Condition `json:"conditions"`
}

func (*NotCondition) ConditionKey

func (*NotCondition) ConditionKey() string

type NumericStateCondition

type NumericStateCondition struct {
	EntityId string  `json:"entity_id"`
	Above    float64 `json:"above"`
}

func (*NumericStateCondition) ConditionKey

func (*NumericStateCondition) ConditionKey() string

type NumericStateTrigger

type NumericStateTrigger struct {
	EntityId      string        `json:"entity_id"`
	Above         float64       `json:"above"`
	Below         float64       `json:"below"`
	ValueTemplate string        `json:"value_template"`
	For           time.Duration `json:"for"`
}

func (*NumericStateTrigger) Platform

func (*NumericStateTrigger) Platform() string

type OrCondition

type OrCondition struct {
	Conditions []Condition `json:"conditions"`
}

func (*OrCondition) ConditionKey

func (*OrCondition) ConditionKey() string

type ResultError

type ResultError struct {
	Code    string
	Message string
}

type ResultMessage

type ResultMessage struct {
	Id      int
	Success bool
	Result  interface{}
	Error   ResultError `json:"error,omitempty"`
}

func (ResultMessage) Type

func (ResultMessage) Type() string

type SceneAction

type SceneAction struct {
	Scene string `json:"scene"`
}

func (*SceneAction) KeyFieldName

func (*SceneAction) KeyFieldName() string

type Service

type Service struct {
	Domain      string                   `json:"domain"`
	Name        string                   `json:"name"`
	Description string                   `json:"description"`
	Fields      map[string]*ServiceField `json:"fields"`
}

func (*Service) Call

func (s *Service) Call(data map[string]interface{}) ([]State, error)

type ServiceAction

type ServiceAction struct {
	Service  string                 `json:"service"`
	EntityId *string                `json:"entity_id,omitempty"`
	Data     map[string]interface{} `json:"data,omitempty"`
}

func (*ServiceAction) KeyFieldName

func (*ServiceAction) KeyFieldName() string

type ServiceField

type ServiceField struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Type        ServiceFieldType `json:"type"`
	Example     interface{}      `json:"example"`
	Values      []interface{}    `json:"values"`
	Default     interface{}      `json:"default"`
}

func (*ServiceField) UnmarshalJSON

func (s *ServiceField) UnmarshalJSON(data []byte) error

type ServiceFieldType

type ServiceFieldType string

func (ServiceFieldType) String

func (s ServiceFieldType) String() string

type State

type State struct {
	Attributes map[string]interface{} `json:"attributes"`
	Context    struct {
		Id       string  `json:"id"`
		ParentId *string `json:"parent_id"`
		UserId   *string `json:"user_id"`
	} `json:"context"`
	EntityId    string    `json:"entity_id"`
	LastChanged time.Time `json:"last_Changed"`
	LastUpdated time.Time `json:"last_updated"`
	State       string    `json:"state"`
}

type StateCondition

type StateCondition struct {
	EntityId string        `json:"entity_id"`
	State    StringOrFloat `json:"state"`
}

func (*StateCondition) ConditionKey

func (*StateCondition) ConditionKey() string

type StateTrigger

type StateTrigger struct {
	EntityId string        `json:"entity_id,omitempty"`
	From     StringOrFloat `json:"from"`
	To       StringOrFloat `json:"to"`
	For      time.Duration `json:"for"`
}

func (*StateTrigger) Platform

func (*StateTrigger) Platform() string

type StringOrFloat

type StringOrFloat struct {
}

StringOrFloat represents a value that is either a string or an integer.

func StringOrIntFromFloat64

func StringOrIntFromFloat64(f float64) StringOrFloat

func StringOrIntFromString

func StringOrIntFromString(s string) StringOrFloat

func (StringOrFloat) MarshalJSON

func (s StringOrFloat) MarshalJSON() ([]byte, error)

func (StringOrFloat) String

func (s StringOrFloat) String() string

func (StringOrFloat) UnmarshalJSON

func (s StringOrFloat) UnmarshalJSON(data []byte) error

type SunCondition

type SunCondition struct {
	AfterOffset  float64 `json:"after_offset"`
	BeforeOffset float64 `json:"before_offset"`
	After        string  `json:"after"`
	Before       string  `json:"before"`
}

func (*SunCondition) ConditionKey

func (*SunCondition) ConditionKey() string

type SunTrigger

type SunTrigger struct {
	Offset float64 `json:"offset"`
	Event  string  `json:"event"`
}

func (*SunTrigger) Platform

func (*SunTrigger) Platform() string

type SystemOptions

type SystemOptions struct {
	DisableNewEntities bool `json:"disable_new_entities"`
}

type TemplateCondition

type TemplateCondition struct {
	ValueTemplate string `json:"value_template"`
}

func (*TemplateCondition) ConditionKey

func (*TemplateCondition) ConditionKey() string

type TemplateTrigger

type TemplateTrigger struct {
	ValueTemplate string `json:"value_template"`
}

func (*TemplateTrigger) Platform

func (*TemplateTrigger) Platform() string

type TimeCondition

type TimeCondition struct {
	After  string `json:"after"`
	Before string `json:"before"`
}

func (*TimeCondition) ConditionKey

func (*TimeCondition) ConditionKey() string

type TimePatternTrigger

type TimePatternTrigger struct {
	Hours   StringOrFloat `json:"hours"`
	Minutes StringOrFloat `json:"minutes"`
	Seconds StringOrFloat `json:"seconds"`
}

func (*TimePatternTrigger) Platform

func (*TimePatternTrigger) Platform() string

type TimeTrigger

type TimeTrigger struct {
	// A time like HH:MM:SS, 24-hour time.
	At string `json:"at"`
}

func (*TimeTrigger) Platform

func (*TimeTrigger) Platform() string

type Trigger

type Trigger interface {
	Platform() string
}

type WaitAction

type WaitAction struct {
	WaitTemplate string `json:"wait_template"`
	Timeout      int    `json:"timeout,omitempty"`
}

func (*WaitAction) KeyFieldName

func (*WaitAction) KeyFieldName() string

type WebhookTrigger

type WebhookTrigger struct {
	WebhookId string `json:"webhook_id"`
}

func (*WebhookTrigger) Platform

func (*WebhookTrigger) Platform() string

type ZoneCondition

type ZoneCondition struct {
	EntityId string `json:"entity_id"`
	Zone     string `json:"zone"`
}

func (*ZoneCondition) ConditionKey

func (*ZoneCondition) ConditionKey() string

type ZoneTrigger

type ZoneTrigger struct {
	EntityId string `json:"entity_id"`
	Zone     string `json:"zone"`
	Event    string `json:"event"`
}

func (*ZoneTrigger) Platform

func (*ZoneTrigger) Platform() string