Skip to content
This repository was archived by the owner on Mar 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
8ba19d0
Adds a minimal example system and closes #14
lmas Dec 2, 2024
16bc5cc
minor cleanup
lmas Dec 3, 2024
b6728c4
Merge branch 'master' into ethermostat
lmas Dec 3, 2024
a9aa393
Merges in master and renames the system to influxdb
lmas Jan 22, 2025
2e3dbe9
added return statements to errors
Pake-TU Jan 24, 2025
5aea0b9
Added testfile
Pake-TU Jan 24, 2025
8800a7e
Installs dependencies for the tests too in the workflow
lmas Jan 24, 2025
c45cedf
added some tests
Pake-TU Jan 24, 2025
e0cf7f8
Removes unrelated systems
lmas Jan 24, 2025
ec99300
Merges in updates from workflow
lmas Jan 24, 2025
ab51c5a
Cleans up the example unitasset and system
lmas Jan 24, 2025
81fa3ec
removed comfortstat from zigbee branch
Pake-TU Jan 27, 2025
9ea6be5
Fixed test for newResource, now working
Pake-TU Jan 27, 2025
d6de189
added systemconfig template because it's needed for the tests
Pake-TU Jan 27, 2025
9996348
test
Pake-TU Jan 27, 2025
50d30ec
test2
Pake-TU Jan 27, 2025
4a1a5d7
Makefile back to normal
Pake-TU Jan 27, 2025
ba91d61
Fixed workflow (git tests)
Pake-TU Jan 27, 2025
665be03
Added new tests, work in progress
Pake-TU Jan 28, 2025
39a4dc4
Added new tests etc
Pake-TU Jan 28, 2025
99dc342
Tested pretty much all the code possible in things.go, moving on to Z…
Pake-TU Jan 29, 2025
e54fbd5
changed tests, and added new tests
Pake-TU Feb 3, 2025
af798aa
More tests, and fixed some problems with earlier tests
Pake-TU Feb 3, 2025
0c663de
Picks a better name for the system
lmas Feb 3, 2025
d95def2
Merges in master
lmas Feb 3, 2025
bb11160
issue #60: finalises the system setup
lmas Feb 3, 2025
a7aed2c
Fixed some merge comments
Pake-TU Feb 4, 2025
7b0c41d
Fixes spelling error on signal's unit
lmas Feb 4, 2025
b3ee023
finished #60: made an initial system that is able to collect data
lmas Feb 4, 2025
0e3dada
Adds collector and influxdb to docker-compose
lmas Feb 4, 2025
914ced5
changed a few comments
Pake-TU Feb 6, 2025
5d605be
Merge branch 'ZigBeeValve' of github.com:lmas/d0020e_code into ZigBee…
Pake-TU Feb 6, 2025
245145e
Added functions and other goodies
Pake-TU Feb 10, 2025
f5b76cf
Added test for getConnectedUnits()
Pake-TU Feb 11, 2025
9a9cbae
Fixed some PR comments
Pake-TU Feb 12, 2025
8f869d2
Added code for a WebsocketClient, needs to be tested on Raspberry Pi
Pake-TU Feb 13, 2025
75522b0
Forgot to add go.mod & go.sum files
Pake-TU Feb 13, 2025
ebbb495
Forgot to add a link to useful info, and a line of code to properly c…
Pake-TU Feb 13, 2025
5162103
Added an error message to pass linter in example code for listening t…
Pake-TU Feb 14, 2025
40042e2
new branch test
SimonPergel Jan 21, 2025
98498b9
new test file added
SimonPergel Jan 22, 2025
2d02dd0
Corrected the calculating function
Jan 22, 2025
70efeb1
Fixed API calls to only do it one time with several instances?
Jan 23, 2025
d5b10b9
Small fix to make the instances sleep a bit
Jan 23, 2025
6d27800
more tests added
SimonPergel Jan 23, 2025
8bf2a01
added more tests for the getters in things.go
SimonPergel Jan 23, 2025
e7611ef
Fixed API to not be called in init_template
Jan 24, 2025
f4154a0
Installs dependencies for the tests too in the workflow
lmas Jan 24, 2025
0824d80
fixed the set-functions in thing.go and added more tests
SimonPergel Jan 24, 2025
f8cf743
Added working tests for getters och setters functions
SimonPergel Jan 24, 2025
47bb06e
added some more tests
SimonPergel Jan 24, 2025
052a331
adding tests plus cleaning up things.go
SimonPergel Jan 28, 2025
e1070be
trying to test processfeedbackLoop
SimonPergel Jan 28, 2025
0194683
trying to test processfeedbackLoop
SimonPergel Jan 28, 2025
b043b42
cleand up some things
SimonPergel Jan 29, 2025
db36b3b
working in GetapiPrice test
SimonPergel Jan 29, 2025
2ae7a32
cleaned up some comments and added some comments to parts with no ex…
SimonPergel Jan 29, 2025
4e085bc
More tests
SimonPergel Jan 29, 2025
a4c09cd
not there yet, but the push tests are woring fine
SimonPergel Jan 30, 2025
1e40839
not there yet, but the pushed tests are working fine
SimonPergel Jan 30, 2025
6b2253a
more tests
SimonPergel Jan 30, 2025
f037c09
fixes testing bad body
lmas Jan 30, 2025
1176878
test for things.go is completed
SimonPergel Jan 30, 2025
487a675
added working test of the GET parts
SimonPergel Jan 31, 2025
2503417
cleaned up and added some comments to clarify diffrent parts
SimonPergel Feb 2, 2025
bad24d0
added test for the PUT part in Comfortstat.go
SimonPergel Feb 3, 2025
f7f4673
Updated newUnitAsset
SimonPergel Feb 3, 2025
f86d739
updated getapiprice function to match linter tests
SimonPergel Feb 3, 2025
c095e91
added a part that validate the url in getApiPricedata
SimonPergel Feb 4, 2025
962f02e
added error handling in getApiPricedata
SimonPergel Feb 4, 2025
41cf05a
added error handling in the pricefeedbackloop
SimonPergel Feb 4, 2025
d903944
added error handling in pricefeedbackloop
SimonPergel Feb 4, 2025
fcf56c3
cleaned up some log.prints in the set-functions
SimonPergel Feb 4, 2025
6d04361
moved the check for the statuscode to the right place, before reading…
SimonPergel Feb 4, 2025
ac17486
fixed so that i run the tests directly after the fuction call
SimonPergel Feb 4, 2025
9602770
changed the name to a more suitable name
SimonPergel Feb 4, 2025
aabd58e
Reverts " changed the name to a more suitable name"
lmas Feb 4, 2025
896b92a
changed to a more suitable name
SimonPergel Feb 4, 2025
750739f
replaced the sleep in things.go to Comfortstat.go
Feb 5, 2025
9f2aec8
Added user temperature to the comfortstat
Feb 7, 2025
f5734c9
added some comments and removed emty lines
SimonPergel Feb 7, 2025
3150c3c
fixed the setter-methods
SimonPergel Feb 7, 2025
07796b9
Added special case for the user temp
Feb 10, 2025
68988ce
Changed userTemp to UserTemp so it is exported as json
Feb 10, 2025
2679a32
cleaned up some emty rows and created some explanatory comments
SimonPergel Feb 11, 2025
77d7fce
Resolved all the comments in the review part
SimonPergel Feb 11, 2025
fe99ea1
Removed one feedbackloop as it was unnecessary, fixed the hourly pric…
Feb 11, 2025
78ceb6d
added so the user can choose price region
SimonPergel Feb 12, 2025
a728e2f
cleand up the new switchRegion function and added some comments
SimonPergel Feb 12, 2025
5e304d5
Added tests for the newly implemented features(Usertemp and REgion c…
SimonPergel Feb 13, 2025
bb0a152
Cleand up the new funtions that have been implemented
SimonPergel Feb 13, 2025
0c05591
Merge remote-tracking branch 'origin/dev' into ZigBeeValve
lmas Feb 14, 2025
9ff159b
Removes uninteresting log line
lmas Feb 14, 2025
a517104
Merge pull request #74 from lmas/ZigBeeValve
lmas Feb 14, 2025
e3b9bc1
Adds new linter
lmas Jan 24, 2025
181419a
Ignores test files while running gocyclo
lmas Feb 12, 2025
007791e
Adds spellchecking tool
lmas Feb 14, 2025
d726bc4
Fixes all the speeeeling errors
lmas Feb 14, 2025
33880a8
Adds manual spellcheck to makefile
lmas Feb 14, 2025
619780a
Updates system to reflect latest updates in dev branch
lmas Feb 14, 2025
eeedbc7
Merge branch 'dev' into influxdb
lmas Feb 14, 2025
88abfe1
Adds spellcheck config and ignore a word
lmas Feb 14, 2025
b521dd0
Fixes some small typos (only a few compared to the others huehue)
lmas Feb 14, 2025
bac617b
Merge pull request #75 from lmas/influxdb
lmas Feb 14, 2025
54d1fa1
Fixes some small things in comfortstat
lmas Feb 14, 2025
d6337f8
Make the influxdb shut up and stop spamming the logs
lmas Feb 14, 2025
94a0d64
More tiny fixes on json data
lmas Feb 14, 2025
5febf8c
Force use local timezone on docker
lmas Feb 14, 2025
20e7673
Fixes *even harder* the docker timezones
lmas Feb 14, 2025
714e345
no longer uses index, uses uniqueid to send requests via zigbee gatew…
Pake-TU Feb 14, 2025
55a5eff
Merge branch 'dev' of github.com:lmas/d0020e_code into dev
Pake-TU Feb 14, 2025
cfe6465
Adds project description and a silly Oxford comma
lmas Feb 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests and Linters
name: Linters, Spellcheck, and Tests

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
jobs:
Linters:
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- name: Setup go
Expand All @@ -19,15 +19,24 @@ jobs:
- name: Run linters
run: make lint

Spellcheck:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- uses: crate-ci/[email protected]

Tests:
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Install dependencies
run: make deps
- name: Run tests
run: make test
- name: Report stats
Expand Down
138 changes: 94 additions & 44 deletions Comfortstat/Comfortstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
// instantiate the System
sys := components.NewSystem("Comfortstat", ctx)

// Instatiate the Capusle
// Instantiate the Capsule
sys.Husk = &components.Husk{
Description: " is a controller for a consumed servo motor position based on a consumed temperature",
Certificate: "ABCD",
Expand All @@ -31,6 +31,9 @@ func main() {

// instantiate a template unit asset
assetTemplate := initTemplate()
// Calling initAPI() starts the pricefeedbackloop that fetches the current electricity price for the particular hour
initAPI()
time.Sleep(1 * time.Second)
assetName := assetTemplate.GetName()
sys.UAssets[assetName] = &assetTemplate

Expand All @@ -45,8 +48,8 @@ func main() {
if err := json.Unmarshal(raw, &uac); err != nil {
log.Fatalf("Resource configuration error: %+v\n", err)
}
ua, cleanup := newUnitAsset(uac, &sys, servsTemp)
defer cleanup()
ua, startup := newUnitAsset(uac, &sys, servsTemp)
startup()
sys.UAssets[ua.GetName()] = &ua
}

Expand All @@ -66,117 +69,164 @@ func main() {
time.Sleep(2 * time.Second) // allow the go routines to be executed, which might take more time than the main routine to end
}

// TODO: change the namne, will get one function for each of the four cases
// Serving handles the resources services. NOTE: it exepcts those names from the request URL path
// Serving handles the resources services. NOTE: it expects those names from the request URL path
func (t *UnitAsset) Serving(w http.ResponseWriter, r *http.Request, servicePath string) {
switch servicePath {
case "min_temperature":
t.set_minTemp(w, r)
case "max_temperature":
t.set_maxTemp(w, r)
case "max_price":
t.set_maxPrice(w, r)
case "min_price":
t.set_minPrice(w, r)
case "SEK_price":
t.set_SEKprice(w, r)
case "desired_temp":
t.set_desiredTemp(w, r)
case "MinTemperature":
t.httpSetMinTemp(w, r)
case "MaxTemperature":
t.httpSetMaxTemp(w, r)
case "MaxPrice":
t.httpSetMaxPrice(w, r)
case "MinPrice":
t.httpSetMinPrice(w, r)
case "SEKPrice":
t.httpSetSEKPrice(w, r)
case "DesiredTemp":
t.httpSetDesiredTemp(w, r)
case "userTemp":
t.httpSetUserTemp(w, r)
case "Region":
t.httpSetRegion(w, r)
default:
http.Error(w, "Invalid service request [Do not modify the services subpath in the configurration file]", http.StatusBadRequest)
}
}

func (rsc *UnitAsset) set_SEKprice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetSEKPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
signalErr := rsc.getSEK_price()
signalErr := rsc.getSEKPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

// TODO: split up this function to two sepreate function that sets on max and min price.
func (rsc *UnitAsset) set_minTemp(w http.ResponseWriter, r *http.Request) {
// All these functions below handles HTTP "PUT" or "GET" requests to modefy or retrieve the MAX/MIN temprature/price and desierd temperature
// For the PUT case - the "HTTPProcessSetRequest(w, r)" is called to prosses the data given from the user and if no error,
// call the set functions in things.go with the value witch updates the value in the struct
func (rsc *UnitAsset) httpSetMinTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return

}
rsc.setMin_temp(sig)
rsc.setMinTemp(sig)
case "GET":
signalErr := rsc.getMin_temp()
signalErr := rsc.getMinTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}
func (rsc *UnitAsset) set_maxTemp(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetMaxTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setMaxTemp(sig)
case "GET":
signalErr := rsc.getMaxTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

func (rsc *UnitAsset) httpSetMinPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setMax_temp(sig)
rsc.setMinPrice(sig)
case "GET":
signalErr := rsc.getMax_temp()
signalErr := rsc.getMinPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)

}
}

// LOOK AT: I guess that we probable only need to if there is a PUT from user?
// LOOK AT: so not the GET!
// For PUT - the "HTTPProcessSetRequest(w, r)" is called to prosses the data given from the user and if no error, call set_minMaxprice with the value
// wich updates the value in thge struct
func (rsc *UnitAsset) set_minPrice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetMaxPrice(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setMin_price(sig)
rsc.setMaxPrice(sig)
case "GET":
signalErr := rsc.getMin_price()
signalErr := rsc.getMaxPrice()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)

}
}

func (rsc *UnitAsset) set_maxPrice(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetDesiredTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
//log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setMax_price(sig)
rsc.setDesiredTemp(sig)
case "GET":
signalErr := rsc.getMax_price()
signalErr := rsc.getDesiredTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}

}

func (rsc *UnitAsset) httpSetUserTemp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setUserTemp(sig)
case "GET":
signalErr := rsc.getUserTemp()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
}
}

func (rsc *UnitAsset) set_desiredTemp(w http.ResponseWriter, r *http.Request) {
func (rsc *UnitAsset) httpSetRegion(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
sig, err := usecases.HTTPProcessSetRequest(w, r)
if err != nil {
log.Println("Error with the setting request of the position ", err)
http.Error(w, "request incorrectly formatted", http.StatusBadRequest)
return
}
rsc.setDesired_temp(sig)
rsc.setRegion(sig)
case "GET":
signalErr := rsc.getDesired_temp()
signalErr := rsc.getRegion()
usecases.HTTPProcessGetRequest(w, r, &signalErr)
default:
http.Error(w, "Method is not supported.", http.StatusNotFound)
Expand Down
Loading