add lifx driver. It works with the bulb, but the code is a bit smelly.
This commit is contained in:
@@ -22,6 +22,7 @@ type DriverKind string
|
||||
var (
|
||||
DTHue DriverKind = "Hue"
|
||||
DTNanoLeaf DriverKind = "Nanoleaf"
|
||||
DTLIFX DriverKind = "LIFX"
|
||||
)
|
||||
|
||||
var ValidDriverKinds = []DriverKind{
|
||||
|
||||
+21
-1
@@ -35,7 +35,7 @@ func ParseColorValue(raw string) (ColorValue, error) {
|
||||
return ColorValue{}, ErrBadInput
|
||||
}
|
||||
|
||||
if tokens[0] == "kelvin" {
|
||||
if tokens[0] == "kelvin" || tokens[0] == "k" {
|
||||
parsedPart, err := strconv.Atoi(tokens[1])
|
||||
if err != nil {
|
||||
return ColorValue{}, ErrBadInput
|
||||
@@ -59,5 +59,25 @@ func ParseColorValue(raw string) (ColorValue, error) {
|
||||
return ColorValue{Hue: math.Mod(part1, 360), Saturation: math.Min(math.Max(part2, 0), 1)}, nil
|
||||
}
|
||||
|
||||
if tokens[0] == "hsk" {
|
||||
parts := strings.Split(tokens[1], ",")
|
||||
if len(parts) < 3 {
|
||||
return ColorValue{}, ErrUnknownColorFormat
|
||||
}
|
||||
|
||||
part1, err1 := strconv.ParseFloat(parts[0], 64)
|
||||
part2, err2 := strconv.ParseFloat(parts[1], 64)
|
||||
part3, err3 := strconv.Atoi(parts[2])
|
||||
if err1 != nil || err2 != nil || err3 != nil {
|
||||
return ColorValue{}, ErrBadInput
|
||||
}
|
||||
|
||||
return ColorValue{
|
||||
Hue: math.Mod(part1, 360),
|
||||
Saturation: math.Min(math.Max(part2, 0), 1),
|
||||
Kelvin: part3,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return ColorValue{}, ErrUnknownColorFormat
|
||||
}
|
||||
|
||||
+7
-4
@@ -50,6 +50,7 @@ type DeviceRepository interface {
|
||||
var (
|
||||
DCPower DeviceCapability = "Power"
|
||||
DCColorHS DeviceCapability = "ColorHS"
|
||||
DCColorHSK DeviceCapability = "ColorHSK"
|
||||
DCColorKelvin DeviceCapability = "ColorKelvin"
|
||||
DCButtons DeviceCapability = "Buttons"
|
||||
DCPresence DeviceCapability = "Presence"
|
||||
@@ -89,10 +90,12 @@ func (d *Device) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Device) HasCapability(capacity DeviceCapability) bool {
|
||||
func (d *Device) HasCapability(capabilities ...DeviceCapability) bool {
|
||||
for _, c := range d.Capabilities {
|
||||
if c == capacity {
|
||||
return true
|
||||
for _, c2 := range capabilities {
|
||||
if c == c2 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +113,7 @@ func (d *Device) SetState(newState NewDeviceState) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if (parsed.IsKelvin() && d.HasCapability(DCColorKelvin)) || (parsed.IsHueSat() && d.HasCapability(DCColorHS)) {
|
||||
if (parsed.IsKelvin() && d.HasCapability(DCColorKelvin, DCColorHSK)) || (parsed.IsHueSat() && d.HasCapability(DCColorHS)) {
|
||||
d.State.Color = parsed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,3 +15,10 @@ var ErrIncorrectToken = errors.New("driver is not accepting authentication infor
|
||||
var ErrUnexpectedResponse = errors.New("driver api returned unexpected response (wrong driver selected?)")
|
||||
var ErrBridgeSearchFailed = errors.New("bridge search failed")
|
||||
var ErrAddressOnlyDryRunnable = errors.New("this address may only be used for a dry run")
|
||||
|
||||
var ErrInvalidAddress = errors.New("invalid mac address")
|
||||
var ErrPayloadTooShort = errors.New("payload too short")
|
||||
var ErrInvalidPacketSize = errors.New("invalid packet size")
|
||||
var ErrReadTimeout = errors.New("read timeout")
|
||||
var ErrUnrecognizedPacketType = errors.New("packet type not recognized")
|
||||
var ErrBridgeRunningRequired = errors.New("this operation cannot be performed when bridge is not running")
|
||||
|
||||
Reference in New Issue
Block a user