Example #1
0
def get_alarm_by_time(request, device_id, timer):

    alarm_record = accessdb.get_specified_alarm_time(device_id, timer)

    # If record is not exist, return false
    if alarm_record is None or alarm_record.active is False:
        return HttpResponse(json.dumps({'status': False, 'timer': timer, 'dev': device_id}),
                            content_type='application/json')

    now_time = apitimer.get_now_time_without_second()
    alarm_time = alarm_record.time

    time_string = apitimer.get_interval(now_time, alarm_time)
    # If have error have been happened
    if time_string is None:
        time_string = ""
    action = alarm_record.action
    return HttpResponse(json.dumps({'status': True, 'timer': timer, 'dev': device_id, 'action': action,
                                    'remain': time_string}), content_type='application/json')
Example #2
0
def get_all_alarm_by_time(request):
    dev_list = accessdb.get_device_list()
    if dev_list is None:
        return HttpResponse(json.dumps({'status': False}), content_type='application/json')

    info_list = {}
    for dev in dev_list:

        timer_list = accessdb.get_alarm_time_list_from_device_pk(dev.id)
        if timer_list is None:
            return HttpResponse(json.dumps({'status': False}), content_type='application/json')
        detail_alarm_list = {}
        for timer in timer_list:

            remain_time = None

            # Enable alarm time
            if timer.active:
                now_time = apitimer.get_now_time_without_second()
                remain_time = apitimer.get_interval(now_time, timer.time)

            action = timer.action
            if remain_time is None or remain_time == '':
                #print 'qua han, '
                remain_time = ''
                action = ''

            detail = {}

            detail['action'] = action
            detail['remain'] = remain_time

            key = 'timer%s' % timer.timer
            detail_alarm_list[key] = detail

        key = 'dev%s' % dev.id
        info_list[key] = detail_alarm_list

    return HttpResponse(json.dumps({'status': True, 'info': info_list}), content_type='application/json')