Skip to content

Commit

Permalink
Develop (#210)
Browse files Browse the repository at this point in the history
* issues #64 technical debt
* fix script binds
* update sun and moon plugins
* update weather met
* update weather owm
  • Loading branch information
e154 authored Sep 1, 2022
1 parent 83a8414 commit 1483df8
Show file tree
Hide file tree
Showing 101 changed files with 1,826 additions and 1,779 deletions.
9 changes: 7 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (

"github.com/e154/smart-home/api/controllers"
gw "github.com/e154/smart-home/api/stub/api"
"github.com/e154/smart-home/common"
"github.com/e154/smart-home/common/logger"
"github.com/e154/smart-home/system/rbac"
)
Expand Down Expand Up @@ -213,7 +212,13 @@ func (a *Api) Start() (err error) {
r.URL, _ = r.URL.Parse(r.RequestURI)
fileServer.ServeHTTP(w, r)
})
httpv1.Handle("/api_static", http.FileServer(http.Dir(common.StoragePath())))
//httpv1.Handle("/api_static", http.FileServer(http.Dir(common.StoragePath())))
fileServer2 := http.FileServer(http.Dir("./data/static"))
httpv1.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
r.RequestURI = strings.ReplaceAll(r.RequestURI, "/static/", "/")
r.URL, _ = r.URL.Parse(r.RequestURI)
fileServer2.ServeHTTP(w, r)
})

// swagger
if a.cfg.Swagger {
Expand Down
14 changes: 13 additions & 1 deletion api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5089,6 +5089,16 @@
"items": {
"$ref": "#/definitions/apiAttribute"
}
},
"map": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/apiAttribute"
}
},
"time": {
"type": "string",
"format": "date-time"
}
}
},
Expand Down Expand Up @@ -7019,7 +7029,9 @@
"STRING",
"FLOAT",
"BOOL",
"ARRAY"
"ARRAY",
"MAP",
"TIME"
],
"default": "INT"
},
Expand Down
16 changes: 16 additions & 0 deletions api/dto/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ import (
"github.com/e154/smart-home/api/stub/api"
"github.com/e154/smart-home/common"
m "github.com/e154/smart-home/models"
"google.golang.org/protobuf/types/known/timestamppb"
)

// AttributeFromApi ...
func AttributeFromApi(apiAttr map[string]*api.Attribute) (attributes m.Attributes) {
return attributeFromApi(apiAttr)
}

func attributeFromApi(apiAttr map[string]*api.Attribute) (attributes m.Attributes) {
attributes = make(m.Attributes)
for k, v := range apiAttr {
attr := &m.Attribute{
Expand All @@ -47,6 +52,12 @@ func AttributeFromApi(apiAttr map[string]*api.Attribute) (attributes m.Attribute
case api.Types_ARRAY:
// attr.Value = v.GetArray()
attr.Type = common.AttributeArray
case api.Types_MAP:
attr.Type = common.AttributeMap
attr.Value = AttributeFromApi(v.GetMap())
case api.Types_TIME:
attr.Value = v.GetTime().AsTime()
attr.Type = common.AttributeTime
}
attributes[k] = attr
}
Expand Down Expand Up @@ -75,6 +86,11 @@ func AttributeToApi(attributes m.Attributes) (apiAttr map[string]*api.Attribute)
apiAttr[k].Float = common.Float32(float32(v.Float64()))
case "array":
apiAttr[k].Type = api.Types_ARRAY
case "map":
apiAttr[k].Type = api.Types_MAP
case "time":
apiAttr[k].Type = api.Types_TIME
apiAttr[k].Time = timestamppb.New(v.Time())
}
}
return
Expand Down
6 changes: 6 additions & 0 deletions api/protos/attributes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ package api;

option go_package = "/api";

import "google/protobuf/timestamp.proto";

enum Types {
INT = 0;
STRING = 1;
FLOAT = 2;
BOOL = 3;
ARRAY = 4;
MAP = 5;
TIME = 6;
}

message Attribute {
Expand All @@ -20,4 +24,6 @@ message Attribute {
optional bool bool = 5;
optional float float = 6;
repeated Attribute array = 7;
map<string, Attribute> map = 8;
optional google.protobuf.Timestamp time = 9;
}
5 changes: 2 additions & 3 deletions api/stub/api/area.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/stub/api/area_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 81 additions & 40 deletions api/stub/api/attributes.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/stub/api/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/stub/api/auth_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/stub/api/automation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/stub/api/automation_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/stub/api/backup.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1483df8

Please sign in to comment.