hass

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const PingInterval = time.Minute

Variables

This section is empty.

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 MarshalSensorRegistration added in v1.0.1

func MarshalSensorRegistration(s Sensor) *sensorRegistrationInfo

func MarshalSensorUpdate added in v1.0.1

func MarshalSensorUpdate(s Sensor) *sensorUpdateInfo

func StartWebsocket added in v0.3.5

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

Types

type ComparableStringer added in v1.2.0

type ComparableStringer interface {
	comparable
	String() string
}

type DeviceInfo added in v1.3.0

type DeviceInfo interface {
	DeviceID() string
	AppID() string
	AppName() string
	AppVersion() string
	DeviceName() string
	Manufacturer() string
	Model() string
	OsName() string
	OsVersion() string
	SupportsEncryption() bool
	AppData() interface{}
	MarshalJSON() ([]byte, error)
}

type EncryptedRequest

type EncryptedRequest struct {
	Type          string          `json:"type"`
	EncryptedData json.RawMessage `json:"encrypted_data,omitempty"`
	Encrypted     bool            `json:"encrypted"`
}

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) Get added in v1.0.0

func (c *HassConfig) Get(property string) (interface{}, error)

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() json.RawMessage

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)

func (*HassConfig) Set added in v1.0.0

func (c *HassConfig) Set(property string, value interface{}) error

func (*HassConfig) Validate added in v1.0.0

func (c *HassConfig) Validate() error

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 RegistrationDetails added in v1.3.0

type RegistrationDetails struct {
	Server, Token binding.String
	Device        DeviceInfo
}

func (*RegistrationDetails) Validate added in v1.3.0

func (r *RegistrationDetails) Validate() bool

type RegistrationRequest

type RegistrationRequest struct {
	AppData            interface{} `json:"app_data,omitempty"`
	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"`
}

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"`
}

func RegisterWithHass

func RegisterWithHass(registration *RegistrationDetails) (*RegistrationResponse, error)

type Request

type Request interface {
	RequestType() RequestType
	RequestData() json.RawMessage
	ResponseHandler(bytes.Buffer)
}

type RequestType

type RequestType int
const (
	RequestTypeRegisterSensor     RequestType // register_sensor
	RequestTypeUpdateSensorStates             // update_sensor_states
)

func (RequestType) String

func (i RequestType) String() string

type Response

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

type Sensor

type Sensor interface {
	SensorUpdate
	Disabled() bool
	Registered() bool
	MarshalJSON() ([]byte, error)
	UnMarshalJSON([]byte) error
}

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 string          `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

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, notifyCh chan fyne.Notification, 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