devices

package
v0.0.0-...-6312dd6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeString  = "string"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
	TypeNumber  = "number"

	UnitHectopascal = "hectopascal"
	UnitKelvin      = "kelvin"
	UnitPercentage  = "percentage"
	UnitArcDegrees  = "arcdegrees"
	UnitCelsius     = "celsius"
	UnitLux         = "lux"
	UnitSeconds     = "seconds"
	UnitPPM         = "ppm"

	CapabilityAlarm                    Capability = "Alarm"
	CapabilityAirQualitySensor         Capability = "AirQualitySensor"
	CapabilityBarometricPressureSensor Capability = "BarometricPressureSensor"
	CapabilityBinarySensor             Capability = "BinarySensor"
	CapabilityCamera                   Capability = "Camera"
	CapabilityColorControl             Capability = "ColorControl"
	CapabilityColorSensor              Capability = "ColorSensor"
	CapabilityDoorSensor               Capability = "DoorSensor"
	CapabilityEnergyMonitor            Capability = "EnergyMonitor"
	CapabilityHumiditySensor           Capability = "HumiditySensor"
	CapabilityLeakSensor               Capability = "LeakSensor"
	CapabilityLight                    Capability = "Light"
	CapabilityLock                     Capability = "Lock"
	CapabilityMotionSensor             Capability = "MotionSensor"
	CapabilityMultiLevelSensor         Capability = "MultiLevelSensor"
	CapabilityMultiLevelSwitch         Capability = "MultiLevelSwitch"
	CapabilityOnOffSwitch              Capability = "OnOffSwitch"
	CapabilityPushButton               Capability = "PushButton"
	CapabilitySmartPlug                Capability = "SmartPlug"
	CapabilitySmokeSensor              Capability = "SmokeSensor"
	CapabilityTemperatureSensor        Capability = "TemperatureSensor"
	CapabilityThermostat               Capability = "Thermostat"
	CapabilityVideoCamera              Capability = "VideoCamera"

	OpenProperty              = "OpenProperty"
	PushedProperty            = "PushedProperty"
	SmokeProperty             = "SmokeProperty"
	TargetTemperatureProperty = "TargetTemperatureProperty"
	TemperatureProperty       = "TemperatureProperty"
	ThermostatModeProperty    = "ThermostatModeProperty"
	VideoProperty             = "VideoProperty"
	VoltageProperty           = "VoltageProperty"
)

Variables

This section is empty.

Functions

func Color16ToRGB

func Color16ToRGB(colorStr string) (red, green, blue int, err error)

Types

type AdapterHandler

type AdapterHandler interface {
	GetId() string
	SendPropertyChangedNotification(deviceId string, p properties.PropertyDescription)
	Send(messageType messages.MessageType, data any)
}

type BinarySensor

type BinarySensor struct {
	*Device
	Bool properties.BooleanEntity
}

func NewBinarySensor

func NewBinarySensor(id string, opts ...Option) *BinarySensor

func (*BinarySensor) AddProperties

func (device *BinarySensor) AddProperties(props ...properties.Entity)

func (*BinarySensor) IsOn

func (device *BinarySensor) IsOn() bool

type BinarySensorHandler

type BinarySensorHandler interface {
	IsOn() bool
}

type Capability

type Capability = string

type Device

type Device struct {
	Context             string           `json:"@context,omitempty"`
	AtType              []Capability     `json:"@type,omitempty"`
	Id                  string           `json:"id,omitempty"`
	Title               string           `json:"title,omitempty"`
	Description         string           `json:"description,omitempty"`
	Links               []DeviceLink     `json:"links,omitempty"`
	Forms               []DeviceForm     `json:"forms,omitempty"`
	BaseHref            string           `json:"baseHref,omitempty"`
	Pin                 *DevicePin       `json:"pin,omitempty"`
	Properties          DeviceProperties `json:"properties,omitempty"`
	Actions             DeviceActions    `json:"actions,omitempty"`
	Events              DeviceEvents     `json:"events,omitempty"`
	CredentialsRequired bool             `json:"credentialsRequired,omitempty"`
	// contains filtered or unexported fields
}

func NewDevice

func NewDevice(description DeviceDescription, opts ...Option) *Device

func (*Device) AddProperty

func (d *Device) AddProperty(p properties.Entity)

func (*Device) GetAction

func (d *Device) GetAction(id string) actions.Action

func (*Device) GetActions

func (d *Device) GetActions() map[string]actions.Action

func (*Device) GetAdapter

func (d *Device) GetAdapter() AdapterHandler

func (*Device) GetAtContext

func (d *Device) GetAtContext() string

func (*Device) GetAtType

func (d *Device) GetAtType() []string

func (*Device) GetBaseHref

func (d *Device) GetBaseHref() string

func (*Device) GetCredentialsRequired

func (d *Device) GetCredentialsRequired() bool

func (*Device) GetDescription

func (d *Device) GetDescription() string

func (*Device) GetDevice

func (d *Device) GetDevice() *Device

func (*Device) GetEvent

func (d *Device) GetEvent(id string) events.Event

func (*Device) GetEvents

func (d *Device) GetEvents() map[string]events.Event

func (*Device) GetHandler

func (d *Device) GetHandler() AdapterHandler

func (*Device) GetId

func (d *Device) GetId() string
func (d *Device) GetLink() []DeviceLink

func (*Device) GetPin

func (d *Device) GetPin() *DevicePin

func (*Device) GetProperties

func (d *Device) GetProperties() map[string]properties.Entity

func (*Device) GetProperty

func (d *Device) GetProperty(id string) properties.Entity

func (*Device) GetTitle

func (d *Device) GetTitle() string

func (*Device) HandleRemoved

func (d *Device) HandleRemoved()

func (*Device) NotifyPropertyChanged

func (d *Device) NotifyPropertyChanged(p properties.PropertyDescription)

func (*Device) SetCredentials

func (d *Device) SetCredentials(username, password string) error

func (*Device) SetHandler

func (d *Device) SetHandler(h AdapterHandler)

func (*Device) SetPin

func (d *Device) SetPin(pin string) error

func (*Device) ToMessage

func (d *Device) ToMessage() *messages.Device

type DeviceActions

type DeviceActions map[string]actions.Action

type DeviceDescription

type DeviceDescription struct {
	Id          string
	AtType      []Capability
	Title       string
	Description string
}

type DeviceEvents

type DeviceEvents map[string]events.Event

type DeviceForm

type DeviceForm struct {
}
type DeviceLink struct {
	Href      string `json:"href,omitempty"`
	Rel       string `json:"rel,omitempty"`
	MediaType string `json:"mediaType,omitempty"`
}

type DevicePin

type DevicePin struct {
	Required bool   `json:"required,omitempty"`
	Pattern  string `json:"pattern,omitempty"`
}

type DeviceProperties

type DeviceProperties map[string]properties.Entity

type Entity

type Entity interface {
	SetHandler(h AdapterHandler)
	GetAdapter() AdapterHandler
	GetId() string
	GetAtContext() string
	GetProperty(id string) properties.Entity
	GetAtType() []string
	ToMessage() *messages.Device
	SetCredentials(username, password string) error
	SetPin(pin string) error
	GetDevice() *Device
}

type Light

type Light struct {
	*Device
	OnOff            properties.BooleanEntity
	Brightness       properties.IntegerEntity
	ColorMode        properties.Entity
	Color            properties.Entity
	ColorTemperature properties.Entity
}

func NewLightBulb

func NewLightBulb(id string, opts ...Option) *Light

func NewSmartPlug

func NewSmartPlug(id string, opts ...Option) *Light

func (*Light) AddProperties

func (light *Light) AddProperties(props ...properties.Entity)

func (*Light) SetBrightness

func (light *Light) SetBrightness(brightness int) error

func (*Light) Toggle

func (light *Light) Toggle() error

func (*Light) TurnOff

func (light *Light) TurnOff() error

func (*Light) TurnOn

func (light *Light) TurnOn() error

type LightHandler

type LightHandler interface {
	TurnOn() error
	TurnOff() error
	SetBrightness(brightness int) error
}

type MotionSensor

type MotionSensor struct {
	*Device
	// contains filtered or unexported fields
}

func NewMotionSensor

func NewMotionSensor(id string, opts ...Option) *MotionSensor

func (*MotionSensor) AddProperties

func (sensor *MotionSensor) AddProperties(props ...properties.Entity)

type MultiLevelSensor

type MultiLevelSensor struct {
	*Device
	// contains filtered or unexported fields
}

func NewMultiLevelSensor

func NewMultiLevelSensor(id string, opts ...Option) *MultiLevelSensor

func (*MultiLevelSensor) AddProperties

func (sensor *MultiLevelSensor) AddProperties(props ...properties.Entity)

type MultiLevelSwitch

type MultiLevelSwitch struct {
	*Device
}

func NewMultiLevelSwitch

func NewMultiLevelSwitch(id string, opts ...Option) *MultiLevelSwitch

type OnOffSwitch

type OnOffSwitch struct {
	*Device
	OnOff            properties.BooleanEntity
	Brightness       properties.IntegerEntity
	ColorMode        properties.Entity
	Color            properties.Entity
	ColorTemperature properties.Entity
}

func NewOnOffSwitch

func NewOnOffSwitch(id string, opts ...Option) *OnOffSwitch

func NewThermostat

func NewThermostat(id string, opts ...Option) *OnOffSwitch

func (*OnOffSwitch) AddProperties

func (device *OnOffSwitch) AddProperties(props ...properties.Entity)

func (*OnOffSwitch) Toggle

func (device *OnOffSwitch) Toggle() error

func (*OnOffSwitch) TurnOff

func (device *OnOffSwitch) TurnOff() error

func (*OnOffSwitch) TurnOn

func (device *OnOffSwitch) TurnOn() error

type OnOffSwitchDevice

type OnOffSwitchDevice interface {
	TurnOn() error
	TurnOff() error
	Toggle() error
}

type Option

type Option func(device *Device)

func WithCredentialsRequired

func WithCredentialsRequired() Option

func WithDescription

func WithDescription(des string) Option

func WithPin

func WithPin(pin string) Option

func WithTitle

func WithTitle(title string) Option

type SmartPlug

func (*SmartPlug) AddProperties

func (plug *SmartPlug) AddProperties(props ...properties.Entity)

func (*SmartPlug) Toggle

func (plug *SmartPlug) Toggle() error

func (*SmartPlug) TurnOff

func (plug *SmartPlug) TurnOff() error

func (*SmartPlug) TurnOn

func (plug *SmartPlug) TurnOn() error

type SmartPlugDevice

type SmartPlugDevice interface {
	OnOffSwitchDevice
}

type Thermostat

type Thermostat struct {
	*Device
	Temperature       properties.NumberEntity
	TargetTemperature properties.NumberEntity
	HeatingCooling    properties.StringEntity
	ThermostatMode    properties.StringEntity
}

func (*Thermostat) AddProperties

func (device *Thermostat) AddProperties(props ...properties.Entity)

Jump to

Keyboard shortcuts

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