SHM: make serial configurable (#28198)
This commit is contained in:
parent
d680fff9d0
commit
b7fd7e44f4
5 changed files with 51 additions and 1 deletions
|
|
@ -44,6 +44,7 @@ type Config struct {
|
|||
AllowControl_ bool `json:"allowControl,omitempty"` // deprecated
|
||||
VendorId string `json:"vendorId"`
|
||||
DeviceId string `json:"deviceId"`
|
||||
DeviceSerial string `json:"deviceSerial"`
|
||||
}
|
||||
|
||||
// NewFromConfig creates a new SEMP instance from configuration and starts it
|
||||
|
|
@ -60,6 +61,24 @@ func NewFromConfig(cfg Config, hostUri string, site site.API, addr string, route
|
|||
return err
|
||||
}
|
||||
|
||||
// Only if DeviceSerial is explicitly configured: validate it and patch the
|
||||
// UUID node (last 6 bytes) to ensure the UDN and DeviceSerial are stable across restarts.
|
||||
// Ideally we'd have used the same machine-id approach as UniqueDeviceID does, but that
|
||||
// would break existing installations that relied on the node ID of the UUID which was set to the MAC address
|
||||
// of the host. See https://github.com/evcc-io/evcc/issues/28126 for context.
|
||||
if cfg.DeviceSerial != "" {
|
||||
b, err := hex.DecodeString(cfg.DeviceSerial)
|
||||
if err != nil {
|
||||
return fmt.Errorf("device serial: %w", err)
|
||||
}
|
||||
if len(b) != 6 {
|
||||
return fmt.Errorf("invalid device serial: %v. Must be 12 characters HEX string", cfg.DeviceSerial)
|
||||
}
|
||||
|
||||
// replaces the node (last 6 bytes) of a UUID with the given bytes.
|
||||
copy(uid[10:], b)
|
||||
}
|
||||
|
||||
var did []byte
|
||||
if cfg.DeviceId == "" {
|
||||
if did, err = UniqueDeviceID(); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue