Use feature 'required-binding'
[apps/hvac.git] / binding / hvac-demo-binding.c
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Copyright (C) 2016 Konsulko Group
4  * Author "Romain Forlot"
5  * Author "Jose Bolo"
6  * Author "Scott Murray <scott.murray@konsulko.com>"
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #define _GNU_SOURCE
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdbool.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <sys/ioctl.h>
29 #include <net/if.h>
30 #include <linux/can.h>
31 #include <math.h>
32 #include <json-c/json.h>
33
34 #define AFB_BINDING_VERSION 2
35 #include <afb/afb-binding.h>
36
37 #define RED "/sys/class/leds/blinkm-3-9-red/brightness"
38 #define GREEN "/sys/class/leds/blinkm-3-9-green/brightness"
39 #define BLUE "/sys/class/leds/blinkm-3-9-blue/brightness"
40
41 #define CAN_DEV "vcan0"
42
43 #ifndef NULL
44 #define NULL 0
45 #endif
46
47 static const struct afb_binding_interface *interface;
48 static struct afb_event event;
49
50 /*****************************************************************************************/
51 /*****************************************************************************************/
52 /**                                                                                     **/
53 /**                                                                                     **/
54 /**        SECTION: UTILITY FUNCTIONS                                                   **/
55 /**                                                                                     **/
56 /**                                                                                     **/
57 /*****************************************************************************************/
58 /*****************************************************************************************/
59
60 /*
61  * @brief Retry a function 3 times
62  *
63  * @param int function(): function that return an int wihtout any parameter
64  *
65  * @ return : 0 if ok, -1 if failed
66  *
67  */
68 static int retry( int(*func)())
69 {
70         int i;
71
72         for (i=0;i<4;i++)
73         {
74                 if ( (*func)() >= 0)
75                 {
76                         return 0;
77                 }
78                 usleep(100000);
79         }
80         return -1;
81 }
82
83 /*****************************************************************************************/
84 /*****************************************************************************************/
85 /**                                                                                     **/
86 /**                                                                                     **/
87 /**        SECTION: HANDLE CAN DEVICE                                                   **/
88 /**                                                                                     **/
89 /**                                                                                     **/
90 /*****************************************************************************************/
91 /*****************************************************************************************/
92
93 // Initialize CAN hvac array that will be sent trough the socket
94 static struct {
95         const char *name;
96         uint8_t value;
97 } hvac_values[] = {
98         { "LeftTemperature", 21 },
99         { "RightTemperature", 21 },
100         { "Temperature", 21 },
101         { "FanSpeed", 0 },
102         { "ACEnabled", 0 },
103         { "LeftLed", 15 },
104         { "RightLed", 15 }
105 };
106
107 // Holds RGB combinations for each temperature
108 static struct {
109         const int temperature;
110         const int rgb[3];
111 } degree_colours[] = {
112         {15, {0, 0, 229} },
113         {16, {22, 0, 204} },
114         {17, {34, 0, 189} },
115         {18, {46, 0, 175} },
116         {19, {58, 0, 186} },
117         {20, {70, 0, 146} },
118         {21, {82, 0, 131} },
119         {22, {104, 0, 116} },
120         {23, {116, 0, 102} },
121         {24, {128, 0, 87} },
122         {25, {140, 0, 73} },
123         {26, {152, 0, 58} },
124         {27, {164, 0, 43} },
125         {28, {176, 0, 29} },
126         {29, {188, 0, 14} },
127         {30, {201, 0, 5} }
128 };
129
130 struct can_handler {
131         int socket;
132         bool simulation;
133         char *send_msg;
134         struct sockaddr_can txAddress;
135 };
136
137 struct led_paths {
138         char *red;
139         char *green;
140         char *blue;
141 }led_paths_values = {
142         .red = RED,
143         .green = GREEN,
144         .blue = BLUE
145 };
146
147 static struct can_handler can_handler = { .socket = -1, .simulation = false, .send_msg = "SENDING CAN FRAME"};
148
149 static int open_can_dev_helper()
150 {
151         struct ifreq ifr;
152
153         AFB_DEBUG("CAN Handler socket : %d", can_handler.socket);
154         close(can_handler.socket);
155
156         can_handler.socket = socket(PF_CAN, SOCK_RAW, CAN_RAW);
157         if (can_handler.socket < 0)
158         {
159                 AFB_ERROR("socket could not be created");
160         }
161         else
162         {
163                 // Attempts to open a socket to CAN bus
164                 strcpy(ifr.ifr_name, CAN_DEV);
165                 if(ioctl(can_handler.socket, SIOCGIFINDEX, &ifr) < 0)
166                 {
167                         AFB_ERROR("ioctl failed");
168                 }
169                 else
170                 {
171                         can_handler.txAddress.can_family = AF_CAN;
172                         can_handler.txAddress.can_ifindex = ifr.ifr_ifindex;
173
174                         // And bind it to txAddress
175                         if (bind(can_handler.socket, (struct sockaddr *)&can_handler.txAddress, sizeof(can_handler.txAddress)) < 0)
176                         {
177                                 AFB_ERROR("bind failed");
178                         }
179                         else {
180                                 return 0;
181                         }
182                 }
183                 close(can_handler.socket);
184                 can_handler.socket = -1;
185         }
186         return -1;
187 }
188
189 static int open_can_dev()
190 {
191         int rc = retry(open_can_dev_helper);
192         if(rc < 0)
193         {
194                 AFB_ERROR("Open of interface %s failed. Falling back to simulation mode", CAN_DEV);
195                 can_handler.socket = 0;
196                 can_handler.simulation = true;
197                 can_handler.send_msg = "FAKE CAN FRAME";
198                 rc = 0;
199         }
200         return rc;
201 }
202
203 // Get original get temperature function from cpp hvacplugin code
204 static uint8_t to_can_temp(uint8_t value)
205 {
206         int result = ((0xF0 - 0x10) / 15) * (value - 15) + 0x10;
207         if (result < 0x10)
208                 result = 0x10;
209         if (result > 0xF0)
210                 result = 0xF0;
211
212         return (uint8_t)result;
213 }
214
215 static uint8_t read_temp_left_zone()
216 {
217         return hvac_values[0].value;
218 }
219
220 static uint8_t read_temp_right_zone()
221 {
222         return hvac_values[1].value;
223 }
224
225 static uint8_t read_temp_left_led()
226 {
227         return hvac_values[5].value;
228 }
229
230 static uint8_t read_temp_right_led()
231 {
232         return hvac_values[6].value;
233 }
234
235 static uint8_t read_temp()
236 {
237         return (uint8_t)(((int)read_temp_left_zone() + (int)read_temp_right_zone()) >> 1);
238 }
239
240 static uint8_t read_fanspeed()
241 {
242         return hvac_values[3].value;
243 }
244
245 /* 
246  * @param: None
247  *
248  * @brief: Parse JSON configuration file for blinkm path
249  */
250 static int parse_config()
251 {
252         struct json_object *ledtemp = NULL;
253         struct json_object *jobj = json_object_from_file("/etc/hvac.json");
254
255         // Check if .json file has been parsed as a json_object
256         if (!jobj) {
257                 AFB_ERROR("JSON file could not be opened!\n");
258                 return 1;
259         }
260
261         // Check if json_object with key "ledtemp" has been found in .json file
262         if (!json_object_object_get_ex(jobj, "ledtemp", &ledtemp)){
263                 AFB_ERROR("Key not found!\n");
264                 return 1;
265         }
266
267         // Extract directory paths for each LED colour
268         json_object_object_foreach(ledtemp, key, value) {
269                 if (strcmp(key, "red") == 0) {
270                         led_paths_values.red = json_object_get_string(value);
271                 } else if (strcmp(key, "green") == 0) {
272                         led_paths_values.green = json_object_get_string(value);
273                 } else if (strcmp(key, "blue") == 0) {
274                         led_paths_values.blue = json_object_get_string(value);
275                 }
276         }
277
278         // return 0 if all succeeded
279         return 0;
280
281 }
282
283 /* 
284  * @brief Writing to LED for both temperature sliders
285  */
286 static int temp_write_led()
287 {
288
289         int rc = -1, red_value, green_value, blue_value;
290         int right_temp;
291         int left_temp;
292
293         left_temp = read_temp_left_led() - 15;
294         right_temp = read_temp_right_led() - 15;
295
296         // Calculates average colour value taken from the temperature toggles
297         red_value = (degree_colours[left_temp].rgb[0] + degree_colours[right_temp].rgb[0]) / 2;
298         green_value = (degree_colours[left_temp].rgb[1] + degree_colours[right_temp].rgb[1]) / 2;
299         blue_value = (degree_colours[left_temp].rgb[2] + degree_colours[right_temp].rgb[2]) / 2;
300         
301         // default path: /sys/class/leds/blinkm-3-9-red/brightness
302         FILE* r = fopen(led_paths_values.red, "w");
303         if(r){
304                 fprintf(r, "%d", red_value);
305                 fclose(r);
306         } else {
307                 AFB_ERROR("Unable to open red LED path!\n");
308                 return -1;
309         }
310
311         // default path: /sys/class/leds/blinkm-3-9-green/brightness
312         FILE* g = fopen(led_paths_values.green, "w");
313         if(g){
314                 fprintf(g, "%d", green_value);
315                 fclose(g);
316         } else {
317                 AFB_ERROR("Unable to open green LED path!\n");
318                 return -1;
319         }
320
321         // default path: /sys/class/leds/blinkm-3-9-blue/brightness
322         FILE* b = fopen(led_paths_values.blue, "w");
323         if(b){
324                 fprintf(b, "%d", blue_value);
325                 fclose(b);
326         } else {
327                 AFB_ERROR("Unable to open blue LED path!\n");
328                 return -1;
329         }
330
331         return 0;
332 }
333
334 /*
335  * @brief Get temperature of left toggle in HVAC system
336  *
337  * @param struct afb_req : an afb request structure
338  *
339  */
340 static void temp_left_zone_led(struct afb_req request)
341 {
342         int i = 5, rc, x, changed;
343         double d;
344         struct json_object *query, *val;
345         uint8_t values[sizeof hvac_values / sizeof *hvac_values];
346         uint8_t saves[sizeof hvac_values / sizeof *hvac_values];
347
348         AFB_WARNING("In temp_left_zone_led.");
349
350         query = afb_req_json(request);
351
352         /* records initial values */
353         AFB_WARNING("Records initial values");
354         values[i] = saves[i] = hvac_values[i].value;
355
356
357         if (json_object_object_get_ex(query, hvac_values[i].name, &val))
358         {
359                 AFB_WARNING("Value of values[i] = %d", values[i]);
360                 AFB_WARNING("We got it. Tests if it is an int or double.");
361                 if (json_object_is_type(val, json_type_int)) {
362                         x = json_object_get_int(val);
363                         AFB_WARNING("We get an int: %d",x);
364                 }
365                 else if (json_object_is_type(val, json_type_double)) {
366                         d = json_object_get_double(val);
367                         x = (int)round(d);
368                         AFB_WARNING("We get a double: %f => %d",d,x);
369                 }
370                 else {
371                         afb_req_fail_f(request, "bad-request",
372                                 "argument '%s' isn't integer or double", hvac_values[i].name);
373                         return;
374                 }
375                 if (x < 0 || x > 255)
376                 {
377                         afb_req_fail_f(request, "bad-request",
378                                 "argument '%s' is out of bounds", hvac_values[i].name);
379                         return;
380                 }
381                 if (values[i] != x) {
382                         values[i] = (uint8_t)x;
383                         changed = 1;
384                         AFB_WARNING("%s changed to %d", hvac_values[i].name,x);
385                 }
386         }
387         else {
388                 AFB_WARNING("%s not found in query!",hvac_values[i].name);
389         }
390
391
392         if (changed) {
393                 hvac_values[i].value = values[i]; // update structure at line 102
394                 AFB_WARNING("WRITE_LED: value: %d", hvac_values[i].value);
395                 rc = temp_write_led();
396                 if (rc >= 0)
397                         afb_req_success(request, NULL, NULL);
398                 else if (retry(temp_write_led)) {
399                         /* restore initial values */
400                         hvac_values[i].value = saves[i];
401                         afb_req_fail(request, "error", "I2C error");
402                 }
403         }
404 }
405
406 /*
407  * @brief Get temperature of right toggle in HVAC system
408  *
409  * @param struct afb_req : an afb request structure
410  *
411  */
412 static void temp_right_zone_led(struct afb_req request)
413 {
414         int i = 6, rc, x, changed;
415         double d;
416         struct json_object *query, *val;
417         uint8_t values[sizeof hvac_values / sizeof *hvac_values];
418         uint8_t saves[sizeof hvac_values / sizeof *hvac_values];
419
420         AFB_WARNING("In temp_right_zone_led.");
421
422         query = afb_req_json(request);
423
424         /* records initial values */
425         AFB_WARNING("Records initial values");
426         values[i] = saves[i] = hvac_values[i].value;
427
428
429         if (json_object_object_get_ex(query, hvac_values[i].name, &val))
430         {
431                 AFB_WARNING("Value of values[i] = %d", values[i]);
432                 AFB_WARNING("We got it. Tests if it is an int or double.");
433                 if (json_object_is_type(val, json_type_int)) {
434                         x = json_object_get_int(val);
435                         AFB_WARNING("We get an int: %d",x);
436                 }
437                 else if (json_object_is_type(val, json_type_double)) {
438                         d = json_object_get_double(val);
439                         x = (int)round(d);
440                         AFB_WARNING("We get a double: %f => %d",d,x);
441                 }
442                 else {
443                         afb_req_fail_f(request, "bad-request",
444                                 "argument '%s' isn't integer or double", hvac_values[i].name);
445                         return;
446                 }
447                 if (x < 0 || x > 255)
448                 {
449                         afb_req_fail_f(request, "bad-request",
450                                 "argument '%s' is out of bounds", hvac_values[i].name);
451                         return;
452                 }
453                 if (values[i] != x) {
454                         values[i] = (uint8_t)x;
455                         changed = 1;
456                         AFB_WARNING("%s changed to %d", hvac_values[i].name,x);
457                 }
458         }
459         else {
460                 AFB_WARNING("%s not found in query!", hvac_values[i].name);
461         }
462
463
464         if (changed) {
465                 hvac_values[i].value = values[i]; // update structure at line 102
466                 AFB_WARNING("WRITE_LED: value: %d", hvac_values[i].value);
467                 rc = temp_write_led();
468                 if (rc >= 0)
469                         afb_req_success(request, NULL, NULL);
470                 else if (retry(temp_write_led)) {
471                         /* restore initial values */
472                         hvac_values[i].value = saves[i];
473                         afb_req_fail(request, "error", "I2C error");
474                 }
475         }
476 }
477
478 static int write_can()
479 {
480         struct can_frame txCanFrame;
481         int rc = 0;
482
483         rc = can_handler.socket;
484         if (rc >= 0)
485         {
486                 // Hardcoded can_id and dlc (data lenght code)
487                 txCanFrame.can_id = 0x30;
488                 txCanFrame.can_dlc = 8;
489                 txCanFrame.data[0] = to_can_temp(read_temp_left_zone());
490                 txCanFrame.data[1] = to_can_temp(read_temp_right_zone());
491                 txCanFrame.data[2] = to_can_temp(read_temp());
492                 txCanFrame.data[3] = 0xf0;
493                 txCanFrame.data[4] = read_fanspeed();
494                 txCanFrame.data[5] = 1;
495                 txCanFrame.data[6] = 0;
496                 txCanFrame.data[7] = 0;
497
498                 AFB_DEBUG("%s: %d %d [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
499                         can_handler.send_msg,
500                         txCanFrame.can_id, txCanFrame.can_dlc,
501                         txCanFrame.data[0], txCanFrame.data[1], txCanFrame.data[2], txCanFrame.data[3],
502                         txCanFrame.data[4], txCanFrame.data[5], txCanFrame.data[6], txCanFrame.data[7]);
503
504                 if(!can_handler.simulation)
505                 {
506                         rc = (int)sendto(can_handler.socket, &txCanFrame, sizeof(struct can_frame), 0,
507                                 (struct sockaddr*)&can_handler.txAddress, sizeof(can_handler.txAddress));
508                         if (rc < 0)
509                         {
510                                 AFB_ERROR("Sending CAN frame failed.");
511                         }
512                 }
513         }
514         else
515         {
516                 AFB_ERROR("socket not initialized. Attempt to reopen can device socket.");
517                 open_can_dev();
518         }
519         return rc;
520 }
521
522 /*****************************************************************************************/
523 /*****************************************************************************************/
524 /**                                                                                     **/
525 /**                                                                                     **/
526 /**        SECTION: BINDING VERBS IMPLEMENTATION                                        **/
527 /**                                                                                     **/
528 /**                                                                                     **/
529 /*****************************************************************************************/
530 /*****************************************************************************************/
531
532 /*
533  * @brief Get fan speed HVAC system
534  *
535  * @param struct afb_req : an afb request structure
536  *
537  */
538 static void get_fanspeed(struct afb_req request)
539 {
540         json_object *ret_json;
541         uint8_t fanspeed = read_fanspeed();
542
543         ret_json = json_object_new_object();
544         json_object_object_add(ret_json, "FanSpeed", json_object_new_int(fanspeed));
545
546         afb_req_success(request, ret_json, NULL);
547 }
548
549 /*
550  * @brief Read Consign right zone temperature for HVAC system
551  *
552  * @param struct afb_req : an afb request structure
553  *
554  */
555 static void get_temp_right_zone(struct afb_req request)
556 {
557         json_object *ret_json;
558         uint8_t temp = read_temp_right_zone();
559
560         ret_json = json_object_new_object();
561         json_object_object_add(ret_json, "RightTemperature", json_object_new_int(temp));
562
563         afb_req_success(request, ret_json, NULL);
564 }
565
566 /*
567  * @brief Read Consign left zone temperature for HVAC system
568  *
569  * @param struct afb_req : an afb request structure
570  *
571  */
572 static void get_temp_left_zone(struct afb_req request)
573 {
574         json_object *ret_json;
575         uint8_t temp = read_temp_left_zone();
576
577         ret_json = json_object_new_object();
578         json_object_object_add(ret_json, "LeftTemperature", json_object_new_int(temp));
579
580         afb_req_success(request, ret_json, NULL);
581 }
582
583 /*
584  * @brief Read all values
585  *
586  * @param struct afb_req : an afb request structure
587  *
588  */
589 static void get(struct afb_req request)
590 {
591         AFB_DEBUG("Getting all values");
592         json_object *ret_json;
593
594         ret_json = json_object_new_object();
595         json_object_object_add(ret_json, "LeftTemperature", json_object_new_int(read_temp_left_zone()));
596         json_object_object_add(ret_json, "RightTemperature", json_object_new_int(read_temp_right_zone()));
597         json_object_object_add(ret_json, "FanSpeed", json_object_new_int(read_fanspeed()));
598
599         afb_req_success(request, ret_json, NULL);
600 }
601
602 /*
603  * @brief Set a component value using a json object retrieved from request
604  *
605  * @param struct afb_req : an afb request structure
606  *
607  */
608 static void set(struct afb_req request)
609 {
610         int i, rc, x, changed;
611         double d;
612         struct json_object *query, *val;
613         uint8_t values[sizeof hvac_values / sizeof *hvac_values];
614         uint8_t saves[sizeof hvac_values / sizeof *hvac_values];
615
616         /* records initial values */
617         AFB_DEBUG("Records initial values");
618         i = (int)(sizeof hvac_values / sizeof *hvac_values);
619         while (i) {
620                 i--;
621                 values[i] = saves[i] = hvac_values[i].value;
622         }
623
624         /* Loop getting arguments */
625         query = afb_req_json(request);
626         changed = 0;
627         i = (int)(sizeof hvac_values / sizeof *hvac_values);
628         AFB_DEBUG("Looping for args. i: %d", i);
629         while (i)
630         {
631                 i--;
632                 AFB_DEBUG("Searching... query: %s, i: %d, comp: %s", json_object_to_json_string(query), i, hvac_values[i].name);
633                 if (json_object_object_get_ex(query, hvac_values[i].name, &val))
634                 {
635                         AFB_DEBUG("We got it. Tests if it is an int or double.");
636                         if (json_object_is_type(val, json_type_int)) {
637                                 x = json_object_get_int(val);
638                                 AFB_DEBUG("We get an int: %d",x);
639                         }
640                         else if (json_object_is_type(val, json_type_double)) {
641                                 d = json_object_get_double(val);
642                                 x = (int)round(d);
643                                 AFB_DEBUG("We get a double: %f => %d",d,x);
644                         }
645                         else {
646                                 afb_req_fail_f(request, "bad-request",
647                                         "argument '%s' isn't integer or double", hvac_values[i].name);
648                                 return;
649                         }
650                         if (x < 0 || x > 255)
651                         {
652                                 afb_req_fail_f(request, "bad-request",
653                                         "argument '%s' is out of bounds", hvac_values[i].name);
654                                 return;
655                         }
656                         if (values[i] != x) {
657                                 values[i] = (uint8_t)x;
658                                 changed = 1;
659                                 AFB_DEBUG("%s changed to %d",hvac_values[i].name,x);
660                         }
661                 }
662                 else {
663                         AFB_DEBUG("%s not found in query!",hvac_values[i].name);
664                 }
665         }
666
667         /* attemps to set new values */
668         AFB_DEBUG("Diff: %d", changed);
669         if (changed)
670         {
671                 i = (int)(sizeof hvac_values / sizeof *hvac_values);
672                 while (i) {
673                         i--;
674                         hvac_values[i].value = values[i];
675                 }
676                 rc = write_can();
677                 if (rc >= 0)
678                         afb_req_success(request, NULL, NULL);
679                 else if (retry(write_can)) {
680                         /* restore initial values */
681                         i = (int)(sizeof hvac_values / sizeof *hvac_values);
682                         while (i) {
683                                 i--;
684                                 hvac_values[i].value = saves[i];
685                         }
686                         afb_req_fail(request, "error", "CAN error");
687                 }
688         }
689         else {
690                 afb_req_success(request, NULL, "No changes");
691         }
692 }
693
694 int bindingServicePreInit(struct afb_service service)
695 {
696         return open_can_dev();
697 }
698
699 int bindingServiceInit(struct afb_service service)
700 {
701         event = afb_daemon_make_event("language");
702         if(parse_config() != 0)
703                 AFB_WARNING("Default values are being used!\n");
704         if(afb_daemon_require_api("identity", 1))
705                 return -1;
706         return afb_service_call_sync("identity", "subscribe", NULL, NULL);
707 }
708
709 void onEvent(const char *event_name, struct json_object *object)
710 {
711         json_object *args, *language = json_object_new_object();
712         json_object *id_evt_name, *current_identity;
713
714         AFB_NOTICE("Event '%s' received: %s", event_name,
715                 json_object_to_json_string_ext(object, JSON_C_TO_STRING_PRETTY));
716
717         if (json_object_object_get_ex(object, "eventName", &id_evt_name) &&
718           !strcmp(json_object_get_string(id_evt_name), "login") &&
719           !afb_service_call_sync("identity", "get", NULL, &current_identity)) {
720                 json_object *response;
721                 if (! json_object_object_get_ex(current_identity, "response", &response) || ! json_object_object_get_ex(response, "graphPreferredLanguage", &language)) {
722                         language = json_object_new_string("en_US");
723                 }
724                 afb_event_broadcast(event, language);
725         }
726 }
727
728 // TODO: Have to change session management flag to AFB_SESSION_CHECK to use token auth
729 static const struct afb_verb_v2 _afb_verbs_v2_hvac[]= {
730         {
731                 .verb = "get_temp_left_zone",
732                 .callback = get_temp_left_zone,
733                 .auth = NULL,
734                 .info = "Get the left zone temperature",
735                 .session = AFB_SESSION_NONE_V2
736         },
737         {
738                 .verb = "get_temp_right_zone",
739                 .callback = get_temp_right_zone,
740                 .auth = NULL,
741                 .info = "Get the right zone temperature",
742                 .session = AFB_SESSION_NONE_V2
743         },
744         {
745                 .verb = "get_fanspeed",
746                 .callback = get_fanspeed,
747                 .auth = NULL,
748                 .info = "Read fan speed",
749                 .session = AFB_SESSION_NONE_V2
750         },
751         {
752                 .verb = "get",
753                 .callback = get,
754                 .auth = NULL,
755                 .info = "Read all speed",
756                 .session = AFB_SESSION_NONE_V2
757         },
758         {
759                 .verb = "set",
760                 .callback = set,
761                 .auth = NULL,
762                 .info = "Set a HVAC component value",
763                 .session = AFB_SESSION_NONE_V2
764         },
765         {
766                 .verb = "temp_left_zone_led",
767                 .callback = temp_left_zone_led,
768                 .auth = NULL,
769                 .info = "Turn on LED on left temperature zone",
770                 .session = AFB_SESSION_NONE_V2
771         },
772         {
773                 .verb = "temp_right_zone_led",
774                 .callback = temp_right_zone_led,
775                 .auth = NULL,
776                 .info = "Turn on LED on left temperature zone",
777                 .session = AFB_SESSION_NONE_V2
778
779         },
780         {
781                 .verb = NULL,
782                 .callback = NULL,
783                 .auth = NULL,
784                 .info = NULL,
785                 .session = 0
786         }
787 };
788
789 const struct afb_binding_v2 afbBindingV2 = {
790     .api = "hvac",
791     .specification = NULL,
792     .info = "HVAC service",
793     .verbs = _afb_verbs_v2_hvac,
794     .preinit = bindingServicePreInit,
795     .init = bindingServiceInit,
796     .onevent = onEvent,
797     .noconcurrency = 0
798 };