You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
846 B

3 years ago
  1. package handlerfactory
  2. import (
  3. "gopkg.in/yaml.v2"
  4. "io"
  5. "io/ioutil"
  6. "strings"
  7. )
  8. type FactoryConfig struct {
  9. Mode FCMOde `yaml:"mode"`
  10. Target string `yaml:"target"`
  11. SceneNames []string `yaml:"scenes"`
  12. TriggerDeviceID string `yaml:"trigger_device_id"`
  13. }
  14. type FCMOde string
  15. var (
  16. SceneDimmer FCMOde = "SceneDimmer"
  17. )
  18. func ParseConfigs(reader io.Reader) ([]FactoryConfig, error) {
  19. readAll, err := ioutil.ReadAll(reader)
  20. if err != nil {
  21. return nil, err
  22. }
  23. splits := strings.Split(string(readAll), "\n---\n")
  24. configs := make([]FactoryConfig, 0, 8)
  25. for _, split := range splits {
  26. var factoryConfig FactoryConfig
  27. err := yaml.NewDecoder(strings.NewReader(split)).Decode(&factoryConfig)
  28. if err != nil {
  29. return nil, err
  30. }
  31. configs = append(configs, factoryConfig)
  32. }
  33. return configs, nil
  34. }