Skip to content

Commit 54217b9

Browse files
committed
First commit
0 parents  commit 54217b9

File tree

19 files changed

+1035
-0
lines changed

19 files changed

+1035
-0
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
pull_request:
9+
types: [opened, reopened]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version: 1.19
23+
24+
- name: Install dependencies
25+
run: go mod download
26+
27+
- name: Build
28+
run: go build -o sconnector-cli .
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: binaries
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
jobs:
9+
releases-matrix:
10+
name: Release Go Binary
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
# build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
15+
goos: [linux, windows, darwin]
16+
goarch: ["386", amd64, arm64]
17+
exclude:
18+
- goarch: "386"
19+
goos: darwin
20+
- goarch: arm64
21+
goos: windows
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: alexbacchin/[email protected]
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
goos: ${{ matrix.goos }}
28+
goarch: ${{ matrix.goarch }}
29+
goversion: "https://go.dev/dl/go1.19.7.linux-amd64.tar.gz"
30+
binary_name: "sconnector-cli"
31+
ldflags: "-X 'github.com/alexbacchin/ConnectorBridgeCLI/cmd.version=${{ github.ref_name }}'"
32+
33+
releases-matrix-arm:
34+
name: Release Go Binary ARM
35+
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
goos: [linux]
39+
goarch: [arm]
40+
goarm: ["6","7"]
41+
steps:
42+
- uses: actions/checkout@v3
43+
- uses: wangyoucao577/go-release-action@master
44+
with:
45+
github_token: ${{ secrets.GITHUB_TOKEN }}
46+
goos: ${{ matrix.goos }}
47+
goarch: ${{ matrix.goarch }}
48+
goarm: ${{ matrix.goarm }}
49+
goversion: "https://go.dev/dl/go1.19.7.linux-amd64.tar.gz"
50+
binary_name: "sconnector-cli"
51+
ldflags: "-X 'github.com/alexbacchin/ConnectorBridgeCLI/cmd.version=${{ github.ref_name }}'"

.github/workflows/release-docker.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: docker
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
9+
10+
jobs:
11+
docker:
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v3
17+
-
18+
name: Set up QEMU
19+
uses: docker/setup-qemu-action@v2
20+
-
21+
name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v2
23+
-
24+
name: Login to Docker Hub
25+
uses: docker/login-action@v2
26+
with:
27+
username: ${{ secrets.DOCKERHUB_USERNAME }}
28+
password: ${{ secrets.DOCKERHUB_TOKEN }}
29+
-
30+
name: Build and push
31+
uses: docker/build-push-action@v4
32+
with:
33+
context: .
34+
file: build/builder/Dockerfile
35+
platforms: linux/amd64,linux/arm64,linux/arm/v7
36+
push: true
37+
tags: alexbacchin/sconnector-cli:${{ github.ref_name }}, alexbacchin/sconnector-cli:latest
38+
build-args: SCONNECTOR_CLI_VERSION=${{ github.ref_name }}

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
*.code-workspace
23+
.vscode

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Alex Bacchin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# ConnectorBridgeCLI
3+
4+
5+
This ConnectorBridgeCLI allows for both directly controlling blinds that support wifi-connection and controlling Uni- and Bi-direction blinds that connect to a 433MHz WiFi bridge. The following bridges are reported to work with this integration:
6+
7+
- CM-20 Motion Blinds bridge
8+
- CMD-01 Motion Blinds mini-bridge
9+
- DD7002B Connector bridge
10+
- D1554 Connector mini-bridge
11+
- DD7002B Brel-Home box
12+
- D1554 Brel Home USB plug
13+
14+
15+
This ConnectorBridgeCLI integration allows you to control the following brands:
16+
17+
- AMP Motorization
18+
- Bliss Automation - Alta Window Fashions
19+
- Bloc Blinds
20+
- Brel Home
21+
- 3 Day Blinds
22+
- Diaz
23+
- Dooya
24+
- Gaviota
25+
- Havana Shade
26+
- Hurrican Shutters Wholesale
27+
- Inspired Shades
28+
- iSmartWindow
29+
- Martec
30+
- Motion Blinds
31+
- Raven Rock MFG
32+
- ScreenAway
33+
- Smart Blinds
34+
- Smart Home
35+
- Uprise Smart Shades
36+
- No Bull Blinds
37+
38+
## Configuration
39+
40+
The default communication is via Multicast, but it might not work on your network. You can override with the Bridge IP address.
41+
42+
1. Find your bridge IP address. You might need to look at your router
43+
2. The bridge port is set to 31200. Unlikely the default value needs to be changed
44+
3. Retrieve the API key from the mobile app. Settings -> About -> Tap 5 times anywhere on the screen
45+
4. Devices IDs are usually the same as set on the remote control.
46+
5. Download the executable from [Releases](https://github.com/alexbacchin/ConnectorBridgeCLI/releases) page
47+
48+
### Variables
49+
Flag | Environment Variable | Description |
50+
|--|--|--|
51+
| --host |CONNECTOR_BRIDGE_HOST | The hostname of IP address of the Connector Bridge -0 |
52+
| --port |CONNECTOR_BRIDGE_PORT | The port for the Connector Bridge connection. Default 31200 |
53+
| --apikey | CONNECTOR_BRIDGE_APIKEY | The ApiKey to authenticate with Connector Bridge |
54+
55+
```bash
56+
sconnector-cli <command> <device_id> --host=192.168.0.189 --apikey=<Bridge API key> --port=31200
57+
```
58+
```bash
59+
export CONNECTOR_BRIDGE_HOST=192.168.0.189
60+
export CONNECTOR_BRIDGE_APIKEY=<Bridge API key>
61+
sconnector-cli <command> <device_id>
62+
```
63+
## Commands
64+
The following commands were added on this:
65+
66+
### Open, Close and Stop
67+
Send the command to the device
68+
```
69+
sconnector-cli open 1 --host=192.168.0.189 --apikey=<Bridge API key>
70+
sconnector-cli stop 1 --host=192.168.0.189 --apikey=<Bridge API key>
71+
sconnector-cli close 1 --host=192.168.0.189 --apikey=<Bridge API key>
72+
```
73+
### Set Position
74+
Send the command to set the position the device. Position must be between 0 and 100
75+
```bash
76+
sconnector-cli set-position 1 50 --host=192.168.0.189 --apikey=<Bridge API key>
77+
```
78+
### Server
79+
Start a API Server to receive commands via HTTP, this is useful to integrate with other devices that do not support command line.
80+
This command has extra settings:
81+
| Flag | Environment Variable | Description |
82+
|--|--|--|
83+
| --server-port | CONNECTOR_API_SERVER_PORT | The listening port for the web server. Default 8080 |
84+
| --server-apikey | CONNECTOR_API_SERVER_APIKEY | The API Key to be used when requesting to the web server (Header: X-API-Key) |
85+
86+
Running the server
87+
```bash
88+
export CONNECTOR_BRIDGE_HOST=192.168.0.189
89+
export CONNECTOR_BRIDGE_APIKEY=<Bridge API key>
90+
sconnector-cli server --server-apikey=ControlMe!
91+
```
92+
To stop exit the server CTRL+C
93+
94+
#### Server Paths
95+
The commands are available with simple GET
96+
/open/<device_id>
97+
/close/<device_id>
98+
/stop/<device_id>
99+
/position/<device_id>/<position>
100+
101+
Sending a request to the server:
102+
```bash
103+
curl -H "X-API-Key: ControlMe!" http://localhost:8080/open/1
104+
```
105+
### Docker
106+
Docker images https://hub.docker.com/r/alexbacchin/sconnector-cli
107+

build/builder/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
##
2+
## STEP 1 - BUILD
3+
##
4+
ARG SCONNECTOR_CLI_VERSION=0.0.1
5+
# specify the base image to be used for the application, alpine or ubuntu
6+
FROM golang:1.19-alpine AS build
7+
8+
# create a working directory inside the image
9+
WORKDIR /app
10+
11+
# copy Go modules and dependencies to image
12+
COPY go.mod ./
13+
14+
# download Go modules and dependencies
15+
RUN go mod download
16+
17+
ADD . ./
18+
19+
# compile application
20+
RUN CGO_ENABLED=0 GOOS=linux go build -o sconnector-cli -ldflags "-X 'github.com/alexbacchin/ConnectorBridgeCLI/cmd.version=${SCONNECTOR_CLI_VERSION}'"
21+
22+
##
23+
## STEP 2 - DEPLOY
24+
##
25+
FROM alpine:latest
26+
27+
WORKDIR /
28+
USER 1001
29+
COPY --from=build --chown=1001 /app/sconnector-cli /
30+
31+
EXPOSE 8080
32+
ENTRYPOINT [ "/sconnector-cli" ]

cmd/close.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"strconv"
9+
10+
"github.com/alexbacchin/ConnectorBridgeCLI/pkg/shadeconnector"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// closeCmd represents the close command
15+
var closeCmd = &cobra.Command{
16+
Use: "close [device id]",
17+
Short: "Send the close operation to a Device",
18+
Long: `Send the close operation to the device via the UDP.`,
19+
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
20+
Run: func(cmd *cobra.Command, args []string) {
21+
shadeconnector.Init(host, port, apiKey)
22+
device_id, err := strconv.Atoi(args[0])
23+
if err != nil {
24+
fmt.Printf("device ID must me a number: %s", err)
25+
return
26+
}
27+
shadeconnector.Operation(device_id, int(shadeconnector.Close))
28+
fmt.Printf("Close device %s sucessfully", args[0])
29+
fmt.Println()
30+
31+
},
32+
}
33+
34+
func init() {
35+
rootCmd.AddCommand(closeCmd)
36+
}

cmd/open.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"strconv"
9+
10+
"github.com/alexbacchin/ConnectorBridgeCLI/pkg/shadeconnector"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// openCmd represents the open command
15+
var openCmd = &cobra.Command{
16+
Use: "open [device id]",
17+
Short: "Send the Open operation to a Device",
18+
Long: `Send the open operation to the device via the UDP.`,
19+
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
20+
Run: func(cmd *cobra.Command, args []string) {
21+
shadeconnector.Init(host, port, apiKey)
22+
device_id, err := strconv.Atoi(args[0])
23+
if err != nil {
24+
fmt.Printf("device ID must me a number: %s", err)
25+
return
26+
}
27+
shadeconnector.Operation(device_id, int(shadeconnector.Open))
28+
fmt.Printf("Open device %s sucessfully", args[0])
29+
fmt.Println()
30+
},
31+
}
32+
33+
func init() {
34+
rootCmd.AddCommand(openCmd)
35+
36+
}

0 commit comments

Comments
 (0)