Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fix lights test
Browse files Browse the repository at this point in the history
  • Loading branch information
groupsky committed Nov 17, 2024
1 parent a958b1b commit 2d9626b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/lights-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ jobs:
- name: Run containers
run: |
sudo chown -R 1000:1000 data/nodered
docker compose --env-file example.env up --build --force-recreate -d
docker compose --env-file example.env up --build --force-recreate -d automations features broker
- name: Setup node
uses: actions/[email protected]
with:
node-version: 14
node-version: 22
node-version-file: docker/test/.nvmrc

- name: Run tests
run: |
Expand Down
1 change: 1 addition & 0 deletions docker/test/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
45 changes: 22 additions & 23 deletions docker/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const timer = setTimeout(() => {
console.error('Timeout!')
process.exit(1)
}, 2000)
let interval = null

const publish = (topic, payload) => {
console.log(`> [${topic}]: ${JSON.stringify(payload)}`)
Expand All @@ -15,39 +14,39 @@ const publish = (topic, payload) => {

client.on('connect', () => {
console.log('connected, sending...')
client.subscribe('#', async (err) => {
client.subscribe(['#'], async (err) => {
if (err) {
console.log('Error sending', err)
process.exit(1)
}
let inputs = 0
setInterval(() => {
inputs = inputs === 0 ? 1 << 27 : 0
publish('/modbus/dry-switches/mbsl32di2/reading', JSON.stringify({
"inputs": inputs,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
}))
}, 100)
await publish('/modbus/dry-switches/mbsl32di2/reading', {
"inputs": 0,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
})
await publish('/modbus/dry-switches/mbsl32di2/reading', {
"inputs": 1 << 27,
"_tz": Date.now(),
"_ms": 7,
"_addr": 32,
"_type": "mbsl32di",
"device": "mbsl32di2"
})
})
})

client.on('message', (topic, message) => {
console.log(`< [${topic}]: ${message}`)
// message is Buffer
switch (topic) {
case '/modbus/dry-switches/relays00-15/write': {
const msg = JSON.parse(message)
if (msg.out8 === true) {
clearTimeout(timer)
clearInterval(interval)
client.end()
}
if (topic === '/modbus/dry-switches/relays00-15/write') {
const msg = JSON.parse(message)
if (msg.out8 === true) {
clearTimeout(timer)
client.end()
}
break
}
})

Expand Down

0 comments on commit 2d9626b

Please sign in to comment.