add beginning of CLI app and some backend fixes.

This commit is contained in:
2021-09-24 16:58:24 +02:00
parent 7a6ee3f87b
commit 06fa73b916
13 changed files with 632 additions and 11 deletions
+2 -2
View File
@@ -23,10 +23,10 @@ func (c *ColorValue) IsKelvin() bool {
func (c *ColorValue) String() string {
if c.Kelvin > 0 {
return fmt.Sprintf("kelvin:%d", c.Kelvin)
return fmt.Sprintf("k:%d", c.Kelvin)
}
return fmt.Sprintf("hsv:%f,%f", c.Hue, c.Saturation)
return fmt.Sprintf("hs:%g,%g", c.Hue, c.Saturation)
}
func ParseColorValue(raw string) (ColorValue, error) {
+28 -3
View File
@@ -19,6 +19,12 @@ type Device struct {
Tags []string `json:"tags"`
}
type DeviceUpdate struct {
Icon *string `json:"icon"`
Name *string `json:"name"`
UserProperties map[string]*string `json:"userProperties"`
}
// DeviceState contains optional state values that
// - Power: Whether the device is powered on
// - Color: Color value, if a color setting can be set on the device
@@ -32,10 +38,10 @@ type DeviceState struct {
}
type NewDeviceState struct {
Power *bool `json:"power"`
Color *string `json:"color"`
Power *bool `json:"power"`
Color *string `json:"color"`
Intensity *float64 `json:"intensity"`
Temperature int `json:"temperature"`
Temperature *int `json:"temperature"`
}
type DeviceCapability string
@@ -79,6 +85,25 @@ var Capabilities = []DeviceCapability{
DCTemperatureSensor,
}
func (d *Device) ApplyUpdate(update DeviceUpdate) {
if update.Name != nil {
d.Name = *update.Name
}
if update.Icon != nil {
d.Icon = *update.Icon
}
if d.UserProperties == nil {
d.UserProperties = make(map[string]string)
}
for key, value := range update.UserProperties {
if value != nil {
d.UserProperties[key] = *value
} else {
delete(d.UserProperties, key)
}
}
}
func (d *Device) Validate() error {
d.Name = strings.Trim(d.Name, " \t\n ")
if d.Name == "" {
+1 -2
View File
@@ -7,6 +7,5 @@ var (
RKBridgeID ReferenceKind = "BridgeID"
RKTag ReferenceKind = "Tag"
RKAll ReferenceKind = "All"
RKName ReferenceKind = "Name"
)