mirta 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.mjs +14 -9
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useEvent, isFunction } from '@mirta/basics';
1
+ import { useEvent, mqttToBoolean, isFunction } from '@mirta/basics';
2
2
  export * from '@mirta/basics';
3
3
  import '@mirta/polyfills';
4
4
 
@@ -116,21 +116,26 @@ function createControl(context, controlId, options) {
116
116
  trackMqtt(`/devices/${deviceId}/controls/${controlId}`, (payload) => {
117
117
  const incomingType = typeof payload.value;
118
118
  const expectingType = typeMappings[type];
119
+ let value;
119
120
  if (incomingType === 'string' && expectingType === 'number') {
120
- const value = Number(payload.value);
121
- if (isNaN(value)) {
121
+ const parsedValue = Number(payload.value);
122
+ if (isNaN(parsedValue)) {
122
123
  log.error(`Value ignored: control '${deviceId}/${controlId}' expects number, but Number(value) is NaN.`);
123
124
  return;
124
125
  }
125
- setValue(value, true);
126
+ value = parsedValue;
127
+ }
128
+ else if (expectingType === 'boolean') {
129
+ value = mqttToBoolean(payload.value);
130
+ }
131
+ else if (incomingType !== expectingType) {
132
+ log.error(`Value ignored: control '${deviceId}/${controlId}' expects type '${expectingType}', but received '${incomingType}'`);
133
+ return;
126
134
  }
127
135
  else {
128
- if (incomingType !== expectingType) {
129
- log.error(`Value ignored: control '${deviceId}/${controlId}' expects type '${expectingType}', but received '${incomingType}'`);
130
- return;
131
- }
132
- setValue(payload.value, true);
136
+ value = payload.value;
133
137
  }
138
+ setValue(value, true);
134
139
  });
135
140
  return {
136
141
  get value() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mirta",
3
3
  "description": "The powerful framework to write smart home automation scripts.",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "license": "Unlicense",
6
6
  "keywords": [
7
7
  "mirta",
@@ -36,9 +36,9 @@
36
36
  "url": "https://pay.cloudtips.ru/p/58512cca"
37
37
  },
38
38
  "dependencies": {
39
- "@mirta/globals": "0.2.0",
40
- "@mirta/basics": "0.2.0",
41
- "@mirta/polyfills": "0.2.0"
39
+ "@mirta/basics": "0.2.2",
40
+ "@mirta/globals": "0.2.2",
41
+ "@mirta/polyfills": "0.2.2"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"