diff options
author | Roger Zanoni <rzanoni@igalia.com> | 2023-12-28 20:07:05 -0300 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2024-01-29 12:07:20 +0000 |
commit | c323ab8fde212120d8d1914d453afeb55b3576e5 (patch) | |
tree | 2f3565da1e623d69297b00d2a5e1e2b261692810 /src/js/buttons.js | |
parent | 5f1b6075982b872b5db4e2195e53d19529278d5c (diff) |
Update HVAC app to use grpc-web instead of websockets
Adapt the HTML5 applications to use kuksa.val service
Bug-AGL: SPEC-4599
Signed-off-by: Roger Zanoni <rzanoni@igalia.com>
Change-Id: I3e36a6c08041db8fb59fd7f20497c1c156bbb2f7
Diffstat (limited to 'src/js/buttons.js')
-rw-r--r-- | src/js/buttons.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/js/buttons.js b/src/js/buttons.js index 76d2143..c593445 100644 --- a/src/js/buttons.js +++ b/src/js/buttons.js @@ -14,15 +14,6 @@ * limitations under the License. */ - - -var values = { - ac: false, - recirculation: false, - rear: false, - front: false -}; - var paths = { ac: PATHS.airConditioning, recirculation: PATHS.recirculation, @@ -30,7 +21,7 @@ var paths = { front: PATHS.frontDefroster, }; -var nodes = {} +var nodes = new Map(); export function init() { nodes[PATHS.airConditioning] = document.getElementById('ac'); @@ -40,10 +31,15 @@ export function init() { nodes['up'] = document.getElementById('up'); nodes['down'] = document.getElementById('down'); nodes['right'] = document.getElementById('right'); + + nodes.forEach(function(node, path) { + node.setAttribute('value', false); + }); } -export function update(path, value) { +export function update(path, dp) { if (path == PATHS.leftAirDistribution) { + var value = dp.getString(); if (value == 'UP') { nodes['up'].setAttribute('value', true); nodes['down'].setAttribute('value', false); @@ -60,20 +56,25 @@ export function update(path, value) { } } else { var node = nodes[path]; + var value = dp.getBool(); node.setAttribute('value', value); } } export function toggle(node) { var key = node.getAttribute('key'); - values[key] = !values[key]; + if (KUKSA.isLocked(paths[key])) { + return; + } + if (key == 'up') { - KUKSA.set(PATHS.leftAirDistribution, 'UP'); + KUKSA.setString(PATHS.leftAirDistribution, 'UP'); } else if (key == 'down') { - KUKSA.set(PATHS.leftAirDistribution, 'DOWN'); + KUKSA.setString(PATHS.leftAirDistribution, 'DOWN'); } else if (key == 'right') { - KUKSA.set(PATHS.leftAirDistribution, 'MIDDLE'); + KUKSA.setString(PATHS.leftAirDistribution, 'MIDDLE'); } else { - KUKSA.set(paths[key], values[key]); + var value = node.getAttribute('value').toLowerCase() == 'true'; + KUKSA.setBool(paths[key], !value); } } |