#include <string>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "temp_sensor.h"

double TemperatureSensor::get_temperature() const {
  double result = 0.0;
  std::string line;
  std::ifstream sensor_data(_sensor_file);
  std::getline(sensor_data, line);
  if (line.substr(line.size() - 3) == "YES") {
    std::getline(sensor_data, line);
    std::string::size_type i = line.find_last_of("t=");
    if (i != std::string::npos) {
      result = atoi(line.substr(i + 1).c_str()) / 1000.0;
      std::cout << result;
    }
  }
  return result;
}

