Skip to content

Commit e7a85a7

Browse files
committed
feat(device): Add support for fan; close #26
1 parent c2ede02 commit e7a85a7

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

device-types.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const percentage = (val) => {
2626
return { key: 'percentage', value: val }
2727
}
2828

29+
const speed = (val) => {
30+
const isValid = Number.isInteger(val) && val >= 0 && val <= 10
31+
if (!isValid) {
32+
return false
33+
}
34+
return { key: 'speed', value: val }
35+
}
36+
2937
const colorTemperatureInKelvin = (val) => {
3038
const isValid = Number.isInteger(val) && val >= 1000 && val <= 10000
3139
if (!isValid) {
@@ -278,6 +286,8 @@ const diffDecoratorFactory = (anotherDecorator) => {
278286
Lock: ['lockState'],
279287
Unlock: ['lockState'],
280288
SetMode: ['mode', 'instance'],
289+
AdjustRangeValue: ['speed'],
290+
SetRangeValue: ['speed'],
281291
Activate: ['isActivated'],
282292
Deactivate: ['isActivated'],
283293
SetTargetTemperature: ['targetTemperature', 'targetScale'],
@@ -427,6 +437,17 @@ const types = {
427437
},
428438
decorator: defaultDecorator,
429439
},
440+
FAN: {
441+
defaultState: {
442+
powerState: 'OFF',
443+
speed: 0,
444+
},
445+
validators: {
446+
powerState,
447+
speed,
448+
},
449+
decorator: defaultDecorator,
450+
},
430451
GARAGE_DOOR_OPENER: {
431452
defaultState: {
432453
mode: 'Position.Up',

examples/fan.json

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
[
2+
{
3+
"id": "1deb9367.51a3fd",
4+
"type": "inject",
5+
"z": "7ecdfb0b.fa7794",
6+
"name": "on",
7+
"props": [{ "p": "payload" }],
8+
"repeat": "",
9+
"crontab": "",
10+
"once": false,
11+
"onceDelay": 0.1,
12+
"topic": "",
13+
"payload": "{\"powerState\":\"ON\"}",
14+
"payloadType": "json",
15+
"x": 930,
16+
"y": 520,
17+
"wires": [["1de955b6.491d3a"]]
18+
},
19+
{
20+
"id": "dab12600.fd0d08",
21+
"type": "inject",
22+
"z": "7ecdfb0b.fa7794",
23+
"name": "off",
24+
"props": [{ "p": "payload" }],
25+
"repeat": "",
26+
"crontab": "",
27+
"once": false,
28+
"onceDelay": 0.1,
29+
"topic": "",
30+
"payload": "{\"powerState\":\"OFF\"}",
31+
"payloadType": "json",
32+
"x": 930,
33+
"y": 560,
34+
"wires": [["1de955b6.491d3a"]]
35+
},
36+
{
37+
"id": "1de955b6.491d3a",
38+
"type": "vsh-virtual-device",
39+
"z": "7ecdfb0b.fa7794",
40+
"name": "bedroom fan",
41+
"topic": "bedroom/fan",
42+
"connection": "",
43+
"template": "FAN",
44+
"passthrough": true,
45+
"diff": false,
46+
"x": 1230,
47+
"y": 520,
48+
"wires": [["c402af75.7847"]]
49+
},
50+
{
51+
"id": "6375e148.f86cc",
52+
"type": "comment",
53+
"z": "7ecdfb0b.fa7794",
54+
"name": "FAN",
55+
"info": "",
56+
"x": 910,
57+
"y": 340,
58+
"wires": []
59+
},
60+
{
61+
"id": "c402af75.7847",
62+
"type": "debug",
63+
"z": "7ecdfb0b.fa7794",
64+
"name": "",
65+
"active": true,
66+
"tosidebar": true,
67+
"console": false,
68+
"tostatus": false,
69+
"complete": "false",
70+
"statusVal": "",
71+
"statusType": "auto",
72+
"x": 1510,
73+
"y": 520,
74+
"wires": []
75+
},
76+
{
77+
"id": "2bb6a27f.f9fd7e",
78+
"type": "inject",
79+
"z": "7ecdfb0b.fa7794",
80+
"name": "speed: 1",
81+
"props": [{ "p": "payload" }],
82+
"repeat": "",
83+
"crontab": "",
84+
"once": false,
85+
"onceDelay": 0.1,
86+
"topic": "",
87+
"payload": "{\"speed\":1}",
88+
"payloadType": "json",
89+
"x": 940,
90+
"y": 600,
91+
"wires": [["1de955b6.491d3a"]]
92+
},
93+
{
94+
"id": "a2e1af48.ab3c2",
95+
"type": "comment",
96+
"z": "7ecdfb0b.fa7794",
97+
"name": "Alexa, set the bedroom fan speed to 7.",
98+
"info": "",
99+
"x": 1050,
100+
"y": 380,
101+
"wires": []
102+
},
103+
{
104+
"id": "394a1805.f60018",
105+
"type": "comment",
106+
"z": "7ecdfb0b.fa7794",
107+
"name": "Alexa, set the fan speed on the bedroom fan to maximum.",
108+
"info": "",
109+
"x": 1110,
110+
"y": 420,
111+
"wires": []
112+
},
113+
{
114+
"id": "33cd6994.775376",
115+
"type": "inject",
116+
"z": "7ecdfb0b.fa7794",
117+
"name": "speed: 5",
118+
"props": [{ "p": "payload" }],
119+
"repeat": "",
120+
"crontab": "",
121+
"once": false,
122+
"onceDelay": 0.1,
123+
"topic": "",
124+
"payload": "{\"speed\":5}",
125+
"payloadType": "json",
126+
"x": 940,
127+
"y": 640,
128+
"wires": [["1de955b6.491d3a"]]
129+
},
130+
{
131+
"id": "8c250365.04683",
132+
"type": "inject",
133+
"z": "7ecdfb0b.fa7794",
134+
"name": "speed: 10",
135+
"props": [{ "p": "payload" }],
136+
"repeat": "",
137+
"crontab": "",
138+
"once": false,
139+
"onceDelay": 0.1,
140+
"topic": "",
141+
"payload": "{\"speed\":10}",
142+
"payloadType": "json",
143+
"x": 940,
144+
"y": 680,
145+
"wires": [["1de955b6.491d3a"]]
146+
}
147+
]

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The _virtual smart home_ skill is available in the Amazon skill stores in the fo
2424
- Color Changing Light Bulb
2525
- Dimmable Light Bulb
2626
- Dimmer Switch
27+
- Fan
2728
- Garage Door Opener
2829
- Plug
2930
- Switch

virtual-device.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<option value="COLOR_CHANGING_LIGHT_BULB">Color Changing Light Bulb</option>
8585
<option value="DIMMABLE_LIGHT_BULB">Dimmable Light Bulb</option>
8686
<option value="DIMMER_SWITCH">Dimmer Switch</option>
87+
<option value="FAN">Fan</option>
8788
<option value="GARAGE_DOOR_OPENER">Garage Door Opener</option>
8889
<option value="PLUG">Plug</option>
8990
<option value="SCENE">Scene</option>
@@ -383,6 +384,20 @@ <h4>Dimmer Switch</h4>
383384
<dd>Brightness in % (0...100)</dd>
384385
</dl>
385386

387+
<h4>Fan</h4>
388+
<dl class="message-properties">
389+
<dt>
390+
payload.powerState
391+
<span class="property-type">string</span>
392+
</dt>
393+
<dd>'ON' or 'OFF'</dd>
394+
<dt>
395+
payload.speed
396+
<span class="property-type">int</span>
397+
</dt>
398+
<dd>Fan speed (0...10)</dd>
399+
</dl>
400+
386401
<h4>Garage Door Opener</h4>
387402
<dl class="message-properties">
388403
<dt>

0 commit comments

Comments
 (0)