forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Homematic: better error messages (evcc-io#6835)
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 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
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,37 @@ | ||
package homematic | ||
|
||
import ( | ||
"encoding/xml" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test MethodResponse response | ||
func TestUnmarshalMethodResponse(t *testing.T) { | ||
|
||
{ | ||
// Double response test | ||
var res MethodResponse | ||
|
||
xmlstr := `<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><double>20698.0</double></value></param></params></methodResponse>` | ||
assert.NoError(t, xml.Unmarshal([]byte(strings.Replace(string(xmlstr), "ISO-8859-1", "UTF-8", 1)), &res)) | ||
|
||
assert.Equal(t, float64(20698), res.Value.CCUFloat) | ||
} | ||
|
||
{ | ||
// Faulty response test | ||
var res MethodResponse | ||
|
||
xmlstr := `<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i4>-2</i4></value></member><member><name>faultString</name><value>Invalid device</value></member></struct></value></fault></methodResponse>` | ||
assert.NoError(t, xml.Unmarshal([]byte(strings.Replace(string(xmlstr), "ISO-8859-1", "UTF-8", 1)), &res)) | ||
|
||
assert.Equal(t, "faultCode", res.Fault[0].Name) | ||
assert.Equal(t, int64(-2), res.Fault[0].Value.CCUInt) | ||
assert.Equal(t, "faultString", res.Fault[1].Name) | ||
assert.Equal(t, "Invalid device", res.Fault[1].Value.CCUString) | ||
} | ||
|
||
} |