Skip to content

Commit

Permalink
feat: initial code (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma committed Oct 22, 2023
1 parent baef86f commit 6aae65d
Show file tree
Hide file tree
Showing 13 changed files with 627 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
push:
tags:
- '*'

name: release
jobs:
release:

runs-on: ubuntu-latest
env:
GO_VERSION: "1.21"

steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout code
uses: actions/checkout@v4

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- main
pull_request:

name: run tests
jobs:
test:

runs-on: ubuntu-latest
env:
GOOS: js
GOARCH: wasm
GO_VERSION: "1.21"
GOLANGCI_LINT_VERSION: v1.55.0

steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout code
uses: actions/checkout@v4

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run linter
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
skip-pkg-cache: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
51 changes: 51 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
run:
tests: false
deadline: 5m

linters-settings:
gofumpt:
extra-rules: true

linters:
enable-all: true
disable:
- interfacebloat
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- interfacer # deprecated
- scopelint # deprecated
- maligned # deprecated
- golint # deprecated
- deadcode # deprecated
- exhaustivestruct # deprecated
- ifshort # deprecated
- nosnakecase # deprecated
- structcheck # deprecated
- varcheck # deprecated
- cyclop # duplicate of gocyclo
- depguard
- exhaustive
- exhaustruct
- forcetypeassert
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- gocyclo
- goerr113
- gomnd
- ireturn
- nestif
- nlreturn
- nonamedreturns
- tagliatelle
- varnamelen
- wrapcheck
- wsl

issues:
exclude-use-default: false
exclude:
- 'ST1000: at least one file in a package should have a package comment'
- 'package-comments: should have a package comment'
35 changes: 35 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
project_name: solar
dist: dist

gomod:
proxy: true

builds:
- main: ./
binary: "{{ .ProjectName }}"
goos:
- js
goarch:
- wasm
env:
- CGO_ENABLED=0

archives:
- format: binary
name_template: '{{ .Binary }}'

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^doc:'
- '^tests:'
- '^test:'
- '^chore:'

checksum:
name_template: '{{ .ProjectName }}_checksums.txt'

snapshot:
name_template: "{{ .Tag }}"
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
GOOS=js
GOARCH=wasm

export GOOS
export GOARCH

# Format all files
fmt:
@echo "==> Formatting source"
@gofmt -s -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
@echo "==> Done"
.PHONY: fmt

# Tidy the go.mod file
tidy:
@echo "==> Cleaning go.mod"
@go mod tidy
@echo "==> Done"
.PHONY: tidy

# Lint the project
lint:
@echo "==> Linting Go files"
@golangci-lint run ./...
.PHONY: lint

# Run all tests
test:
@go test -cover ./...
.PHONY: test

# Build the commands
build:
@goreleaser release --clean --snapshot
.PHONY: build

39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
![Logo](http://svg.wiersma.co.za/glasslabs/module?title=CLOCK&tag=a%20simple%20clock%20module)

Clock is a simple clock module for [looking glass](http://github.com/glasslabs/looking-glass)

![Screenshot](.readme/screenshot.png)

## Usage

Clone the clock into a path under your modules path and add the module path
to under modules in your configuration.

```yaml
modules:
- name: simple-clock
url: https://github.com/glasslabs/clock/releases/download/v1.0.0/clock.wasm
position: top:right
config:
timeFormat: 15:04
```

## Configuration

### Time Format (timeFormat)

*Default: 15:04*

Formats the time display of the clock using Go's [time formatting syntax](https://golang.org/pkg/time/#Time.Format).

### Date Format (dateFormat)

*Default: Monday, January 2*

Formats the date display of the clock using Go's [time formatting syntax](https://golang.org/pkg/time/#Time.Format).

### Time Zone (timezone)

*Default: Local*

The timezone name according to [IANA Time Zone databse](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
31 changes: 31 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<svg viewBox="0 0 300 300" width="250" height="250">
<g id="chart">
<circle r="125" cx="150" cy="150" transform="rotate(123,150,150)"
fill="none" stroke="rgb(40,40,40)" stroke-width="45" stroke-dasharray="640.82 785.40"/>
<circle id="load" r="140" cx="150" cy="150" class="chart" style="--percentage: 0"/>
<circle id="pv" r="130" cx="150" cy="150" class="chart" style="--percentage: 0"/>
<circle id="battery" r="120" cx="150" cy="150" class="chart" style="--percentage: 0"/>
<circle id="grid" r="110" cx="150" cy="150" class="chart" style="--percentage: 0"/>
</g>

<g id="icons">
<path id="grid-disconnect" d="M 35.5246 29.8246 L 19.8005 3.7476 c -0.3974 -0.659 -1.1109 -1.062 -1.8805 -1.062 c -0.7696 0 -1.4832 0.4029 -1.8805 1.062 L 0.3154 29.8246 c -0.4089 0.6783 -0.421 1.5242 -0.0316 2.2138 c 0.3895 0.6896 1.1201 1.1161 1.9121 1.1161 h 31.4481 c 0.792 0 1.5226 -0.4265 1.9121 -1.1161 C 35.9456 31.3488 35.9335 30.5029 35.5246 29.8246 z M 22.5178 19.5906 l -5.911 8.0822 c -0.1345 0.1839 -0.379 0.2493 -0.5873 0.1571 c -0.2083 -0.0922 -0.3244 -0.317 -0.2787 -0.5403 l 1.2289 -6.0082 H 13.9384 c -0.2927 0 -0.5605 -0.1644 -0.6929 -0.4254 c -0.1324 -0.261 -0.1071 -0.5743 0.0657 -0.8105 l 5.911 -8.0823 c 0.1345 -0.1839 0.379 -0.2493 0.5873 -0.1571 c 0.2084 0.0922 0.3244 0.317 0.2787 0.5403 l -1.2289 6.0082 h 3.0313 c 0.2927 0 0.5605 0.1644 0.6929 0.4254 C 22.716 19.041 22.6906 19.3544 22.5178 19.5906 z"
transform="translate(130,185)"
fill="rgb(242, 73, 92)"
class="off"
/>
</g>

<g id="batterySoC" style="--percentage: 0">
<rect x="105" y="240" width="90" height="28" rx="2" ry="2"
fill="none" stroke="rgb(100,100,100)"/>
<rect x="107" y="242" height="24" width="86" class="fill"/>
<text x="150" y="255" dominant-baseline="middle" text-anchor="middle" class="value">0%</text>
</g>

<text id="loadText" x="50%" y="50%" class="number" dominant-baseline="middle" text-anchor="middle">
<tspan class="super"></tspan>
<tspan class="sub" dx="-20" dy="6"></tspan>
<tspan class="units" dx="-10" dy="6">kWh</tspan>
</text>
</svg>
67 changes: 67 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.chart {
r: var(--radius);
transform: rotate(-90deg);
transform-origin: center center;
fill: none;
stroke-width: 5;
stroke: #444;
stroke-dasharray: calc(2 * pi * var(--radius));
stroke-dashoffset: calc(2 * pi * var(--radius) * (1 - ((var(--percentage) / 100) * -0.4)));
transition: stroke-dashoffset 0.3s linear 0.1s;
}

#load.chart {
--radius: 140;
stroke: rgb(115, 191, 105);
}

#pv.chart {
--radius: 130;
stroke: rgb(255, 152, 48);
}

#battery.chart {
--radius: 120;
stroke: rgb(87, 148, 242);
}

#grid.chart {
--radius: 110;
stroke: rgb(242, 73, 92);
}

#icons .off {
display: none;
}

#batterySoC .fill {
fill: rgb(87, 148, 242);
width: calc(86px * (var(--percentage) / 100));
transition: width 0.3s linear 0.1s;
}

#batterySoC.warning .fill {
fill: rgb(255, 152, 48);
}

#batterySoC.low .fill {
fill: rgb(242, 73, 92);
}

#batterySoC > text {
fill: #fff;
font-size: 20px;
}

#loadText {
fill: #fff;
font-size: 70px;
}

#loadText .sub {
font-size: 45px;
}

#loadText .units {
font-size: 20px;
}
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/glasslabs/solar

go 1.21.3

require (
github.com/glasslabs/client-go v0.1.0
github.com/pawal/go-hass v0.0.0-20230221123149-b1b116a7432d
)

require (
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom/v2 v2.0.0-20230808055721-96db8f4d5e3b // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/glasslabs/client-go v0.1.0 h1:a2Ob6EMyglz+Jy53diQv62ZCBVA4/BONF3e2APcnlr0=
github.com/glasslabs/client-go v0.1.0/go.mod h1:CpO4gMLfNrbhZQsNlNjq1KcGUAk35eCWj35YBb2xccw=
github.com/pawal/go-hass v0.0.0-20230221123149-b1b116a7432d h1:8tAKssHhfrcb3zHE/EpS+p3fYUk4RLROOGoPba6/tHs=
github.com/pawal/go-hass v0.0.0-20230221123149-b1b116a7432d/go.mod h1:dEToidnncZjw4CqHXSpE0KI17uDI86Gt0Gfp5PEJKyA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/js/dom/v2 v2.0.0-20230808055721-96db8f4d5e3b h1:XOEHdukvK2DAtBpN8kQbuj6UIK5dz9DLvqc51o6w4L0=
honnef.co/go/js/dom/v2 v2.0.0-20230808055721-96db8f4d5e3b/go.mod h1:+JtEcbinwR4znM12aluJ3WjKgvhDPKPQ8hnP4YM+4jI=
Loading

0 comments on commit 6aae65d

Please sign in to comment.