<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<style>
	table, th, td {
			border: 1px solid black;
			border-collapse: collapse;
	}
	</style>
	<title>Iotsa Devices</title>
</head>
<body>
	<h1>Iotsa Devices</h1>
	{% if set %}
		{% set modModule = {} %}
		{% set _ = modModule.update({key_1 : value_1}) if change_1 else None %}
		{% set _ = modModule.update({key_2 : value_2}) if change_2 else None %}
		{% set _ = modModule.update({key_3 : value_3}) if change_3 else None %}
		{% set deviceStatus = pluginObject._getorset(device, module=module, protocol=protocol, credentials=credentials, port=port, noverify=noverify, token=token, **modModule) %}
	{% endif %}
	{% set deviceStatus = pluginObject._getorset(device, module=module, protocol=protocol, credentials=credentials, port=port, noverify=noverify, includeConfig=True, token=token) %}
	{% set device = deviceStatus.device %}
	{% set config = deviceStatus.get('config', {}) %}
	{% set module = deviceStatus.module %}
	{% set status = deviceStatus.get(module, {}) %}
	{% set message = deviceStatus.message %}	
	{% if message %}
		<h2>User Intervention Required</h2>
		<p><b>Message:</b> {{message}}</p>
		{% if message[:4] == '502 ' %}
			<p>If the SSL certificate of iotsa device "{{device}}" is not trusted by this Igor please try to connect using the form at the bottom of the
			<a href="_showDeviceList.html">iotsa device list</a> page and select the <em>Do not check SSL certificates</em> option.</p>
		{% elif message[:4] == '401 ' %}
			<p>To allow access to module "{{module}}" iotsa device "{{device}}" requires either a trusted capability (which Igor does not have yet) or
			username/passord credentials. You can use the latter by selecting this device on the form at the bottom of 
			<a href="_showDeviceList.html">iotsa device list</a> and providing them in the <em>credentials</em> field.</p>
		{% endif %}
	{% endif %}
	

	<h2>Status for device {{device}}, module {{module}}</h2>
	<table>
		<tr><th>Key</th><th>Value</th></tr>
		{% for k, v in status.items() %}
			<tr><td>{{k}}</td><td>{{v}}</td></tr>
		{% endfor %}
	</table>
	
	<h2>Changing {{module}} configuration</h2>
	
	{% if config.currentMode == 1 %}
		<p>Device {{device}} is in configuration mode.</p>
	{% elif config.requestedMode == 1 %}
		<p>
		You have requested configuration mode, but not rebooted {{device}} yet. Please do so within {{config.requestedModeTimeout}} seconds and select
		<a href="_showModule.html?device={{device}}&module={{module}}">refresh</a>
		to reload this page.
		</p>
	{% else %}
		<p>To change {{module}} configuration {{device}} may have to be in configuration mode. You can request the device to go to configuration mode on the 
		<a href="_showDevice.html?device={{device}}">device status page</a>.
		</p>
	{% endif %}
	<form>
		<input type="hidden" name="device" value="{{device}}">
		<input type="hidden" name="module" value="{{module}}">
		<input type="hidden" name="set" value="1">
		<table>
			<tr>
				<th>Set?</th>
				<th><Key/th>
				<th>Value</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="change_1" value="1" id="change_1">
				<td><input type="text" name="key_1" oninput="document.getElementById('change_1').checked=true"></td>
				<td><input type="text" name="value_1"></td>
			</tr>
			<tr>
				<td><input type="checkbox" name="change_2" value="1" id="change_2">
				<td><input type="text" name="key_2" oninput="document.getElementById('change_2').checked=true"></td>
				<td><input type="text" name="value_2"></td>
			</tr>
			<tr>
				<td><input type="checkbox" name="change_3" value="1" id="change_3">
				<td><input type="text" name="key_3" oninput="document.getElementById('change_3').checked=true"></td>
				<td><input type="text" name="value_3"></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="Set key/value pairs">
			</tr>
		</table>
	</form>
	<hr>
	<a href="_showDevice.html?device={{device}}">Return to {{device}} device status page.</a><br>
	{% if returnTo %}
		<a href="{{returnTo}}">Return to {{returnTo}}.</a><br>
	{% endif %}
	<a href="/plugin/{{pluginName}}/page/index.html">Return to iotsa device setup page.</a><br>
	<a href="/">Return to Igor homepage</a>
	

</body>
</html>
