Skip to content

Commit

Permalink
Merge pull request #35 from Jalle19/lint
Browse files Browse the repository at this point in the history
Add formatting checker
  • Loading branch information
Jalle19 authored Jan 21, 2022
2 parents 011af39 + df5e5f6 commit ba178ef
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 85 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run linters

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
prettier:
name: Check formatting with Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install dependencies
run: npm ci
- name: Check formatting
run: npm run check-prettier
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Run tests

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"quoteProps": "preserve"
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Retain MQTT discovery configuration messages (fixes https://github.com/Jalle19/eda-modbus-bridge/issues/29)
* 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`

## 2.0.0

Expand Down
58 changes: 31 additions & 27 deletions app/modbus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const getFlagSummary = async (modbusClient) => {
result = await mutex.runExclusive(async () => modbusClient.readCoils(12, 1))
summary = {
...summary,
'summerNightCooling': result.data[0]
'summerNightCooling': result.data[0],
}

return summary
Expand Down Expand Up @@ -163,7 +163,7 @@ export const getReadings = async (modbusClient) => {
export const getSettings = async (modbusClient) => {
let result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(57, 1))
let settings = {
'overPressureDelay': result.data[0]
'overPressureDelay': result.data[0],
}

result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(100, 4))
Expand All @@ -178,7 +178,7 @@ export const getSettings = async (modbusClient) => {
result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(135, 1))
settings = {
...settings,
'temperatureTarget': parseTemperature(result.data[0])
'temperatureTarget': parseTemperature(result.data[0]),
}

return settings
Expand Down Expand Up @@ -232,21 +232,21 @@ export const getDeviceInformation = async (modbusClient) => {
result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(154, 1))
deviceInformation = {
...deviceInformation,
'coolingTypeInstalled': getCoolingTypeName(result.data[0])
'coolingTypeInstalled': getCoolingTypeName(result.data[0]),
}

result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(171, 1))
deviceInformation = {
...deviceInformation,
'heatingTypeInstalled': getHeatingTypeName(result.data[0])
'heatingTypeInstalled': getHeatingTypeName(result.data[0]),
}

result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(597, 3))
deviceInformation = {
...deviceInformation,
'familyType': getDeviceFamilyName(result.data[0]),
'serialNumber': result.data[1],
'softwareVersion': result.data[2] / 100
'softwareVersion': result.data[2] / 100,
}

return deviceInformation
Expand All @@ -257,7 +257,7 @@ export const getAlarmHistory = async (modbusClient) => {

const startRegister = 385
const endRegister = 518
const alarmOffset = 7;
const alarmOffset = 7

for (let register = startRegister; register <= endRegister; register += alarmOffset) {
const result = await mutex.runExclusive(async () => modbusClient.readHoldingRegisters(register, alarmOffset))
Expand All @@ -280,7 +280,7 @@ export const getAlarmHistory = async (modbusClient) => {
}

export const getAlarmStatuses = async (modbusClient) => {
let alarms = {...AVAILABLE_ALARMS}
let alarms = { ...AVAILABLE_ALARMS }

// Use the alarm history to determine the state of each alarm
const alarmHistory = await getAlarmHistory(modbusClient)
Expand All @@ -300,24 +300,26 @@ export const getAlarmStatuses = async (modbusClient) => {
}

const getDeviceFamilyName = (familyTypeInt) => {
return [
'Pingvin',
'Pandion',
'Pelican',
'Pegasos',
'Pegasos XL',
'LTR-3',
'LTR-6̈́',
'LTR-7',
'LTR-7 XL'
][familyTypeInt] ?? 'unknown'
return (
[
'Pingvin', // prettier-hack
'Pandion',
'Pelican',
'Pegasos',
'Pegasos XL',
'LTR-3',
'LTR-6̈́',
'LTR-7',
'LTR-7 XL',
][familyTypeInt] ?? 'unknown'
)
}

const getCoolingTypeName = (coolingTypeInt) => {
// 0=Ei jäähdytintä, 1=CW, 2=HP, 3=CG, 4=CX, 5=CX_INV, 6=X2CX, 7=CXBIN, 8=Cooler
return [
null,
'CW',
'CW', // prettier-hack
'HP',
'CG',
'CX',
Expand All @@ -331,13 +333,15 @@ const getCoolingTypeName = (coolingTypeInt) => {
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 [
'ED',
'EDW',
'HP',
'EDE',
'SLP PWM',
][heatingTypeInt] ?? 'unknown'
return (
[
'ED', // prettier-hack
'EDW',
'HP',
'EDE',
'SLP PWM',
][heatingTypeInt] ?? 'unknown'
)
}

export const createModelNameString = (deviceInformation) => {
Expand Down
Loading

0 comments on commit ba178ef

Please sign in to comment.