fix(pkg/config): add functions to get pressure sensors

This commit is contained in:
Markus Pesch 2019-07-02 22:40:00 +02:00
parent 825511c3b5
commit 93c08d8147
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -13,16 +13,20 @@ import (
) )
var humiditySensorModels = map[types.SensorModel]types.SensorModel{ var humiditySensorModels = map[types.SensorModel]types.SensorModel{
types.BME280: types.BME280,
types.DHT11: types.DHT11, types.DHT11: types.DHT11,
types.DHT22: types.DHT22, types.DHT22: types.DHT22,
}
var pressureSensorModels = map[types.SensorModel]types.SensorModel{
types.BME280: types.BME280, types.BME280: types.BME280,
} }
var temperatureSensorModels = map[types.SensorModel]types.SensorModel{ var temperatureSensorModels = map[types.SensorModel]types.SensorModel{
types.BME280: types.BME280,
types.DHT11: types.DHT11, types.DHT11: types.DHT11,
types.DHT22: types.DHT22, types.DHT22: types.DHT22,
types.DS18B20: types.DS18B20, types.DS18B20: types.DS18B20,
types.BME280: types.BME280,
} }
// Configuration of flucky // Configuration of flucky
@ -253,7 +257,7 @@ func (c *Configuration) GetHumiditySensors(option Option) []sensor.Sensor {
} }
} }
// GetHumiditySensorsByName returns a list of temperature sensors by name, // GetHumiditySensorsByName returns a list of humidity sensors by name,
// uuid or wire-id // uuid or wire-id
func (c *Configuration) GetHumiditySensorsByName(names []string) []sensor.Sensor { func (c *Configuration) GetHumiditySensorsByName(names []string) []sensor.Sensor {
configHumiditySensors := make(map[string]*types.Sensor, 0) configHumiditySensors := make(map[string]*types.Sensor, 0)
@ -277,6 +281,56 @@ func (c *Configuration) GetHumiditySensorsByName(names []string) []sensor.Sensor
return c.convertSensors(humiditySensors) return c.convertSensors(humiditySensors)
} }
// GetPressureSensors returns a list of pressure sensors
func (c *Configuration) GetPressureSensors(option Option) []sensor.Sensor {
sensors := c.getPressureSensors()
cachedSensors := make([]*types.Sensor, 0)
switch option {
case ENABLED:
for _, sensor := range sensors {
if sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(cachedSensors)
case DISABLED:
for _, sensor := range sensors {
if !sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(cachedSensors)
default:
return c.convertSensors(cachedSensors)
}
}
// GetPressureSensorsByName returns a list of pressure sensors by name,
// uuid or wire-id
func (c *Configuration) GetPressureSensorsByName(names []string) []sensor.Sensor {
configPressureSensors := make(map[string]*types.Sensor, 0)
for _, name := range names {
for _, s := range c.getPressureSensors() {
switch name {
case s.SensorID:
configPressureSensors[s.SensorID] = s
case s.SensorName:
configPressureSensors[s.SensorID] = s
}
}
}
pressureSensors := make([]*types.Sensor, 0)
for _, cs := range configPressureSensors {
pressureSensors = append(pressureSensors, cs)
}
return c.convertSensors(pressureSensors)
}
func (c *Configuration) GetRGBLEDs(option Option) []rgbled.RGBLED { func (c *Configuration) GetRGBLEDs(option Option) []rgbled.RGBLED {
rgbLEDs := c.RGBLEDs rgbLEDs := c.RGBLEDs
@ -506,6 +560,16 @@ func (c *Configuration) getHumiditySensors() []*types.Sensor {
return humiditySensors return humiditySensors
} }
func (c *Configuration) getPressureSensors() []*types.Sensor {
pressureSensors := make([]*types.Sensor, 0)
for _, s := range c.Sensors {
if _, ok := pressureSensorModels[s.SensorModel]; ok {
pressureSensors = append(pressureSensors, s)
}
}
return pressureSensors
}
func (c *Configuration) getTemperatureSensors() []*types.Sensor { func (c *Configuration) getTemperatureSensors() []*types.Sensor {
temperatureSensors := make([]*types.Sensor, 0) temperatureSensors := make([]*types.Sensor, 0)
for _, s := range c.Sensors { for _, s := range c.Sensors {