Skip to content

Commit c376123

Browse files
committed
refactor(homeMatic): simplify JSON-RPC Params and add Id property to requests
1 parent d161f22 commit c376123

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

source/CreativeCoders.HomeMatic/Backup/CcuBackupService.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ private async Task<string> LoginAsync(CancellationToken cancellationToken)
8989
{
9090
var request = new JsonRpcRequest
9191
{
92+
Id = Environment.TickCount,
9293
Method = "Session.login",
93-
Params = new Dictionary<string, string>
94-
{
95-
["username"] = _credential.UserName,
96-
["password"] = _credential.Password
97-
}
94+
Params = ["username", _credential.UserName, "password", _credential.Password]
9895
};
9996

10097
var apiUrl = new Uri(_baseUrl, "/api/homematic.cgi");
@@ -123,11 +120,9 @@ private async Task LogoutAsync(string sessionId, CancellationToken cancellationT
123120
{
124121
var request = new JsonRpcRequest
125122
{
123+
Id = Environment.TickCount,
126124
Method = "Session.logout",
127-
Params = new Dictionary<string, string>
128-
{
129-
["_session_id_"] = sessionId
130-
}
125+
Params = ["_session_id_", sessionId]
131126
};
132127

133128
var apiUrl = new Uri(_baseUrl, "/api/homematic.cgi");
@@ -146,11 +141,14 @@ private async Task LogoutAsync(string sessionId, CancellationToken cancellationT
146141

147142
private record JsonRpcRequest
148143
{
144+
[JsonPropertyName("id")]
145+
public required int Id { get; init; }
146+
149147
[JsonPropertyName("method")]
150148
public required string Method { get; init; }
151149

152150
[JsonPropertyName("params")]
153-
public required Dictionary<string, string> Params { get; init; }
151+
public required object?[] Params { get; init; }
154152
}
155153

156154
private record JsonRpcResponse

0 commit comments

Comments
 (0)