Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit f176e60

Browse files
committed
The date format does not apply to live status
1 parent b018dc7 commit f176e60

4 files changed

Lines changed: 44 additions & 30 deletions

File tree

src/CodeCaster.GoodWe/GoodWeClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,18 @@ public async Task<GoodWeApiResponse<PowerStationMonitorData>> GetMonitorDetailRa
148148
return new GoodWeApiResponse<PowerStationMonitorData>(response);
149149
}
150150

151-
public async Task<GoodWeApiResponse<InverterData>> GetPlantListAsync(CancellationToken cancellationToken)
151+
public async Task<GoodWeApiResponse<PlantData>> GetPlantListAsync(CancellationToken cancellationToken)
152152
{
153153
string endpoint = _apiRoot + GetPowerStationInfoEndpoint;
154154

155155
var request = new PowerStationListRequest(pageIndex: 1);
156156

157-
var response = await TryRequest<InverterData>(() => _client.PostAsJsonAsync(endpoint, request, cancellationToken), cancellationToken);
157+
var response = await TryRequest<PlantData>(() => _client.PostAsJsonAsync(endpoint, request, cancellationToken), cancellationToken);
158158

159159
await WriteJson("GetInverterListAsync", response);
160160

161161
// TODO: error handling
162-
return new GoodWeApiResponse<InverterData>(response);
162+
return new GoodWeApiResponse<PlantData>(response);
163163
}
164164

165165
[DebuggerStepThrough]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace CodeCaster.GoodWe.Json
5+
{
6+
public class DateTimeFormatAttribute : JsonConverterAttribute
7+
{
8+
private readonly string _format;
9+
10+
public DateTimeFormatAttribute(string format)
11+
{
12+
_format = format;
13+
}
14+
15+
public override JsonConverter CreateConverter(Type typeToConvert)
16+
{
17+
if (typeToConvert == typeof(DateTime?))
18+
{
19+
return new NullableDateTimeConverter(this._format);
20+
}
21+
else if (typeToConvert == typeof(DateTime))
22+
{
23+
return new DateTimeConverter(this._format);
24+
}
25+
26+
throw new ArgumentException("Cannot create converter for type " + typeToConvert, nameof(typeToConvert));
27+
}
28+
}
29+
}

src/CodeCaster.GoodWe/Json/GoodWeResponses.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Globalization;
43
using System.Text.Json.Serialization;
54

65
// JSON...
@@ -10,22 +9,6 @@
109

1110
namespace CodeCaster.GoodWe.Json
1211
{
13-
/*
14-
{
15-
"hasError": false,
16-
"code": 100001,
17-
"msg": "No access, please login.",
18-
"data": null,
19-
"components": {
20-
"para": null,
21-
"langVer": 89,
22-
"timeSpan": 0,
23-
"api": "http://semsportal.com:82/api/v1/PowerStation/GetMonitorDetailByPowerstationId",
24-
"msgSocketAdr": ""
25-
}
26-
}
27-
*/
28-
2912
internal class ResponseBase<TData>
3013
{
3114
public bool HasError { get; set; }
@@ -67,7 +50,7 @@ public class DateSetting
6750
public string date_text { get; set; }
6851
}
6952

70-
public class InverterData
53+
public class PlantData
7154
{
7255
public int record { get; set; }
7356
public List<AddressWithInverters>? list { get; set; }
@@ -346,6 +329,14 @@ public class Soc
346329

347330
public class Inverter
348331
{
332+
[DateTimeFormat("MM/dd/yyyy HH:mm:ss")]
333+
public DateTime? last_refresh_time { get; set; }
334+
335+
[DateTimeFormat("MM/dd/yyyy HH:mm:ss")]
336+
public DateTime? turnon_time { get; set; }
337+
338+
public InverterData d { get; set; }
339+
349340
public string? sn { get; set; }
350341
public Dict dict { get; set; }
351342
public bool is_stored { get; set; }
@@ -356,11 +347,9 @@ public class Inverter
356347
public float emonth { get; set; }
357348
public float etotal { get; set; }
358349
public int status { get; set; }
359-
public DateTime? turnon_time { get; set; }
360350
public string? releation_id { get; set; }
361351
public string? type { get; set; }
362352
public float capacity { get; set; }
363-
public D d { get; set; }
364353
public bool it_change_flag { get; set; }
365354
public float tempperature { get; set; }
366355
public string? check_code { get; set; }
@@ -387,7 +376,6 @@ public class Inverter
387376
public string? total_generation { get; set; }
388377
public string? daily_generation { get; set; }
389378
public string? battery_charging { get; set; }
390-
public DateTime? last_refresh_time { get; set; }
391379
public string? bms_status { get; set; }
392380
public string? pw_id { get; set; }
393381
public string? fault_message { get; set; }
@@ -441,7 +429,7 @@ public class Right
441429
public int faultMsgCode { get; set; }
442430
}
443431

444-
public class D
432+
public class InverterData
445433
{
446434
public string? pw_id { get; set; }
447435
public string? capacity { get; set; }

src/CodeCaster.PVBridge.Service/Properties/launchSettings.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
"commandName": "Project",
55

66
"commandLineArgs": "service run",
7+
//"commandLineArgs": "service install",
8+
//"commandLineArgs": "sync",
79
//"commandLineArgs": "sync 2020-12-01 --until 2020-12-31 --input GoodWe --output CSV",
810
//"commandLineArgs": "sync 2020-12-01 -u 2020-12-31",
9-
//"commandLineArgs": "service install",
1011
//"commandLineArgs": "sync 2022-03-01 -i GoodWe --output PVOutput",
1112
//"commandLineArgs": "syncperiod 2022-03-01 2022-03-99",
1213
//"commandLineArgs": "syncday 2022-03-31",
1314
//"commandLineArgs": "sync --help",
1415
//"commandLineArgs": "service --idle",
1516
//"commandLineArgs": "--help",
16-
//"commandLineArgs": "--syncperiod 2021-05-25 2021-06-25T23:59:59",
17-
//"commandLineArgs": "--syncperiod 2022-03-01 2022-03-01T23:59:59",
18-
//"commandLineArgs": "--syncbacklog",
19-
//"commandLineArgs": "--install \".\\PVBridge.exe\"",
2017
"environmentVariables": {
2118
"DOTNET_ENVIRONMENT": "Development"
2219
},

0 commit comments

Comments
 (0)