#!/bin/sh

. /usr/share/libubox/jshn.sh
. /lib/functions.sh

function get_wlan_temperature()
{
  :
}

function get_sfp_temperature()
{
  echo "-274"
}

function get_cpu_temperature()
{
  echo "-274"
}

function get_temperature_status()
{
  local hasSfp="$(db -q get hw.board.hasSfp)"

  json_init

  json_add_array "status"

  json_add_object
  json_add_string "name" "cpu"
  json_add_int "temperature" "$(get_cpu_temperature)"
  json_close_object

  [ -s /etc/config/wireless ] && get_wlan_temperature

  [ "$hasSfp" = "1" ] && {
	  json_add_object
	  json_add_string "name" "sfp"
	  json_add_int "temperature" "$(get_sfp_temperature)"
	  json_close_object
  }

  json_close_array

  json_dump
}

function dump_invalid()
{
  json_init
  json_add_string "fault" "invalid request"
  json_dump
}

case "$1" in
    status)
        get_temperature_status
        ;;
    *)
        dump_invalid
        ;;
esac
