Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Bug fixes:
Browse files Browse the repository at this point in the history
Add device now returns the new ID
Demo Sensor Values return correct type
  • Loading branch information
p3tecracknell committed Jun 8, 2013
1 parent 4213741 commit 55af3b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tellprox/msensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, protocol, model, id, datatypes):
self.datatypes = datatypes

def value(self, datatype):
return MSensorValue('val', 1369347055)
return MSensorValue(5, 1369347055)

def has_temperature(self):
return self.datatypes & TELLSTICK_TEMPERATURE != 0
Expand Down
43 changes: 30 additions & 13 deletions tellprox/tellstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,26 @@ def route_devices(self, func):
if not func == 'list': bh.raise404()

supportedMethods = self.get_supported_methods()
self.load_devices()
return { 'device': [
self.map_device_to_json(device, supportedMethods)
for k, device in self.devices.iteritems()
]}

def route_device(self, func):
if (func == 'add'): resp = self.add_device()
id = ''
if (func == 'add'):
resp = self.add_device()
print resp
if type(resp) is td.Device:
id = resp.id
print id
resp = TELLSTICK_SUCCESS
else:
""" With the only function that does not require ID out of the way,
determine the device we want to interact with """
id = bh.get_int('id')
self.load_devices()
if (self.devices.has_key(id)):
device = self.devices[id]
if (func == 'info'):
Expand All @@ -73,7 +82,7 @@ def route_device(self, func):
else:
resp = "Device " + "\"" + str(id) + "\" not found!"

return self.map_response(resp)
return self.map_response(resp, id)

def add_device(self):
if (self.config['editable'] is False):
Expand All @@ -83,13 +92,13 @@ def add_device(self):
if (clientid != self.config['client_id']):
return "Client \"" + str(clientid) + "\" not found!"

# TODO try/catch handling
self.core.add_device(
bh.get_string('name'),
bh.get_string('protocol'),
bh.get_string('model'))

return TELLSTICK_SUCCESS
try:
return self.core.add_device(
bh.get_string('name'),
bh.get_string('protocol'),
bh.get_string('model'))
except Exception as e:
return e

def device_command(self, device, func, value = ''):
# TODO replace with try/catch
Expand All @@ -102,9 +111,13 @@ def device_command(self, device, func, value = ''):
elif (func == 'turnon'): device.turn_on()
elif (func == 'turnoff'): device.turn_off()
elif (func == 'up'): device.up()
elif (func == 'toggle'): self.toggle_device(device)

return TELLSTICK_SUCCESS

def toggle_device(self, device):
a = 1

def device_set_parameter(self, device, attr):
if (attr == 'parameter'):
resp = device.set_parameter(bh.get_string('parameter'), bh.get_string('value'))
Expand All @@ -121,16 +134,15 @@ def route_clients(self, func):
return { 'client': [self.get_client_info()] }

def route_client(self, func):
if not func == 'list': bh.raise404()

clientid = self.get_client_id()
if (clientid != config['client_id']):
if (clientid != self.config['client_id']):
return { "error" : "Client \"" + str(clientid) + "\" not found!" }
return self.get_client_info()

def route_sensors(self, func):
if not func == 'list': bh.raise404()

self.load_sensors()
includeIgnored = True if bh.get_int('includeignored') == 1 else False
return { 'sensor': [
self.map_sensor_to_json(sensor)
Expand All @@ -142,6 +154,8 @@ def route_sensor(self, func):
# The ID should be an integer, but we store them in the dictionary as
# strings, so treat as such
id = str(bh.get_int('id'))

self.load_sensors()
resp = TELLSTICK_SUCCESS
if (self.sensors.has_key(id)):
sensor = self.sensors[id]
Expand Down Expand Up @@ -235,7 +249,10 @@ def get_client_info(self):

def map_response(self, cmdresp, id = '', method = ''):
if (cmdresp == TELLSTICK_SUCCESS):
return { "status" : "success" }
resp = { "status" : "success" }
if not id == '':
resp['id'] = id
return resp
elif isinstance(cmdresp, int):
id = str(id)
if (cmdresp == TELLSTICK_ERROR_DEVICE_NOT_FOUND):
Expand Down

0 comments on commit 55af3b8

Please sign in to comment.