@ya-modbus/driver-bac002 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -2
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/src/index.d.ts +51 -0
- package/dist/cjs/src/index.d.ts.map +1 -0
- package/dist/cjs/src/index.js +260 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/index.d.ts +51 -0
- package/dist/esm/src/index.d.ts.map +1 -0
- package/dist/esm/src/index.js +256 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +68 -4
package/README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ya-modbus/driver-bac002
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Driver for the BAC-002 room thermostat (fan coil thermostat with RS-485), for ya-modbus.
|
|
4
|
+
|
|
5
|
+
Registers 0-7 (the settings and the clock) follow the vendor document
|
|
6
|
+
"Thermostat Interface Protocol V1.0, Model BAC 1000", in `docs/bac-1000-modbus-protocol.pdf`.
|
|
7
|
+
The read-only registers 8-10 are not in that document: they come from an older reader of this
|
|
8
|
+
device and from the
|
|
9
|
+
[Wiren Board page for the BAC-002ALN](https://wiki.wirenboard.com/wiki/BAC-002ALN).
|
|
10
|
+
The 5 to 35 °C target range comes from the vendor user guide.
|
|
11
|
+
|
|
12
|
+
## Device Information
|
|
13
|
+
|
|
14
|
+
- **Model**: BAC-002
|
|
15
|
+
- **Type**: Room thermostat for fan coil units, with RS-485
|
|
16
|
+
- **Communication**: Modbus RTU
|
|
17
|
+
- **Default settings**:
|
|
18
|
+
- Address: 1
|
|
19
|
+
- Baud rate: 9600
|
|
20
|
+
- Parity: none
|
|
21
|
+
- Data bits: 8
|
|
22
|
+
- Stop bits: 1
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @ya-modbus/driver-bac002
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { createDriver, DEFAULT_CONFIG } from '@ya-modbus/driver-bac002'
|
|
34
|
+
import { createRTUTransport } from '@ya-modbus/transport'
|
|
35
|
+
|
|
36
|
+
const transport = await createRTUTransport({
|
|
37
|
+
port: '/dev/ttyUSB0',
|
|
38
|
+
baudRate: DEFAULT_CONFIG.baudRate,
|
|
39
|
+
parity: DEFAULT_CONFIG.parity,
|
|
40
|
+
dataBits: DEFAULT_CONFIG.dataBits,
|
|
41
|
+
stopBits: DEFAULT_CONFIG.stopBits,
|
|
42
|
+
slaveId: DEFAULT_CONFIG.defaultAddress,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const driver = await createDriver({ transport })
|
|
46
|
+
|
|
47
|
+
// One read of the device returns every data point you ask for
|
|
48
|
+
const values = await driver.readDataPoints(['power', 'mode', 'target_temperature'])
|
|
49
|
+
console.log(values)
|
|
50
|
+
// { power: 'on', mode: 'heating', target_temperature: 21.5 }
|
|
51
|
+
|
|
52
|
+
// Change settings
|
|
53
|
+
await driver.writeDataPoint('mode', 'cooling')
|
|
54
|
+
await driver.writeDataPoint('target_temperature', 24)
|
|
55
|
+
await driver.writeDataPoint('fan_setting', 'auto')
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Data points
|
|
59
|
+
|
|
60
|
+
Enum data points read and write text values. Writing any other value fails with a message that
|
|
61
|
+
lists the valid ones, and nothing is sent to the device.
|
|
62
|
+
|
|
63
|
+
| Data point | Type | Unit | Access | Values |
|
|
64
|
+
| --------------------- | ------- | ---- | ------ | ----------------------------------------------- |
|
|
65
|
+
| `power` | enum | | rw | `off`, `on` |
|
|
66
|
+
| `fan_setting` | enum | | rw | `auto`, `high`, `mid`, `low` |
|
|
67
|
+
| `mode` | enum | | rw | `cooling`, `heating`, `ventilation` |
|
|
68
|
+
| `target_temperature` | float | °C | rw | 5 to 35, rounded to steps of 0.5 |
|
|
69
|
+
| `lock` | enum | | rw | `unlock`, `lock` |
|
|
70
|
+
| `clock_minutes` | integer | min | rw | 0 to 59 |
|
|
71
|
+
| `clock_hours` | integer | h | rw | 0 to 23 |
|
|
72
|
+
| `week_day` | enum | | rw | `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun` |
|
|
73
|
+
| `current_temperature` | float | °C | r | Room temperature, one decimal |
|
|
74
|
+
| `valve` | integer | | r | Raw valve number from the device |
|
|
75
|
+
| `valve_status` | enum | | r | `off`, `on` |
|
|
76
|
+
| `fan` | integer | | r | Raw fan number from the device |
|
|
77
|
+
| `fan_status` | enum | | r | `off`, `high`, `mid`, `low` |
|
|
78
|
+
|
|
79
|
+
A register value that has no meaning (for example mode 9) reads as `unknown`, for every enum data
|
|
80
|
+
point. `unknown` is listed so you can read it, but you cannot write it. `valve_status` is `on`
|
|
81
|
+
for any raw valve value above 0. A week day that is not set (0) also reads `unknown`.
|
|
82
|
+
|
|
83
|
+
## Old field to data point
|
|
84
|
+
|
|
85
|
+
These are the fields the old reader published and the data points that replace them.
|
|
86
|
+
|
|
87
|
+
| Old field | Data point |
|
|
88
|
+
| ------------- | --------------------- |
|
|
89
|
+
| `power` | `power` |
|
|
90
|
+
| `fanSetting` | `fan_setting` |
|
|
91
|
+
| `fanStatus` | `fan_status` |
|
|
92
|
+
| `mode` | `mode` |
|
|
93
|
+
| `valveStatus` | `valve_status` |
|
|
94
|
+
| `targetTemp` | `target_temperature` |
|
|
95
|
+
| `currentTemp` | `current_temperature` |
|
|
96
|
+
| `lock` | `lock` |
|
|
97
|
+
| `fan` | `fan` |
|
|
98
|
+
| `valve` | `valve` |
|
|
99
|
+
| `weekDay` | `week_day` |
|
|
100
|
+
| `minutes` | `clock_minutes` |
|
|
101
|
+
| `hours` | `clock_hours` |
|
|
102
|
+
|
|
103
|
+
The text values (`off`, `high`, `heating`, `mon`, and so on) are the same as before.
|
|
104
|
+
|
|
105
|
+
## Differences from the old reader
|
|
106
|
+
|
|
107
|
+
- Names are in snake_case, and the clock fields are `clock_minutes` and `clock_hours`.
|
|
108
|
+
- Writes go through `writeDataPoint`, one data point at a time. The old writer's raw register
|
|
109
|
+
writes and its register scan are not part of the driver.
|
|
110
|
+
- A week day that is not set reads as `unknown`. The old reader showed `??`.
|
|
111
|
+
- A register value with no meaning reads as `unknown`. The old reader passed the raw number
|
|
112
|
+
through. Use `valve` and `fan` for the raw numbers.
|
|
113
|
+
- `valve_status` is `on` for any raw valve value above 0. The old reader passed values above 1
|
|
114
|
+
through.
|
|
115
|
+
- Temperatures are signed, so a room below 0 °C reads as `-1`, not `6552.6`.
|
|
116
|
+
- The clock fields accept whole numbers only. The old writer rounded `12.4` to `12`.
|
|
117
|
+
- The target temperature must be from 5 to 35 before rounding, the range of the vendor user
|
|
118
|
+
guide. The old writer allowed 0 to 100.
|
|
119
|
+
|
|
120
|
+
## Target temperature step
|
|
121
|
+
|
|
122
|
+
The driver rounds the target temperature to 0.5 °C and writes it in tenths of a degree, as the
|
|
123
|
+
old writer did. A value like `21.3` is written as `21.5`. The register itself holds tenths of a
|
|
124
|
+
degree. The vendor document gives the accuracy as 0.5 °C, so finer steps are not useful.
|
|
125
|
+
|
|
126
|
+
## Testing
|
|
127
|
+
|
|
128
|
+
Tests run against the Modbus emulator over TCP, so every read and write uses the real protocol.
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm test -w @ya-modbus/driver-bac002
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
GPL-3.0-or-later
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAC-002 room thermostat driver
|
|
3
|
+
*
|
|
4
|
+
* Registers 0-7 come from the vendor document "Thermostat Interface Protocol V1.0, Model BAC 1000"
|
|
5
|
+
* (docs/bac-1000-modbus-protocol.pdf). Registers 8-10 are not in it: they come from an older
|
|
6
|
+
* reader of this device and from the Wiren Board page for the BAC-002ALN. The 5-35 °C range of
|
|
7
|
+
* the target temperature comes from the vendor user guide.
|
|
8
|
+
*
|
|
9
|
+
* One read of holding registers 0-10 (function 3) returns everything:
|
|
10
|
+
*
|
|
11
|
+
* | Register | Data point | Raw value | Access |
|
|
12
|
+
* | -------- | ------------------- | ------------------------------------------ | ------ |
|
|
13
|
+
* | 0 | `power` | 0 off, 1 on | rw |
|
|
14
|
+
* | 1 | `fan_setting` | 0 auto, 1 high, 2 mid, 3 low | rw |
|
|
15
|
+
* | 2 | `mode` | 0 cooling, 1 heating, 2 ventilation | rw |
|
|
16
|
+
* | 3 | `target_temperature`| tenths of a degree | rw |
|
|
17
|
+
* | 4 | `lock` | 0 unlock, 1 lock | rw |
|
|
18
|
+
* | 5 | `clock_minutes` | 0-59 | rw |
|
|
19
|
+
* | 6 | `clock_hours` | 0-23 | rw |
|
|
20
|
+
* | 7 | `week_day` | 1 mon ... 7 sun (0 when not set) | rw |
|
|
21
|
+
* | 8 | `current_temperature` | tenths of a degree | r |
|
|
22
|
+
* | 9 | `valve`, `valve_status` | number; 0 off, above 0 on | r |
|
|
23
|
+
* | 10 | `fan`, `fan_status` | number; 0 off, 1 high, 2 mid, 3 low | r |
|
|
24
|
+
*/
|
|
25
|
+
import type { CreateDriverFunction } from '@ya-modbus/driver-types';
|
|
26
|
+
/**
|
|
27
|
+
* Factory default serial settings of the BAC-002
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_CONFIG: {
|
|
30
|
+
readonly baudRate: 9600;
|
|
31
|
+
readonly parity: "none";
|
|
32
|
+
readonly dataBits: 8;
|
|
33
|
+
readonly stopBits: 1;
|
|
34
|
+
readonly defaultAddress: 1;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Serial settings in the vendor protocol document: 9600 bps, 8 data bits, 1 stop bit, no parity,
|
|
38
|
+
* address 1-255 (limited here to the Modbus range 1-247)
|
|
39
|
+
*/
|
|
40
|
+
export declare const SUPPORTED_CONFIG: {
|
|
41
|
+
readonly validBaudRates: readonly [9600];
|
|
42
|
+
readonly validParity: readonly ["none"];
|
|
43
|
+
readonly validDataBits: readonly [8];
|
|
44
|
+
readonly validStopBits: readonly [1];
|
|
45
|
+
readonly validAddressRange: readonly [1, 247];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Create BAC-002 device driver
|
|
49
|
+
*/
|
|
50
|
+
export declare const createDriver: CreateDriverFunction;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,KAAK,EACV,oBAAoB,EAKrB,MAAM,yBAAyB,CAAA;AAEhC;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;CAMa,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;CAMa,CAAA;AA0O1C;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,oBAyC1B,CAAA"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BAC-002 room thermostat driver
|
|
4
|
+
*
|
|
5
|
+
* Registers 0-7 come from the vendor document "Thermostat Interface Protocol V1.0, Model BAC 1000"
|
|
6
|
+
* (docs/bac-1000-modbus-protocol.pdf). Registers 8-10 are not in it: they come from an older
|
|
7
|
+
* reader of this device and from the Wiren Board page for the BAC-002ALN. The 5-35 °C range of
|
|
8
|
+
* the target temperature comes from the vendor user guide.
|
|
9
|
+
*
|
|
10
|
+
* One read of holding registers 0-10 (function 3) returns everything:
|
|
11
|
+
*
|
|
12
|
+
* | Register | Data point | Raw value | Access |
|
|
13
|
+
* | -------- | ------------------- | ------------------------------------------ | ------ |
|
|
14
|
+
* | 0 | `power` | 0 off, 1 on | rw |
|
|
15
|
+
* | 1 | `fan_setting` | 0 auto, 1 high, 2 mid, 3 low | rw |
|
|
16
|
+
* | 2 | `mode` | 0 cooling, 1 heating, 2 ventilation | rw |
|
|
17
|
+
* | 3 | `target_temperature`| tenths of a degree | rw |
|
|
18
|
+
* | 4 | `lock` | 0 unlock, 1 lock | rw |
|
|
19
|
+
* | 5 | `clock_minutes` | 0-59 | rw |
|
|
20
|
+
* | 6 | `clock_hours` | 0-23 | rw |
|
|
21
|
+
* | 7 | `week_day` | 1 mon ... 7 sun (0 when not set) | rw |
|
|
22
|
+
* | 8 | `current_temperature` | tenths of a degree | r |
|
|
23
|
+
* | 9 | `valve`, `valve_status` | number; 0 off, above 0 on | r |
|
|
24
|
+
* | 10 | `fan`, `fan_status` | number; 0 off, 1 high, 2 mid, 3 low | r |
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.createDriver = exports.SUPPORTED_CONFIG = exports.DEFAULT_CONFIG = void 0;
|
|
28
|
+
const driver_sdk_1 = require("@ya-modbus/driver-sdk");
|
|
29
|
+
/**
|
|
30
|
+
* Factory default serial settings of the BAC-002
|
|
31
|
+
*/
|
|
32
|
+
exports.DEFAULT_CONFIG = {
|
|
33
|
+
baudRate: 9600,
|
|
34
|
+
parity: 'none',
|
|
35
|
+
dataBits: 8,
|
|
36
|
+
stopBits: 1,
|
|
37
|
+
defaultAddress: 1,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Serial settings in the vendor protocol document: 9600 bps, 8 data bits, 1 stop bit, no parity,
|
|
41
|
+
* address 1-255 (limited here to the Modbus range 1-247)
|
|
42
|
+
*/
|
|
43
|
+
exports.SUPPORTED_CONFIG = {
|
|
44
|
+
validBaudRates: [9600],
|
|
45
|
+
validParity: ['none'],
|
|
46
|
+
validDataBits: [8],
|
|
47
|
+
validStopBits: [1],
|
|
48
|
+
validAddressRange: [1, 247],
|
|
49
|
+
};
|
|
50
|
+
/** Number of registers in the one read that returns every data point */
|
|
51
|
+
const REGISTER_COUNT = 11;
|
|
52
|
+
/**
|
|
53
|
+
* Fields that hold a text value out of a fixed list, such as `heating`.
|
|
54
|
+
* `names` maps each text value to the register value.
|
|
55
|
+
*/
|
|
56
|
+
function enumField(register, dataPoint, names, labels, normalize = (raw) => raw) {
|
|
57
|
+
return {
|
|
58
|
+
register,
|
|
59
|
+
dataPoint: { ...dataPoint, type: 'enum', enumValues: { ...labels, unknown: 'Unknown value' } },
|
|
60
|
+
decode: (raw) => {
|
|
61
|
+
// A register value with no meaning reads as 'unknown', so one odd register
|
|
62
|
+
// does not break the read of the other data points
|
|
63
|
+
const found = Object.entries(names).find(([, value]) => value === normalize(raw));
|
|
64
|
+
return found === undefined ? 'unknown' : found[0];
|
|
65
|
+
},
|
|
66
|
+
...(dataPoint.access === 'rw' && {
|
|
67
|
+
encode: (value) => {
|
|
68
|
+
if (typeof value !== 'string' || !Object.hasOwn(names, value)) {
|
|
69
|
+
throw new Error((0, driver_sdk_1.formatEnumError)(dataPoint.id, value, Object.keys(names)));
|
|
70
|
+
}
|
|
71
|
+
return names[value];
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function integerField(register, dataPoint) {
|
|
77
|
+
const { id, min = 0, max = 0xffff } = dataPoint;
|
|
78
|
+
const isInRange = (0, driver_sdk_1.createRangeValidator)(min, max);
|
|
79
|
+
return {
|
|
80
|
+
register,
|
|
81
|
+
dataPoint: { ...dataPoint, type: 'integer' },
|
|
82
|
+
decode: (raw) => raw,
|
|
83
|
+
...(dataPoint.access === 'rw' && {
|
|
84
|
+
encode: (value) => {
|
|
85
|
+
if (!(0, driver_sdk_1.isValidInteger)(value) || !isInRange(value)) {
|
|
86
|
+
throw new Error((0, driver_sdk_1.formatRangeError)(id, value, min, max));
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function temperatureField(register, dataPoint) {
|
|
94
|
+
const { min = 0, max = 100 } = dataPoint;
|
|
95
|
+
const isInRange = (0, driver_sdk_1.createRangeValidator)(min, max);
|
|
96
|
+
return {
|
|
97
|
+
register,
|
|
98
|
+
dataPoint: { ...dataPoint, type: 'float', unit: '°C', decimals: 1 },
|
|
99
|
+
// Signed 16-bit, so -1.0 degrees is not read as 6552.6
|
|
100
|
+
decode: (raw) => (raw > 0x7fff ? raw - 0x10000 : raw) / 10,
|
|
101
|
+
...(dataPoint.access === 'rw' && {
|
|
102
|
+
// The vendor document gives an accuracy of 0.5 degrees, and the old writer rounded the same way
|
|
103
|
+
encode: (value) => {
|
|
104
|
+
if (!isInRange(value)) {
|
|
105
|
+
throw new Error((0, driver_sdk_1.formatRangeError)(dataPoint.id, value, min, max));
|
|
106
|
+
}
|
|
107
|
+
return Math.round(value * 2) * 5;
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const POWER = { off: 0, on: 1 };
|
|
113
|
+
const FAN_SETTING = { auto: 0, high: 1, mid: 2, low: 3 };
|
|
114
|
+
const MODE = { cooling: 0, heating: 1, ventilation: 2 };
|
|
115
|
+
const LOCK = { unlock: 0, lock: 1 };
|
|
116
|
+
const WEEK_DAY = { mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6, sun: 7 };
|
|
117
|
+
const VALVE_STATUS = { off: 0, on: 1 };
|
|
118
|
+
const FAN_STATUS = { off: 0, high: 1, mid: 2, low: 3 };
|
|
119
|
+
const FIELDS = [
|
|
120
|
+
enumField(0, { id: 'power', name: 'Power', access: 'rw', description: 'Thermostat power: off or on' }, POWER, { off: 'Off', on: 'On' }),
|
|
121
|
+
enumField(1, {
|
|
122
|
+
id: 'fan_setting',
|
|
123
|
+
name: 'Fan Setting',
|
|
124
|
+
access: 'rw',
|
|
125
|
+
description: 'Wanted fan speed: auto, high, mid or low',
|
|
126
|
+
}, FAN_SETTING, { auto: 'Auto', high: 'High', mid: 'Medium', low: 'Low' }),
|
|
127
|
+
enumField(2, {
|
|
128
|
+
id: 'mode',
|
|
129
|
+
name: 'Mode',
|
|
130
|
+
access: 'rw',
|
|
131
|
+
description: 'Operating mode: cooling, heating or ventilation',
|
|
132
|
+
}, MODE, { cooling: 'Cooling', heating: 'Heating', ventilation: 'Ventilation' }),
|
|
133
|
+
temperatureField(3, {
|
|
134
|
+
id: 'target_temperature',
|
|
135
|
+
name: 'Target Temperature',
|
|
136
|
+
access: 'rw',
|
|
137
|
+
description: 'Wanted room temperature in degrees Celsius (5 to 35)',
|
|
138
|
+
min: 5,
|
|
139
|
+
max: 35,
|
|
140
|
+
}),
|
|
141
|
+
enumField(4, {
|
|
142
|
+
id: 'lock',
|
|
143
|
+
name: 'Lock',
|
|
144
|
+
access: 'rw',
|
|
145
|
+
description: 'Keypad lock: lock or unlock',
|
|
146
|
+
}, LOCK, { unlock: 'Unlocked', lock: 'Locked' }),
|
|
147
|
+
integerField(5, {
|
|
148
|
+
id: 'clock_minutes',
|
|
149
|
+
name: 'Clock Minutes',
|
|
150
|
+
unit: 'min',
|
|
151
|
+
access: 'rw',
|
|
152
|
+
description: 'Minutes of the thermostat clock (0-59)',
|
|
153
|
+
min: 0,
|
|
154
|
+
max: 59,
|
|
155
|
+
}),
|
|
156
|
+
integerField(6, {
|
|
157
|
+
id: 'clock_hours',
|
|
158
|
+
name: 'Clock Hours',
|
|
159
|
+
unit: 'h',
|
|
160
|
+
access: 'rw',
|
|
161
|
+
description: 'Hours of the thermostat clock (0-23)',
|
|
162
|
+
min: 0,
|
|
163
|
+
max: 23,
|
|
164
|
+
}),
|
|
165
|
+
enumField(7, {
|
|
166
|
+
id: 'week_day',
|
|
167
|
+
name: 'Week Day',
|
|
168
|
+
access: 'rw',
|
|
169
|
+
description: 'Day of the week of the thermostat clock (mon to sun). Reads as unknown when the device has no day set',
|
|
170
|
+
}, WEEK_DAY, {
|
|
171
|
+
mon: 'Monday',
|
|
172
|
+
tue: 'Tuesday',
|
|
173
|
+
wed: 'Wednesday',
|
|
174
|
+
thu: 'Thursday',
|
|
175
|
+
fri: 'Friday',
|
|
176
|
+
sat: 'Saturday',
|
|
177
|
+
sun: 'Sunday',
|
|
178
|
+
}),
|
|
179
|
+
temperatureField(8, {
|
|
180
|
+
id: 'current_temperature',
|
|
181
|
+
name: 'Current Temperature',
|
|
182
|
+
access: 'r',
|
|
183
|
+
description: 'Measured room temperature in degrees Celsius',
|
|
184
|
+
}),
|
|
185
|
+
integerField(9, {
|
|
186
|
+
id: 'valve',
|
|
187
|
+
name: 'Valve',
|
|
188
|
+
access: 'r',
|
|
189
|
+
description: 'Raw valve value from the device',
|
|
190
|
+
}),
|
|
191
|
+
enumField(9, {
|
|
192
|
+
id: 'valve_status',
|
|
193
|
+
name: 'Valve Status',
|
|
194
|
+
access: 'r',
|
|
195
|
+
description: 'Valve state: off or on',
|
|
196
|
+
}, VALVE_STATUS, { off: 'Off', on: 'On' },
|
|
197
|
+
// Any value above 0 means the valve is open
|
|
198
|
+
(raw) => Math.min(raw, 1)),
|
|
199
|
+
integerField(10, {
|
|
200
|
+
id: 'fan',
|
|
201
|
+
name: 'Fan',
|
|
202
|
+
access: 'r',
|
|
203
|
+
description: 'Raw fan value from the device',
|
|
204
|
+
}),
|
|
205
|
+
enumField(10, {
|
|
206
|
+
id: 'fan_status',
|
|
207
|
+
name: 'Fan Status',
|
|
208
|
+
access: 'r',
|
|
209
|
+
description: 'Fan state now: off, high, mid or low',
|
|
210
|
+
}, FAN_STATUS, { off: 'Off', high: 'High', mid: 'Medium', low: 'Low' }),
|
|
211
|
+
];
|
|
212
|
+
const DATA_POINTS = FIELDS.map((field) => field.dataPoint);
|
|
213
|
+
const FIELD_BY_ID = new Map(FIELDS.map((field) => [field.dataPoint.id, field]));
|
|
214
|
+
function findField(id) {
|
|
215
|
+
const field = FIELD_BY_ID.get(id);
|
|
216
|
+
if (field === undefined) {
|
|
217
|
+
throw new Error(`Unknown data point: ${id}`);
|
|
218
|
+
}
|
|
219
|
+
return field;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Create BAC-002 device driver
|
|
223
|
+
*/
|
|
224
|
+
const createDriver = ({ transport }) => {
|
|
225
|
+
const readFields = async (fields) => {
|
|
226
|
+
const buffer = await transport.readHoldingRegisters(0, REGISTER_COUNT);
|
|
227
|
+
if (buffer.length < REGISTER_COUNT * 2) {
|
|
228
|
+
throw new Error(`Buffer too short: expected at least ${REGISTER_COUNT * 2} bytes, got ${buffer.length}`);
|
|
229
|
+
}
|
|
230
|
+
const result = {};
|
|
231
|
+
for (const field of fields) {
|
|
232
|
+
result[field.dataPoint.id] = field.decode(buffer.readUInt16BE(field.register * 2));
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
const driver = {
|
|
237
|
+
name: 'BAC-002',
|
|
238
|
+
manufacturer: 'Unknown',
|
|
239
|
+
model: 'BAC-002',
|
|
240
|
+
dataPoints: DATA_POINTS,
|
|
241
|
+
async readDataPoint(id) {
|
|
242
|
+
const field = findField(id);
|
|
243
|
+
const values = await readFields([field]);
|
|
244
|
+
return values[id];
|
|
245
|
+
},
|
|
246
|
+
async readDataPoints(ids) {
|
|
247
|
+
return readFields(ids.map(findField));
|
|
248
|
+
},
|
|
249
|
+
async writeDataPoint(id, value) {
|
|
250
|
+
const field = findField(id);
|
|
251
|
+
if (field.encode === undefined) {
|
|
252
|
+
throw new Error(`Data point ${id} is read-only`);
|
|
253
|
+
}
|
|
254
|
+
await transport.writeSingleRegister(field.register, field.encode(value));
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
return Promise.resolve(driver);
|
|
258
|
+
};
|
|
259
|
+
exports.createDriver = createDriver;
|
|
260
|
+
//# sourceMappingURL=index.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