---
- name: Install PulseAudio bluetooth with LDAC/aptX support
  aur:
    name:
      - libldac
      - pulseaudio-modules-bt-git
    user: "{{ user.name }}"
  tags:
    - aur
  notify:
    - restart pulse as user

- name: Install bluetooth libraries and tools
  pacman:
    name:
      - pulseaudio-bluetooth
      - bluez
      - bluez-libs
      - bluez-utils
      - bluez-firmware
      - blueman
    state: present
  notify:
    - restart pulse as user

- name: Auto-switch between HSP/HSF and A2DP
  lineinfile:
      dest: /etc/pulse/default.pa
      regex: "^load-module module-bluetooth-policy"
      state: present
      line: "load-module module-bluetooth-policy auto_switch=2"
  notify:
    - restart pulse as user

- name: Do not auto power on the bluetooth device
  command: gsettings set org.blueman.plugins.powermanager auto-power-on false
  become: yes
  become_user: "{{ user.name }}"

- name: Unblock the bluetooth service
  service: name="rfkill-block@bluetooth.service" enabled=no state=stopped
  when: bluetooth.disable == False

- name: Enable and start the bluetooth service
  service: name=bluetooth.service enabled=yes state=started
  when: bluetooth.disable == False

- name: Disable and stop the bluetooth service
  service: name=bluetooth.service enabled=no state=stopped
  when: bluetooth.disable == True

- name: Block the bluetooth service
  service: name="rfkill-block@bluetooth.service" enabled=yes state=started
  when: bluetooth.disable == True
