calvinmclean/automated-garden

Refactor moisture as a WeatherClient so I can de-couple it from a Garden and not require a Garden struct for moisture details

calvinmclean opened this issue · 1 comments

Re-add:

// TODO: Can I re-enable this if moisture comes from WeatherClient instead of garden? Follow up issue #95
if ws.HasSoilMoistureControl() {
	logger.Debug("getting moisture data for WaterSchedule")
	soilMoisture, err := wsr.getMoisture(ctx, garden, ws)
	if err != nil {
		logger.WithError(err).Warn("unable to get moisture data for WaterSchedule")
	} else {
		logger.Debugf("successfully got moisture data for WaterSchedule: %f", soilMoisture)
		response.WeatherData.SoilMoisturePercent = &soilMoisture
	}
}

around line 60 in water_schedule_responses.go (NewWaterScheduleResponse)

This might be a little tricky because the weather client in this case needs access to InfluxDB client

The main motivation here was to remove the requirement of knowing the Garden when executing a water action.

This change would require storing a GardenID as part of a WeatherClientConfig, which would then couple the Config and the WaterSchedule that uses it to a specific Garden, so the compromise of knowing a Garden at execution time is fine because it is already built-in to the design.