Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta charset="utf-8" />
- <title>Hemmet</title>
- <style type="text/css">
- body{
- zoom: 200%;
- -moz-transform: scale(2);
- -moz-transform-origin: 0 0;
- }
- </style>
- <script type="text/javascript">
- var devices = [
- { id: 'HallwayFloorOne', title: 'Hallen' },
- { id: 'DiningRoomWindows', title: 'Matsalsfönster' },
- { id: 'OutsideStair', title: 'Trappen ute' },
- { id: 'HallwayFloorTwo', title: 'Hallen uppe' },
- { id: 'DiningRoom', title: 'Matsalen'},
- { id: 'Driveway', title: 'Uppfarten'}
- ];
- function createEntry(device) {
- var li = document.createElement('li');
- li.appendChild(createButton('off', function () {
- performAction(device.id, 'turnoff');
- }));
- li.appendChild(document.createTextNode(device.title));
- li.appendChild(createButton('on', function () {
- performAction(device.id, 'turnon');
- }));
- return li;
- }
- function performAction(deviceId, command) {
- requestGet('DeviceCommand?device=' + deviceId + '&command=' + command);
- }
- function requestGet(param){
- var address = 'http://192.168.0.138:1880';
- var httpRequest = new XMLHttpRequest();
- httpRequest.timeout = 500;
- httpRequest.open('GET', address + '/' + param);
- // httpRequest.open('GET', 'http://192.168.0.138:1880/DeviceCommand?device=' + deviceId + '&command=' + command);
- httpRequest.send(null);
- }
- function init() {
- var deviceContainer = document.getElementById('deviceList');
- devices.forEach(function (device) {
- var li = createEntry(device);
- deviceContainer.appendChild(li);
- });
- document.getElementById('startBarnkanalen').addEventListener('click', function(){
- requestGet('WebToIr?device=thomson&command=9');
- requestGet('WebToIr?device=tv&command=power');
- requestGet('WebToIr?command=power&device=tv'); //need two entries to start tv...
- setTimeout(function(){
- requestGet('WebToIr?device=receiver&command=power');
- setTimeout(function(){
- requestGet('WebToIr?device=receiver&command=cbl_sat');
- },1500);
- },1500);
- });
- }
- function createButton(text, func) {
- var button = document.createElement("button");
- button.innerText = text;
- button.addEventListener('click', func)
- return button;
- }
- document.addEventListener('DOMContentLoaded', init);
- </script>
- </head>
- <body>
- <div id="deviceControl">
- <ul id="deviceList"></ul>
- <ul>
- <button id="startBarnkanalen">Starta barnkanalen</button>
- </ul>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement