// NewWarp creates a new configurable charger
NewWarp creates a new configurable charger
// NewWarp creates a new configurable charger
func NewWarp(mqttconf mqtt.Config, topic string, timeout time.Duration) (*Warp, error) {
	log := util.NewLogger("warp")
	client, err := mqtt.RegisteredClientOrDefault(log, mqttconf)
	if err != nil {
		return nil, err
	}
	wb := &Warp{
		log:    log,
		root:   topic,
		client: client,
	}
	timer := provider.NewMqtt(log, client,
		fmt.Sprintf("%s/evse/state", topic), 1, timeout,
	).StringGetter()
	stringG := func(topic string) func() (string, error) {
		g := provider.NewMqtt(log, client, topic, 1, 0).StringGetter()
		return func() (val string, err error) {
			if val, err = g(); err == nil {
				_, err = timer()
			}
			return val, err
		}
	}
	wb.enabledG = stringG(fmt.Sprintf("%s/evse/auto_start_charging", topic))
	wb.statusG = stringG(fmt.Sprintf("%s/evse/state", topic))
	wb.meterG = stringG(fmt.Sprintf("%s/meter/state", topic))
	wb.meterDetailsG = stringG(fmt.Sprintf("%s/meter/detailed_values", topic))
	wb.enableS = provider.NewMqtt(log, client,
		fmt.Sprintf("%s/evse/auto_start_charging_update", topic), 1, 0).
		WithPayload(`{ "auto_start_charging": ${enable} }`).
		BoolSetter("enable")
	wb.maxcurrentS = provider.NewMqtt(log, client,
		fmt.Sprintf("%s/evse/current_limit", topic), 1, 0).
		WithPayload(`{ "current": ${maxcurrent} }`).
		IntSetter("maxcurrent")
	return wb, nil
}
func NewWarp ( mqttconf mqtt . Config , topic string , timeout time . Duration ) ( * Warp , error ) { log := util . NewLogger ( " " ) client , err := mqtt . RegisteredClientOrDefault ( log , mqttconf ) if err != nil { return nil , err } wb := & Warp { log : log , root : topic , client : client , } timer := provider . NewMqtt ( log , client , fmt . Sprintf ( " " , topic ) , 1 , timeout , ) . StringGetter ( ) stringG := func ( topic string ) func ( ) ( string , error ) { g := provider . NewMqtt ( log , client , topic , 1 , 0 ) . StringGetter ( ) return func ( ) ( val string , err error ) { if val , err = g ( ) ; err == nil { _ , err = timer ( ) } return val , err } } wb . enabledG = stringG ( fmt . Sprintf ( " " , topic ) ) wb . statusG = stringG ( fmt . Sprintf ( " " , topic ) ) wb . meterG = stringG ( fmt . Sprintf ( " " , topic ) ) wb . meterDetailsG = stringG ( fmt . Sprintf ( " " , topic ) ) wb . enableS = provider . NewMqtt ( log , client , fmt . Sprintf ( " " , topic ) , 1 , 0 ) . WithPayload ( `{ "auto_start_charging": ${enable} }` ) . BoolSetter ( " " ) wb . maxcurrentS = provider . NewMqtt ( log , client , fmt . Sprintf ( " " , topic ) , 1 , 0 ) . WithPayload ( `{ "current": ${maxcurrent} }` ) . IntSetter ( " " ) return wb , nil }
NewWarp creates a new configurable charger
NewWarp creates a new configurable charger
// timeout handler