refac(pkg/types): remove deprecated prefix name of struct attributes
This commit is contained in:
@ -43,8 +43,8 @@ func (c *Configuration) AddRGBLED(rgbLED *types.RGBLED) error {
|
||||
}
|
||||
|
||||
// check if sensor has a valid device id
|
||||
if rgbLED.DeviceID != c.Device.DeviceID {
|
||||
rgbLED.DeviceID = c.Device.DeviceID
|
||||
if rgbLED.DeviceID != c.Device.ID {
|
||||
rgbLED.DeviceID = c.Device.ID
|
||||
}
|
||||
|
||||
// overwrite creation date
|
||||
@ -59,31 +59,31 @@ func (c *Configuration) AddRGBLED(rgbLED *types.RGBLED) error {
|
||||
// AddSensor add a new sensor
|
||||
func (c *Configuration) AddSensor(sensor *types.Sensor) error {
|
||||
|
||||
// check if sensorID is a valid UUID string
|
||||
if !validUUID.MatchString(sensor.SensorID) {
|
||||
sensor.SensorID = uuid.NewV4().String()
|
||||
// check if ID is a valid UUID string
|
||||
if !validUUID.MatchString(sensor.ID) {
|
||||
sensor.ID = uuid.NewV4().String()
|
||||
}
|
||||
|
||||
// check if sensor name and sensor uuid already exists
|
||||
for _, s := range c.Sensors {
|
||||
if s.SensorName == sensor.SensorName {
|
||||
return fmt.Errorf("Sensor %v already exists", s.SensorName)
|
||||
if s.Name == sensor.Name {
|
||||
return fmt.Errorf("Sensor %v already exists", s.Name)
|
||||
}
|
||||
|
||||
if s.SensorID == sensor.SensorID {
|
||||
return fmt.Errorf("Sensor %v with UUID %v already exists", s.SensorName, s.SensorID)
|
||||
if s.ID == sensor.ID {
|
||||
return fmt.Errorf("Sensor %v with UUID %v already exists", s.Name, s.ID)
|
||||
}
|
||||
|
||||
if s.WireID != nil && sensor.WireID != nil {
|
||||
if *s.WireID == *sensor.WireID {
|
||||
return fmt.Errorf("Sensor with 1wire-id %v already exists as %v", *s.WireID, s.SensorName)
|
||||
return fmt.Errorf("Sensor with 1wire-id %v already exists as %v", *s.WireID, s.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if sensor has a valid device id
|
||||
if sensor.DeviceID != c.Device.DeviceID {
|
||||
sensor.DeviceID = c.Device.DeviceID
|
||||
if sensor.ID != c.Device.ID {
|
||||
sensor.ID = c.Device.ID
|
||||
}
|
||||
|
||||
// overwrite creation date
|
||||
@ -135,16 +135,16 @@ func (c *Configuration) DisableSensor(name string) error {
|
||||
|
||||
// disable sensor matched after name
|
||||
if !validUUID.MatchString(name) &&
|
||||
sensor.SensorName == name {
|
||||
sensor.SensorEnabled = false
|
||||
sensor.Name == name {
|
||||
sensor.Enabled = false
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
||||
// remove machted uuid
|
||||
if validUUID.MatchString(name) &&
|
||||
sensor.SensorID == name {
|
||||
sensor.SensorEnabled = false
|
||||
sensor.ID == name {
|
||||
sensor.Enabled = false
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@ -195,16 +195,16 @@ func (c *Configuration) EnableSensor(name string) error {
|
||||
|
||||
// disable sensor matched after name
|
||||
if !validUUID.MatchString(name) &&
|
||||
sensor.SensorName == name {
|
||||
sensor.SensorEnabled = true
|
||||
sensor.Name == name {
|
||||
sensor.Enabled = true
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
||||
// remove machted uuid
|
||||
if validUUID.MatchString(name) &&
|
||||
sensor.SensorID == name {
|
||||
sensor.SensorEnabled = true
|
||||
sensor.ID == name {
|
||||
sensor.Enabled = true
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@ -226,14 +226,14 @@ func (c *Configuration) GetHumiditySensors(option Option) []sensor.Sensor {
|
||||
switch option {
|
||||
case ENABLED:
|
||||
for _, sensor := range sensors {
|
||||
if sensor.SensorEnabled {
|
||||
if sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
return c.convertSensors(cachedSensors)
|
||||
case DISABLED:
|
||||
for _, sensor := range sensors {
|
||||
if !sensor.SensorEnabled {
|
||||
if !sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
@ -251,10 +251,10 @@ func (c *Configuration) GetHumiditySensorsByName(names []string) []sensor.Sensor
|
||||
for _, name := range names {
|
||||
for _, s := range c.getHumiditySensors() {
|
||||
switch name {
|
||||
case s.SensorID:
|
||||
configHumiditySensors[s.SensorID] = s
|
||||
case s.SensorName:
|
||||
configHumiditySensors[s.SensorID] = s
|
||||
case s.ID:
|
||||
configHumiditySensors[s.ID] = s
|
||||
case s.Name:
|
||||
configHumiditySensors[s.ID] = s
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,14 +276,14 @@ func (c *Configuration) GetPressureSensors(option Option) []sensor.Sensor {
|
||||
switch option {
|
||||
case ENABLED:
|
||||
for _, sensor := range sensors {
|
||||
if sensor.SensorEnabled {
|
||||
if sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
return c.convertSensors(cachedSensors)
|
||||
case DISABLED:
|
||||
for _, sensor := range sensors {
|
||||
if !sensor.SensorEnabled {
|
||||
if !sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
@ -301,10 +301,10 @@ func (c *Configuration) GetPressureSensorsByName(names []string) []sensor.Sensor
|
||||
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
|
||||
case s.ID:
|
||||
configPressureSensors[s.ID] = s
|
||||
case s.Name:
|
||||
configPressureSensors[s.ID] = s
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -369,14 +369,14 @@ func (c *Configuration) GetSensors(option Option) []sensor.Sensor {
|
||||
switch option {
|
||||
case ENABLED:
|
||||
for _, sensor := range c.Sensors {
|
||||
if sensor.SensorEnabled {
|
||||
if sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
return c.convertSensors(cachedSensors)
|
||||
case DISABLED:
|
||||
for _, sensor := range c.Sensors {
|
||||
if !sensor.SensorEnabled {
|
||||
if !sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
@ -404,14 +404,14 @@ func (c *Configuration) GetTemperatureSensors(option Option) []sensor.Sensor {
|
||||
switch option {
|
||||
case ENABLED:
|
||||
for _, sensor := range sensors {
|
||||
if sensor.SensorEnabled {
|
||||
if sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
return c.convertSensors(cachedSensors)
|
||||
case DISABLED:
|
||||
for _, sensor := range sensors {
|
||||
if !sensor.SensorEnabled {
|
||||
if !sensor.Enabled {
|
||||
cachedSensors = append(cachedSensors, sensor)
|
||||
}
|
||||
}
|
||||
@ -429,10 +429,10 @@ func (c *Configuration) GetTemperatureSensorsByName(names []string) []sensor.Sen
|
||||
for _, name := range names {
|
||||
for _, s := range c.getTemperatureSensors() {
|
||||
switch name {
|
||||
case s.SensorID:
|
||||
configTemperatureSensors[s.SensorID] = s
|
||||
case s.SensorName:
|
||||
configTemperatureSensors[s.SensorID] = s
|
||||
case s.ID:
|
||||
configTemperatureSensors[s.ID] = s
|
||||
case s.Name:
|
||||
configTemperatureSensors[s.ID] = s
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -469,13 +469,13 @@ func (c *Configuration) RemoveSensor(name string) error {
|
||||
for i, sensor := range c.Sensors {
|
||||
// remove machted name
|
||||
if !validUUID.MatchString(name) &&
|
||||
sensor.SensorName == name {
|
||||
sensor.Name == name {
|
||||
c.Sensors = append(c.Sensors[:i], c.Sensors[i+1:]...)
|
||||
return nil
|
||||
}
|
||||
// remove machted uuid
|
||||
if validUUID.MatchString(name) &&
|
||||
sensor.SensorID == name {
|
||||
sensor.ID == name {
|
||||
c.Sensors = append(c.Sensors[:i], c.Sensors[i+1:]...)
|
||||
return nil
|
||||
}
|
||||
@ -498,9 +498,9 @@ func (c *Configuration) RenameRGBLED(oldName, newName string) error {
|
||||
// RenameSensor renames a sensor identified by the name or the UUID
|
||||
func (c *Configuration) RenameSensor(oldName, newName string) error {
|
||||
for _, sensor := range c.Sensors {
|
||||
if sensor.SensorName == oldName ||
|
||||
sensor.SensorID == oldName {
|
||||
sensor.SensorName = newName
|
||||
if sensor.Name == oldName ||
|
||||
sensor.ID == oldName {
|
||||
sensor.Name = newName
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -535,7 +535,7 @@ func (c *Configuration) convertSensors(sensors []*types.Sensor) []sensor.Sensor
|
||||
cachedSensors := make([]sensor.Sensor, 0)
|
||||
|
||||
for _, s := range sensors {
|
||||
switch s.SensorModel {
|
||||
switch s.Model {
|
||||
case types.BME280:
|
||||
cachedSensors = append(cachedSensors, &sensor.BME280{
|
||||
Sensor: s,
|
||||
@ -572,7 +572,7 @@ func (c *Configuration) convertRGBLEDs(rgbLEDs []*types.RGBLED) []rgbled.RGBLED
|
||||
func (c *Configuration) getHumiditySensors() []*types.Sensor {
|
||||
humiditySensors := make([]*types.Sensor, 0)
|
||||
for _, s := range c.Sensors {
|
||||
if _, ok := humiditySensorModels[s.SensorModel]; ok {
|
||||
if _, ok := humiditySensorModels[s.Model]; ok {
|
||||
humiditySensors = append(humiditySensors, s)
|
||||
}
|
||||
}
|
||||
@ -582,7 +582,7 @@ func (c *Configuration) getHumiditySensors() []*types.Sensor {
|
||||
func (c *Configuration) getPressureSensors() []*types.Sensor {
|
||||
pressureSensors := make([]*types.Sensor, 0)
|
||||
for _, s := range c.Sensors {
|
||||
if _, ok := pressureSensorModels[s.SensorModel]; ok {
|
||||
if _, ok := pressureSensorModels[s.Model]; ok {
|
||||
pressureSensors = append(pressureSensors, s)
|
||||
}
|
||||
}
|
||||
@ -592,7 +592,7 @@ func (c *Configuration) getPressureSensors() []*types.Sensor {
|
||||
func (c *Configuration) getTemperatureSensors() []*types.Sensor {
|
||||
temperatureSensors := make([]*types.Sensor, 0)
|
||||
for _, s := range c.Sensors {
|
||||
if _, ok := temperatureSensorModels[s.SensorModel]; ok {
|
||||
if _, ok := temperatureSensorModels[s.Model]; ok {
|
||||
temperatureSensors = append(temperatureSensors, s)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user