small fixed, device repo and some device api
This commit is contained in:
+15
-2
@@ -34,19 +34,28 @@ type DeviceState struct {
|
||||
type NewDeviceState struct {
|
||||
Power *bool `json:"power"`
|
||||
Color *string `json:"color"`
|
||||
Intensity int `json:"intensity"`
|
||||
Intensity *float64 `json:"intensity"`
|
||||
Temperature int `json:"temperature"`
|
||||
}
|
||||
|
||||
type DeviceCapability string
|
||||
|
||||
type DeviceRepository interface {
|
||||
FindByID(ctx context.Context, id int) (*Device, error)
|
||||
Find(ctx context.Context, id int) (*Device, error)
|
||||
FetchByReference(ctx context.Context, kind ReferenceKind, value string) ([]Device, error)
|
||||
Save(ctx context.Context, device *Device) error
|
||||
Delete(ctx context.Context, device *Device) error
|
||||
}
|
||||
|
||||
func DeviceCapabilitiesToStrings(caps []DeviceCapability) []string {
|
||||
res := make([]string, 0, len(caps))
|
||||
for _, cap := range caps {
|
||||
res = append(res, string(cap))
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
var (
|
||||
DCPower DeviceCapability = "Power"
|
||||
DCColorHS DeviceCapability = "ColorHS"
|
||||
@@ -118,5 +127,9 @@ func (d *Device) SetState(newState NewDeviceState) error {
|
||||
}
|
||||
}
|
||||
|
||||
if newState.Intensity != nil && d.HasCapability(DCIntensity) {
|
||||
d.State.Intensity = *newState.Intensity
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ var (
|
||||
RKDeviceID ReferenceKind = "DeviceID"
|
||||
RKBridgeID ReferenceKind = "BridgeID"
|
||||
RKTag ReferenceKind = "Tag"
|
||||
RKAll ReferenceKind = "All"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user