Author SHA1 Message Date
Stian Fredrik Aune 3bf8cbef2f Mill option for local client
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build is passing
2023-02-12 22:18:17 +01:00
Stian Fredrik Aune 5db753e401 Fix Gen 3 support in mill
continuous-integration/drone/push Build is passing
2022-09-21 21:41:46 +02:00
gisle 2a750ae1f7 add lucy color command for conversions.
continuous-integration/drone/push Build is passing
2022-02-28 23:04:28 +01:00
gisle f1ed6da6d7 Squashed commit of the following:
continuous-integration/drone/push Build is passing
commit 62e7cb88f4
Author: Gisle Aune <dev@gisle.me>
Date:   Mon Feb 28 22:52:06 2022 +0100

    refactor color system to be separate from models, also move errors out of models.

commit df865574bf
Author: Gisle Aune <dev@gisle.me>
Date:   Mon Feb 21 19:27:42 2022 +0100

    rework color system and make it work with drivers.
2022-02-28 22:52:25 +01:00
5 changed files with 135 additions and 14 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ import (
func main() {
db := config.DBX().DB
log.Printf("Target version: %s",time.Now().Format("20060102150405"))
log.Printf("Target version: %s", time.Now().Format("20060102150405"))
log.Printf("Database: %s:%d/%s", config.MySqlHost(), config.MySqlPort(), config.MySqlSchema())
log.Printf("Authenticating as: %s", config.MySqlUsername())
+4
View File
@@ -36,6 +36,10 @@ EVENT HANDLER FACTORY COMMANDS
factory run <file.yaml>
MISC COMMANDS
color <color>
File example (use '---' to delimit multiple configs in one file):
mode: SceneDimmer
target: tag:Soverom
+24
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"git.aiterp.net/lucifer/new-server/app/client"
"git.aiterp.net/lucifer/new-server/internal/color"
"git.aiterp.net/lucifer/new-server/models"
"log"
"os"
@@ -92,6 +93,29 @@ func main() {
WriteDeviceInfoTable(os.Stdout, devices)
}
case "color":
{
col, err := color.Parse(cmd.Params.Get(0).StringOr("hs:0,0"))
if err != nil {
log.Fatalln(err)
}
if col.IsKelvin() {
fmt.Println(col.String())
}
if hs, ok := col.ToHS(); ok {
fmt.Println(hs.String())
}
if hsk, ok := col.ToHSK(); ok {
fmt.Println(hsk.String())
}
if xy, ok := col.ToXY(); ok {
fmt.Println(xy.String())
}
if rgb, ok := col.ToRGB(); ok {
fmt.Println(rgb.String())
}
}
case "factory":
factoryCmd(ctx, c)
+81 -1
View File
@@ -6,6 +6,7 @@ import (
"crypto/rand"
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
"git.aiterp.net/lucifer/new-server/internal/lerrors"
"git.aiterp.net/lucifer/new-server/models"
@@ -83,11 +84,16 @@ func (b *bridge) listDevices(ctx context.Context) ([]models.Device, error) {
}
func (b *bridge) pushStateChange(ctx context.Context, deviceModel models.Device) error {
if ip, ok := deviceModel.DriverProperties["ip"].(string); ok {
return b.pushWifiStateChange(ctx, ip, deviceModel.State.Temperature)
}
b.mu.Lock()
if b.luciferMillIDMap == nil {
b.luciferMillIDMap = make(map[int]int, 4)
b.millLuciferIDMap = make(map[int]int, 4)
}
subDomain := deviceModel.DriverProperties["subDomain"].(string)
if b.luciferMillIDMap[deviceModel.ID] == 0 {
millID, _ := strconv.Atoi(deviceModel.InternalID)
@@ -100,8 +106,10 @@ func (b *bridge) pushStateChange(ctx context.Context, deviceModel models.Device)
if deviceModel.State.Power {
status = 1
}
if subDomainIsGen2(subDomain) {
powerReq := deviceControlReqBody{
SubDomain: deviceModel.DriverProperties["subDomain"].(string),
SubDomain: subDomain,
DeviceID: b.luciferMillIDMap[deviceModel.ID],
TestStatus: 1,
Status: status,
@@ -121,6 +129,66 @@ func (b *bridge) pushStateChange(ctx context.Context, deviceModel models.Device)
if err != nil {
return err
}
} else {
sd, _ := strconv.Atoi(subDomain)
tempReq := deviceControlGen3Body{
Operation: "SINGLE_CONTROL",
Status: status,
SubDomain: sd,
DeviceId: b.luciferMillIDMap[deviceModel.ID],
HoldTemp: deviceModel.State.Temperature,
}
err := b.command(ctx, "deviceControlGen3ForApp", tempReq, nil)
if err != nil {
return err
}
powerReq := deviceControlGen3Body{
Operation: "SWITCH",
Status: status,
SubDomain: sd,
DeviceId: b.luciferMillIDMap[deviceModel.ID],
}
err = b.command(ctx, "deviceControlGen3ForApp", powerReq, nil)
if err != nil {
return err
}
}
return nil
}
func (b *bridge) pushWifiStateChange(ctx context.Context, ip string, temperature int) error {
b.mu.Lock()
defer b.mu.Unlock()
data, err := json.Marshal(wifiSetTemperatureBody{
Type: "Normal",
Value: temperature,
})
if err != nil {
return err
}
req, err := http.NewRequestWithContext(
ctx,
"POST",
fmt.Sprintf("http://%s/set-temperature", ip),
bytes.NewReader(data),
)
if err != nil {
return err
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
if res.StatusCode > 299 {
return errors.New("mill: negative response from " + ip)
}
return nil
}
@@ -239,3 +307,15 @@ func addDefaultHeaders(req *http.Request) {
req.Header.Add("X-Zc-Seq-Id", "1")
req.Header.Add("X-Zc-Version", "1")
}
var gen2subDomains = []string{"863", "5316", "5317", "5332", "5333", "6933"}
func subDomainIsGen2(subDomain string) bool {
for _, gen2sd := range gen2subDomains {
if subDomain == gen2sd {
return true
}
}
return false
}
+13
View File
@@ -65,6 +65,19 @@ type deviceControlReqBody struct {
PowerLevel int `json:"powerLevel"`
}
type deviceControlGen3Body struct {
Operation string `json:"operation"`
Status int `json:"status"`
SubDomain int `json:"subDomain"`
DeviceId int `json:"deviceId"`
HoldTemp int `json:"holdTemp,omitempty"`
}
type wifiSetTemperatureBody struct {
Type string `json:"type"`
Value int `json:"value"`
}
var location *time.Location
func init() {