Started work on fullfillment of requests

This commit is contained in:
2022-12-14 05:30:46 +01:00
parent e4369ebf41
commit 36cd0e9b61
14 changed files with 1100 additions and 67 deletions

View File

@@ -1,13 +1,13 @@
use serde::Serialize;
use serde_with::skip_serializing_none;
use crate::response::State;
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Payload {
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_string: Option<String>,
commands: Vec<Command>,
}
@@ -22,10 +22,10 @@ impl Payload {
}
}
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Command {
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
ids: Vec<String>,

View File

@@ -1,15 +1,15 @@
use std::collections::HashMap;
use serde::Serialize;
use serde_with::skip_serializing_none;
use crate::response::State;
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Payload {
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_string: Option<String>,
devices: HashMap<String, Device>,
}
@@ -33,12 +33,12 @@ pub enum Status {
Error,
}
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Device {
online: bool,
status: Status,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(flatten)]

View File

@@ -1,15 +1,17 @@
use serde::Serialize;
use serde_with::skip_serializing_none;
use crate::attributes::Attributes;
use crate::device;
use crate::types::Type;
use crate::traits::Trait;
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Payload {
agent_user_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub debug_string: Option<String>,
pub devices: Vec<Device>,
}
@@ -24,6 +26,7 @@ impl Payload {
}
}
#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Device {
@@ -31,16 +34,12 @@ pub struct Device {
#[serde(rename = "type")]
device_type: Type,
pub traits: Vec<Trait>,
pub name: DeviceName,
pub name: device::Name,
pub will_report_state: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub notification_supported_by_agent: Option<bool>,
#[serde(skip_serializing_if = "String::is_empty")]
pub room_hint: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub device_info: Option<DeviceInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
pub attributes: Option<Attributes>,
pub room_hint: Option<String>,
pub device_info: Option<device::Info>,
pub attributes: Attributes,
}
impl Device {
@@ -49,51 +48,16 @@ impl Device {
id: id.into(),
device_type,
traits: Vec::new(),
name: DeviceName {
default_names: Vec::new(),
name: name.into(),
nicknames: Vec::new() },
name: device::Name::new(name),
will_report_state: false,
notification_supported_by_agent: None,
room_hint: "".into(),
room_hint: None,
device_info: None,
attributes: None,
attributes: Attributes::default(),
}
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeviceName {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub default_names: Vec<String>,
name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub nicknames: Vec<String>,
}
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeviceInfo {
#[serde(skip_serializing_if = "String::is_empty")]
pub manufacturer: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub model: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub hw_version: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub sw_version: String,
// attributes
// customData
// otherDeviceIds
}
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Attributes {
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
@@ -107,15 +71,15 @@ mod tests {
let mut device = Device::new("123", "Night light", Type::Kettle);
device.traits.push(Trait::OnOff);
device.name.default_names.push("My Outlet 1234".to_string());
device.name.nicknames.push("wall plug".to_string());
device.name.add_default_name("My Outlet 1234");
device.name.add_nickname("wall plug");
device.room_hint = "kitchen".into();
device.device_info = Some(DeviceInfo {
manufacturer: "lights-out-inc".to_string(),
model: "hs1234".to_string(),
hw_version: "3.2".to_string(),
sw_version: "11.4".to_string(),
device.room_hint = Some("kitchen".into());
device.device_info = Some(device::Info {
manufacturer: Some("lights-out-inc".to_string()),
model: Some("hs1234".to_string()),
hw_version: Some("3.2".to_string()),
sw_version: Some("11.4".to_string()),
});
sync_resp.add_device(device);