add beginning of CLI app and some backend fixes.
This commit is contained in:
@@ -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
@@ -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
@@ -7,6 +7,5 @@ var (
|
||||
RKBridgeID ReferenceKind = "BridgeID"
|
||||
RKTag ReferenceKind = "Tag"
|
||||
RKAll ReferenceKind = "All"
|
||||
RKName ReferenceKind = "Name"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user