Skip to content
This repository has been archived by the owner on May 23, 2020. It is now read-only.

Commit

Permalink
Close #6 Add device creation from admin
Browse files Browse the repository at this point in the history
  • Loading branch information
tikismoke committed Oct 9, 2016
1 parent 0c894b9 commit 61a42a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 18 additions & 2 deletions admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import nest
import locale
import time
import json


### package specific functions
Expand All @@ -34,9 +35,23 @@ def get_device_list(username , password):
for structure in napi.structures:
return_value = return_value + "Nest.Home name: " + " " + str(structure.name) + "\n"
for ProtectDevice in structure.protectdevices:
return_value = return_value + "Nest.Protect serial: " + " " + str(ProtectDevice.name) + "\n"
return_value = return_value + "Nest.Protect serial: " + " " + str(ProtectDevice.where) + " " + str(ProtectDevice.serial) + "\n"
for device in structure.devices:
return_value = return_value + "Nest.Thermostat serial: " + " " + str(device.name) + "\n"
return_value = return_value + "Nest.Thermostat serial: " + " " + str(device.where) + " " + str(device.serial) + "\n"
return return_value
except:
return unicode("ERROR getting Nest information!\nCheck your configuration.\nOr wait some time if you do too much request in little time.", 'utf-8')

def get_device(username , password):
napi = nest.Nest(username , password)
try:
return_value = []
for structure in napi.structures:
return_value.append({'type':'nest.home','where':str(structure.name),'serial':str(structure.name)})
for ProtectDevice in structure.protectdevices:
return_value.append({'type':'nest.protect','where':str(ProtectDevice.where),'serial':str(ProtectDevice.serial)})
for device in structure.devices:
return_value.append({'type':'nest.thermostat','where':str(device.where),'serial':str(device.serial)})
return return_value
except:
return unicode("ERROR getting Nest information\nCheck your configuration", 'utf-8')
Expand Down Expand Up @@ -65,6 +80,7 @@ def index(client_id):
mactive="clients",
active = 'advanced',
device_list = get_device_list(nest_email_account,nest_password_account),
devices = get_device(nest_email_account,nest_password_account),
errorlog = get_info_from_log(geterrorlogcmd))

except TemplateNotFound:
Expand Down
20 changes: 20 additions & 0 deletions admin/templates/plugin_nestdevice.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@
<div class="panel-body">
<pre>{{ device_list }}</pre>
</div>
<table class='table'>
<thead>
<tr>
<th>{% trans %}Serial (Clic to create device){% endtrans %}</th>
<th>{% trans %}Device Type{% endtrans %}</th>
<th>{% trans %}Device Where{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for device in devices %}
<tr>
<td>
<a href="/client/{{ clientid }}/dmg_devices/new/type/{{device.type}}?serial={{ device.serial }}&name={{ device.serial }}">{{ device.serial }}</a></td>
<td>{{ device.type }}</td>
<td>{{ device.where }}</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>
</div>

Expand Down

0 comments on commit 61a42a3

Please sign in to comment.