Exemplo n.º 1
0
def set_alarm_time(device_id, timer, action, alarm_time):

    if action == 'on' or action == 'off':

        # Get alertTime
        alarm_record = accessdb.get_specified_alarm_time(device_id, timer)
        # alarm time is not exist. Create a new alarm time record
        if alarm_record is None:

            # Get device
            dev = accessdb.get_device_from_pk(device_id)
            # Device is not exist. Create new device
            if dev is None:
                dev_name = "dev%s" % device_id
                dev = accessdb.create_device(dev_name, '')
                # Can't create device
                if dev is None:
                    return False
            alarm_record = accessdb.create_alarm_using_time(dev, action, alarm_time, timer)
            # Check create alarm time record
            if alarm_record is None:
                return False
            else:
                return True

        else:
            # Have exist alarm time
            result = accessdb.enable_alarm_time(device_id, action, alarm_time, timer)
            return result

    # Action is removed
    if action == 'remove':
        result = accessdb.disable_alarm_time(device_id, timer)
        return result

    # Can't known this action
    return False
Exemplo n.º 2
0
def remove_alarm_by_time(request, device_id, timer):
    result = accessdb.disable_alarm_time(device_id, timer)
    return return_json(result)