-
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tariffs: swallow startup errors (#16258)
- Loading branch information
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package tariff | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/evcc-io/evcc/api" | ||
) | ||
|
||
// Wrapper wraps an api.Tariff to capture initialization errors | ||
type Wrapper struct { | ||
typ string | ||
config map[string]interface{} | ||
err error | ||
} | ||
|
||
// NewWrapper creates an offline tariff wrapper | ||
func NewWrapper(typ string, other map[string]interface{}, err error) api.Tariff { | ||
v := &Wrapper{ | ||
typ: typ, | ||
config: other, | ||
err: fmt.Errorf("tariff not available: %w", err), | ||
} | ||
|
||
return v | ||
} | ||
|
||
// WrappedConfig indicates a device with wrapped configuration | ||
func (v *Wrapper) WrappedConfig() (string, map[string]interface{}) { | ||
return v.typ, v.config | ||
} | ||
|
||
// Rates implements the api.Tariff interface | ||
func (t *Wrapper) Rates() (api.Rates, error) { | ||
return nil, t.err | ||
} | ||
|
||
// Type implements the api.Tariff interface | ||
func (t *Wrapper) Type() api.TariffType { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters