- Now the cache isn't cleared and fetched from zero each update, but only when there's missing information for a day
- Fixed a bug that prevented new users from saving changes in the config
NOTE: Turns out that HomeAssistant's API only returns data for the last 10 days. Looks like we will have to improve the caching system to work around this.
config.db.Exec("INSERT INTO cache(time,green_energy_percentage,energy_consumption) VALUES (?,?,?);",dayStart(time.Now()).Unix(),greenEnergyPercentage.Value,historyPolledSmartEnergySummation.Value)
fmt.Println("Error deleting previous records to cache: -",err.Error())
return
returnerr
}
forkey,day:=rangegreenEnergyPercentage{
_,err:=config.db.Exec("INSERT INTO cache(time,green_energy_percentage,energy_consumption) VALUES (?,?,?);",day.DayTime.Unix(),greenEnergyPercentage[key].Value,historyPolledSmartEnergySummation[key].Value)
iferr!=nil{
fmt.Println("Error adding record to cache: -",err.Error())
return
returnerr
}
}
returnnil
}
func(configConfig)readCache()(CacheData,error){
rows,err:=config.db.Query("SELECT time, green_energy_percentage, energy_consumption FROM cache")
start:=dayStart(time.Now()).AddDate(0,0,-8)
rows,err:=config.db.Query("SELECT time, green_energy_percentage, energy_consumption FROM cache WHERE time > ?",start.Unix())