diff --git a/wlokalu/api/presence.py b/wlokalu/api/presence.py index cf6ef90..3fe4340 100644 --- a/wlokalu/api/presence.py +++ b/wlokalu/api/presence.py @@ -46,7 +46,22 @@ def sensor_state(sensor_id, state, context = None): return sensor_update_state(sensor_id, state, context) def list_sensors(): - return [] # TODO + return Sensor.objects.all().order_by('sensor_id') + +def list_list_sensors(): + sensors = {} + order = [] + for s in ListSensor.objects.all().order_by('sensor_id'): + entry = { + 'name': s.subname, + 'since': s.since, + } + if s.name not in sensors: + sensors[s.name] = { 'name': s.name, 'entries': [entry] } + order.append(s.name) + else: + sensors[s.name]['entries'].append(entry) + return [sensors[s] for s in order] def delete_sensor(sensor_id, context = None): sensors = Sensor.objects.filter(sensor_id = sensor_id) diff --git a/wlokalu/views.py b/wlokalu/views.py index 848fa4c..febb2f3 100644 --- a/wlokalu/views.py +++ b/wlokalu/views.py @@ -43,6 +43,8 @@ def list(request, nick = None): 'form_target': form_target, 'form': form, 'present': presence.list_people(), + 'sensors': presence.list_sensors(), + 'list_sensors': presence.list_list_sensors(), }) return HttpResponse(template.render(context))