Skip to content

Commit

Permalink
Merge pull request #39 from Jalle19/nodejs12
Browse files Browse the repository at this point in the history
Run tests on Node.js 12.x too
  • Loading branch information
Jalle19 authored Jan 22, 2022
2 parents ba178ef + d2d83b9 commit e93dd57
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ jobs:
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 12.x, 14.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Publish only changed settings or modes in MQTT callback (fixes https://github.com/Jalle19/eda-modbus-bridge/issues/33)
* Add alarms support (fixes https://github.com/Jalle19/eda-modbus-bridge/issues/31)
* Format code using `prettier`
* Support running on Node.js 12.x (fixes https://github.com/Jalle19/eda-modbus-bridge/issues/38)

## 2.0.0

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Run tests](https://github.com/Jalle19/eda-modbus-bridge/actions/workflows/test.yml/badge.svg)](https://github.com/Jalle19/eda-modbus-bridge/actions/workflows/test.yml)

An HTTP/MQTT bridge for Enervent ventilation units with EDA automation (e.g. Pingvin). It provides a REST-ful HTTP interface
for interacting with the ventilation unit (reading temperatures and changing certain settings), as well as an MQTT
client which can publish readings/settings regularly and be used to control the ventilation unit.
An HTTP/MQTT bridge for Enervent ventilation units with EDA automation (e.g. Pingvin and Pandion). It provides a REST-ful
HTTP interface for interacting with the ventilation unit (reading temperatures and changing certain settings), as well
as an MQTT client which can publish readings/settings regularly and be used to control the ventilation unit.

Communication happens over RS-485 (Modbus RTU) by connecting a serial device to the "Freeway" port on the ventilation
unit's computer board.
Expand All @@ -19,8 +19,8 @@ https://www.home-assistant.io/integrations/switch.rest/ with minimal effort. See

## Requirements

* Node.js (only tested with 14.x)
* An Enervent Pingvin ventilation unit (other EDA-based units may work, but the Modbus register numbers probably differ)
* Node.js 12.x or newer
* An Enervent ventilation unit with EDA automation (Pingvin and Pandion confirmed working)
* An RS-485 device (e.g. `/dev/ttyUSB0`) connected to the Enervent unit's Freeway port

## Usage
Expand Down
8 changes: 4 additions & 4 deletions app/modbus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const getAlarmStatuses = async (modbusClient) => {
return alarms
}

const getDeviceFamilyName = (familyTypeInt) => {
export const getDeviceFamilyName = (familyTypeInt) => {
return (
[
'Pingvin', // prettier-hack
Expand All @@ -311,7 +311,7 @@ const getDeviceFamilyName = (familyTypeInt) => {
'LTR-6̈́',
'LTR-7',
'LTR-7 XL',
][familyTypeInt] ?? 'unknown'
][familyTypeInt] || 'unknown'
)
}

Expand All @@ -330,7 +330,7 @@ const getCoolingTypeName = (coolingTypeInt) => {
][coolingTypeInt]
}

const getHeatingTypeName = (heatingTypeInt) => {
export const getHeatingTypeName = (heatingTypeInt) => {
// 0=Ei lämmitintä, 1=VPK, 2=HP, 3=SLP, 4=SLP PWM. Mapping known values to the actual names used on the product,
// these seem to be internal
return (
Expand All @@ -340,7 +340,7 @@ const getHeatingTypeName = (heatingTypeInt) => {
'HP',
'EDE',
'SLP PWM',
][heatingTypeInt] ?? 'unknown'
][heatingTypeInt] || 'unknown'
)
}

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"check-prettier": "prettier --check eda-modbus-bridge.mjs app/",
"prettier": "prettier --write eda-modbus-bridge.mjs app/"
"check-prettier": "prettier --check eda-modbus-bridge.mjs app/ tests/",
"prettier": "prettier --write eda-modbus-bridge.mjs app/ tests/"
},
"repository": {
"type": "git",
Expand Down
60 changes: 39 additions & 21 deletions tests/modbus.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
parseTemperature,
createModelNameString, parseAlarmTimestamp
createModelNameString,
parseAlarmTimestamp,
getDeviceFamilyName,
getHeatingTypeName,
} from '../app/modbus.mjs'

test('parse temperature', () => {
Expand All @@ -12,28 +15,34 @@ test('parse temperature', () => {

test('create model name from device information', () => {
// Heating, no cooling, DC fan
expect(createModelNameString({
familyType: 'Pingvin',
fanType: 'EC',
heatingTypeInstalled: 'EDE',
coolingTypeInstalled: null,
})).toEqual('Pingvin eco EDE')
expect(
createModelNameString({
familyType: 'Pingvin',
fanType: 'EC',
heatingTypeInstalled: 'EDE',
coolingTypeInstalled: null,
})
).toEqual('Pingvin eco EDE')

// Heating, cooling, DC fan
expect(createModelNameString({
familyType: 'Pegasus',
fanType: 'EC',
heatingTypeInstalled: 'EDE',
coolingTypeInstalled: 'CG',
})).toEqual('Pegasus eco EDE - CG')
expect(
createModelNameString({
familyType: 'Pegasus',
fanType: 'EC',
heatingTypeInstalled: 'EDE',
coolingTypeInstalled: 'CG',
})
).toEqual('Pegasus eco EDE - CG')

// No heating, no cooling, AC fan
expect(createModelNameString({
familyType: 'Pandion',
fanType: 'AC',
heatingTypeInstalled: null,
coolingTypeInstalled: null,
})).toEqual('Pandion')
expect(
createModelNameString({
familyType: 'Pandion',
fanType: 'AC',
heatingTypeInstalled: null,
coolingTypeInstalled: null,
})
).toEqual('Pandion')
})

test('parse alarm timestamp', () => {
Expand All @@ -46,13 +55,22 @@ test('parse alarm timestamp', () => {
21, // day
13, // hour
45, // minute
]
],
}

const timestamp = parseAlarmTimestamp(alarmResult)

// The ventilation unit is assumed to be using the same timezone as the computer running this software,
// i.e. the result from Modbus is in local time.
expect(timestamp.toLocaleString('fi-FI')).toEqual('21.1.2022 klo 13.45.00')
expect(timestamp.toLocaleString('en-US')).toEqual('1/21/2022, 1:45:00 PM')
})

test('device family name', () => {
expect(getDeviceFamilyName(0)).toEqual('Pingvin')
expect(getDeviceFamilyName(999)).toEqual('unknown')
})

test('heating type name', () => {
expect(getHeatingTypeName(0)).toEqual('ED')
expect(getHeatingTypeName(999)).toEqual('unknown')
})

0 comments on commit e93dd57

Please sign in to comment.