Skip to content

Commit 473a410

Browse files
Add actionlint to pre-commit, refactor test initialization, and improve version handling in CI workflow.
1 parent d15d5c8 commit 473a410

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

.github/workflows/addon.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ jobs:
1919

2020
- name: Set version from tag
2121
id: version
22-
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
22+
run: |
23+
version="${GITHUB_REF_NAME#v}"
24+
echo "version=${version}" >> "$GITHUB_OUTPUT"
2325
2426
- name: Update config.yaml version
25-
run: sed -i "s/^version:.*/version: ${GITHUB_REF_NAME#v}/" ha-addon/config.yaml
27+
run: |
28+
version="${GITHUB_REF_NAME#v}"
29+
sed -i "s/^version:.*/version: ${version}/" ha-addon/config.yaml
2630
2731
- name: Commit version bump
2832
run: |

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ repos:
1818
- id: end-of-file-fixer
1919
- id: check-yaml
2020
- id: check-merge-conflict
21+
22+
- repo: https://github.com/rhysd/actionlint
23+
rev: v1.7.7
24+
hooks:
25+
- id: actionlint

serve/parity_test.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ func (ms *messageStore) get(topic string) ([]byte, bool) {
4343
return v, ok
4444
}
4545

46-
func (ms *messageStore) topics() []string {
47-
ms.mu.Lock()
48-
defer ms.mu.Unlock()
49-
topics := make([]string, 0, len(ms.messages))
50-
for t := range ms.messages {
51-
topics = append(topics, t)
52-
}
53-
return topics
54-
}
55-
5646
// startTestBroker starts an embedded mochi-mqtt broker on a random port.
5747
// Returns the broker, its TCP address, and a message store that captures all published messages.
5848
func startTestBroker(t *testing.T) (*mqtt.Server, string, *messageStore) {
@@ -79,7 +69,8 @@ func TestMQTTRESTSensorParity(t *testing.T) {
7969
_, addr, store := startTestBroker(t)
8070

8171
// Set up mock system with known values
82-
sys := newTestSystem(t) // SOC=85, PV=600+440, Load=500
72+
sys := newTestSystem(t) // SOC=85, PV=600+440, Load=500
73+
unitInfos := sys.Units() // capture before hub starts to avoid race
8374
hub := NewHub(sys, 50*time.Millisecond, 50*time.Millisecond)
8475

8576
ctx, cancel := context.WithCancel(context.Background())
@@ -93,7 +84,6 @@ func TestMQTTRESTSensorParity(t *testing.T) {
9384
ClientID: "test-publisher",
9485
TopicPrefix: "homeassistant",
9586
}
96-
unitInfos := sys.Units()
9787
pub, err := NewMQTTPublisher(mqttCfg, hub, unitInfos)
9888
require.NoError(t, err)
9989
go pub.Run(ctx)
@@ -178,6 +168,7 @@ func TestMQTTRESTControlParity(t *testing.T) {
178168
_, addr, store := startTestBroker(t)
179169

180170
sys := newTestSystem(t)
171+
unitInfos := sys.Units()
181172
hub := NewHub(sys, 50*time.Millisecond, 50*time.Millisecond)
182173

183174
ctx, cancel := context.WithCancel(context.Background())
@@ -190,7 +181,7 @@ func TestMQTTRESTControlParity(t *testing.T) {
190181
ClientID: "test-publisher",
191182
TopicPrefix: "homeassistant",
192183
}
193-
pub, err := NewMQTTPublisher(mqttCfg, hub, sys.Units())
184+
pub, err := NewMQTTPublisher(mqttCfg, hub, unitInfos)
194185
require.NoError(t, err)
195186
go pub.Run(ctx)
196187
time.Sleep(300 * time.Millisecond)
@@ -328,6 +319,7 @@ func TestMQTTControlRoundTrip(t *testing.T) {
328319
broker, addr, store := startTestBroker(t)
329320

330321
sys := newTestSystem(t)
322+
unitInfos := sys.Units()
331323
hub := NewHub(sys, 50*time.Millisecond, 50*time.Millisecond)
332324

333325
ctx, cancel := context.WithCancel(context.Background())
@@ -340,7 +332,7 @@ func TestMQTTControlRoundTrip(t *testing.T) {
340332
ClientID: "test-publisher",
341333
TopicPrefix: "homeassistant",
342334
}
343-
pub, err := NewMQTTPublisher(mqttCfg, hub, sys.Units())
335+
pub, err := NewMQTTPublisher(mqttCfg, hub, unitInfos)
344336
require.NoError(t, err)
345337
go pub.Run(ctx)
346338
time.Sleep(300 * time.Millisecond)

0 commit comments

Comments
 (0)