Skip to content

Commit

Permalink
优化场景联动
Browse files Browse the repository at this point in the history
  • Loading branch information
smthing committed Jun 13, 2024
1 parent fd7c73b commit a5b61d1
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions driverbox/export/linkedge/linkedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ func (linkEdge *service) triggerLinkEdge(id string, depth int, conf ...ModelConf
return errors.New("check condition error: " + e.Error())
}

//组合相同设备的点位action
actions := make(map[string][]plugin.PointData)
sucCount := 0
//执行动作
for _, action := range config.Action {
Expand Down Expand Up @@ -405,17 +407,26 @@ func (linkEdge *service) triggerLinkEdge(id string, depth int, conf ...ModelConf
helper.Logger.Error(fmt.Sprintf("execute linkEdge:%s action error:%s", id, e.Error()))
continue
}
err := core.SendSinglePoint(devicePointAction.DeviceId, plugin.WriteMode, plugin.PointData{
points, ok := actions[devicePointAction.DeviceId]
if !ok {
points = make([]plugin.PointData, 0)
}
points = append(points, plugin.PointData{
PointName: devicePointAction.DevicePoint,
Value: devicePointAction.Value,
})
if err != nil {
helper.Logger.Error("execute linkEdge error", zap.String("linkEdge", id),
zap.String("pointName", devicePointAction.DevicePoint), zap.String("pointValue", devicePointAction.Value), zap.Error(err))
} else {
sucCount++
helper.Logger.Info(fmt.Sprintf("execute linkEdge:%s action", id))
}
actions[devicePointAction.DeviceId] = points
//err := core.SendSinglePoint(devicePointAction.DeviceId, plugin.WriteMode, plugin.PointData{
// PointName: devicePointAction.DevicePoint,
// Value: devicePointAction.Value,
//})
//if err != nil {
// helper.Logger.Error("execute linkEdge error", zap.String("linkEdge", id),
// zap.String("pointName", devicePointAction.DevicePoint), zap.String("pointValue", devicePointAction.Value), zap.Error(err))
//} else {
// sucCount++
// helper.Logger.Info(fmt.Sprintf("execute linkEdge:%s action", id))
//}
break
//触发下一个场景联动
case ActionTypeLinkEdge:
Expand All @@ -440,6 +451,18 @@ func (linkEdge *service) triggerLinkEdge(id string, depth int, conf ...ModelConf
}
}
}
//遍历执行acitons
for deviceId, points := range actions {
err := core.SendBatchWrite(deviceId, points)
if err != nil {
helper.Logger.Error("execute linkEdge error", zap.String("linkEdge", id),
zap.String("deviceId", deviceId), zap.Any("points", points), zap.Error(err))
} else {
sucCount = sucCount + len(points)
helper.Logger.Info(fmt.Sprintf("execute linkEdge:%s action", id))
}
}
//预览情况下未持久化场景联动,id为空
if id != "" {
// value:全部成功\部分成功\全部失败
if sucCount == len(config.Action) {
Expand Down

0 comments on commit a5b61d1

Please sign in to comment.