def themes():
    themes = [{
        'theme_id',
        'name',
        'user_id',
        'settings',
        'active'
    }]
    themes = data_interface.get_user_themes(get_active_user()['user_id'])
    return render_template("internal/themes.html", themes=themes)
def add_new_device_for_vendor(vendor_id):
    form = get_vendor_form(vendor_id)
    if form.validate_on_submit():
        data_interface.add_new_device(user_id=get_active_user()['user_id'],
                                      device_type=form.device_type.data,
                                      vendor=get_vendor_backend_id(vendor_id),
                                      configuration=get_vendor_configuration_data(vendor_id, form),
                                      name=form.name.data)
        flash("New device successfully added!", 'success')
        return redirect(url_for('.show_devices'))
    return render_template("internal/new_device.html", new_device_form=form)
예제 #3
0
def add_new_room():
    form = AddNewRoomForm()
    if form.validate_on_submit():
        try:
            data_interface.add_new_room(user_id=get_active_user()['user_id'], name=form.name.data)
        except Exception as ex:
            logging.error("Adding new room failed: {}".format(ex))
            flash("Error", "danger")
            return render_template("internal/new_room.html", new_room_form=form)
        flash("New room successfully added!", 'success')
        return redirect(url_for('.index'))
    return render_template("internal/new_room.html", new_room_form=form)
예제 #4
0
def view_room(room_id):
    room = data_interface.get_room_info(room_id)
    all_devices = data_interface.get_user_devices(get_active_user()['user_id'])
    print(all_devices)
    linked_devices = [d for d in all_devices if d['room_id'] is not None]
    unlinked_devices = [d for d in all_devices if d['room_id'] is None]
    room_devices = [d for d in all_devices if d['room_id'] == room_id]
    thermostats = [d for d in room_devices if d['device_type'] == "thermostat"]
    light_switches = [d for d in room_devices if d['device_type'] == "light_switch"]
    door_sensors = [d for d in room_devices if d['device_type'] == "door_sensor"]
    motion_sensors = [d for d in room_devices if d['device_type'] == "motion_sensor"]
    return render_template("internal/roomview.html", room=room, thermostats=thermostats, light_switches=light_switches,
                           door_sensors=door_sensors, motion_sensors=motion_sensors, unlinked_devices=unlinked_devices,
                           linked_devices=linked_devices)
def show_devices():
    all_vendors = get_all_vendors_list()
    devices = data_interface.get_user_devices(get_active_user()['user_id'])
    logging.info("devices: {}".format(devices))
    rooms = data_interface.get_user_default_rooms()
    rooms = sorted(rooms, key=lambda k: k['name'])
    any_linked = False
    any_unlinked = False
    moveinfo = []
    if devices:
        for device in devices:
            if device['room_id'] is not None:
                any_linked = True
            elif device['room_id'] is None:
                any_unlinked = True
    # change from default to focal user
    # test requires here to check if devices returns devices correctly
    return render_template("internal/devices.html", devices=devices, groupactions=shared.actions.groupactions,
                           rooms=rooms, all_vendors=all_vendors, table1=any_unlinked, table2=any_linked)
def create_trigger_action_for(device_id, actor_id):
    device_info = data_interface.get_device_info(device_id)
    device_type = device_info["device_type"]
    actor_info = data_interface.get_device_info(actor_id)
    actor_type = actor_info["device_type"]
    if actor_type == "thermostat":
        action_form = CreateTriggerActionFormThermostat()
    else:
        raise Exception()
    if not action_form.validate_on_submit():
        return create_trigger_for(device_id)
    result = data_interface.add_new_trigger(sensor_id=device_id,
                                            actor_id=actor_id,
                                            event=action_form.event.data,
                                            event_params=action_form.event_parameters.data,
                                            action=action_form.action.data,
                                            action_params=str(action_form.action_parameters.data),
                                            user_id=get_active_user()["user_id"])
    return redirect(url_for('.show_device', device_id=device_id))
예제 #7
0
def show_all_triggers():
    all_triggers = data_interface.get_triggers_for_user(
        get_active_user()["user_id"])
    return render_template("internal/triggers/all_triggers.html",
                           all_triggers=all_triggers)
def add_theme():
    devices = data_interface.get_user_devices(get_active_user()['user_id'])
    rooms = data_interface.get_user_default_rooms()
    rooms = sorted(rooms, key=lambda k: k['name'])
    return render_template("internal/add_theme.html", devices=devices,
                           rooms=rooms)