#!/bin/sh
# tlp - switch bluetooth/nfc/wifi/wwan on/off
#
# Copyright (c) 2023 Thomas Koch <linrunner at gmx.net> and others.
# SPDX-License-Identifier: GPL-2.0-or-later

# --- Source libraries

for lib in /usr/share/tlp/tlp-func-base /usr/share/tlp/func.d/25-tlp-func-rf /usr/share/tlp/func.d/30-tlp-func-rf-sw; do
    # shellcheck disable=SC1090
    . "$lib"
done

# --- MAIN

# read configuration: quit on error, trace allowed
read_config 1 0

carg1=$1
parse_args4config "$@"
add_sbin2path
self=${0##*/}

case $self in
    bluetooth|nfc|wifi|wwan)
        case $carg1 in
            on)
                device_switch "$self" on
                # shellcheck disable=SC2154
                echo_device_state "$self" "$_devs"
                ;;

            off)
                device_switch "$self" off
                echo_device_state "$self" "$_devs"
                ;;

            toggle)
                device_switch "$self" toggle
                echo_device_state "$self" "$_devs"
                ;;

            *)
                device_state "$self"
                echo_device_state "$self" "$_devs"
                ;;
        esac
        ;;

    *)
        echo "Error: unknown device type \"$self\"." 1>&2
        do_exit 1
        ;;
esac

do_exit 0
