refactor color system to be separate from models, also move errors out of models.
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-02-28 22:52:06 +01:00
parent df865574bf
commit 62e7cb88f4
32 changed files with 532 additions and 516 deletions
+2 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"git.aiterp.net/lucifer/new-server/internal/color"
"git.aiterp.net/lucifer/new-server/models"
"golang.org/x/sync/errgroup"
"log"
@@ -283,7 +284,6 @@ func (b *Bridge) MakeCongruent(ctx context.Context) (int, error) {
} else if xyColor, ok := device.State.Color.ToXY(); ok && light.Color != nil {
xy := light.Color.Gamut.Conform(*xyColor.XY).Round()
if xy.DistanceTo(light.Color.XY) > 0.0009 || (light.ColorTemperature != nil && light.ColorTemperature.Mirek != nil) {
log.Println(xyColor.String(), device.State.Color.String())
update.ColorXY = &xy
changed = true
}
@@ -428,7 +428,7 @@ func (b *Bridge) GenerateDevices() []models.Device {
}
if light.Color != nil {
if device.State.Color.IsEmpty() {
device.State.Color = models.ColorValue{
device.State.Color = color.Color{
XY: &light.Color.XY,
}
}
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"git.aiterp.net/lucifer/new-server/models"
"git.aiterp.net/lucifer/new-server/internal/lerrors"
"io"
"log"
"net"
@@ -52,7 +52,7 @@ func (c *Client) Register(ctx context.Context) (string, error) {
}
}
if result[0].Success == nil {
return "", models.ErrUnexpectedResponse
return "", lerrors.ErrUnexpectedResponse
}
c.token = result[0].Success.Username
+5 -5
View File
@@ -4,7 +4,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"git.aiterp.net/lucifer/new-server/models"
"git.aiterp.net/lucifer/new-server/internal/color"
"strings"
"time"
)
@@ -152,9 +152,9 @@ type LightDimming struct {
}
type LightColor struct {
Gamut models.ColorGamut `json:"gamut"`
GamutType string `json:"gamut_type"`
XY models.ColorXY `json:"xy"`
Gamut color.Gamut `json:"gamut"`
GamutType string `json:"gamut_type"`
XY color.XY `json:"xy"`
}
type LightCT struct {
@@ -182,7 +182,7 @@ type LightAlert struct {
type ResourceUpdate struct {
Name *string
Power *bool
ColorXY *models.ColorXY
ColorXY *color.XY
Brightness *float64
Mirek *int
TransitionDuration *time.Duration
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"git.aiterp.net/lucifer/new-server/internal/lerrors"
"git.aiterp.net/lucifer/new-server/models"
"net/http"
"sync"
@@ -19,7 +20,7 @@ type Driver struct {
func (d *Driver) SearchBridge(ctx context.Context, address, token string, dryRun bool) ([]models.Bridge, error) {
if address == "" {
if !dryRun {
return nil, models.ErrAddressOnlyDryRunnable
return nil, lerrors.ErrAddressOnlyDryRunnable
}
res, err := http.Get("https://discovery.meethue.com")