@@ -26,8 +26,8 @@ type CarWings struct {
26
26
* embed
27
27
user , password string
28
28
session * carwings.Session
29
- statusG func () (interface {} , error )
30
- climateG func () (interface {} , error )
29
+ statusG func () (carwings. BatteryStatus , error )
30
+ climateG func () (carwings. ClimateStatus , error )
31
31
refreshKey string
32
32
refreshTime time.Time
33
33
}
@@ -91,13 +91,8 @@ func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
91
91
return nil , fmt .Errorf ("login failed: %w" , err )
92
92
}
93
93
94
- v .statusG = provider.Cached [ ](func () (interface {}, error ) {
95
- return v .status ()
96
- }, cc .Cache )
97
-
98
- v .climateG = provider.Cached [ ](func () (interface {}, error ) {
99
- return v .session .ClimateControlStatus ()
100
- }, cc .Cache )
94
+ v .statusG = provider .Cached [carwings.BatteryStatus ](v .status , cc .Cache )
95
+ v .climateG = provider .Cached [carwings.ClimateStatus ](v .session .ClimateControlStatus , cc .Cache )
101
96
102
97
return v , nil
103
98
}
@@ -112,11 +107,11 @@ func (v *CarWings) connectIfRequired(err error) error {
112
107
return err
113
108
}
114
109
115
- func (v * CarWings ) status () (interface {} , error ) {
110
+ func (v * CarWings ) status () (carwings. BatteryStatus , error ) {
116
111
// api result is stale
117
112
if v .refreshKey != "" {
118
113
if err := v .refreshResult (); err != nil {
119
- return nil , err
114
+ return * new (carwings. BatteryStatus ) , err
120
115
}
121
116
}
122
117
@@ -125,7 +120,7 @@ func (v *CarWings) status() (interface{}, error) {
125
120
if err == nil {
126
121
if elapsed := time .Since (bs .Timestamp ); elapsed > carwingsStatusExpiry {
127
122
if err = v .refreshRequest (); err != nil {
128
- return nil , err
123
+ return * new (carwings. BatteryStatus ) , err
129
124
}
130
125
131
126
err = api .ErrMustRetry
@@ -182,7 +177,7 @@ func (v *CarWings) refreshRequest() (err error) {
182
177
// SoC implements the api.Vehicle interface
183
178
func (v * CarWings ) SoC () (float64 , error ) {
184
179
res , err := v .statusG ()
185
- if res , ok := res .(carwings. BatteryStatus ); err == nil && ok {
180
+ if err == nil {
186
181
return float64 (res .StateOfCharge ), nil
187
182
}
188
183
@@ -196,7 +191,7 @@ func (v *CarWings) Status() (api.ChargeStatus, error) {
196
191
status := api .StatusA // disconnected
197
192
198
193
res , err := v .statusG ()
199
- if res , ok := res .(carwings. BatteryStatus ); err == nil && ok {
194
+ if err == nil {
200
195
if res .PluginState == carwings .Connected {
201
196
status = api .StatusB // connected, not charging
202
197
}
@@ -213,7 +208,7 @@ var _ api.VehicleRange = (*CarWings)(nil)
213
208
// Range implements the api.VehicleRange interface
214
209
func (v * CarWings ) Range () (int64 , error ) {
215
210
res , err := v .statusG ()
216
- if res , ok := res .(carwings. BatteryStatus ); err == nil && ok {
211
+ if err == nil {
217
212
return int64 (res .CruisingRangeACOn ) / 1000 , nil
218
213
}
219
214
@@ -226,7 +221,7 @@ var _ api.VehicleClimater = (*CarWings)(nil)
226
221
func (v * CarWings ) Climater () (active bool , outsideTemp float64 , targetTemp float64 , err error ) {
227
222
res , err := v .climateG ()
228
223
229
- if res , ok := res .(carwings. ClimateStatus ); err == nil && ok {
224
+ if err == nil {
230
225
active = res .Running
231
226
targetTemp = float64 (res .Temperature )
232
227
outsideTemp = targetTemp
0 commit comments