// configure creates a configured device from a template so we can test it
configure creates a configured device from a template so we can test it
// configure creates a configured device from a template so we can test it
func (d *DeviceTest) configure() (interface{}, error) {
	b, _, err := d.Template.RenderResult(false, d.ConfigValues)
	if err != nil {
		return nil, err
	}
	var instance struct {
		Type  string
		Other map[string]interface{} `yaml:",inline"`
	}
	if err := yaml.Unmarshal(b, &instance); err != nil {
		return nil, err
	}
	var v interface{}
	switch DeviceCategories[d.DeviceCategory].class {
	case DeviceClassMeter:
		v, err = meter.NewFromConfig(instance.Type, instance.Other)
	case DeviceClassCharger:
		v, err = charger.NewFromConfig(instance.Type, instance.Other)
	case DeviceClassVehicle:
		v, err = vehicle.NewFromConfig(instance.Type, instance.Other)
	}
	return v, err
}
func ( d * DeviceTest ) configure ( ) ( interface { } , error ) { b , _ , err := d . Template . RenderResult ( false , d . ConfigValues ) if err != nil { return nil , err } var instance struct { Type string Other map [ string ] interface { } `yaml:",inline"` } if err := yaml . Unmarshal ( b , & instance ) ; err != nil { return nil , err } var v interface { } switch DeviceCategories [ d . DeviceCategory ] . class { case DeviceClassMeter : v , err = meter . NewFromConfig ( instance . Type , instance . Other ) case DeviceClassCharger : v , err = charger . NewFromConfig ( instance . Type , instance . Other ) case DeviceClassVehicle : v , err = vehicle . NewFromConfig ( instance . Type , instance . Other ) } return v , err }
configure creates a configured device from a template so we can test it
configure creates a configured device from a template so we can test it