fix: refresh action cache and classify auth failures
This commit is contained in:
@@ -19,8 +19,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
deviceSpecUA = "mijiaAPI/4.1.2"
|
||||
deviceSpecMaxSize = 8 << 20
|
||||
deviceSpecUA = "mijiaAPI/4.1.2"
|
||||
deviceSpecMaxSize = 8 << 20
|
||||
deviceCacheVersion = 2
|
||||
)
|
||||
|
||||
var deviceSpecURL = "https://home.miot-spec.com/spec/"
|
||||
@@ -444,7 +445,7 @@ func writeDeviceInfoCache(path string, info DeviceInfo) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||
return fmt.Errorf("create device info cache directory: %w", err)
|
||||
}
|
||||
cache := deviceInfoCache{Name: info.Name, Model: info.Model}
|
||||
cache := deviceInfoCache{Version: deviceCacheVersion, Name: info.Name, Model: info.Model}
|
||||
for _, property := range info.Properties {
|
||||
cache.Properties = append(cache.Properties, propertyCache{
|
||||
PropertySpec: property,
|
||||
@@ -505,6 +506,7 @@ type actionCache struct {
|
||||
}
|
||||
|
||||
type deviceInfoCache struct {
|
||||
Version int `json:"version"`
|
||||
Name string `json:"name"`
|
||||
Model string `json:"model"`
|
||||
Properties []propertyCache `json:"properties"`
|
||||
@@ -524,6 +526,12 @@ func decodeDeviceInfo(data []byte, model string) (DeviceInfo, error) {
|
||||
}
|
||||
return DeviceInfo{}, fmt.Errorf("trailing content: %w", err)
|
||||
}
|
||||
if cache.Version < deviceCacheVersion {
|
||||
return DeviceInfo{}, fmt.Errorf("device info cache stale: version %d, want %d", cache.Version, deviceCacheVersion)
|
||||
}
|
||||
if cache.Version != deviceCacheVersion {
|
||||
return DeviceInfo{}, fmt.Errorf("unsupported device info cache version %d", cache.Version)
|
||||
}
|
||||
|
||||
info := DeviceInfo{Name: cache.Name, Model: cache.Model}
|
||||
for _, cachedProperty := range cache.Properties {
|
||||
|
||||
Reference in New Issue
Block a user