<commit_before>package TemperatureSensorController

import (
	"errors"
	"io/ioutil"
	"strconv"
	"strings"
)

// ReadTemperature is used to access the current temperature from the temperature sensor
func ReadTemperature() (float32, error) {
	var error error
	var bytes []byte
	bytes, error = ioutil.ReadFile("/sys/bus/w1/devices/28-8000001fa053/w1_slave")

	if error != nil {
		return 0, error
	}

	var wholeText = string(bytes)
	var lines = strings.Split(wholeText, "\n")
	if strings.HasSuffix(lines[0], "NO") {
		return 0, errors.New("Read temperature from sensor failed - the sensor returned 'NO'")
	}

	var indexOfT = strings.Index(lines[1], "t=")
	if indexOfT == -1 {
		return 0, errors.New("Read temperature from sensor failed - 't=' not found")
	}

	var temperatureAsString = string(lines[1][indexOfT+2:])
	var temperature float64
	temperature, error = strconv.ParseFloat(temperatureAsString, 32)<commit_msg>Added workaround for bug with temperature sensor not showing the actual temp from the first read.<commit_after>package TemperatureSensorController

import (
	"errors"
	"io/ioutil"
	"strconv"
	"strings"
	"time"
)

// ReadTemperature is used to access the current temperature from the temperature sensor
func ReadTemperature() (float32, error) {
	var error error
	var bytes []byte
	var path = "/sys/bus/w1/devices/28-8000001fa053/w1_slave"

	bytes, error = ioutil.ReadFile(path)
	time.Sleep(time.Second)
	bytes, error = ioutil.ReadFile(path)

	if error != nil {
		return 0, error
	}

	var wholeText = string(bytes)
	var lines = strings.Split(wholeText, "\n")
	if strings.HasSuffix(lines[0], "NO") {
		return 0, errors.New("Read temperature from sensor failed - the sensor returned 'NO'")
	}

	var indexOfT = strings.Index(lines[1], "t=")
	if indexOfT == -1 {
		return 0, errors.New("Read temperature from sensor failed - 't=' not found")
	}

	var temperatureAsString = string(lines[1][indexOfT+2:])
	var temperature float64
	temperature, error = strconv.ParseFloat(temperatureAsString, 32)
{'fraction_non_alphanumeric': 0.11944027986006997, 'fraction_numerical': 0.02798600699650175, 'mean_word_length': 4.736389684813753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630097', 'n_tokens_mistral': 705, 'n_tokens_neox': 648, 'n_words': 194}