<?php
class ThermalInfo
{
    private $thermalInfo = null;

    public function __construct($thermalInfo = null) {
        
        if ($thermalInfo !== null) {
            $this->thermalInfo = new stdClass();
            $this->thermalInfo->thermalinfo = $thermalInfo;
        }
    }
    
    public function getThermalInfo() {
        return $this->thermalInfo;
    }
    
    public function initThermalInfo()
    {
        if ($this->thermalInfo == null) {
            $this->thermalInfo = new stdClass(); //PhonalisaCtrldConnector::getThermalInfo();
        }
    }

    public function getCPUTemperature()
    {
        $this->initThermalInfo();
        $temp = (int)(@$this->thermalInfo->thermalinfo->cpu)."";
        if (StringHelper::endsWith($temp, "000")) {
            $temp = substr($temp, 0, -3);
        }
        return $temp;
    }
    
    public function isEnabled()
    {
        $this->initThermalInfo();
        
        if (empty((array) @$this->thermalInfo->thermalinfo)) {
            return false;
        }
        
        if (empty(@$this->thermalInfo->thermalinfo->cpu)) {
            return false;
        }
        
        if ($this->thermalInfo->thermalinfo->cpu === "?") {
            return false;
        }
        
        return true;
    }

}