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")]
use serde::{Deserialize, Serialize};
pub mod integrations;
pub mod light;
// TODO: Templates
@ -11,9 +12,22 @@ pub type Template = ();
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// #[cfg_attr(feature = "serde", serde(flatten))]
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>,
#[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>,
/// A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with `availability_topic`.
availability: Availability,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
device: Option<Device>,
}
@ -36,7 +50,10 @@ impl Default for AvailabilityMode {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
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),
/// The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with `availability`.
AvailabilityTopic(String),
}
@ -44,9 +61,16 @@ pub enum Availability {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
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>,
/// The payload that represents the unavailable state.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
payload_not_available: Option<String>,
/// An MQTT topic subscribed to receive availability (online/offline) updates.
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>,
}
@ -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.
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.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
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"]].
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
connections: Option<Vec<String>>,
/// The hardware version of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
hw_version: Option<String>,
/// 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>>>,
/// The manufacturer of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
manufacturer: Option<String>,
/// The model of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
model: Option<String>,
/// The name of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
name: Option<String>,
/// The serial number of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
serial_number: Option<String>,
/// 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>,
/// The firmware version of the device.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
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.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
via_device: Option<String>,
}