hass

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const PingInterval = time.Minute

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

MarshalLocationUpdate will take a device type that implements LocationUpdate and marshal it into a locationUpdateInfo struct that can be sent as a request to HA

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.

func StartWebsocket added in v0.3.5

func StartWebsocket(ctx context.Context, doneCh chan struct{})

Types

type EncryptedRequest

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

type HassConfig added in v0.0.6

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

func NewHassConfig added in v0.0.6

func NewHassConfig(ctx context.Context) *HassConfig

func (*HassConfig) GetEntityState added in v0.0.6

func (h *HassConfig) GetEntityState(entity string) map[string]interface{}

func (*HassConfig) IsEntityDisabled added in v0.0.7

func (h *HassConfig) IsEntityDisabled(entity string) bool

func (*HassConfig) Refresh added in v0.0.7

func (h *HassConfig) Refresh(ctx context.Context)

func (*HassConfig) RequestData added in v0.0.6

func (h *HassConfig) RequestData() interface{}

func (*HassConfig) RequestType added in v0.0.6

func (h *HassConfig) RequestType() RequestType

func (*HassConfig) ResponseHandler added in v0.0.6

func (h *HassConfig) ResponseHandler(resp bytes.Buffer)

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(bytes.Buffer)
}

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.

const (
	Apparent_power             SensorDeviceClass = iota + 1 // Apparent power
	Aqi                                                     // Air Quality Index
	Atmospheric_pressure                                    // Atmospheric pressure.
	SensorBattery                                           // Percentage of battery that is left
	Carbon_dioxide                                          // Concentration of carbon dioxide.
	Carbon_monoxide                                         // Concentration of carbon monoxide.
	Current                                                 // Current
	Data_rate                                               // Data rate
	Data_size                                               // Data size
	Date                                                    // Date. Requires native_value to be a Python datetime.date object, or None.
	Distance                                                // Generic distance
	Duration                                                // Time period. Should not update only due to time passing. The device or service needs to give a new data point to update.
	Energy                                                  // Energy, this device class should used for sensors representing energy consumption, for example an electricity meter. Represents power over time. Not to be confused with power.
	EnergyStorage                                           // Stored energy, this device class should be used for sensors representing stored energy, for example the amount of electric energy currently stored in a battery or the capacity of a battery. Represents power over time. Not to be confused with power.
	Enum                                                    // The sensor has a limited set of (non-numeric) states. The options property must be set to a list of possible states when using this device class.
	Frequency                                               // Frequency
	Gas                                                     // Volume of gas. Gas consumption measured as energy in kWh instead of a volume should be classified as energy.
	Humidity                                                // Relative humidity
	Illuminance                                             // Light level
	Irradiance                                              // Irradiance
	Moisture                                                // Moisture
	Monetary                                                // Monetary value with a currency.
	Nitrogen_dioxide                                        // Concentration of nitrogen dioxide
	Nitrogen_monoxide                                       // Concentration of nitrogen monoxide
	Nitrous_oxide                                           // Concentration of nitrous oxide
	Ozone                                                   // Concentration of ozone
	Pm1                                                     // Concentration of particulate matter less than 1 micrometer
	Pm25                                                    // Concentration of particulate matter less than 2.5 micrometers
	Pm10                                                    // Concentration of particulate matter less than 10 micrometers
	Power_factor                                            // Power Factor
	SensorPower                                             //  Power
	Precipitation                                           // Accumulated precipitation
	Precipitation_intensity                                 // Precipitation intensity
	Pressure                                                // Pressure
	Reactive_power                                          // Reactive power
	Signal_strength                                         // Signal strength
	Sound_pressure                                          // Sound pressure
	Speed                                                   // Generic speed
	Sulphur_dioxide                                         // Concentration of sulphure dioxide
	SensorTemperature                                       // Temperature
	Timestamp                                               // Timestamp. Requires native_value to return a Python datetime.datetime object, with time zone information, or None.
	Volatile_organic_compounds                              // Concentration of volatile organic compounds
	Voltage                                                 // Voltage
	Volume                                                  // Generic stored volume, this device class should be used for sensors representing a stored volume, for example the amount of fuel in a fuel tank.
	Water                                                   // Water consumption
	Weight                                                  // Generic mass; weight is used instead of mass to fit with every day language.
	Wind_speed                                              // Wind speed
)

func (SensorDeviceClass) String

func (i SensorDeviceClass) String() string

type SensorStateClass

type SensorStateClass int

SensorStateClass reflects the HA state class of the sensor.

const (
	StateMeasurement     SensorStateClass = iota + 1 // measurement
	StateTotal                                       // total
	StateTotalIncreasing                             // total_increasing
)

func (SensorStateClass) String

func (i SensorStateClass) String() string

type SensorType

type SensorType int

SensorType reflects the type of sensor, sensor or binary_sensor.

const (
	TypeSensor SensorType = iota + 1 // sensor
	TypeBinary                       // 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 WebSocket added in v0.3.5

type WebSocket struct {
	ReadCh  chan *webSocketData
	WriteCh chan *webSocketData
	// contains filtered or unexported fields
}

func NewWebsocket

func NewWebsocket(ctx context.Context, doneCh chan struct{}) *WebSocket

func (*WebSocket) OnClose added in v0.3.5

func (c *WebSocket) OnClose(socket *gws.Conn, code uint16, reason []byte)

func (*WebSocket) OnError added in v0.3.5

func (c *WebSocket) OnError(socket *gws.Conn, err error)

func (*WebSocket) OnMessage added in v0.3.5

func (c *WebSocket) OnMessage(socket *gws.Conn, message *gws.Message)

func (*WebSocket) OnOpen added in v0.3.5

func (c *WebSocket) OnOpen(socket *gws.Conn)

func (*WebSocket) OnPing added in v0.3.5

func (c *WebSocket) OnPing(socket *gws.Conn, payload []byte)

func (*WebSocket) OnPong added in v0.3.5

func (c *WebSocket) OnPong(socket *gws.Conn, payload []byte)

Jump to

Keyboard shortcuts

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