<commit_before><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Raspberry Pi - Controls</title>
<script type="text/javascript" src="mtc-1.5.1.js"></script>
<script type="text/javascript" src="mtm-1.5.1.js"></script>
<script type="text/javascript" src="ui-c.js"></script>
<script type="text/javascript" src="ui-s.js"></script>
<script type="text/javascript" src="ui-ls.js"></script>
<script type="text/javascript" src="ws.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript">


	window.addEvent('load',function(){
	
		var websocket=new WebsocketControlQuery('ws://'+window.location.hostname+':8080').addEvent('connect',function(){
				
			
			var getDevices=function(callback){
				websocket.execute('list_devices', {}, function(response){
					callback(JSON.parse(response));
				});
			};
			
			
			var setDeviceValue=function(pin, value){
				websocket.execute('set_device_value', {pin:pin, value:value}, function(response){
					console.log(response);
				});
				
			}
			
			getDevices(function(devices){
				
				
				var deviceMap={};
				
				Array.each(devices,function(device){
					var state=device.state;
					var container=$$('body')[0].appendChild(new Element('div'));
					var control=new UISwitchControl(container, {state:state}).addEvent("change",function(newState){
						if(state!=newState){
							setDeviceValue(device.pin, newState);
							state=newState;
						}
					});
					container.appendChild(new Element('label', {html:device.name}));
					if(device.direction==='in'){
						control.disable(); //read display only device
					}
					
					device.control=control; 
					
				});
				
				
				websocket.addEvent('notification.statechange', function(response){
					
					var data=JSON.parse(response);
					Array.each(devices,function(device){
						
						if(device.pin===data.pin){
							device.control.setValue(data.value);
						}
						
					});
					
				})
				
				
			});
			
			
			
			
			
			
			
		});






	
		
		
		
	});


	


</script>
</head>
<body><commit_msg>added todo comment. there could be a server client notification loop.<commit_after><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Raspberry Pi - Controls</title>
<script type="text/javascript" src="mtc-1.5.1.js"></script>
<script type="text/javascript" src="mtm-1.5.1.js"></script>
<script type="text/javascript" src="ui-c.js"></script>
<script type="text/javascript" src="ui-s.js"></script>
<script type="text/javascript" src="ui-ls.js"></script>
<script type="text/javascript" src="ws.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript">


	window.addEvent('load',function(){
	
		var websocket=new WebsocketControlQuery('ws://'+window.location.hostname+':8080').addEvent('connect',function(){
				
			
			var getDevices=function(callback){
				websocket.execute('list_devices', {}, function(response){
					callback(JSON.parse(response));
				});
			};
			
			
			var setDeviceValue=function(pin, value){
				websocket.execute('set_device_value', {pin:pin, value:value}, function(response){
					console.log(response);
				});
				
			}
			
			
			websocket.addEvent('notification.statechange', function(response){
				
				var data=JSON.parse(response);
				Array.each(devices,function(device){
					
					if(device.pin===data.pin){
						
						// control is added to device on initialization below.		
						device.control.setValue(data.value);	
						// TODO: the event for this setValue task, should be suppressed, otherwise
						// a notification will be sent to the server, and strange race conditions 
						// could occur.
					}
					
				});
				
			});
			
			
			getDevices(function(devices){
				
				
				var deviceMap={};
				
				
				
				Array.each(devices,function(device){
					var state=device.state;
					var container=$$('body')[0].appendChild(new Element('div'));
					var control=new UISwitchControl(container, {state:state}).addEvent("change",function(newState){
						if(state!=newState){
							setDeviceValue(device.pin, newState);
							state=newState;
						}
					});
					container.appendChild(new Element('label', {html:device.name}));
					if(device.direction==='in'){
						control.disable(); //read display only device
					}
					
					device.control=control; 
					
				});
				
				
				
				
				
			});
			
			
			
			
			
			
			
		});






	
		
		
		
	});


	


</script>
</head>
<body>
{'fraction_non_alphanumeric': 0.1686557081738347, 'fraction_numerical': 0.005404188245890566, 'mean_word_length': 3.009025270758123, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4843873', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1342, 'n_words': 214}