unit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Units = map[string]UnitBuilder{
	"single_fan":  SingleFanConfig{},
	"dummy":       DummyConfig{},
	"relay_dummy": RelayDummyConfig{},
}

Functions

This section is empty.

Types

type DummyConfig

type DummyConfig struct {
	HumOn  float64         `json:"hum_on"`
	HumOff float64         `json:"hum_off"`
	FanOn  config.Duration `json:"fan_on"`
	FanOff config.Duration `json:"fan_off"`

	HumidifierRelay int `json:"humidifier_relay"`
	FanRelay        int `json:"fan_rly"`

	NoRelay bool `json:"no_relay"`

	FakeTemp float64 `json:"fake_temp"`
	FakeHum  float64 `json:"fake_hum"`
}

DummyConfig is a standard unit config

func (DummyConfig) BuildFromJSON

func (c DummyConfig) BuildFromJSON(data []byte, client api.API, log tools.Logger) (Unit, error)

type DummyUnit

type DummyUnit struct {
	DummyConfig
	// contains filtered or unexported fields
}

DummyUnit is a standard unit implementation

func NewDummyUnit

func NewDummyUnit(
	c DummyConfig,
	client api.API,
	log tools.Logger,
) *DummyUnit

func (*DummyUnit) GetState

func (c *DummyUnit) GetState() interface{}

func (*DummyUnit) Refresh

func (c *DummyUnit) Refresh() error

func (*DummyUnit) SetState

func (c *DummyUnit) SetState(state interface{})

type DummyUnitState

type DummyUnitState struct {
	Humidifier     bool      `json:"humidifier"`
	Fan            bool      `json:"fan"`
	FanLastToggled time.Time `json:"fan_last_toggled"`
}

DummyUnitState is the persistent state for the unit

type RelayDummyConfig

type RelayDummyConfig struct {
	HumidifierRelay int `json:"humidifier_relay"`
	FanRelay        int `json:"fan_rly"`

	HumidifierState bool `json:"humidifier_state"`
	FanState        bool `json:"fan_state"`
}

RelayDummyConfig is a standard unit config

func (RelayDummyConfig) BuildFromJSON

func (c RelayDummyConfig) BuildFromJSON(data []byte, client api.API, log tools.Logger) (Unit, error)

type RelayDummyUnit

type RelayDummyUnit struct {
	RelayDummyConfig
	// contains filtered or unexported fields
}

RelayDummyUnit is a standard unit implementation

func NewRelayDummyUnit

func NewRelayDummyUnit(
	c RelayDummyConfig,
	client api.API,
	log tools.Logger,
) *RelayDummyUnit

func (*RelayDummyUnit) GetState

func (c *RelayDummyUnit) GetState() interface{}

func (*RelayDummyUnit) Refresh

func (c *RelayDummyUnit) Refresh() error

func (*RelayDummyUnit) SetState

func (c *RelayDummyUnit) SetState(state interface{})

type SingleFanConfig

type SingleFanConfig struct {
	HumRelay int `json:"hum_relay"`
	FanRelay int `json:"fan_rly"`

	TemperatureCelciusADC int    `json:"temp_adc"`
	RelativeHumidityADC   int    `json:"rh_adc"`
	VoltageCalibrationADC int    `json:"vcc_adc"`
	StatsDAddress         string `json:"statsd_address"`
	Name                  string `json:"name"`

	HumOn  float64         `json:"hum_on"`
	HumOff float64         `json:"hum_off"`
	FanOn  config.Duration `json:"fan_on"`
	FanOff config.Duration `json:"fan_off"`

	InvertHumPin bool `json:"invert_hum_pin"`
	InvertFanPin bool `json:"invert_fan_pin"`
}

SingleFanConfig is a standard unit config

func (SingleFanConfig) BuildFromJSON

func (c SingleFanConfig) BuildFromJSON(data []byte, client api.API, log tools.Logger) (Unit, error)

type SingleFanUnit

type SingleFanUnit struct {
	SingleFanConfig
	// contains filtered or unexported fields
}

SingleFanUnit is a standard unit implementation

func NewSingleFanUnit

func NewSingleFanUnit(
	c SingleFanConfig,
	client api.API,
	log tools.Logger,
) *SingleFanUnit

func (*SingleFanUnit) GetState

func (c *SingleFanUnit) GetState() interface{}

func (*SingleFanUnit) Refresh

func (c *SingleFanUnit) Refresh() error

func (*SingleFanUnit) SetState

func (c *SingleFanUnit) SetState(state interface{})

type SingleFanUnitState

type SingleFanUnitState struct {
	Humidifier     bool      `json:"humidifier"`
	Fan            bool      `json:"fan"`
	FanLastToggled time.Time `json:"fan_last_toggled"`
}

SingleFanUnitState is the persistent state for the unit

type Unit

type Unit interface {
	Refresh() error
	SetState(interface{})
	GetState() interface{}
}

Unit represents some sensors and things

type UnitBuilder

type UnitBuilder interface {
	BuildFromJSON(data []byte, client api.API, logger tools.Logger) (Unit, error)
}

UnitBuilder is used to encode a Unit in JSON

func GetBlankUnitBuilder

func GetBlankUnitBuilder(kind string) (*UnitBuilder, error)

Jump to

Keyboard shortcuts

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