fix(pkg/rgb-led): complete rgb-led pkg
This commit is contained in:
		| @@ -5,6 +5,7 @@ import ( | ||||
|  | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/go-flucky/flucky/pkg/rgbled" | ||||
| 	"github.com/go-flucky/flucky/pkg/sensor" | ||||
|  | ||||
| 	"github.com/go-flucky/flucky/pkg/types" | ||||
| @@ -308,6 +309,51 @@ func (c *Configuration) GetHumiditySensorsByName(names []string) []sensor.Humidi | ||||
| 	return c.convertHumiditySensors(humiditySensors) | ||||
| } | ||||
|  | ||||
| func (c *Configuration) GetRGBLEDs(option Option) []rgbled.RGBLED { | ||||
| 	rgbLEDs := c.RGBLEDs | ||||
|  | ||||
| 	switch option { | ||||
| 	case ENABLED: | ||||
| 		for i, rgbLED := range c.RGBLEDs { | ||||
| 			if !rgbLED.RGBLEDEnabled { | ||||
| 				rgbLEDs = append(rgbLEDs[:i], rgbLEDs[i+1:]...) | ||||
| 			} | ||||
| 		} | ||||
| 		return c.convertRGBLEDs(rgbLEDs) | ||||
| 	case DISABLED: | ||||
| 		for i, rgbLED := range c.RGBLEDs { | ||||
| 			if rgbLED.RGBLEDEnabled { | ||||
| 				rgbLEDs = append(rgbLEDs[:i], rgbLEDs[i+1:]...) | ||||
| 			} | ||||
| 		} | ||||
| 		return c.convertRGBLEDs(rgbLEDs) | ||||
| 	default: | ||||
| 		return c.convertRGBLEDs(rgbLEDs) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c *Configuration) GetRGBLEDsByName(names []string) []rgbled.RGBLED { | ||||
| 	configRGBLEDs := make(map[string]*types.RGBLED, 0) | ||||
|  | ||||
| 	for _, name := range names { | ||||
| 		for _, led := range c.RGBLEDs { | ||||
| 			switch name { | ||||
| 			case led.RGBLEDID: | ||||
| 				configRGBLEDs[led.RGBLEDID] = led | ||||
| 			case led.RGBLEDName: | ||||
| 				configRGBLEDs[led.RGBLEDID] = led | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	rgbLEDs := make([]*types.RGBLED, 0) | ||||
| 	for _, rgbLED := range configRGBLEDs { | ||||
| 		rgbLEDs = append(rgbLEDs, rgbLED) | ||||
| 	} | ||||
|  | ||||
| 	return c.convertRGBLEDs(rgbLEDs) | ||||
| } | ||||
|  | ||||
| // GetTemperatureSensors returns a list of temperature sensors | ||||
| func (c *Configuration) GetTemperatureSensors(option Option) []sensor.TemperatureSensor { | ||||
| 	temperatureSensors := c.getTemperatureSensors() | ||||
| @@ -457,6 +503,18 @@ func (c *Configuration) convertHumiditySensors(sensors []*types.Sensor) []sensor | ||||
| 	return humiditySensors | ||||
| } | ||||
|  | ||||
| func (c *Configuration) convertRGBLEDs(rgbLEDs []*types.RGBLED) []rgbled.RGBLED { | ||||
| 	leds := make([]rgbled.RGBLED, 0) | ||||
|  | ||||
| 	for _, rgbLED := range rgbLEDs { | ||||
| 		leds = append(leds, &rgbled.LED{ | ||||
| 			RGBLED: rgbLED, | ||||
| 		}) | ||||
| 	} | ||||
|  | ||||
| 	return leds | ||||
| } | ||||
|  | ||||
| func (c *Configuration) convertTemperatureSensors(sensors []*types.Sensor) []sensor.TemperatureSensor { | ||||
| 	temperatureSensors := make([]sensor.TemperatureSensor, 0) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user