fix: renamed packages
This commit is contained in:
@ -3,12 +3,26 @@ package sensor
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
|
||||
)
|
||||
|
||||
func sensorExists(wirePath, sensorID string) bool {
|
||||
// Exists returns a boolean if the sensor exists
|
||||
func Exists(wirePath, sensorID string) bool {
|
||||
sensorPath := filepath.Join(wirePath, sensorID)
|
||||
if _, err := os.Stat(sensorPath); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsRedundant returns a boolean if the sensorID is in the array
|
||||
func IsRedundant(sensorID string, sensors []*types.WireSensor) bool {
|
||||
for _, sensor := range sensors {
|
||||
if sensor.ID == sensorID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package sensor
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,10 +7,12 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
|
||||
)
|
||||
|
||||
func AddTemperature(sensorID, sensorName, configDir, wirePath string) error {
|
||||
// AddDS18B20 a new temperature sensor from type ds18b20
|
||||
func AddDS18B20(sensorID, sensorName, configDir, wirePath string) error {
|
||||
|
||||
// read cnf file
|
||||
cnf, err := config.Read(configDir)
|
||||
@ -19,13 +21,19 @@ func AddTemperature(sensorID, sensorName, configDir, wirePath string) error {
|
||||
}
|
||||
|
||||
// check if sensor exists
|
||||
if !sensorExists(wirePath, sensorID) {
|
||||
if !sensor.Exists(wirePath, sensorID) {
|
||||
return fmt.Errorf("Can not find sensor: %v", filepath.Join(wirePath, sensorID))
|
||||
}
|
||||
|
||||
// check if sensor is redundant
|
||||
if sensor.IsRedundant(sensorID, cnf.TemperatureSensors) {
|
||||
return fmt.Errorf("Sensor %v already exists as temperature sensor", sensorID)
|
||||
}
|
||||
|
||||
temperatureSensor := &types.WireSensor{
|
||||
ID: sensorID,
|
||||
Name: sensorName,
|
||||
Typ: types.SENSOR_DS18B20,
|
||||
WirePath: wirePath,
|
||||
}
|
||||
|
||||
@ -40,7 +48,8 @@ func AddTemperature(sensorID, sensorName, configDir, wirePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrintTemperature(w io.Writer, configDir string, quiet bool) error {
|
||||
// Print a list with the given writer w over all temperature sensors
|
||||
func Print(w io.Writer, configDir string, quiet bool) error {
|
||||
|
||||
// read cnf file
|
||||
cnf, err := config.Read(configDir)
|
||||
@ -53,14 +62,14 @@ func PrintTemperature(w io.Writer, configDir string, quiet bool) error {
|
||||
|
||||
// headline
|
||||
if !quiet {
|
||||
fmt.Fprint(tw, "id\tname\tpath\n")
|
||||
fmt.Fprint(tw, "id\tname\ttype\tpath\n")
|
||||
}
|
||||
|
||||
for _, sensor := range cnf.TemperatureSensors {
|
||||
if quiet {
|
||||
fmt.Fprintf(tw, "%v\n", sensor.ID)
|
||||
} else {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\n", sensor.ID, sensor.Name, sensor.WirePath)
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", sensor.ID, sensor.Name, sensor.Typ, sensor.WirePath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +78,8 @@ func PrintTemperature(w io.Writer, configDir string, quiet bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveTemperature(sensorID, configDir string) error {
|
||||
// Remove a temperature sensor over the given sensor id
|
||||
func Remove(sensorID, configDir string) error {
|
||||
|
||||
// read cnf file
|
||||
cnf, err := config.Read(configDir)
|
Reference in New Issue
Block a user