浏览代码

:recycle: fix some imports and destructured calls for tests

master
toj 1年前
父节点
当前提交
4e2e115609
共有 4 个文件被更改,包括 18 次插入6 次删除
  1. 2
    2
      src/api.js
  2. 2
    0
      src/controller.js
  3. 13
    3
      src/core/channel.js
  4. 1
    1
      test/channel.spec.js

+ 2
- 2
src/api.js 查看文件

@@ -1,8 +1,8 @@
1 1
 import { fromLiquid } from './core/utils.js'
2 2
 
3 3
 import { Container } from './core/container.js'
4
-import { Reading, Channel } from './core/channel'
5
-import { Controller } from './core/controller'
4
+import { Reading, Channel } from './core/channel.js'
5
+import { Controller } from './controller.js'
6 6
 import { InputConf } from './input.js'
7 7
 
8 8
 /**

+ 2
- 0
src/controller.js 查看文件

@@ -1,3 +1,5 @@
1
+import { updateChannel } from "./core/channel.js"
2
+
1 3
 let allWarnings = []
2 4
 
3 5
 // const _makeWarning = (msg, channelOrSensor) => ({

+ 13
- 3
src/core/channel.js 查看文件

@@ -17,7 +17,7 @@ class Reading {
17 17
      * @param {*} param0.min
18 18
      * @param {*} param0.max
19 19
      */
20
-    constructor({ onRead, unit, min, max }) {
20
+    constructor({ onRead=() => "err", unit, min, max }) {
21 21
         this._readVal = onRead
22 22
         this.unit = unit
23 23
         this.max = max
@@ -81,14 +81,24 @@ class Channel {
81 81
     get val() {
82 82
         return this._reader.val
83 83
     }
84
+    // Just used to simplify updateChannel()
85
+    get onRead() {
86
+        return this._reader._readVal
87
+    }
88
+    get min() {
89
+        return this._reader.min
90
+    }
91
+    get max() {
92
+        return this._reader.max
93
+    }
84 94
     get unit() {
85 95
         return this._reader.unit
86 96
     }
87 97
     get aboveRange() {
88
-        return this._reader.val > this._reader.max
98
+        return this.val > this.max
89 99
     }
90 100
     get belowRange() {
91
-        return this._reader.val < this._reader.min
101
+        return this.val < this.min
92 102
     }
93 103
     get inRange() {
94 104
         return this._reader.val && !this.aboveRange && !this.belowRange

+ 1
- 1
test/channel.spec.js 查看文件

@@ -13,7 +13,7 @@ test('channel - instantiate channel with readers correctly', () => {
13 13
     let testChan = new Channel({ interval: 1, reader: testReader })
14 14
 
15 15
     // Test that the channel and channel.reader are working
16
-    expect(testChan.lastUpdate == now).toStrictEqual(true)
16
+    expect(testChan.lastUpdate - now < 10).toStrictEqual(true)
17 17
     expect(testChan.val).toStrictEqual(70)
18 18
     expect(testChan.unit).toStrictEqual('F')
19 19
 

正在加载...
取消
保存