hardybarth-salia: add rfid identifier (#20321)
This commit is contained in:
parent
9a08324d8b
commit
2db934e0fa
3 changed files with 90 additions and 6 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
package salia
|
package salia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HeartBeat = "salia/heartbeat"
|
HeartBeat = "salia/heartbeat"
|
||||||
ChargeMode = "salia/chargemode"
|
ChargeMode = "salia/chargemode"
|
||||||
|
|
@ -87,4 +92,40 @@ type Port struct {
|
||||||
EvPresent int `json:"ev_present,string"`
|
EvPresent int `json:"ev_present,string"`
|
||||||
Charging int `json:",string"`
|
Charging int `json:",string"`
|
||||||
GridCurrentLimit float64 `json:"grid_current_limit,string"`
|
GridCurrentLimit float64 `json:"grid_current_limit,string"`
|
||||||
|
Session struct {
|
||||||
|
AuthorizationStatus string `json:"authorization_status"`
|
||||||
|
AuthorizationMethod string `json:"authorization_method"`
|
||||||
|
} `json:"session"`
|
||||||
|
RFID struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Available string `json:"available"`
|
||||||
|
Authorizereq string `json:"authorizereq"`
|
||||||
|
AuthorizationRequest AuthorizationRequest `json:"authorization_request"`
|
||||||
|
} `json:"rfid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthorizationRequest struct {
|
||||||
|
Protocol string
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthorizationRequest) UnmarshalJSON(data []byte) error {
|
||||||
|
s, err := strconv.Unquote(string(data))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var arr []string
|
||||||
|
if err := json.Unmarshal([]byte(s), &arr); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(arr) == 2 {
|
||||||
|
*a = AuthorizationRequest{
|
||||||
|
Protocol: arr[0],
|
||||||
|
Key: arr[1],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
charger/echarge/salia/types_test.go
Normal file
42
charger/echarge/salia/types_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
package salia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAuthorizationRequestUnmarshalJSON(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
jsonInput string
|
||||||
|
expected AuthorizationRequest
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Leerer JSON-String",
|
||||||
|
// Dieser Input repräsentiert ein leeres Stringliteral.
|
||||||
|
jsonInput: "\"\"",
|
||||||
|
expected: AuthorizationRequest{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Korrekte Authentifizierungsanfrage (als JSON-String)",
|
||||||
|
// Realer Input: ein JSON-String, der ein Array repräsentiert.
|
||||||
|
// Das Ergebnis soll durch Unquote den Inhalt ["ISO14443","9af18400"] liefern.
|
||||||
|
jsonInput: "\"[\\\"ISO14443\\\",\\\"9af18400\\\"]\"",
|
||||||
|
expected: AuthorizationRequest{Protocol: "ISO14443", Key: "9af18400"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
var ar AuthorizationRequest
|
||||||
|
err := json.Unmarshal([]byte(tc.jsonInput), &ar)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unerwarteter Fehler: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ar.Protocol != tc.expected.Protocol || ar.Key != tc.expected.Key {
|
||||||
|
t.Errorf("Falsches Ergebnis: got %+v, expected %+v", ar, tc.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -266,12 +266,13 @@ func (wb *Salia) currents() (float64, float64, float64, error) {
|
||||||
return i.L1.Actual / 1e3, i.L2.Actual / 1e3, i.L3.Actual / 1e3, err
|
return i.L1.Actual / 1e3, i.L2.Actual / 1e3, i.L3.Actual / 1e3, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// var _ api.Identifier = (*Salia)(nil)
|
func (wb *Salia) Identify() (string, error) {
|
||||||
|
res, err := wb.apiG.Get()
|
||||||
// // Identify implements the api.Identifier interface
|
if err != nil {
|
||||||
// func (wb *Salia) Identify() (string, error) {
|
return "", err
|
||||||
// return "", api.ErrNotAvailable
|
}
|
||||||
// }
|
return res.Secc.Port0.RFID.AuthorizationRequest.Key, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (wb *Salia) getPhases() (int, error) {
|
func (wb *Salia) getPhases() (int, error) {
|
||||||
res, err := wb.apiG.Get()
|
res, err := wb.apiG.Get()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue