diff --git a/src/ToMqttNet/DeviceTypes/MqttAlarmControlPanelDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttAlarmControlPanelDiscoveryConfig.cs new file mode 100644 index 0000000..2b05071 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttAlarmControlPanelDiscoveryConfig.cs @@ -0,0 +1,182 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt alarm panel platform enables the possibility to control MQTT capable alarm panels. The Alarm icon will change state after receiving a new state from state_topic. If these messages are published with RETAIN flag, the MQTT alarm panel will receive an instant state update after subscription and will start with the correct state. Otherwise, the initial state will be unknown. + /// + public class MqttAlarmControlPanelDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "alarm_control_panel"; + + + /// + /// If defined, specifies a code to enable or disable the alarm in the frontend. Note that the code is validated locally and blocks sending MQTT messages to the remote device. For remote code validation, the code can be configured to either of the special values REMOTE_CODE (numeric code) or REMOTE_CODE_TEXT (text code). In this case, local code validation is bypassed but the frontend will still show a numeric or text code dialog. Use command_template to send the code to the remote device. Example configurations for remote code validation can be found here. + /// + [JsonProperty("code")] + public string? Code { get; set; } + + /// + /// If true the code is required to arm the alarm. If false the code is not validated. + /// , default: true + /// + [JsonProperty("code_arm_required")] + public bool? CodeArmRequired { get; set; } + + /// + /// If true the code is required to disarm the alarm. If false the code is not validated. + /// , default: true + /// + [JsonProperty("code_disarm_required")] + public bool? CodeDisarmRequired { get; set; } + + /// + /// If true the code is required to trigger the alarm. If false the code is not validated. + /// , default: true + /// + [JsonProperty("code_trigger_required")] + public bool? CodeTriggerRequired { get; set; } + + /// + /// The template used for the command payload. Available variables: action and code. + /// , default: action + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the alarm state. + /// + [JsonProperty("command_topic")] + public string CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload to set armed-away mode on your Alarm Panel. + /// , default: ARM_AWAY + /// + [JsonProperty("payload_arm_away")] + public string? PayloadArmAway { get; set; } + + /// + /// The payload to set armed-home mode on your Alarm Panel. + /// , default: ARM_HOME + /// + [JsonProperty("payload_arm_home")] + public string? PayloadArmHome { get; set; } + + /// + /// The payload to set armed-night mode on your Alarm Panel. + /// , default: ARM_NIGHT + /// + [JsonProperty("payload_arm_night")] + public string? PayloadArmNight { get; set; } + + /// + /// The payload to set armed-vacation mode on your Alarm Panel. + /// , default: ARM_VACATION + /// + [JsonProperty("payload_arm_vacation")] + public string? PayloadArmVacation { get; set; } + + /// + /// The payload to set armed-custom-bypass mode on your Alarm Panel. + /// , default: ARM_CUSTOM_BYPASS + /// + [JsonProperty("payload_arm_custom_bypass")] + public string? PayloadArmCustomBypass { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload to disarm your Alarm Panel. + /// , default: DISARM + /// + [JsonProperty("payload_disarm")] + public string? PayloadDisarm { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload to trigger the alarm on your Alarm Panel. + /// , default: TRIGGER + /// + [JsonProperty("payload_trigger")] + public string? PayloadTrigger { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The MQTT topic subscribed to receive state updates. + /// + [JsonProperty("state_topic")] + public string StateTopic { get; set; } + + /// + /// Defines a template to extract the value. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttBinarySensorDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttBinarySensorDiscoveryConfig.cs index 81e9868..533e866 100644 --- a/src/ToMqttNet/DeviceTypes/MqttBinarySensorDiscoveryConfig.cs +++ b/src/ToMqttNet/DeviceTypes/MqttBinarySensorDiscoveryConfig.cs @@ -5,35 +5,119 @@ namespace ToMqttNet /// /// The mqtt binary sensor platform uses an MQTT message received to set the binary sensor’s state to on or off. /// - public class MqttBinarySensorDiscoveryConfig : MqttDiscoveryConfig + public class MqttBinarySensorDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "binary_sensor"; - [JsonProperty("state_topic")] - public string? StateTopic { get; set; } + /// + /// Sets the class of the device, changing the device state and icon that is displayed on the frontend. + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } - /// - /// Defines a template that returns a string to be compared to payload_on/payload_off or an empty string, in which case the MQTT message will be removed. Available variables: entity_id. Remove this option when ‘payload_on’ and ‘payload_off’ are sufficient to match your payloads (i.e no pre-processing of original message is required). - /// - [JsonProperty("value_template")] - public string? ValueTemplate { get; set; } + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes unavailable. + /// + [JsonProperty("expire_after")] + public long? ExpireAfter { get; set; } + + /// + /// Sends update events (which results in update of state object’s last_changed) even if the sensor’s state hasn’t changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensor’s new state is different to the current one). + /// , default: false + /// + [JsonProperty("force_update")] + public bool? ForceUpdate { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } - /// + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// For sensors that only send on state updates (like PIRs), this variable sets a delay in seconds after which the sensor’s state will be updated back to off. + /// + [JsonProperty("off_delay")] + public long? OffDelay { get; set; } + + /// + /// The string that represents the online state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The string that represents the offline state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// /// The string that represents the off state. It will be compared to the message in the state_topic (see value_template for details) - /// + /// , default: OFF + /// [JsonProperty("payload_off")] public string? PayloadOff { get; set; } - /// + /// /// The string that represents the on state. It will be compared to the message in the state_topic (see value_template for details) - /// + /// , default: ON + /// [JsonProperty("payload_on")] public string? PayloadOn { get; set; } - /// - /// Sets the class of the device, changing the device state and icon that is displayed on the frontend. - /// - [JsonProperty("device_class")] - public string? DeviceClass { get; set; } + /// + /// The maximum QoS level to be used when receiving messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// The MQTT topic subscribed to receive sensor’s state. + /// + [JsonProperty("state_topic")] + public string StateTopic { get; set; } + + /// + /// Defines a template that returns a string to be compared to payload_on/payload_off or an empty string, in which case the MQTT message will be removed. Available variables: entity_id. Remove this option when ‘payload_on’ and ‘payload_off’ are sufficient to match your payloads (i.e no pre-processing of original message is required). + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } } } diff --git a/src/ToMqttNet/DeviceTypes/MqttButtonDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttButtonDiscoveryConfig.cs index 48c6395..2434301 100644 --- a/src/ToMqttNet/DeviceTypes/MqttButtonDiscoveryConfig.cs +++ b/src/ToMqttNet/DeviceTypes/MqttButtonDiscoveryConfig.cs @@ -5,27 +5,102 @@ namespace ToMqttNet /// /// The mqtt button platform lets you send an MQTT message when the button is pressed in the frontend or the button press service is called. This can be used to expose some service of a remote device, for example reboot. /// - public class MqttButtonDiscoveryConfig : MqttDiscoveryConfig + public class MqttButtonDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "button"; - /// + /// + /// Defines a template to generate the payload to send to command_topic. + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// /// The MQTT topic to publish commands to trigger the button. - /// + /// [JsonProperty("command_topic")] public string? CommandTopic { get; set; } - /// - /// Defines a template to generate the payload to send to command_topic. - /// - [JsonProperty("command_template")] - public string? CommandTemplate { get; set; } + /// + /// The type/class of the button to set the icon in the frontend. + /// , default: None + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the published messages. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } - /// + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// /// The payload To send to trigger the button. - /// + /// , default: PRESS + /// [JsonProperty("payload_press")] public string? PayloadPress { get; set; } + /// + /// The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + } } diff --git a/src/ToMqttNet/DeviceTypes/MqttCameraControlPanelDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttCameraControlPanelDiscoveryConfig.cs new file mode 100644 index 0000000..6713552 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttCameraControlPanelDiscoveryConfig.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt camera platform allows you to integrate the content of an image file sent through MQTT into Home Assistant as a camera. Every time a message under the topic in the configuration is received, the image displayed in Home Assistant will also be updated. + /// + public class MqttCameraControlPanelDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "camera"; + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Implies force_update of the current sensor state when a message is received on this topic. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The MQTT topic to subscribe to. + /// + [JsonProperty("topic")] + public string Topic { get; set; } + + /// + /// An ID that uniquely identifies this camera. If two cameras have the same unique ID Home Assistant will raise an exception. + /// + [JsonProperty("unique_id")] + public string? UniqueId { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttClimateDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttClimateDiscoveryConfig.cs new file mode 100644 index 0000000..c964b8e --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttClimateDiscoveryConfig.cs @@ -0,0 +1,413 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt climate platform lets you control your MQTT enabled HVAC devices. + /// + public class MqttClimateDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "climate"; + + /// + /// A template to render the value received on the action_topic with. + /// + [JsonProperty("action_template")] + public string? ActionTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the current action. If this is set, the climate graph uses the value received as data source. Valid values: off, heating, cooling, drying, idle, fan. + /// + [JsonProperty("action_topic")] + public string? ActionTopic { get; set; } + + /// + /// The MQTT topic to publish commands to switch auxiliary heat. + /// + [JsonProperty("aux_command_topic")] + public string? AuxCommandTopic { get; set; } + + /// + /// A template to render the value received on the aux_state_topic with. + /// + [JsonProperty("aux_state_template")] + public string? AuxStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the auxiliary heat mode. If this is not set, the auxiliary heat mode works in optimistic mode (see below). + /// + [JsonProperty("aux_state_topic")] + public string? AuxStateTopic { get; set; } + + /// + /// The MQTT topic to publish commands to change the away mode. + /// + [JsonProperty("away_mode_command_topic")] + public string? AwayModeCommandTopic { get; set; } + + /// + /// A template to render the value received on the away_mode_state_topic with. + /// + [JsonProperty("away_mode_state_template")] + public string? AwayModeStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the HVAC away mode. If this is not set, the away mode works in optimistic mode (see below). + /// + [JsonProperty("away_mode_state_topic")] + public string? AwayModeStateTopic { get; set; } + + /// + /// A template with which the value received on current_temperature_topic will be rendered. + /// + [JsonProperty("current_temperature_template")] + public string? CurrentTemperatureTemplate { get; set; } + + /// + /// The MQTT topic on which to listen for the current temperature. + /// + [JsonProperty("current_temperature_topic")] + public string? CurrentTemperatureTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// A template to render the value sent to the fan_mode_command_topic with. + /// + [JsonProperty("fan_mode_command_template")] + public string? FanModeCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the fan mode. + /// + [JsonProperty("fan_mode_command_topic")] + public string? FanModeCommandTopic { get; set; } + + /// + /// A template to render the value received on the fan_mode_state_topic with. + /// + [JsonProperty("fan_mode_state_template")] + public string? FanModeStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the HVAC fan mode. If this is not set, the fan mode works in optimistic mode (see below). + /// + [JsonProperty("fan_mode_state_topic")] + public string? FanModeStateTopic { get; set; } + + /// + /// A list of supported fan modes. + /// Default: + /// + ///[“auto”, “low”, “medium”, “high”] + /// + [JsonProperty("fan_modes")] + public List? FanModes { get; set; } + + /// + /// A template to render the value sent to the hold_command_topic with. + /// + [JsonProperty("hold_command_template")] + public string? HoldCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the hold mode. + /// + [JsonProperty("hold_command_topic")] + public string? HoldCommandTopic { get; set; } + + /// + /// A template to render the value received on the hold_state_topic with. + /// + [JsonProperty("hold_state_template")] + public string? HoldStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the HVAC hold mode. If this is not set, the hold mode works in optimistic mode (see below). + /// + [JsonProperty("hold_state_topic")] + public string? HoldStateTopic { get; set; } + + /// + /// A list of available hold modes. + /// + [JsonProperty("hold_modes")] + public List? HoldModes { get; set; } + + /// + /// Set the initial target temperature. + /// , default: 21 + /// + [JsonProperty("initial")] + public long? Initial { get; set; } + + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Maximum set point available. + /// + [JsonProperty("max_temp")] + public double? MaxTemp { get; set; } + + /// + /// Minimum set point available. + /// + [JsonProperty("min_temp")] + public double? MinTemp { get; set; } + + /// + /// A template to render the value sent to the mode_command_topic with. + /// + [JsonProperty("mode_command_template")] + public string? ModeCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the HVAC operation mode. + /// + [JsonProperty("mode_command_topic")] + public string? ModeCommandTopic { get; set; } + + /// + /// A template to render the value received on the mode_state_topic with. + /// + [JsonProperty("mode_state_template")] + public string? ModeStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the HVAC operation mode. If this is not set, the operation mode works in optimistic mode (see below). + /// + [JsonProperty("mode_state_topic")] + public string? ModeStateTopic { get; set; } + + /// + /// A list of supported modes. Needs to be a subset of the default values. + /// Default: + /// + ///[“auto”, “off”, “cool”, “heat”, “dry”, “fan_only”] + /// + [JsonProperty("modes")] + public List? Modes { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload that represents disabled state. + /// , default: OFF + /// + [JsonProperty("payload_off")] + public string? PayloadOff { get; set; } + + /// + /// The payload that represents enabled state. + /// , default: ON + /// + [JsonProperty("payload_on")] + public string? PayloadOn { get; set; } + + /// + /// The MQTT topic to publish commands to change the power state. This is useful if your device has a separate power toggle in addition to mode. + /// + [JsonProperty("power_command_topic")] + public string? PowerCommandTopic { get; set; } + + /// + /// The desired precision for this device. Can be used to match your actual thermostat’s precision. Supported values are 0.1, 0.5 and 1.0. + /// Default: + /// + ///0.1 for Celsius and 1.0 for Fahrenheit. + /// + [JsonProperty("precision")] + public double? Precision { get; set; } + + /// + /// The maximum QoS level to be used when receiving and publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// Defines if published messages should have the retain flag set. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// Set to false to suppress sending of all MQTT messages when the current mode is Off. + /// , default: true + /// + [JsonProperty("send_if_off")] + public bool? SendIfOff { get; set; } + + /// + /// A template to render the value sent to the swing_mode_command_topic with. + /// + [JsonProperty("swing_mode_command_template")] + public string? SwingModeCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the swing mode. + /// + [JsonProperty("swing_mode_command_topic")] + public string? SwingModeCommandTopic { get; set; } + + /// + /// A template to render the value received on the swing_mode_state_topic with. + /// + [JsonProperty("swing_mode_state_template")] + public string? SwingModeStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes of the HVAC swing mode. If this is not set, the swing mode works in optimistic mode (see below). + /// + [JsonProperty("swing_mode_state_topic")] + public string? SwingModeStateTopic { get; set; } + + /// + /// A list of supported swing modes. + /// , default: [“on”, “off”] + /// + [JsonProperty("swing_modes")] + public List? SwingModes { get; set; } + + /// + /// A template to render the value sent to the temperature_command_topic with. + /// + [JsonProperty("temperature_command_template")] + public string? TemperatureCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the target temperature. + /// + [JsonProperty("temperature_command_topic")] + public string? TemperatureCommandTopic { get; set; } + + /// + /// A template to render the value sent to the temperature_high_command_topic with. + /// + [JsonProperty("temperature_high_command_template")] + public string? TemperatureHighCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the high target temperature. + /// + [JsonProperty("temperature_high_command_topic")] + public string? TemperatureHighCommandTopic { get; set; } + + /// + /// A template to render the value received on the temperature_high_state_topic with. + /// + [JsonProperty("temperature_high_state_template")] + public string? TemperatureHighStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes in the target high temperature. If this is not set, the target high temperature works in optimistic mode (see below). + /// + [JsonProperty("temperature_high_state_topic")] + public string? TemperatureHighStateTopic { get; set; } + + /// + /// A template to render the value sent to the temperature_low_command_topic with. + /// + [JsonProperty("temperature_low_command_template")] + public string? TemperatureLowCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the target low temperature. + /// + [JsonProperty("temperature_low_command_topic")] + public string? TemperatureLowCommandTopic { get; set; } + + /// + /// A template to render the value received on the temperature_low_state_topic with. + /// + [JsonProperty("temperature_low_state_template")] + public string? TemperatureLowStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes in the target low temperature. If this is not set, the target low temperature works in optimistic mode (see below). + /// + [JsonProperty("temperature_low_state_topic")] + public string? TemperatureLowStateTopic { get; set; } + + /// + /// A template to render the value received on the temperature_state_topic with. + /// + [JsonProperty("temperature_state_template")] + public string? TemperatureStateTemplate { get; set; } + + /// + /// The MQTT topic to subscribe for changes in the target temperature. If this is not set, the target temperature works in optimistic mode (see below). + /// + [JsonProperty("temperature_state_topic")] + public string? TemperatureStateTopic { get; set; } + + /// + /// Defines the temperature unit of the device, C or F. If this is not set, the temperature unit is set to the system temperature unit. + /// + [JsonProperty("temperature_unit")] + public string? TemperatureUnit { get; set; } + + /// + /// Step size for temperature set point. + /// , default: 1 + /// + [JsonProperty("temp_step")] + public double? TempStep { get; set; } + + /// + /// Default template to render the payloads on all *_state_topics with. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttCoverDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttCoverDiscoveryConfig.cs new file mode 100644 index 0000000..010da27 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttCoverDiscoveryConfig.cs @@ -0,0 +1,267 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt cover platform allows you to control an MQTT cover(such as blinds, a roller shutter or a garage door). + /// + public class MqttCoverDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "cover"; + + /// + /// The MQTT topic to publish commands to control the cover. + /// + [JsonProperty("command_topic")] + public string? CommandTopic { get; set; } + + /// + /// Sets the class of the device, changing the device state and icon that is displayed on the frontend. + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if switch works in optimistic mode. + /// Default: + /// + ///false if state or position topic defined, else true. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// The payload that represents the online state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The command payload that closes the cover. + /// , default: CLOSE + /// + [JsonProperty("payload_close")] + public string? PayloadClose { get; set; } + + /// + /// The payload that represents the offline state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The command payload that opens the cover. + /// , default: OPEN + /// + [JsonProperty("payload_open")] + public string? PayloadOpen { get; set; } + + /// + /// The command payload that stops the cover. + /// , default: STOP + /// + [JsonProperty("payload_stop")] + public string? PayloadStop { get; set; } + + /// + /// Number which represents closed position. + /// , default: 0 + /// + [JsonProperty("position_closed")] + public long? PositionClosed { get; set; } + + /// + /// Number which represents open position. + /// , default: 100 + /// + [JsonProperty("position_open")] + public long? PositionOpen { get; set; } + + /// + /// Defines a template that can be used to extract the payload for the position_topic topic. Within the template the following variables are available: entity_id, position_open; position_closed; tilt_min; tilt_max. The entity_id can be used to reference the entity’s attributes with help of the states template function; + /// + [JsonProperty("position_template")] + public string? PositionTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive cover position messages. + /// + [JsonProperty("position_topic")] + public string? PositionTopic { get; set; } + + /// + /// The maximum QoS level to be used when receiving and publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// Defines if published messages should have the retain flag set. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// Defines a template to define the position to be sent to the set_position_topic topic. Incoming position value is available for use in the template {{ position }}. Within the template the following variables are available: entity_id, position, the target position in percent; position_open; position_closed; tilt_min; tilt_max. The entity_id can be used to reference the entity’s attributes with help of the states template function; + /// + [JsonProperty("set_position_template")] + public string? SetPositionTemplate { get; set; } + + /// + /// The MQTT topic to publish position commands to. You need to set position_topic as well if you want to use position topic. Use template if position topic wants different values than within range position_closed - position_open. If template is not defined and position_closed != 100 and position_open != 0 then proper position value is calculated from percentage position. + /// + [JsonProperty("set_position_topic")] + public string? SetPositionTopic { get; set; } + + /// + /// The payload that represents the closed state. + /// , default: closed + /// + [JsonProperty("state_closed")] + public string? StateClosed { get; set; } + + /// + /// The payload that represents the closing state. + /// , default: closing + /// + [JsonProperty("state_closing")] + public string? StateClosing { get; set; } + + /// + /// The payload that represents the open state. + /// , default: open + /// + [JsonProperty("state_open")] + public string? StateOpen { get; set; } + + /// + /// The payload that represents the opening state. + /// , default: opening + /// + [JsonProperty("state_opening")] + public string? StateOpening { get; set; } + + /// + /// The payload that represents the stopped state (for covers that do not report open/closed state). + /// , default: stopped + /// + [JsonProperty("state_stopped")] + public string? StateStopped { get; set; } + + /// + /// The MQTT topic subscribed to receive cover state messages. State topic can only read (open, opening, closed, closing or stopped) state. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// The value that will be sent on a close_cover_tilt command. + /// , default: 0 + /// + [JsonProperty("tilt_closed_value")] + public long? TiltClosedValue { get; set; } + + /// + /// Defines a template that can be used to extract the payload for the tilt_command_topic topic. Within the template the following variables are available: entity_id, tilt_position, the target tilt position in percent; position_open; position_closed; tilt_min; tilt_max. The entity_id can be used to reference the entity’s attributes with help of the states template function; + /// + [JsonProperty("tilt_command_template")] + public string? TiltCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to control the cover tilt. + /// + [JsonProperty("tilt_command_topic")] + public string? TiltCommandTopic { get; set; } + + /// + /// The maximum tilt value. + /// , default: 100 + /// + [JsonProperty("tilt_max")] + public long? TiltMax { get; set; } + + /// + /// The minimum tilt value. + /// , default: 0 + /// + [JsonProperty("tilt_min")] + public long? TiltMin { get; set; } + + /// + /// The value that will be sent on an open_cover_tilt command. + /// , default: 100 + /// + [JsonProperty("tilt_opened_value")] + public long? TiltOpenedValue { get; set; } + + /// + /// Flag that determines if tilt works in optimistic mode. + /// Default: + /// + ///true if tilt_status_topic is not defined, else false + /// + [JsonProperty("tilt_optimistic")] + public bool? TiltOptimistic { get; set; } + + /// + /// Defines a template that can be used to extract the payload for the tilt_status_topic topic. Within the template the following variables are available: entity_id, position_open; position_closed; tilt_min; tilt_max. The entity_id can be used to reference the entity’s attributes with help of the states template function; + /// + [JsonProperty("tilt_status_template")] + public string? TiltStatusTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive tilt status update values. + /// + [JsonProperty("tilt_status_topic")] + public string? TiltStatusTopic { get; set; } + + /// + /// Defines a template that can be used to extract the payload for the state_topic topic. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttDeviceTrackerDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttDeviceTrackerDiscoveryConfig.cs new file mode 100644 index 0000000..242f895 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttDeviceTrackerDiscoveryConfig.cs @@ -0,0 +1,83 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt device tracker platform allows you to define new device_trackers through manual YAML configuration in configuration.yaml and also to automatically discover device_trackers through a discovery schema using the MQTT Discovery protocol. + /// + public class MqttDeviceTrackerDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "device_tracker"; + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as device_tracker attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload value that represents the ‘home’ state for the device. + /// , default: home + /// + [JsonProperty("payload_home")] + public string? PayloadHome { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload value that represents the ‘not_home’ state for the device. + /// , default: not_home + /// + [JsonProperty("payload_not_home")] + public string? PayloadNotHome { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// Attribute of a device tracker that affects state when being used to track a person. Valid options are gps, router, bluetooth, or bluetooth_le. + /// + [JsonProperty("source_type")] + public string? SourceType { get; set; } + + /// + /// The MQTT topic subscribed to receive device tracker state changes. + /// + [JsonProperty("state_topic")] + public string StateTopic { get; set; } + + /// + /// Defines a template that returns a device tracker state. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttDeviceTriggerDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttDeviceTriggerDiscoveryConfig.cs new file mode 100644 index 0000000..4f0f349 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttDeviceTriggerDiscoveryConfig.cs @@ -0,0 +1,55 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt device trigger platform uses an MQTT message payload to generate device trigger events. + /// + public class MqttDeviceTriggerDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "device_trigger"; + + /// + /// The type of automation, must be ‘trigger’. + /// + [JsonProperty("automation_type")] + public string AutomationType { get; set; } + + /// + /// Optional payload to match the payload being sent over the topic. + /// + [JsonProperty("payload")] + public string? Payload { get; set; } + + /// + /// The maximum QoS level to be used when receiving messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// The MQTT topic subscribed to receive trigger events. + /// + [JsonProperty("topic")] + public string Topic { get; set; } + + /// + /// The type of the trigger, e.g. button_short_press. Entries supported by the frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press. If set to an unsupported value, will render as subtype type, e.g. button_1 spammed with type set to spammed and subtype set to button_1 + /// + [JsonProperty("type")] + public string Type { get; set; } + + /// + /// The subtype of the trigger, e.g. button_1. Entries supported by the frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6. If set to an unsupported value, will render as subtype type, e.g. left_button pressed with type set to button_short_press and subtype set to left_button + /// + [JsonProperty("subtype")] + public string Subtype { get; set; } + + /// + /// Defines a template to extract the value. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttFanDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttFanDiscoveryConfig.cs new file mode 100644 index 0000000..cd538d9 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttFanDiscoveryConfig.cs @@ -0,0 +1,247 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt fan platform lets you control your MQTT enabled fans. + /// + public class MqttFanDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "fan"; + + /// + /// Defines a template to generate the payload to send to command_topic. + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the fan state. + /// + [JsonProperty("command_topic")] + public string CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if fan works in optimistic mode + /// Default: + /// + ///true if no state topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// Defines a template to generate the payload to send to oscillation_command_topic. + /// + [JsonProperty("oscillation_command_template")] + public string? OscillationCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the oscillation state. + /// + [JsonProperty("oscillation_command_topic")] + public string? OscillationCommandTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive oscillation state updates. + /// + [JsonProperty("oscillation_state_topic")] + public string? OscillationStateTopic { get; set; } + + /// + /// Defines a template to extract a value from the oscillation. + /// + [JsonProperty("oscillation_value_template")] + public string? OscillationValueTemplate { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload that represents the stop state. + /// , default: OFF + /// + [JsonProperty("payload_off")] + public string? PayloadOff { get; set; } + + /// + /// The payload that represents the running state. + /// , default: ON + /// + [JsonProperty("payload_on")] + public string? PayloadOn { get; set; } + + /// + /// The payload that represents the oscillation off state. + /// , default: oscillate_off + /// + [JsonProperty("payload_oscillation_off")] + public string? PayloadOscillationOff { get; set; } + + /// + /// The payload that represents the oscillation on state. + /// , default: oscillate_on + /// + [JsonProperty("payload_oscillation_on")] + public string? PayloadOscillationOn { get; set; } + + /// + /// A special payload that resets the percentage state attribute to None when received at the percentage_state_topic. + /// , default: None + /// + [JsonProperty("payload_reset_percentage")] + public string? PayloadResetPercentage { get; set; } + + /// + /// A special payload that resets the preset_mode state attribute to None when received at the preset_mode_state_topic. + /// , default: None + /// + [JsonProperty("payload_reset_preset_mode")] + public string? PayloadResetPresetMode { get; set; } + + /// + /// Defines a template to generate the payload to send to percentage_command_topic. + /// + [JsonProperty("percentage_command_template")] + public string? PercentageCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the fan speed state based on a percentage. + /// + [JsonProperty("percentage_command_topic")] + public string? PercentageCommandTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive fan speed based on percentage. + /// + [JsonProperty("percentage_state_topic")] + public string? PercentageStateTopic { get; set; } + + /// + /// Defines a template to extract the percentage value from the payload received on percentage_state_topic. + /// + [JsonProperty("percentage_value_template")] + public string? PercentageValueTemplate { get; set; } + + /// + /// Defines a template to generate the payload to send to preset_mode_command_topic. + /// + [JsonProperty("preset_mode_command_template")] + public string? PresetModeCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the preset mode. + /// + [JsonProperty("preset_mode_command_topic")] + public string? PresetModeCommandTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive fan speed based on presets. + /// + [JsonProperty("preset_mode_state_topic")] + public string? PresetModeStateTopic { get; set; } + + /// + /// Defines a template to extract the preset_mode value from the payload received on preset_mode_state_topic. + /// + [JsonProperty("preset_mode_value_template")] + public string? PresetModeValueTemplate { get; set; } + + /// + /// List of preset modes this fan is capable of running at. Common examples include auto, smart, whoosh, eco and breeze. + /// , default: [] + /// + [JsonProperty("preset_modes")] + public List? PresetModes { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: true + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The maximum of numeric output range (representing 100 %). The number of speeds within the speed_range / 100 will determine the percentage_step. + /// , default: 100 + /// + [JsonProperty("speed_range_max")] + public long? SpeedRangeMax { get; set; } + + /// + /// The minimum of numeric output range (off not included, so speed_range_min - 1 represents 0 %). The number of speeds within the speed_range / 100 will determine the percentage_step. + /// , default: 1 + /// + [JsonProperty("speed_range_min")] + public long? SpeedRangeMin { get; set; } + + /// + /// The MQTT topic subscribed to receive state updates. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// Defines a template to extract a value from the state. + /// + [JsonProperty("state_value_template")] + public string? StateValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttHumidifierDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttHumidifierDiscoveryConfig.cs new file mode 100644 index 0000000..d7a36d5 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttHumidifierDiscoveryConfig.cs @@ -0,0 +1,216 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt humidifier platform lets you control your MQTT enabled humidifiers. + /// + public class MqttHumidifierDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "humidifier"; + + /// + /// Defines a template to generate the payload to send to command_topic. + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the humidifier state. + /// + [JsonProperty("command_topic")] + public string CommandTopic { get; set; } + + /// + /// The device class of the MQTT device. Must be either humidifier or dehumidifier. + /// , default: humidifier + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// The minimum target humidity percentage that can be set. + /// , default: 100 + /// + [JsonProperty("max_humidity")] + public long? MaxHumidity { get; set; } + + /// + /// The maximum target humidity percentage that can be set. + /// , default: 0 + /// + [JsonProperty("min_humidity")] + public long? MinHumidity { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if humidifier works in optimistic mode + /// Default: + /// + ///true if no state topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload that represents the stop state. + /// , default: OFF + /// + [JsonProperty("payload_off")] + public string? PayloadOff { get; set; } + + /// + /// The payload that represents the running state. + /// , default: ON + /// + [JsonProperty("payload_on")] + public string? PayloadOn { get; set; } + + /// + /// A special payload that resets the target_humidity state attribute to None when received at the target_humidity_state_topic. + /// , default: None + /// + [JsonProperty("payload_reset_humidity")] + public string? PayloadResetHumidity { get; set; } + + /// + /// A special payload that resets the mode state attribute to None when received at the mode_state_topic. + /// , default: None + /// + [JsonProperty("payload_reset_mode")] + public string? PayloadResetMode { get; set; } + + /// + /// Defines a template to generate the payload to send to target_humidity_command_topic. + /// + [JsonProperty("target_humidity_command_template")] + public string? TargetHumidityCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the humidifier target humidity state based on a percentage. + /// + [JsonProperty("target_humidity_command_topic")] + public string TargetHumidityCommandTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive humidifier target humidity. + /// + [JsonProperty("target_humidity_state_topic")] + public string? TargetHumidityStateTopic { get; set; } + + /// + /// Defines a template to extract a value for the humidifier target_humidity state. + /// + [JsonProperty("target_humidity_state_template")] + public string? TargetHumidityStateTemplate { get; set; } + + /// + /// Defines a template to generate the payload to send to mode_command_topic. + /// + [JsonProperty("mode_command_template")] + public string? ModeCommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the mode on the humidifier. This attribute ust be configured together with the modes attribute. + /// + [JsonProperty("mode_command_topic")] + public string? ModeCommandTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive the humidifier mode. + /// + [JsonProperty("mode_state_topic")] + public string? ModeStateTopic { get; set; } + + /// + /// Defines a template to extract a value for the humidifier mode state. + /// + [JsonProperty("mode_state_template")] + public string? ModeStateTemplate { get; set; } + + /// + /// List of available modes this humidifier is capable of running at. Common examples include normal, eco, away, boost, comfort, home, sleep, auto and baby. These examples offer built-in translations but other custom modes are allowed as well. This attribute ust be configured together with the mode_command_topic attribute. + /// , default: [] + /// + [JsonProperty("modes")] + public List? Modes { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: true + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The MQTT topic subscribed to receive state updates. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// Defines a template to extract a value from the state. + /// + [JsonProperty("state_value_template")] + public string? StateValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttLockDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttLockDiscoveryConfig.cs new file mode 100644 index 0000000..f7535ad --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttLockDiscoveryConfig.cs @@ -0,0 +1,141 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt lock platform lets you control your MQTT enabled locks. + /// + public class MqttLockDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "lock"; + + /// + /// The MQTT topic to publish commands to change the lock state. + /// + [JsonProperty("command_topic")] + public string CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if lock works in optimistic mode. + /// Default: + /// + ///true if no state_topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload sent to the lock to lock it. + /// , default: LOCK + /// + [JsonProperty("payload_lock")] + public string? PayloadLock { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload sent to the lock to unlock it. + /// , default: UNLOCK + /// + [JsonProperty("payload_unlock")] + public string? PayloadUnlock { get; set; } + + /// + /// The payload sent to the lock to open it. + /// , default: OPEN + /// + [JsonProperty("payload_open")] + public string? PayloadOpen { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The payload sent to by the lock when it’s locked. + /// , default: LOCKED + /// + [JsonProperty("state_locked")] + public string? StateLocked { get; set; } + + /// + /// The MQTT topic subscribed to receive state updates. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// The payload sent to by the lock when it’s unlocked. + /// , default: UNLOCKED + /// + [JsonProperty("state_unlocked")] + public string? StateUnlocked { get; set; } + + /// + /// Defines a template to extract a value from the payload. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttNumberDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttNumberDiscoveryConfig.cs new file mode 100644 index 0000000..696a91d --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttNumberDiscoveryConfig.cs @@ -0,0 +1,132 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt Number platform allows you to integrate devices that might expose configuration options through MQTT into Home Assistant as a Number. Every time a message under the topic in the configuration is received, the number entity will be updated in Home Assistant and vice-versa, keeping the device and Home Assistant in-sync. + /// + public class MqttNumberDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "number"; + + /// + /// Defines a template to generate the payload to send to command_topic. + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the number. + /// + [JsonProperty("command_topic")] + public string CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as number attributes. Implies force_update of the current number state when a message is received on this topic. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Minimum value. + /// , default: 1 + /// + [JsonProperty("min")] + public double? Min { get; set; } + + /// + /// Maximum value. + /// , default: 100 + /// + [JsonProperty("max")] + public double? Max { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if number works in optimistic mode. + /// Default: + /// + ///true if no state_topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// A special payload that resets the state to None when received on the state_topic. + /// , default: “None” + /// + [JsonProperty("payload_reset")] + public string? PayloadReset { get; set; } + + /// + /// The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The MQTT topic subscribed to receive number values. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// Step value. Smallest value 0.001. + /// , default: 1 + /// + [JsonProperty("step")] + public double? Step { get; set; } + + /// + /// Defines the unit of measurement of the sensor, if any. + /// + [JsonProperty("unit_of_measurement")] + public string? UnitOfMeasurement { get; set; } + + /// + /// Defines a template to extract the value. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttSceneDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttSceneDiscoveryConfig.cs new file mode 100644 index 0000000..3621a08 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttSceneDiscoveryConfig.cs @@ -0,0 +1,73 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt scene platform lets you control your MQTT enabled scenes. + /// + public class MqttSceneDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "scene"; + + /// + /// The MQTT topic to publish commands to change the scene state. + /// + [JsonProperty("command_topic")] + public string? CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload that represents on state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_on for details) and sending as on command to the command_topic. + /// , default: ON + /// + [JsonProperty("payload_on")] + public string? PayloadOn { get; set; } + + /// + /// The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttSelectDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttSelectDiscoveryConfig.cs index 1a2681d..d086102 100644 --- a/src/ToMqttNet/DeviceTypes/MqttSelectDiscoveryConfig.cs +++ b/src/ToMqttNet/DeviceTypes/MqttSelectDiscoveryConfig.cs @@ -5,16 +5,100 @@ namespace ToMqttNet /// /// The mqtt Select platform allows you to integrate devices that might expose configuration options through MQTT into Home Assistant as a Select. Every time a message under the topic in the configuration is received, the select entity will be updated in Home Assistant and vice-versa, keeping the device and Home Assistant in sync. /// - public class MqttSelectDiscoveryConfig : MqttDiscoveryConfig + public class MqttSelectDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "select"; + /// + /// Defines a template to generate the payload to send to command_topic. + /// + [JsonProperty("command_template")] + public string? CommandTemplate { get; set; } + + /// + /// The MQTT topic to publish commands to change the selected option. + /// [JsonProperty("command_topic")] - public string? CommandTopic { get; set; } + public string CommandTopic { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes. Implies force_update of the current select state when a message is received on this topic. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if the select works in optimistic mode. + /// Default: + /// + ///true if no state_topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// List of options that can be selected. An empty list or a list with a single item is allowed. + /// [JsonProperty("options")] - public List Options { get; set; } = new List(); + public List Options { get; set; } + + /// + /// The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The MQTT topic subscribed to receive update of the selected option. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + /// + /// Defines a template to extract the value. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } } } diff --git a/src/ToMqttNet/DeviceTypes/MqttSensorDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttSensorDiscoveryConfig.cs index 9526c4c..7d95d59 100644 --- a/src/ToMqttNet/DeviceTypes/MqttSensorDiscoveryConfig.cs +++ b/src/ToMqttNet/DeviceTypes/MqttSensorDiscoveryConfig.cs @@ -6,28 +6,122 @@ namespace ToMqttNet /// /// This mqtt sensor platform uses the MQTT message payload as the sensor value. If messages in this state_topic are published with RETAIN flag, the sensor will receive an instant update with last known value. Otherwise, the initial state will be undefined. /// - public class MqttSensorDiscoveryConfig : MqttDiscoveryConfig + public class MqttSensorDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "sensor"; - [JsonProperty("state_topic")] - public string? StateTopic { get; set; } + /// + /// The type/class of the sensor to set the icon in the frontend. + /// , default: None + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } - [JsonProperty("value_template")] - public string? ValueTemplate { get; set; } + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes unavailable. + /// , default: 0 + /// + [JsonProperty("expire_after")] + public long? ExpireAfter { get; set; } + + /// + /// Sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history. + /// , default: false + /// + [JsonProperty("force_update")] + public bool? ForceUpdate { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Implies force_update of the current sensor state when a message is received on this topic. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Defines a template to extract the last_reset. Available variables: entity_id. The entity_id can be used to reference the entity’s attributes. + /// + [JsonProperty("last_reset_value_template")] + public string? LastResetValueTemplate { get; set; } - /// - /// https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes - /// + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// The state_class of the sensor. + /// , default: None + /// [JsonProperty("state_class")] [JsonConverter(typeof(StringEnumConverter))] - public MqttDiscoveryStateClass StateClass { get; set; } + public MqttDiscoveryStateClass? StateClass { get; set; } - /// - /// https://github.com/home-assistant/core/blob/dev/homeassistant/const.py#L460 - /// - [JsonProperty("unit_of_measurement", NullValueHandling = NullValueHandling.Ignore)] + /// + /// The MQTT topic subscribed to receive sensor values. + /// + [JsonProperty("state_topic")] + public string StateTopic { get; set; } + + /// + /// Defines the units of measurement of the sensor, if any. + /// + [JsonProperty("unit_of_measurement")] public string? UnitOfMeasurement { get; set; } + /// + /// Defines a template to extract the value. Available variables: entity_id. The entity_id can be used to reference the entity’s attributes. If the template throws an error, the current state will be used instead. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } } diff --git a/src/ToMqttNet/DeviceTypes/MqttSwitchDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttSwitchDiscoveryConfig.cs index 83e53f6..7e0df23 100644 --- a/src/ToMqttNet/DeviceTypes/MqttSwitchDiscoveryConfig.cs +++ b/src/ToMqttNet/DeviceTypes/MqttSwitchDiscoveryConfig.cs @@ -5,51 +5,140 @@ namespace ToMqttNet /// /// The mqtt switch platform lets you control your MQTT enabled switches. /// - public class MqttSwitchDiscoveryConfig : MqttDiscoveryConfig + public class MqttSwitchDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "switch"; - /// + /// /// The MQTT topic to publish commands to change the switch state. - /// + /// [JsonProperty("command_topic")] public string? CommandTopic { get; set; } - /// - /// The payload that represents on state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_on for details) and sending as on command to the command_topic. - /// - [JsonProperty("payload_on")] - public object? PayloadOn { get; set; } + /// + /// The type/class of the switch to set the icon in the frontend. + /// , default: None + /// + [JsonProperty("device_class")] + public string? DeviceClass { get; set; } + + /// + /// Flag which defines if the entity should be enabled when first added. + /// , default: true + /// + [JsonProperty("enabled_by_default")] + public bool? EnabledByDefault { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// The category of the entity. + /// , default: None + /// + [JsonProperty("entity_category")] + public string? EntityCategory { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } - /// + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// Flag that defines if switch works in optimistic mode. + /// Default: + /// + ///true if no state_topic defined, else false. + /// + [JsonProperty("optimistic")] + public bool? Optimistic { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// /// The payload that represents off state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_off for details) and sending as off command to the command_topic. - /// + /// , default: OFF + /// [JsonProperty("payload_off")] - public object? PayloadOff { get; set; } + public string? PayloadOff { get; set; } - /// - /// The MQTT topic subscribed to receive state updates. - /// - [JsonProperty("state_topic")] - public string? StateTopic { get; set; } + /// + /// The payload that represents on state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_on for details) and sending as on command to the command_topic. + /// , default: ON + /// + [JsonProperty("payload_on")] + public string? PayloadOn { get; set; } - /// - /// The payload that represents the on state. Used when value that represents on state in the state_topic is different from value that should be sent to the command_topic to turn the device on. - /// Default: payload_on if defined, else ON - /// - [JsonProperty("state_on")] - public object? StateOn { get; set; } + /// + /// The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } - /// + /// /// The payload that represents the off state. Used when value that represents off state in the state_topic is different from value that should be sent to the command_topic to turn the device off. - /// Default: payload_off if defined, else OFF - /// + /// Default: + /// + ///payload_off if defined, else OFF + /// [JsonProperty("state_off")] - public object? StateOff { get; set; } + public string? StateOff { get; set; } + + /// + /// The payload that represents the on state. Used when value that represents on state in the state_topic is different from value that should be sent to the command_topic to turn the device on. + /// Default: + /// + ///payload_on if defined, else ON + /// + [JsonProperty("state_on")] + public string? StateOn { get; set; } + + /// + /// The MQTT topic subscribed to receive state updates. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } - /// + /// /// Defines a template to extract device’s state from the state_topic. To determine the switches’s state result of this template will be compared to state_on and state_off. - /// + /// [JsonProperty("value_template")] public string? ValueTemplate { get; set; } } diff --git a/src/ToMqttNet/DeviceTypes/MqttTagScannerDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttTagScannerDiscoveryConfig.cs new file mode 100644 index 0000000..7fe702c --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttTagScannerDiscoveryConfig.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt tag scanner platform uses an MQTT message payload to generate tag scanned events. + /// + public class MqttTagScannerDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "tag"; + + + /// + /// The MQTT topic subscribed to receive tag scanned events. + /// + [JsonProperty("topic")] + public string Topic { get; set; } + + /// + /// Defines a template that returns a tag ID. + /// + [JsonProperty("value_template")] + public string? ValueTemplate { get; set; } + } +} diff --git a/src/ToMqttNet/DeviceTypes/MqttVacuumDiscoveryConfig.cs b/src/ToMqttNet/DeviceTypes/MqttVacuumDiscoveryConfig.cs new file mode 100644 index 0000000..ea04de5 --- /dev/null +++ b/src/ToMqttNet/DeviceTypes/MqttVacuumDiscoveryConfig.cs @@ -0,0 +1,153 @@ +using Newtonsoft.Json; + +namespace ToMqttNet +{ + /// + /// The mqtt vacuum integration allows you to control your MQTT-enabled vacuum. There are two possible message schemas - legacy and state, chosen by setting the schema configuration parameter. New installations should use the state schema as legacy is deprecated and might be removed someday in the future. The state schema is preferred because the vacuum will then be represented as a StateVacuumDevice which is the preferred parent vacuum entity. + /// + public class MqttVacuumDiscoveryConfig : MqttDiscoveryConfig + { + public override string Component => "vacuum"; + + /// + /// The MQTT topic to publish commands to control the vacuum. + /// + [JsonProperty("command_topic")] + public string? CommandTopic { get; set; } + + /// + /// The encoding of the payloads received and published messages. Set to "" to disable decoding of incoming payload. + /// , default: utf-8 + /// + [JsonProperty("encoding")] + public string? Encoding { get; set; } + + /// + /// List of possible fan speeds for the vacuum. + /// + [JsonProperty("fan_speed_list")] + public List FanSpeedList { get; set; } + + /// + /// Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_template")] + public string? JsonAttributesTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Usage example can be found in MQTT sensor documentation. + /// + [JsonProperty("json_attributes_topic")] + public string? JsonAttributesTopic { get; set; } + + /// + /// Used instead of name for automatic generation of entity_id + /// + [JsonProperty("object_id")] + public string? ObjectId { get; set; } + + /// + /// The payload that represents the available state. + /// , default: online + /// + [JsonProperty("payload_available")] + public string? PayloadAvailable { get; set; } + + /// + /// The payload to send to the command_topic to begin a spot cleaning cycle. + /// , default: clean_spot + /// + [JsonProperty("payload_clean_spot")] + public string? PayloadCleanSpot { get; set; } + + /// + /// The payload to send to the command_topic to locate the vacuum (typically plays a song). + /// , default: locate + /// + [JsonProperty("payload_locate")] + public string? PayloadLocate { get; set; } + + /// + /// The payload that represents the unavailable state. + /// , default: offline + /// + [JsonProperty("payload_not_available")] + public string? PayloadNotAvailable { get; set; } + + /// + /// The payload to send to the command_topic to pause the vacuum. + /// , default: pause + /// + [JsonProperty("payload_pause")] + public string? PayloadPause { get; set; } + + /// + /// The payload to send to the command_topic to tell the vacuum to return to base. + /// , default: return_to_base + /// + [JsonProperty("payload_return_to_base")] + public string? PayloadReturnToBase { get; set; } + + /// + /// The payload to send to the command_topic to begin the cleaning cycle. + /// , default: start + /// + [JsonProperty("payload_start")] + public string? PayloadStart { get; set; } + + /// + /// The payload to send to the command_topic to stop cleaning. + /// , default: stop + /// + [JsonProperty("payload_stop")] + public string? PayloadStop { get; set; } + + /// + /// The maximum QoS level of the state topic. + /// , default: 0 + /// + [JsonProperty("qos")] + public long? Qos { get; set; } + + /// + /// If the published message should have the retain flag on or not. + /// , default: false + /// + [JsonProperty("retain")] + public bool? Retain { get; set; } + + /// + /// The schema to use. Must be state to select the state schema. + /// , default: legacy + /// + [JsonProperty("schema")] + public string? Schema { get; set; } + + /// + /// The MQTT topic to publish custom commands to the vacuum. + /// + [JsonProperty("send_command_topic")] + public string? SendCommandTopic { get; set; } + + /// + /// The MQTT topic to publish commands to control the vacuum’s fan speed. + /// + [JsonProperty("set_fan_speed_topic")] + public string? SetFanSpeedTopic { get; set; } + + /// + /// The MQTT topic subscribed to receive state messages from the vacuum. Messages received on the state_topic must be a valid JSON dictionary, with a mandatory state key and optionally battery_level and fan_speed keys as shown in the example. + /// + [JsonProperty("state_topic")] + public string? StateTopic { get; set; } + + /// + /// List of features that the vacuum supports (possible values are start, stop, pause, return_home, battery, status, locate, clean_spot, fan_speed, send_command). + /// Default: + /// + ///start, stop, return_home, status, battery, clean_spot + /// + [JsonProperty("supported_features")] + public List SupportedFeatures { get; set; } + } +} diff --git a/src/ToMqttNet/MqttConnectionServiceExtensions.cs b/src/ToMqttNet/MqttConnectionServiceExtensions.cs index dfb6772..69b48d6 100644 --- a/src/ToMqttNet/MqttConnectionServiceExtensions.cs +++ b/src/ToMqttNet/MqttConnectionServiceExtensions.cs @@ -15,7 +15,7 @@ public static class MqttDiscoveryConfigExtensions Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore, }; - public static string ToJson(this T config) where T : MqttDiscoveryConfig + public static string ToJson(this T config) where T : MqttDiscoveryConfig { return JsonConvert.SerializeObject(config, DiscoveryJsonSettings); } @@ -23,7 +23,7 @@ public static string ToJson(this T config) where T : MqttDiscoveryConfig public static class MqttConnectionServiceExtensions { - public static Task PublishDiscoveryDocument(this IMqttConnectionService connection, T config) where T : MqttDiscoveryConfig + public static Task PublishDiscoveryDocument(this IMqttConnectionService connection, T config) where T : MqttDiscoveryConfig { return connection.PublishAsync( new MqttApplicationMessageBuilder() diff --git a/src/ToMqttNet/MqttDiscoveryConfig.cs b/src/ToMqttNet/MqttDiscoveryConfig.cs index 20ff2b6..1a802df 100644 --- a/src/ToMqttNet/MqttDiscoveryConfig.cs +++ b/src/ToMqttNet/MqttDiscoveryConfig.cs @@ -4,7 +4,52 @@ namespace ToMqttNet { - public abstract class MqttDiscoveryConfig where T : MqttDiscoveryConfig + /* + * const snakeToPascal = (string) => { + return string.split("/") + .map(snake => snake.split("_") + .map(substr => substr.charAt(0) + .toUpperCase() + + substr.slice(1)) + .join("")) + .join("/"); + }; +$$('.config-vars>div>.config-vars-item') + .map(x => { + var typeMap = { + "template": "string", + "boolean": "bool", + "list": "List<>", + "integer": "long", + "float": "double" + }; + + var result = "///"; + result += "\n/// " + x.getElementsByClassName("config-vars-description")[0].innerText; + var defaultValue = x.getElementsByClassName("config-vars-required")[0].getElementsByClassName("default")[0]; + if(defaultValue.innerText) { + result += "\n/// " + defaultValue.innerText + } + defaultValue = x.getElementsByClassName("config-vars-default")[0]; + if(defaultValue?.innerText) { + result += "\n/// " + defaultValue.innerText.replace(/\n/g, "\n///") + } + var varName = x.getElementsByClassName("config-vars-label-name")[0].innerText.trim(); + result += "\n/// " + result += "\n[JsonProperty(\"" + varName + "\")]" + result += "\npublic " + var varType = x.getElementsByClassName("config-vars-type")[0].innerText.trim(); + result += typeMap[varType] || varType; + if(x.getElementsByClassName("config-vars-required")[0].getElementsByClassName("false")[0]) { + result += "?"; + } + result += " "; + result += snakeToPascal(varName); + result += " { get; set; }"; + return result; + }).join('\n\n') + */ + public abstract class MqttDiscoveryConfig { [JsonProperty("name")] public string? Name { get; init; } @@ -25,7 +70,20 @@ public abstract class MqttDiscoveryConfig where T : MqttDiscoveryConfig /// A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with availability_topic /// [JsonProperty("availability")] - public List? Availablilty { get; init; } + public List? Availability { get; init; } + + /// + /// Defines a template to extract device’s availability from the availability_topic. To determine the devices’s availability result of this template will be compared to payload_available and payload_not_available. + /// + [JsonProperty("availability_template")] + public string? AvailabilityTemplate { get; set; } + + /// + /// The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with availability. + /// + [JsonProperty("availability_topic")] + public string? AvailabilityTopic { get; set; } + /// /// When is configured, this controls the conditions needed to set the entity to available. @@ -38,7 +96,7 @@ public abstract class MqttDiscoveryConfig where T : MqttDiscoveryConfig /// [JsonProperty("availability_mode")] [JsonConverter(typeof(StringEnumConverter))] - public MqttDiscoveryAvailabilityMode? AvailabliltyMode { get; init; } + public MqttDiscoveryAvailabilityMode? AvailabilityMode { get; init; } /// /// Icon for the entity. diff --git a/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs b/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs index 42be072..14a07f2 100644 --- a/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs +++ b/test/ToMqttNet.Test.Unit/MqttDiscoveryConfigTests.cs @@ -45,7 +45,7 @@ public void ToJson_Availability_IsStringBased() // Arrange var sut = new MqttStubDiscoveryConfig() { - AvailabliltyMode = MqttDiscoveryAvailabilityMode.Any + AvailabilityMode = MqttDiscoveryAvailabilityMode.Any }; // Act @@ -88,7 +88,7 @@ public void ToJson_DeviceConnections_ShouldBeAListOfLists() } -public class MqttStubDiscoveryConfig : MqttDiscoveryConfig +public class MqttStubDiscoveryConfig : MqttDiscoveryConfig { public override string Component => "stub"; }