small fixed, device repo and some device api

This commit is contained in:
2021-09-18 16:08:57 +02:00
parent 4e734c86a5
commit 26fcc1f314
19 changed files with 708 additions and 50 deletions
+15 -2
View File
@@ -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
}
+1
View File
@@ -6,6 +6,7 @@ var (
RKDeviceID ReferenceKind = "DeviceID"
RKBridgeID ReferenceKind = "BridgeID"
RKTag ReferenceKind = "Tag"
RKAll ReferenceKind = "All"
)