# REST sensors for homelab services that don't have native HA integrations.
# Sonarr / Radarr / SABnzbd / Plex now use native HA integrations instead —
# their REST sensor definitions were removed 2026-04-19.
#
# Service ports (Atlantis via Tailscale 100.83.230.112):
#   bazarr      6767    /api
#   lazylib     5299    /api
#   abs        13378    /api
#   prowlarr    9696    /api/v1

# -------- Prowlarr --------
- platform: rest
  name: Prowlarr Indexers
  unique_id: homelab_rest_prowlarr_indexers
  resource: "http://100.83.230.112:9696/api/v1/indexer"
  headers:
    X-Api-Key: !secret prowlarr_api_key
  value_template: "{{ value_json | length }}"
  unit_of_measurement: indexers
  scan_interval: 3600

# -------- Bazarr --------
- platform: rest
  name: Bazarr Badges
  unique_id: homelab_rest_bazarr_badges
  resource: "http://100.83.230.112:6767/api/badges"
  headers:
    X-Api-Key: !secret bazarr_api_key
  value_template: "{{ (value_json.missing_subtitles_movies | default(0)) + (value_json.missing_subtitles_episodes | default(0)) }}"
  unit_of_measurement: missing
  json_attributes:
    - missing_subtitles_episodes
    - missing_subtitles_movies
    - throttled_providers
  scan_interval: 600

# -------- LazyLibrarian --------
- platform: rest
  name: LazyLibrarian Version
  unique_id: homelab_rest_lazylibrarian_version
  resource: "http://100.83.230.112:5299/api?apikey=REDACTED_LL_API_KEY&cmd=getVersion"
  value_template: "{{ value_json.current_version | default('?') }}"
  scan_interval: 86400

- platform: rest
  name: LazyLibrarian Wanted Books
  unique_id: homelab_rest_lazylibrarian_wanted_books
  resource: "http://100.83.230.112:5299/api?apikey=REDACTED_LL_API_KEY&cmd=getWanted"
  value_template: "{{ value_json.data | length if value_json.data is defined else 0 }}"
  unit_of_measurement: books
  scan_interval: 600

# -------- Audiobookshelf --------
- platform: rest
  name: Audiobookshelf Libraries
  unique_id: homelab_rest_audiobookshelf_libraries
  resource: "http://100.83.230.112:13378/api/libraries"
  headers:
    Authorization: !secret audiobookshelf_api_key
  value_template: "{{ value_json.libraries | length }}"
  unit_of_measurement: libraries
  scan_interval: 3600

- platform: rest
  name: Audiobookshelf Ebooks
  unique_id: homelab_rest_audiobookshelf_ebooks
  resource: "http://100.83.230.112:13378/api/libraries/5af23ed3-f69d-479b-88bc-1c4911c99d2d/items?limit=1"
  headers:
    Authorization: !secret audiobookshelf_api_key
  value_template: "{{ value_json.total | default(0) }}"
  unit_of_measurement: items
  scan_interval: 3600

- platform: rest
  name: Audiobookshelf Audiobooks
  unique_id: homelab_rest_audiobookshelf_audiobooks
  resource: "http://100.83.230.112:13378/api/libraries/d36776eb-fe81-467f-8fee-19435ee2827b/items?limit=1"
  headers:
    Authorization: !secret audiobookshelf_api_key
  value_template: "{{ value_json.total | default(0) }}"
  unit_of_measurement: items
  scan_interval: 3600
