-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implemented in go to reduce memory amount * position commands * publish positions * feat: support tilt * listen to mqtt * chore: build infrastructure for go chore: build infrastructure for go fix(ci): fix the build * chore(deps): update go to 1.23 * update docu
- Loading branch information
1 parent
5ba74ed
commit b832788
Showing
54 changed files
with
916 additions
and
15,871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,6 @@ config-auth.json | |
.DS_Store | ||
|
||
.idea | ||
*.iml | ||
*.iml | ||
|
||
eltako-to-mqtt-gw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="run" type="GoApplicationRunConfiguration" factoryName="Go Application"> | ||
<module name="miele-to-mqtt-gw" /> | ||
<working_directory value="$PROJECT_DIR$/v2" /> | ||
<parameters value="../production/config/config.json" /> | ||
<kind value="PACKAGE" /> | ||
<package value="github.com/mqtt-home/eltako-to-mqtt-gw" /> | ||
<directory value="$PROJECT_DIR$" /> | ||
<filePath value="$PROJECT_DIR$/v2/main.go" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Build the application from source | ||
FROM golang:1.23 AS build-stage | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . ./ | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o /eltako-to-mqtt-gw | ||
|
||
# Run the tests in the container | ||
FROM build-stage AS run-test-stage | ||
RUN go test -v ./... | ||
|
||
# Deploy the application binary into a lean image | ||
FROM gcr.io/distroless/base-debian11 AS build-release-stage | ||
|
||
WORKDIR / | ||
|
||
COPY --from=build-stage /eltako-to-mqtt-gw /eltako-to-mqtt-gw | ||
|
||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/eltako-to-mqtt-gw", "/var/lib/eltako-to-mqtt-gw/config.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Makefile for Go application | ||
|
||
# Set the Go binary and flags | ||
GO = go | ||
GOFLAGS = -v | ||
|
||
# Set the paths | ||
BUILD_DIR = build | ||
CONFIG_DIR = $(PWD)/../production/config | ||
|
||
# Set the binary name | ||
BINARY_NAME = eltako-to-mqtt-gw | ||
DOCKER_IMAGE_NAME = pharndt/eltako:latest | ||
|
||
.PHONY: build | ||
build: | ||
@echo "Building the application..." | ||
@$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) . | ||
|
||
.PHONY: run | ||
run: build | ||
@echo "Running the application..." | ||
@$(BUILD_DIR)/$(BINARY_NAME) $(CONFIG_DIR)/config.json | ||
|
||
.PHONY: docker | ||
docker: build | ||
@echo "Building Docker image..." | ||
@docker build -t $(DOCKER_IMAGE_NAME) . | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "Cleaning up..." | ||
@rm -rf $(BUILD_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package commands | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type ActionType string | ||
|
||
func (a *ActionType) UnmarshalJSON(data []byte) error { | ||
var s string | ||
if err := json.Unmarshal(data, &s); err != nil { | ||
return err | ||
} | ||
*a = ActionType(strings.ToLower(s)) | ||
return nil | ||
} | ||
|
||
const ( | ||
ActionClose ActionType = "close" | ||
ActionOpen ActionType = "open" | ||
ActionSet ActionType = "set" | ||
ActionCloseAndOpenBlinds ActionType = "closeandopenblinds" | ||
ActionTilt ActionType = "tilt" | ||
) | ||
|
||
type Action struct { | ||
Action ActionType `json:"action"` | ||
Position int `json:"position"` | ||
} | ||
|
||
func Parse(data []byte) (LLCommand, error) { | ||
var command Action | ||
err := json.Unmarshal(data, &command) | ||
|
||
if err == nil { | ||
return command.validate() | ||
} | ||
|
||
return LLCommand{}, err | ||
} | ||
|
||
func (c *Action) validate() (LLCommand, error) { | ||
llc := LLCommand{} | ||
switch strings.ToLower(string(c.Action)) { | ||
case string(ActionClose): | ||
llc.Action = LLActionSet | ||
llc.Position = 0 | ||
case string(ActionOpen): | ||
llc.Action = LLActionSet | ||
llc.Position = 100 | ||
case string(ActionSet): | ||
fallthrough | ||
case "": | ||
llc.Action = LLActionSet | ||
llc.Position = c.Position | ||
case string(ActionCloseAndOpenBlinds): | ||
llc.Action = LLActionTilt | ||
llc.Position = 0 | ||
case string(ActionTilt): | ||
llc.Action = LLActionTilt | ||
llc.Position = c.Position | ||
default: | ||
return llc, fmt.Errorf("invalid action") | ||
} | ||
|
||
return llc, nil | ||
} |
Oops, something went wrong.