controller

package
v0.0.0-...-aeec7d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateConfig

func GenerateConfig(config Config, writeFile, genWifiConfig, genMainConfig, overwrite, interactive bool)

GenerateConfig will create config.h and wifi_config.h based on the provided configurations. It can optionally write to files instead of stdout

Types

type Config

type Config struct {
	MQTTConfig   mqtt.Config `mapstructure:"mqtt"`
	NestedConfig `mapstructure:"controller"`
	LogConfig    server.LogConfig `mapstructure:"log"`
}

Config holds all the options and sub-configs for the mock controller

type Controller

type Controller struct {
	Config
	// contains filtered or unexported fields
}

Controller struct holds the necessary data for running the mock garden-controller

func NewController

func NewController(cfg Config) (*Controller, error)

NewController creates and initializes everything needed to run a Controller based on config

func (*Controller) AssertLightActions

func (c *Controller) AssertLightActions(t *testing.T, expected ...action.LightAction)

AssertLightActions is used to check that all expected LightActions were received, then reset recorded info

func (*Controller) AssertStopActions

func (c *Controller) AssertStopActions(t *testing.T, expected int)

AssertStopActions is used to check that the expected number of StopActions were received, then reset recorded info

func (*Controller) AssertStopAllActions

func (c *Controller) AssertStopAllActions(t *testing.T, expected int)

AssertStopAllActions is used to check that the expected number of StopAllActions were received, then reset recorded info

func (*Controller) AssertWaterActions

func (c *Controller) AssertWaterActions(t *testing.T, expected ...action.WaterMessage)

AssertWaterActions is used to check that all expected WaterMessages were received, then reset recorded info

func (*Controller) Start

func (c *Controller) Start()

Start will run the Controller until it is stopped (blocking)

func (*Controller) Stop

func (c *Controller) Stop()

Stop shuts down the controller

type NestedConfig

type NestedConfig struct {
	// Configs used only for running mock controller
	EnableUI                        bool    `mapstructure:"enable_ui" survey:"enable_ui"`
	MoistureStrategy                string  `mapstructure:"moisture_strategy" survey:"moisture_strategy"`
	MoistureValue                   int     `mapstructure:"moisture_value" survey:"moisture_value"`
	PublishWaterEvent               bool    `mapstructure:"publish_water_event" survey:"publish_water_event"`
	TemperatureValue                float64 `mapstructure:"temperature_value"`
	HumidityValue                   float64 `mapstructure:"humidity_value"`
	TemperatureHumidityDisableNoise bool    `mapstructure:"temperature_humidity_disable_noise"`

	// Configs used for both
	TopicPrefix                 string        `mapstructure:"topic_prefix" survey:"topic_prefix"`
	NumZones                    int           `mapstructure:"num_zones" survey:"num_zones"`
	MoistureInterval            time.Duration `mapstructure:"moisture_interval" survey:"moisture_interval"`
	PublishHealth               bool          `mapstructure:"publish_health" survey:"publish_health"`
	HealthInterval              time.Duration `mapstructure:"health_interval" survey:"health_interval"`
	PublishTemperatureHumidity  bool          `mapstructure:"publish_temperature_humidity" survey:"publish_temperature_humidity"`
	TemperatureHumidityInterval time.Duration `mapstructure:"temperature_humidity_interval" survey:"temperature_humidity_interval"`

	// Configs only used for generate-config
	WifiConfig             `mapstructure:"wifi" survey:"wifi"`
	Zones                  []ZoneConfig  `mapstructure:"zones" survey:"zones"`
	DefaultWaterTime       time.Duration `mapstructure:"default_water_time" survey:"default_water_time"`
	EnableButtons          bool          `mapstructure:"enable_buttons" survey:"enable_buttons"`
	EnableMoistureSensor   bool          `mapstructure:"enable_moisture_sensor" survey:"enable_moisture_sensor"`
	LightPin               string        `mapstructure:"light_pin" survey:"light_pin"`
	StopButtonPin          string        `mapstructure:"stop_water_button" survey:"stop_water_button"`
	DisableWatering        bool          `mapstructure:"disable_watering" survey:"disable_watering"`
	TemperatureHumidityPin string        `mapstructure:"temperature_humidity_pin" survey:"temperature_humidity_pin"`

	MQTTAddress string `survey:"mqtt_address"`
	MQTTPort    int    `survey:"mqtt_port"`
}

NestedConfig is an unfortunate struct that I had to create to have this nested under the 'controller' key in the YAML config

type WifiConfig

type WifiConfig struct {
	SSID     string `mapstructure:"ssid"`
	Password string `mapstructure:"password"`
}

WifiConfig holds WiFi connection details

type ZoneConfig

type ZoneConfig struct {
	PumpPin           string `mapstructure:"pump_pin" survey:"pump_pin"`
	ValvePin          string `mapstructure:"valve_pin" survey:"valve_pin"`
	ButtonPin         string `mapstructure:"button_pin" survey:"button_pin"`
	MoistureSensorPin string `mapstructure:"moisture_sensor_pin" survey:"moisture_sensor_pin"`
}

ZoneConfig has the configuration details for controlling hardware pins

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL