// THIS FILE IS AUTO-GENERATED BY CCGEN
// DO NOT MODIFY

package commandclass

type CommandClassID byte

const (
  {{range .CommandClasses}}
  {{.GetConstName}} CommandClassID = {{.Key}}{{end}}
)

func (c CommandClassID) String() string {
  switch c {
    {{range .CommandClasses}}
    case {{.GetConstName}}:
      return "{{.Help}}"
    {{end}}
    default:
      return fmt.Sprintf("Unknown (0x%X)", byte(c))
  }
}

func Parse(payload []byte) (interface{}, error) {
  switch CommandClassID(payload[0]) {
    {{range $_, $cc := .CommandClasses}}{{if .CanGen}}{{$version := .Version}}
    case {{.GetConstName}}:
      switch payload[1] {
        {{range .Commands}}case {{.Key}}:
          command := {{$cc.GetPackageName}}.{{(ToGoName .Name)}}{}
          err := command.UnmarshalBinary(payload[2:])
          if err != nil {
            return nil, err
          }

          return command, nil
        {{end}}default:
          return nil, errors.New("Unknown command in command class {{.Help}}")
      }
    {{end}}{{end}}

    default:
      return nil, errors.New("Unknown command class")
  }
}

// THIS FILE IS AUTO-GENERATED BY CCGEN
// DO NOT MODIFY

package commandclass

type CommandClassID byte

const (
  {{range .CommandClasses}}
  {{.GetConstName}} CommandClassID = {{.Key}}{{end}}
)

func (c CommandClassID) String() string {
  switch c {
    {{range .CommandClasses}}
    {{if eq .Version 1}}
    case {{.GetConstName}}:
      return "{{.Help}}"
    {{end}}
    {{end}}
    default:
      return fmt.Sprintf("Unknown (0x%X)", byte(c))
  }
}

func Parse(ccVersion uint8, payload []byte) (interface{}, error) {
  switch {
    {{range $_, $cc := .CommandClasses}}{{if .CanGen}}{{$version := .Version}}
    case payload[0] == byte({{.GetConstName}}) && ccVersion == {{$version}}:
      switch payload[1] {
        {{range .Commands}}case {{.Key}}:
          command := {{$cc.GetPackageName}}.{{(ToGoName .Name)}}{}
          if err := command.UnmarshalBinary(payload[2:]); err != nil {
            return nil, err
          }
          return command, nil
        {{end}}default:
          return nil, errors.New("Unknown command in command class {{.Help}}")
      }
    {{end}}{{end}}

    default:
      return nil, errors.New("Unknown command class")
  }
}

Fix errors with duplicate switch cases in generated code
Fix errors with duplicate switch cases in generated code
