From bf7af0ada44914cd6e34891a7e496dd3875c7485 Mon Sep 17 00:00:00 2001 From: Jonas Hansen Date: Wed, 10 Jan 2024 20:39:41 +0100 Subject: [PATCH] Fix nullability --- .../Entities/MqttLawnMowerDiscoveryConfig.cs | 4 ++++ .../Entities/MqttSirenDiscoveryConfig.cs | 6 ++++++ .../Entities/MqttTextDiscoveryConfig.cs | 5 +++++ .../Entities/MqttUpdateDiscoveryConfig.cs | 3 +++ .../Entities/MqttValveDiscoveryConfig.cs | 7 +++++++ .../Entities/MqttWaterHeaterDiscoveryConfig.cs | 8 ++++++++ src/HomeAssistantDiscoveryNet/MqttDiscoveryJsonContext.cs | 1 + 7 files changed, 34 insertions(+) diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttLawnMowerDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttLawnMowerDiscoveryConfig.cs index 51faf75..3d12f5f 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttLawnMowerDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttLawnMowerDiscoveryConfig.cs @@ -38,6 +38,7 @@ public class MqttLawnMowerDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -79,6 +80,7 @@ public class MqttLawnMowerDiscoveryConfig : MqttDiscoveryConfig ///true if no activity_state_topic defined, else false. /// [JsonPropertyName("optimistic")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Optimistic { get; set; } /// @@ -98,6 +100,7 @@ public class MqttLawnMowerDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -117,5 +120,6 @@ public class MqttLawnMowerDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } } diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttSirenDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttSirenDiscoveryConfig.cs index f841774..5f244ec 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttSirenDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttSirenDiscoveryConfig.cs @@ -39,6 +39,7 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -81,6 +82,7 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig ///true if no state_topic defined, else false. /// [JsonPropertyName("optimistic")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Optimistic { get; set; } /// @@ -116,6 +118,7 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -123,6 +126,7 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } /// @@ -160,6 +164,7 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("support_duration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? SupportDuration { get; set; } /// @@ -167,5 +172,6 @@ public class MqttSirenDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("support_volume_set")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? SupportVolumeSet { get; set; } } diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttTextDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttTextDiscoveryConfig.cs index e1f4219..450678f 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttTextDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttTextDiscoveryConfig.cs @@ -26,6 +26,7 @@ public class MqttTextDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -59,6 +60,7 @@ public class MqttTextDiscoveryConfig : MqttDiscoveryConfig /// , default: 255 /// [JsonPropertyName("max")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Max { get; set; } /// @@ -66,6 +68,7 @@ public class MqttTextDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("min")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Min { get; set; } /// @@ -92,6 +95,7 @@ public class MqttTextDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -99,6 +103,7 @@ public class MqttTextDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } /// diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttUpdateDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttUpdateDiscoveryConfig.cs index 4d12174..d593a75 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttUpdateDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttUpdateDiscoveryConfig.cs @@ -28,6 +28,7 @@ public class MqttUpdateDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -92,6 +93,7 @@ public class MqttUpdateDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -111,6 +113,7 @@ public class MqttUpdateDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } /// diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttValveDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttValveDiscoveryConfig.cs index 48899ba..46a9d28 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttValveDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttValveDiscoveryConfig.cs @@ -33,6 +33,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -74,6 +75,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig ///false if the state or position topic is defined; true otherwise. /// [JsonPropertyName("optimistic")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Optimistic { get; set; } /// @@ -115,6 +117,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("position_closed")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? PositionClosed { get; set; } /// @@ -122,6 +125,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: 100 /// [JsonPropertyName("position_open")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? PositionOpen { get; set; } /// @@ -129,6 +133,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -136,6 +141,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("reports_position")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? ReportsPosition { get; set; } /// @@ -143,6 +149,7 @@ public class MqttValveDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } /// diff --git a/src/HomeAssistantDiscoveryNet/Entities/MqttWaterHeaterDiscoveryConfig.cs b/src/HomeAssistantDiscoveryNet/Entities/MqttWaterHeaterDiscoveryConfig.cs index b8710d7..6972b91 100644 --- a/src/HomeAssistantDiscoveryNet/Entities/MqttWaterHeaterDiscoveryConfig.cs +++ b/src/HomeAssistantDiscoveryNet/Entities/MqttWaterHeaterDiscoveryConfig.cs @@ -26,6 +26,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig /// , default: true /// [JsonPropertyName("enabled_by_default")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? EnabledByDefault { get; set; } /// @@ -46,6 +47,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig /// Set the initial target temperature. The default value depends on the temperature unit, and will be 43.3°C or 110°F. /// [JsonPropertyName("initial")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Initial { get; set; } /// @@ -64,12 +66,14 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig /// Maximum set point available. The default value depends on the temperature unit, and will be 60°C or 140°F. /// [JsonPropertyName("max_temp")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public double? MaxTemp { get; set; } /// /// Minimum set point available. The default value depends on the temperature unit, and will be 43.3°C or 110°F. /// [JsonPropertyName("min_temp")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public double? MinTemp { get; set; } /// @@ -118,6 +122,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig ///true if no state topic defined, else false. /// [JsonPropertyName("optimistic")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Optimistic { get; set; } /// @@ -167,6 +172,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig ///0.1 for Celsius and 1.0 for Fahrenheit. /// [JsonPropertyName("precision")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public double? Precision { get; set; } /// @@ -174,6 +180,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig /// , default: 0 /// [JsonPropertyName("qos")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public long? Qos { get; set; } /// @@ -181,6 +188,7 @@ public class MqttWaterHeaterDiscoveryConfig : MqttDiscoveryConfig /// , default: false /// [JsonPropertyName("retain")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? Retain { get; set; } /// diff --git a/src/HomeAssistantDiscoveryNet/MqttDiscoveryJsonContext.cs b/src/HomeAssistantDiscoveryNet/MqttDiscoveryJsonContext.cs index e609535..d18cde7 100644 --- a/src/HomeAssistantDiscoveryNet/MqttDiscoveryJsonContext.cs +++ b/src/HomeAssistantDiscoveryNet/MqttDiscoveryJsonContext.cs @@ -21,6 +21,7 @@ namespace HomeAssistantDiscoveryNet; [JsonSerializable(typeof(MqttSceneDiscoveryConfig))] [JsonSerializable(typeof(MqttSelectDiscoveryConfig))] [JsonSerializable(typeof(MqttSensorDiscoveryConfig))] +[JsonSerializable(typeof(MqttSirenDiscoveryConfig))] [JsonSerializable(typeof(MqttSwitchDiscoveryConfig))] [JsonSerializable(typeof(MqttTagScannerDiscoveryConfig))] [JsonSerializable(typeof(MqttTemplateLightDiscoveryConfig))]