Almost complete with initial migration

This commit is contained in:
Austen Adler 2024-04-08 23:50:37 -04:00
parent ad45bc3431
commit ac7132659c
2 changed files with 177 additions and 762 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ use either::Either;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod integrations;
pub mod light; pub mod light;
// TODO: Templates // TODO: Templates
@ -11,9 +12,22 @@ pub type Template = ();
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// #[cfg_attr(feature = "serde", serde(flatten))] // #[cfg_attr(feature = "serde", serde(flatten))]
pub struct Common { pub struct Common {
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub unique_id: Option<String>,
/// Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) 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`.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
availability_template: Option<Template>, availability_template: Option<Template>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
/// When `availability` is configured, this controls the conditions needed to set the entity to `available`. Valid entries are `all`, `any`, and `latest`. If set to `all`, `payload_available` must be received on all configured availability topics before the entity is marked as online. If set to `any`, `payload_available` must be received on at least one configured availability topic before the entity is marked as online. If set to `latest`, the last `payload_available` or `payload_not_available` received on any configured availability topic controls the availability.
availability_mode: Option<AvailabilityMode>, availability_mode: Option<AvailabilityMode>,
/// A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with `availability_topic`.
availability: Availability, availability: Availability,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
device: Option<Device>, device: Option<Device>,
} }
@ -36,7 +50,10 @@ impl Default for AvailabilityMode {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Availability { pub enum Availability {
/// A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with `availability_topic`.
Availability(CustomAvailability), Availability(CustomAvailability),
/// The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with `availability`.
AvailabilityTopic(String), AvailabilityTopic(String),
} }
@ -44,9 +61,16 @@ pub enum Availability {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub struct CustomAvailability { pub struct CustomAvailability {
/// The payload that represents the available state.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
payload_available: Option<String>, payload_available: Option<String>,
/// The payload that represents the unavailable state.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
payload_not_available: Option<String>, payload_not_available: Option<String>,
/// An MQTT topic subscribed to receive availability (online/offline) updates.
topic: String, topic: String,
/// Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) to extract device's availability from the `topic`. To determine the devices's availability result of this template will be compared to `payload_available` and `payload_not_available`.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
value_template: Option<Template>, value_template: Option<Template>,
} }
@ -56,36 +80,47 @@ pub struct CustomAvailability {
/// Information about the device this light is a part of to tie it into the device registry. Only works when unique_id is set. At least one of identifiers or connections must be present to identify the device. /// Information about the device this light is a part of to tie it into the device registry. Only works when unique_id is set. At least one of identifiers or connections must be present to identify the device.
pub struct Device { pub struct Device {
/// A link to the webpage that can manage the configuration of this device. Can be either an http://, https:// or an internal homeassistant:// URL. /// A link to the webpage that can manage the configuration of this device. Can be either an http://, https:// or an internal homeassistant:// URL.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
configuration_url: Option<String>, configuration_url: Option<String>,
/// A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier]. For example the MAC address of a network interface: "connections": [["mac", "02:5b:26:a8:dc:12"]]. /// A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier]. For example the MAC address of a network interface: "connections": [["mac", "02:5b:26:a8:dc:12"]].
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
connections: Option<Vec<String>>, connections: Option<Vec<String>>,
/// The hardware version of the device. /// The hardware version of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
hw_version: Option<String>, hw_version: Option<String>,
/// A list of IDs that uniquely identify the device. For example a serial number. /// A list of IDs that uniquely identify the device. For example a serial number.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
identifiers: Option<Either<String, Vec<String>>>, identifiers: Option<Either<String, Vec<String>>>,
/// The manufacturer of the device. /// The manufacturer of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
manufacturer: Option<String>, manufacturer: Option<String>,
/// The model of the device. /// The model of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
model: Option<String>, model: Option<String>,
/// The name of the device. /// The name of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
name: Option<String>, name: Option<String>,
/// The serial number of the device. /// The serial number of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
serial_number: Option<String>, serial_number: Option<String>,
/// Suggest an area if the device isn't in one yet. /// Suggest an area if the device isn't in one yet.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
suggested_area: Option<String>, suggested_area: Option<String>,
/// The firmware version of the device. /// The firmware version of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
sw_version: Option<String>, sw_version: Option<String>,
/// Identifier of a device that routes messages between this device and Home Assistant. Examples of such devices are hubs, or parent devices of a sub-device. This is used to show device topology in Home Assistant. /// Identifier of a device that routes messages between this device and Home Assistant. Examples of such devices are hubs, or parent devices of a sub-device. This is used to show device topology in Home Assistant.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
via_device: Option<String>, via_device: Option<String>,
} }