课表组件、天气组件全面升级。
This commit is contained in:
lincube
2026-03-03 15:09:49 +08:00
parent 2d09c1aca2
commit 478ed115a1
47 changed files with 4876 additions and 771 deletions

View File

@@ -335,6 +335,12 @@ public sealed class XiaomiWeatherService : IWeatherDataService, IDisposable
WindDirectionDegree: ReadDouble(currentNode, "wind", "angle", "value") ??
ReadDouble(currentNode, "wind", "direction", "value"),
WeatherCode: weatherCode,
IsDaylight: ReadBool(currentNode, "daylight", "value") ??
ReadBool(currentNode, "daylight") ??
ReadBool(currentNode, "isDaylight") ??
ReadBool(currentNode, "isDay") ??
ReadBool(currentNode, "day") ??
ReadBool(payload, "isDaylight"),
WeatherText: weatherText);
var forecasts = ParseDailyForecasts(dailyNode, days, locale);
@@ -827,6 +833,46 @@ public sealed class XiaomiWeatherService : IWeatherDataService, IDisposable
return null;
}
private static bool? ReadBool(JsonElement? node, params string[] path)
{
if (!node.HasValue)
{
return null;
}
var target = path.Length == 0 ? node : TryGetNode(node.Value, path);
if (!target.HasValue)
{
return null;
}
if (target.Value.ValueKind is JsonValueKind.True or JsonValueKind.False)
{
return target.Value.GetBoolean();
}
if (target.Value.ValueKind == JsonValueKind.Number && target.Value.TryGetInt32(out var number))
{
return number != 0;
}
if (target.Value.ValueKind == JsonValueKind.String)
{
var text = target.Value.GetString();
if (bool.TryParse(text, out var parsed))
{
return parsed;
}
if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
{
return number != 0;
}
}
return null;
}
private static DateTimeOffset? ParseTime(string? raw)
{
if (string.IsNullOrWhiteSpace(raw))