Merge branch 'asmodeus' into feature-scenesystem
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-10-03 18:42:33 +02:00
18 changed files with 514 additions and 77 deletions
+4 -3
View File
@@ -76,9 +76,10 @@ func (b *Bridge) Refresh(ctx context.Context) error {
if state == nil {
state = &hueSensorState{
index: index,
uniqueID: sensor.UniqueID,
externalID: -1,
index: index,
uniqueID: sensor.UniqueID,
externalID: -1,
presenceCooldown: -2,
}
b.sensorStates = append(b.sensorStates, state)
+24 -14
View File
@@ -92,7 +92,7 @@ type hueSensorState struct {
uniqueID string
prevData *SensorData
prevTime time.Time
presenceCooldown bool
presenceCooldown int
}
func (state *hueSensorState) Update(newData SensorData) *models.Event {
@@ -153,26 +153,36 @@ func (state *hueSensorState) Update(newData SensorData) *models.Event {
case "ZLLPresence":
{
if state.prevData != nil && state.prevData.State.Presence != newData.State.Presence {
name := models.ENSensorPresenceStarted
if !newData.State.Presence {
name = models.ENSensorPresenceEnding
state.presenceCooldown = true
}
if newData.State.Presence {
state.presenceCooldown = -1
return &models.Event{
Name: name,
Payload: map[string]string{
"deviceId": strconv.Itoa(state.externalID),
"deviceInternalId": newData.UniqueID,
},
return &models.Event{
Name: models.ENSensorPresenceStarted,
Payload: map[string]string{
"deviceId": strconv.Itoa(state.externalID),
"deviceInternalId": newData.UniqueID,
},
}
} else {
state.presenceCooldown = 0
}
} else if state.presenceCooldown && !newData.State.Presence && time.Since(stateTime) > time.Minute {
state.presenceCooldown = false
}
if state.presenceCooldown == -2 {
state.presenceCooldown = int(time.Since(stateTime) / time.Minute)
}
nextEventWait := time.Minute * time.Duration(state.presenceCooldown)
if state.presenceCooldown != -1 && !newData.State.Presence && time.Since(stateTime) > nextEventWait {
state.presenceCooldown += 1
return &models.Event{
Name: models.ENSensorPresenceEnded,
Payload: map[string]string{
"deviceId": strconv.Itoa(state.externalID),
"deviceInternalId": newData.UniqueID,
"minutesElapsed": strconv.Itoa(state.presenceCooldown - 1),
"secondsElapsed": strconv.Itoa((state.presenceCooldown - 1) * 60),
},
}
}
+13 -3
View File
@@ -37,12 +37,22 @@ func (b *bridge) Devices() []models.Device {
hue, sat, value := colorful.LinearRgb(red, green, blue).Hsv()
shapeType, shapeTypeOK := shapeTypeMap[panel.ShapeType]
if !shapeTypeOK {
shapeType = "NanoLeaf"
}
shapeIcon, shapeIconOK := shapeIconMap[panel.ShapeType]
if !shapeIconOK {
shapeIcon = "lightbulb"
}
results = append(results, models.Device{
ID: -1,
BridgeID: b.externalID,
InternalID: strconv.Itoa(int(panel.ID)),
Icon: "hexagon",
Name: fmt.Sprintf("Hexagon %d", i),
Icon: shapeIcon,
Name: fmt.Sprintf("%s %d", shapeType, i+1),
Capabilities: []models.DeviceCapability{
models.DCPower,
models.DCColorHS,
@@ -83,7 +93,7 @@ func (b *bridge) Refresh(ctx context.Context) error {
b.mu.Lock()
PanelLoop:
for _, panelInfo := range overview.PanelLayout.Data.PositionData {
if panelInfo.PanelID == 0 {
if shapeTypeMap[panelInfo.ShapeType] == "Shapes Controller" {
continue
}
+12
View File
@@ -135,6 +135,18 @@ var shapeTypeMap = map[int]string{
12: "Shapes Controller",
}
var shapeIconMap = map[int]string{
0: "triangle",
1: "rhythm",
2: "Square",
3: "square",
4: "square",
7: "hexagon",
8: "triangle",
9: "triangle-small",
12: "hexagon",
}
var shapeWidthMap = map[int]int{
0: 150,
1: -1,
+17 -2
View File
@@ -14,6 +14,8 @@ type eventHandlerRecord struct {
Priority int `db:"priority"`
TargetKind string `db:"target_kind"`
TargetValue string `db:"target_value"`
From *string `db:"from_tod"`
To *string `db:"to_tod"`
ConditionsJSON json.RawMessage `db:"conditions"`
ActionsJSON json.RawMessage `db:"actions"`
}
@@ -61,12 +63,14 @@ func (r *EventHandlerRepo) Save(ctx context.Context, handler *models.EventHandle
TargetValue: handler.TargetValue,
ConditionsJSON: conditionsJson,
ActionsJSON: actionsJson,
From: handler.From.StringPtr(),
To: handler.To.StringPtr(),
}
if record.ID == 0 {
res, err := r.DBX.NamedExecContext(ctx, `
INSERT INTO event_handler (event_name, one_shot, priority, target_kind, target_value, conditions, actions)
VALUES (:event_name, :one_shot, :priority, :target_kind, :target_value, :conditions, :actions);
INSERT INTO event_handler (event_name, one_shot, priority, target_kind, target_value, conditions, from_tod, to_tod, actions)
VALUES (:event_name, :one_shot, :priority, :target_kind, :target_value, :conditions, :from_tod, :to_tod, :actions);
`, record)
if err != nil {
return dbErr(err)
@@ -87,6 +91,8 @@ func (r *EventHandlerRepo) Save(ctx context.Context, handler *models.EventHandle
target_kind = :target_kind,
target_value = :target_value,
conditions = :conditions,
from_tod = :from_tod,
to_tod = :to_tod,
actions = :actions
WHERE id = :id
`, record)
@@ -139,6 +145,15 @@ func (r *EventHandlerRepo) populate(records []eventHandlerRecord) ([]models.Even
return nil, dbErr(err)
}
handler.From, err = models.ParseTimeOfDayPtr(record.From)
if err != nil {
return nil, dbErr(err)
}
handler.To, err = models.ParseTimeOfDayPtr(record.To)
if err != nil {
return nil, dbErr(err)
}
res = append(res, handler)
}