properties

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: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Brightness       = "brightness"
	Hue              = "hue"
	ColorTemperature = "ct"
	ColorModel       = "color_mode"

	TypeString  Type = "string"
	TypeBoolean Type = "boolean"
	TypeInteger Type = "integer"
	TypeNumber  Type = "number"

	UnitHectopascal Unit = "hectopascal"
	UnitKelvin      Unit = "kelvin"
	UnitPercentage  Unit = "percentage"
	UnitPercent     Unit = "percent"
	UnitWatt        Unit = "watt"
	UnitHertz       Unit = "hertz"
	UnitVolt        Unit = "volt"

	UnitArcDegrees    Unit = "arcdegrees"
	UnitDegreeCelsius Unit = "degree celsius"
	UnitAmpere        Unit = "ampere"
	UnitCelsius       Unit = "celsius"
	UnitLux           Unit = "lux"
	UnitSeconds       Unit = "seconds"
	UnitPPM           Unit = "ppm"

	TypeAlarmProperty                    PropertyType = "AlarmProperty"
	TypeBarometricPressureProperty       PropertyType = "BarometricPressureProperty"
	TypeBooleanProperty                  PropertyType = "BooleanProperty"
	TypeBrightnessProperty               PropertyType = "BrightnessProperty"
	TypeColorModeProperty                PropertyType = "ColorModeProperty"
	TypeColorProperty                    PropertyType = "ColorProperty"
	TypeColorTemperatureProperty         PropertyType = "ColorTemperatureProperty"
	TypeConcentrationProperty            PropertyType = "ConcentrationProperty"
	TypeCurrentProperty                  PropertyType = "CurrentProperty"
	TypeDensityProperty                  PropertyType = "DensityProperty"
	TypeFrequencyProperty                PropertyType = "FrequencyProperty"
	TypeHeatingCoolingProperty           PropertyType = "HeatingCoolingProperty"
	TypeHumidityProperty                 PropertyType = "HumidityProperty"
	TypeImageProperty                    PropertyType = "ImageProperty"
	TypeInstantaneousPowerFactorProperty PropertyType = "InstantaneousPowerFactorProperty"
	TypeInstantaneousPowerProperty       PropertyType = "InstantaneousPowerProperty"
	TypeLeakProperty                     PropertyType = "LeakProperty"
	TypeLevelProperty                    PropertyType = "LevelProperty"
	TypeLockedProperty                   PropertyType = "LockedProperty"
	TypeMotionProperty                   PropertyType = "MotionProperty"
	TypeOnOffProperty                    PropertyType = "OnOffProperty"
	TypeOpenProperty                     PropertyType = "OpenProperty"
	TypePushedProperty                   PropertyType = "PushedProperty"
	TypeSmokeProperty                    PropertyType = "SmokeProperty"
	TypeTargetTemperatureProperty        PropertyType = "TargetTemperatureProperty"
	TypeTemperatureProperty              PropertyType = "TemperatureProperty"
	TypeThermostatModeProperty           PropertyType = "ThermostatModeProperty"
	TypeVideoProperty                    PropertyType = "VideoProperty"
	TypeVoltageProperty                  PropertyType = "VoltageProperty"
)
View Source
const ColorModePropertyEnumColor = "color"
View Source
const ColorModePropertyEnumTemperature = "temperature"

Variables

This section is empty.

Functions

This section is empty.

Types

type Boolean

type Boolean struct {
	*Property
}

func NewBoolean

func NewBoolean(description BooleanPropertyDescription, opts ...Option) *Boolean

func (*Boolean) CheckValue

func (prop *Boolean) CheckValue(v any) bool

func (*Boolean) IsOn

func (prop *Boolean) IsOn() bool

func (*Boolean) OnValueRemoteGet

func (prop *Boolean) OnValueRemoteGet(fn func() bool)

OnValueRemoteGet calls fn when the value was read by a client.

func (*Boolean) OnValueRemoteUpdate

func (prop *Boolean) OnValueRemoteUpdate(fn func(bool))

OnValueRemoteUpdate calls fn when the value was updated by a client.

func (*Boolean) Toggle

func (prop *Boolean) Toggle()

func (*Boolean) TurnOff

func (prop *Boolean) TurnOff() error

func (*Boolean) TurnOn

func (prop *Boolean) TurnOn() error

type BooleanEntity

type BooleanEntity interface {
	Entity
	CheckValue(v any) bool
	TurnOn() error
	TurnOff() error
	IsOn() bool
}

type BooleanProperty

type BooleanProperty struct {
	*Boolean
}

func NewBooleanProperty

func NewBooleanProperty(value bool, args ...string) *BooleanProperty

type BooleanPropertyDescription

type BooleanPropertyDescription struct {
	Name        string `json:"name,omitempty"`
	AtType      string `json:"@type,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	ReadOnly    bool   `json:"readOnly,omitempty"`
	Value       bool   `json:"value,omitempty"`
}

type BrightnessProperty

type BrightnessProperty struct {
	*IntegerProperty
}

func NewBrightnessProperty

func NewBrightnessProperty(value Integer, opts ...Option) *BrightnessProperty

type ColorModeProperty

type ColorModeProperty struct {
	*StringProperty
}

func NewColorModeProperty

func NewColorModeProperty(value ColorModePropertyEnum, opts ...Option) *ColorModeProperty

type ColorModePropertyEnum

type ColorModePropertyEnum = string

type ColorProperty

type ColorProperty struct {
	*StringProperty
}

func NewColorProperty

func NewColorProperty(value string, opts ...Option) *ColorProperty

func (*ColorProperty) SetValue

func (c *ColorProperty) SetValue(v string)

type ColorTemperatureProperty

type ColorTemperatureProperty struct {
	*IntegerProperty
}

func NewColorTemperatureProperty

func NewColorTemperatureProperty(value Integer, opts ...Option) *ColorTemperatureProperty

type ColorTemperaturePropertyDescriptor

type ColorTemperaturePropertyDescriptor struct {
	Title       string  `json:"title,omitempty"`
	Description string  `json:"description,omitempty"`
	Value       Integer `json:"value,omitempty"`
}

type CurrentProperty

type CurrentProperty struct {
	*NumberProperty
}

type DeviceHandler

type DeviceHandler interface {
	GetId() string
	NotifyPropertyChanged(property PropertyDescription)
}

type Entity

type Entity interface {
	MarshalJSON() ([]byte, error)
	GetProperty() *Property
	GetType() Type
	GetTitle() string
	GetName() string
	GetUnit() string
	GetEnum() []any
	GetAtType() PropertyType
	GetDescription() string
	GetMinimum() any
	GetMaximum() any
	GetMultipleOf() any
	IsReadOnly() bool
	ToMessage() messages.Property
	ToDescription() PropertyDescription
	SetCachedValue(value any) bool
	SetCachedValueAndNotify(value any)
	SetTitle(s string) bool
	SetDescription(description string) bool
	SetHandler(d DeviceHandler)
	GetDevice() DeviceHandler
	NotifyChanged()
	GetCachedValue() any
	SetPropertyValue(value any) error
}

type FrequencyProperty

type FrequencyProperty struct {
	*NumberProperty
}

type HSL

type HSL struct {
	H, S, L float64
}

func (HSL) ToHTML

func (c HSL) ToHTML() string

func (HSL) ToRGB

func (c HSL) ToRGB() RGB

type HeatingCoolingProperty

type HeatingCoolingProperty struct {
	*StringProperty
}

func NewHeatingCoolingProperty

func NewHeatingCoolingProperty(value ThermostatModeEnum, opts ...Option) *HeatingCoolingProperty

type InstantaneousPowerFactorProperty

type InstantaneousPowerFactorProperty struct {
	*NumberProperty
}

type InstantaneousPowerProperty

type InstantaneousPowerProperty struct {
	*NumberProperty
}

func NewCurrentProperty

func NewCurrentProperty(value Number, opts ...Option) *InstantaneousPowerProperty

func NewFrequencyProperty

func NewFrequencyProperty(value Number, opts ...Option) *InstantaneousPowerProperty

func NewInstantaneousPowerFactorProperty

func NewInstantaneousPowerFactorProperty(value Number, opts ...Option) *InstantaneousPowerProperty

func NewInstantaneousPowerProperty

func NewInstantaneousPowerProperty(value Number, opts ...Option) *InstantaneousPowerProperty

func NewVoltageProperty

func NewVoltageProperty(value Number, opts ...Option) *InstantaneousPowerProperty

type Integer

type Integer int64

type IntegerEntity

type IntegerEntity interface {
	Entity
	CheckValue(any) Integer
	SetValue(v Integer) error
}

type IntegerProperty

type IntegerProperty struct {
	*Property
}

func NewIntegerProperty

func NewIntegerProperty(desc IntegerPropertyDescription, opts ...Option) *IntegerProperty

func (*IntegerProperty) CheckValue

func (prop *IntegerProperty) CheckValue(v any) Integer

func (*IntegerProperty) GetValue

func (prop *IntegerProperty) GetValue() Integer

func (*IntegerProperty) OnValueRemoteGet

func (prop *IntegerProperty) OnValueRemoteGet(fn func() int)

OnValueRemoteGet calls fn when the value was read by a client.

func (*IntegerProperty) OnValueRemoteUpdate

func (prop *IntegerProperty) OnValueRemoteUpdate(fn func(int))

OnValueRemoteUpdate calls fn when the value was updated by a client.

func (*IntegerProperty) SetValue

func (prop *IntegerProperty) SetValue(v Integer) error

type IntegerPropertyDescription

type IntegerPropertyDescription struct {
	Name       string             `json:"name,omitempty"`
	AtType     string             `json:"@type,omitempty"`
	Minimum    Integer            `json:"minimum,omitempty"`
	Maximum    Integer            `json:"maximum,omitempty"`
	Unit       Unit               `json:"unit"`
	Title      string             `json:"title,omitempty"`
	Enum       []Integer          `json:"enum,omitempty"`
	ReadOnly   bool               `json:"readOnly,omitempty"`
	MultipleOf any                `json:"multipleOf,omitempty"`
	Links      []PropertyLinkElem `json:"links,omitempty"`
	Value      Integer            `json:"value,omitempty"`
}

type LeakProperty

type LeakProperty struct {
	*Boolean
}

func NewLeakProperty

func NewLeakProperty(value bool, opts ...Option) *LeakProperty

type LevelProperty

type LevelProperty struct {
	*NumberProperty
}

func NewLevelProperty

func NewLevelProperty(value Number, min, max Number, opts ...Option) *LevelProperty

type MotionProperty

type MotionProperty struct {
	*Boolean
}

func NewMotionProperty

func NewMotionProperty(value bool, opts ...Option) *MotionProperty

func NewOpenProperty

func NewOpenProperty(value bool, opts ...Option) *MotionProperty

type Number

type Number float64

type NumberEntity

type NumberEntity interface {
	Entity
	CheckValue(v any) Number
	SetValue(Number) error
}

type NumberProperty

type NumberProperty struct {
	*Property
}

func NewNumberProperty

func NewNumberProperty(desc NumberPropertyDescription, opts ...Option) *NumberProperty

func (*NumberProperty) CheckValue

func (prop *NumberProperty) CheckValue(v any) Number

func (*NumberProperty) GetValue

func (prop *NumberProperty) GetValue() Number

func (*NumberProperty) SetValue

func (prop *NumberProperty) SetValue(v Number) error

type NumberPropertyDescription

type NumberPropertyDescription struct {
	Name       string       `json:"name,omitempty"`
	AtType     PropertyType `json:"@type,omitempty"`
	Minimum    any          `json:"minimum,omitempty"`
	Maximum    any          `json:"maximum,omitempty"`
	Enum       []Number     `json:"enum,omitempty"`
	Title      string       `json:"title,omitempty"`
	ReadOnly   bool         `json:"readOnly,omitempty"`
	MultipleOf any          `json:"multipleOf,omitempty"`
	Unit       string       `json:"unit,omitempty"`
	Value      Number       `json:"value,omitempty"`
}

type OnOff

type OnOff interface {
	BooleanEntity
}

type OnOffProperty

type OnOffProperty struct {
	*Boolean
}

func NewOnOffProperty

func NewOnOffProperty(value bool, opts ...Option) *OnOffProperty

type OpenProperty

type OpenProperty struct {
	*Boolean
}

type Option

type Option func(p *Property)

func WithDescription

func WithDescription(description string) Option

func WithName

func WithName(name string) Option

func WithReadOnly

func WithReadOnly() Option

func WithTitle

func WithTitle(title string) Option

func WithUnit

func WithUnit(unit Unit) Option

type Property

type Property struct {
	Name        string       `json:"name"`
	Title       string       `json:"title,omitempty"`
	Type        Type         `json:"type"`
	AtType      PropertyType `json:"@type,omitempty"`
	Unit        Unit         `json:"unit,omitempty"`
	Description string       `json:"description,omitempty"`
	Minimum     any          `json:"minimum,omitempty"`
	Maximum     any          `json:"maximum,omitempty"`
	Enum        []any        `json:"enum,omitempty"`
	ReadOnly    bool         `json:"readOnly"`
	MultipleOf  any          `json:"multipleOf,omitempty"`
	Value       any          `json:"value"`
	// contains filtered or unexported fields
}

func NewProperty

func NewProperty(des PropertyDescription, opts ...Option) *Property

func (*Property) GetAtType

func (p *Property) GetAtType() PropertyType

func (*Property) GetCachedValue

func (p *Property) GetCachedValue() any

func (*Property) GetDescription

func (p *Property) GetDescription() string

func (*Property) GetDevice

func (p *Property) GetDevice() DeviceHandler

func (*Property) GetEnum

func (p *Property) GetEnum() []any

func (*Property) GetMaximum

func (p *Property) GetMaximum() any

func (*Property) GetMinimum

func (p *Property) GetMinimum() any

func (*Property) GetMultipleOf

func (p *Property) GetMultipleOf() any

func (*Property) GetName

func (p *Property) GetName() string

func (*Property) GetProperty

func (p *Property) GetProperty() *Property

func (*Property) GetTitle

func (p *Property) GetTitle() string

func (*Property) GetType

func (p *Property) GetType() string

func (*Property) GetUnit

func (p *Property) GetUnit() string

func (*Property) IsReadOnly

func (p *Property) IsReadOnly() bool

func (Property) MarshalJSON

func (p Property) MarshalJSON() ([]byte, error)

func (*Property) NotifyChanged

func (p *Property) NotifyChanged()

func (*Property) SetCachedValue

func (p *Property) SetCachedValue(value any) bool

func (*Property) SetCachedValueAndNotify

func (p *Property) SetCachedValueAndNotify(value any)

func (*Property) SetDescription

func (p *Property) SetDescription(d string) bool

func (*Property) SetHandler

func (p *Property) SetHandler(h DeviceHandler)

func (*Property) SetPropertyValue

func (p *Property) SetPropertyValue(value any) error

func (*Property) SetTitle

func (p *Property) SetTitle(t string) bool

func (*Property) ToDescription

func (p *Property) ToDescription() PropertyDescription

func (*Property) ToMessage

func (p *Property) ToMessage() messages.Property

type PropertyDescription

type PropertyDescription struct {
	Name        string             `json:"name,omitempty"`
	AtType      string             `json:"@type,omitempty"`
	Title       string             `json:"title,omitempty"`
	Type        string             `json:"type,omitempty"`
	Unit        string             `json:"unit,omitempty"`
	Description string             `json:"description,omitempty"`
	Minimum     any                `json:"minimum,omitempty"`
	Maximum     any                `json:"maximum,omitempty"`
	Enum        []any              `json:"enum,omitempty"`
	ReadOnly    bool               `json:"readOnly,omitempty"`
	MultipleOf  any                `json:"multipleOf,omitempty"`
	Links       []PropertyLinkElem `json:"links,omitempty"`
	Value       any                `json:"value,omitempty"`
}

type PropertyLinkElem

type PropertyLinkElem struct {
}

type PropertyType

type PropertyType = string

type RGB

type RGB struct {
	R, G, B float64
}

func HTMLToRGB

func HTMLToRGB(in string) (RGB, error)

Takes a string like '#123456' or 'ABCDEF' and returns an RGB

func (RGB) ToHSL

func (c RGB) ToHSL() HSL

func (RGB) ToHTML

func (c RGB) ToHTML() string

type SmokeProperty

type SmokeProperty struct {
	*Boolean
}

func NewSmokeProperty

func NewSmokeProperty(value bool, opts ...Option) *SmokeProperty

type StringEntity

type StringEntity interface {
	Entity
	CheckValue(v any) string
	SetValue(v string) error
}

type StringProperty

type StringProperty struct {
	*Property
}

func NewStringProperty

func NewStringProperty(desc StringPropertyDescription, opts ...Option) *StringProperty

func (*StringProperty) CheckValue

func (prop *StringProperty) CheckValue(v any) string

func (*StringProperty) GetValue

func (prop *StringProperty) GetValue() string

func (*StringProperty) OnValueRemoteGet

func (prop *StringProperty) OnValueRemoteGet(fn func() string)

OnValueRemoteGet calls fn when the value was read by a client.

func (*StringProperty) OnValueRemoteUpdate

func (prop *StringProperty) OnValueRemoteUpdate(fn func(string))

OnValueRemoteUpdate calls fn when the value was updated by a client.

func (*StringProperty) SetValue

func (prop *StringProperty) SetValue(v string) error

SetValue sets a value

type StringPropertyDescription

type StringPropertyDescription struct {
	Name     string       `json:"name,omitempty"`
	AtType   PropertyType `json:"@type,omitempty"`
	Enum     []string     `json:"enum,omitempty"`
	Title    string       `json:"title,omitempty"`
	ReadOnly bool         `json:"readOnly,omitempty"`
	Unit     string
	Value    string `json:"value,omitempty"`
}

type TargetTemperatureProperty

type TargetTemperatureProperty struct {
	*NumberProperty
}

func NewTargetTemperatureProperty

func NewTargetTemperatureProperty(value Number, opts ...Option) *TargetTemperatureProperty

type TemperatureProperty

type TemperatureProperty struct {
	*NumberProperty
}

func NewTemperatureProperty

func NewTemperatureProperty(value Number, opts ...Option) *TemperatureProperty

type ThermostatModeEnum

type ThermostatModeEnum string
var ThermostatAuto ThermostatModeEnum = "auto"
var ThermostatCool ThermostatModeEnum = "cool"
var ThermostatDry ThermostatModeEnum = "dry"
var ThermostatHeat ThermostatModeEnum = "heat"
var ThermostatOff ThermostatModeEnum = "off"
var ThermostatWind ThermostatModeEnum = "wind"

type ThermostatModeProperty

type ThermostatModeProperty struct {
	*StringProperty
}

func NewThermostatModeProperty

func NewThermostatModeProperty(value ThermostatModeEnum, opts ...Option) *ThermostatModeProperty

type Type

type Type = string

type Unit

type Unit = string

type VoltageProperty

type VoltageProperty struct {
	*NumberProperty
}

Jump to

Keyboard shortcuts

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