hass

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeSensor SensorType = iota + 1
	TypeBinary

	Apparent_power SensorDeviceClass = iota + 1
	Aqi
	Atmospheric_pressure
	SensorBattery
	Carbon_dioxide
	Carbon_monoxide
	Current
	Data_rate
	Data_size
	Date
	Distance
	Duration
	Energy
	Enum
	Frequency
	Gas
	Humidity
	Illuminance
	Irradiance
	Moisture
	Monetary
	Nitrogen_dioxide
	Nitrogen_monoxide
	Nitrous_oxide
	Ozone
	Pm1
	Pm25
	Pm10
	Power_factor
	SensorPower
	Precipitation
	Precipitation_intensity
	Pressure
	Reactive_power
	Signal_strength
	Sound_pressure
	Speed
	Sulphur_dioxide
	SensorTemperature
	Timestamp
	Volatile_organic_compounds
	Voltage
	Volume
	Water
	Weight
	Wind_speed

	Measurement SensorStateClass = iota
	Total
	Total_increasing
)

Variables

View Source
var ErrInvalidRequestType = errors.New("not a valid RequestType")

Functions

func APIRequest

func APIRequest(ctx context.Context, request Request)

func MarshalJSON

func MarshalJSON(request Request, secret string) ([]byte, error)

func MarshalLocationUpdate

func MarshalLocationUpdate(l LocationUpdate) *locationUpdateInfo

func MarshalSensorData

func MarshalSensorData(s Sensor) interface{}

MarshalSensorDate takes the sensor data and returns the appropriate JSON structure to either register or update the sensor in HA.

Types

type ConfigResponse

type ConfigResponse struct {
	Components   []string `json:"components"`
	ConfigDir    string   `json:"config_dir"`
	Elevation    int      `json:"elevation"`
	Latitude     float64  `json:"latitude"`
	LocationName string   `json:"location_name"`
	Longitude    float64  `json:"longitude"`
	TimeZone     string   `json:"time_zone"`
	UnitSystem   struct {
		Length      string `json:"length"`
		Mass        string `json:"mass"`
		Temperature string `json:"temperature"`
		Volume      string `json:"volume"`
	} `json:"unit_system"`
	Version               string   `json:"version"`
	WhitelistExternalDirs []string `json:"whitelist_external_dirs"`
}

type EncryptedRequest

type EncryptedRequest struct {
	Type          RequestType `json:"type"`
	Encrypted     bool        `json:"encrypted"`
	EncryptedData interface{} `json:"encrypted_data"`
}

type HassWebsocket

type HassWebsocket struct {
	ReadCh  chan *WebsocketResponse
	WriteCh chan interface{}
	// contains filtered or unexported fields
}

func NewWebsocket

func NewWebsocket(ctx context.Context) *HassWebsocket

func (*HassWebsocket) Close

func (ws *HassWebsocket) Close()

func (*HassWebsocket) Read

func (ws *HassWebsocket) Read(ctx context.Context)

func (*HassWebsocket) Write

func (ws *HassWebsocket) Write(ctx context.Context)

type LocationUpdate

type LocationUpdate interface {
	Gps() []float64
	GpsAccuracy() int
	Battery() int
	Speed() int
	Altitude() int
	Course() int
	VerticalAccuracy() int
}

LocationUpdate represents a location update from a platform/device. It provides a bridge between the platform/device specific location info and Home Assistant.

type RegistrationHost

type RegistrationHost struct {
	Server, Token binding.String
	UseTLS        binding.Bool
}

type RegistrationRequest

type RegistrationRequest struct {
	DeviceID           string      `json:"device_id"`
	AppID              string      `json:"app_id"`
	AppName            string      `json:"app_name"`
	AppVersion         string      `json:"app_version"`
	DeviceName         string      `json:"device_name"`
	Manufacturer       string      `json:"manufacturer"`
	Model              string      `json:"model"`
	OsName             string      `json:"os_name"`
	OsVersion          string      `json:"os_version"`
	SupportsEncryption bool        `json:"supports_encryption"`
	AppData            interface{} `json:"app_data,omitempty"`
}

type RegistrationResponse

type RegistrationResponse struct {
	CloudhookURL string `json:"cloudhook_url"`
	RemoteUIURL  string `json:"remote_ui_url"`
	Secret       string `json:"secret"`
	WebhookID    string `json:"webhook_id"`
}

type Request

type Request interface {
	RequestType() RequestType
	RequestData() interface{}
	ResponseHandler(interface{})
}

type RequestType

type RequestType string

ENUM(encrypted,get_config,update_location,register_sensor,update_sensor_states)

const (
	// RequestTypeEncrypted is a RequestType of type encrypted.
	RequestTypeEncrypted RequestType = "encrypted"
	// RequestTypeGetConfig is a RequestType of type get_config.
	RequestTypeGetConfig RequestType = "get_config"
	// RequestTypeUpdateLocation is a RequestType of type update_location.
	RequestTypeUpdateLocation RequestType = "update_location"
	// RequestTypeRegisterSensor is a RequestType of type register_sensor.
	RequestTypeRegisterSensor RequestType = "register_sensor"
	// RequestTypeUpdateSensorStates is a RequestType of type update_sensor_states.
	RequestTypeUpdateSensorStates RequestType = "update_sensor_states"
)

func ParseRequestType

func ParseRequestType(name string) (RequestType, error)

ParseRequestType attempts to convert a string to a RequestType.

func (RequestType) IsValid

func (x RequestType) IsValid() bool

String implements the Stringer interface.

func (RequestType) MarshalText

func (x RequestType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (RequestType) String

func (x RequestType) String() string

String implements the Stringer interface.

func (*RequestType) UnmarshalText

func (x *RequestType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Response

type Response struct {
	Success bool `json:"success,omitempty"`
}

type Sensor

type Sensor interface {
	Attributes() interface{}
	DeviceClass() string
	Icon() string
	Name() string
	State() interface{}
	Type() string
	UniqueID() string
	UnitOfMeasurement() string
	StateClass() string
	EntityCategory() string
	Disabled() bool
	Registered() bool
}

Sensor represents a sensor in HA. As an interface, it leaves it up to the underlying struct to provide the appropriate data for this representation.

type SensorDeviceClass

type SensorDeviceClass int

SensorDeviceClass reflects the HA device class of the sensor.

func (SensorDeviceClass) String

func (i SensorDeviceClass) String() string

type SensorStateClass

type SensorStateClass int

SensorStateClass reflects the HA state class of the sensor.

func (SensorStateClass) String

func (i SensorStateClass) String() string

type SensorType

type SensorType int

SensorType reflects the type of sensor, sensor or binary_sensor.

func (SensorType) String

func (i SensorType) String() string

type SensorUpdate

type SensorUpdate interface {
	Name() string
	ID() string
	Icon() string
	SensorType() SensorType
	DeviceClass() SensorDeviceClass
	StateClass() SensorStateClass
	State() interface{}
	Units() string
	Category() string
	Attributes() interface{}
}

SensorUpdate represents an update for a sensor. It reflects the current state of the sensor at the point in time it is used. It provides a bridge between platform/device and HA implementations of what a sensor is.

type UnencryptedRequest

type UnencryptedRequest struct {
	Type RequestType `json:"type"`
	Data interface{} `json:"data"`
}

type WebsocketResponse

type WebsocketResponse struct {
	Type    string `json:"type"`
	Success bool   `json:"success,omitempty"`
	Error   struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
	ID           int         `json:"id,omitempty"`
	Result       interface{} `json:"result,omitempty"`
	HAVersion    string      `json:"ha_version,omitempty"`
	Notification struct {
		Message   string      `json:"message"`
		Title     string      `json:"title,omitempty"`
		Target    []string    `json:"target,omitempty"`
		Data      interface{} `json:"data,omitempty"`
		ConfirmID string      `json:"confirm_id,omitempty"`
	} `json:"event,omitempty"`
}

Jump to

Keyboard shortcuts

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