From 43d05c10b597b6f9ac1a412d0d9f2a04d0021a48 Mon Sep 17 00:00:00 2001 From: Cedric Schwyter Date: Mon, 10 Jul 2023 16:43:23 +0200 Subject: [PATCH 1/2] chore(types): add more api types to the api client --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 3 +- src-tauri/core/handlers.rs | 8 +- src-tauri/core/macros.rs | 4 +- src-tauri/core/transfer.rs | 676 ++++++++++++++++++++++++------------- src-tauri/lib.rs | 12 +- src-tauri/main.rs | 14 +- 7 files changed, 476 insertions(+), 242 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6c6ac86..eb18a9a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1624,6 +1624,7 @@ version = "0.0.5" dependencies = [ "clap", "env_logger", + "futures", "futures-util", "log", "mdns", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ea029e4..624ad86 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -40,7 +40,8 @@ serde_derive = "1.0.164" thiserror = "1.0.44" specta = "1.0.5" tauri-specta = { version = "1.0.2", features = ["javascript", "typescript"] } -clap = { version = "4.3.19", features = ["derive"] } +clap = { version = "4.3.11", features = ["derive"] } +futures = "0.3.28" [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/src-tauri/core/handlers.rs b/src-tauri/core/handlers.rs index 004d304..179922b 100644 --- a/src-tauri/core/handlers.rs +++ b/src-tauri/core/handlers.rs @@ -4,7 +4,7 @@ use tauri::State; #[allow(unused_imports)] use crate::core::transfer::*; -use crate::{HueHueHueError, HueHueHueState}; +use crate::{HueHueHueBackendError, HueHueHueState}; get!("/resource/light", lights, HueV2LightResponse); get!("/resource/light/{id}", light, HueV2LightResponse, [id]); @@ -226,7 +226,7 @@ get!( pub async fn set_selected_bridge( mdns_name: String, state: State<'_, HueHueHueState>, -) -> Result<(), HueHueHueError> { +) -> Result<(), HueHueHueBackendError> { let mut huehuehue = state.0.lock().await; huehuehue.set_selected_bridge(mdns_name)?; @@ -237,7 +237,7 @@ pub async fn set_selected_bridge( #[specta::specta] pub async fn get_discovered_bridges( state: State<'_, HueHueHueState>, -) -> Result, HueHueHueError> { +) -> Result, HueHueHueBackendError> { let huehuehue = state.0.lock().await; Ok(huehuehue @@ -250,7 +250,7 @@ pub async fn get_discovered_bridges( #[tauri::command] #[specta::specta] -pub async fn abort_discover(state: State<'_, HueHueHueState>) -> Result<(), HueHueHueError> { +pub async fn abort_discover(state: State<'_, HueHueHueState>) -> Result<(), HueHueHueBackendError> { let mut huehuehue = state.0.lock().await; huehuehue.abort_discover() diff --git a/src-tauri/core/macros.rs b/src-tauri/core/macros.rs index 6afa058..d6a815a 100644 --- a/src-tauri/core/macros.rs +++ b/src-tauri/core/macros.rs @@ -4,7 +4,7 @@ macro_rules! endpoint { ($method:expr, $endpoint:expr, $endpointname:ident, $returntype:ident $(, $body:ident)? $(, [$($param:expr),+])?) => { paste::paste! { impl crate::HueHueHue { - pub async fn [<$method:lower _ $endpointname>](&self $(, body: $body)? $(, $($param: impl Into),+)?) -> Result<$returntype, crate::HueHueHueError> { + pub async fn [<$method:lower _ $endpointname>](&self $(, body: $body)? $(, $($param: impl Into),+)?) -> Result<$returntype, crate::HueHueHueBackendError> { #[allow(unused_mut)] let mut endpoint: String = $endpoint.into(); $($(endpoint = endpoint.replace(format!("{{{}}}", stringify!($param)).as_str(), $param.into().as_str()));+;)? @@ -21,7 +21,7 @@ macro_rules! endpoint { #[tauri::command] #[specta::specta] - pub async fn [<$method:lower _ $endpointname>]($(body: $body, )? $($($param: String),+,)? state: tauri::State<'_, crate::HueHueHueState>) -> Result<$returntype, crate::HueHueHueError> { + pub async fn [<$method:lower _ $endpointname>]($(body: $body, )? $($($param: String),+,)? state: tauri::State<'_, crate::HueHueHueState>) -> Result<$returntype, crate::HueHueHueBackendError> { let huehuehue = state.0.lock().await; crate::HueHueHue::[<$method:lower _ $endpointname>](&huehuehue $(,body as $body)? $(,$($param)+)?).await } diff --git a/src-tauri/core/transfer.rs b/src-tauri/core/transfer.rs index e204186..02d4bf1 100644 --- a/src-tauri/core/transfer.rs +++ b/src-tauri/core/transfer.rs @@ -7,15 +7,15 @@ use specta::Type; #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Error { - description: String, + pub description: String, } pub trait HueV2Res: Debug + Type {} #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Response { - errors: Vec, - data: Vec, + pub errors: Vec, + pub data: Vec, } macro_rules! hue_v2_res { @@ -66,9 +66,9 @@ pub enum HueV2ResourceType { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Resource { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, } hue_v2_res!(HueV2Resource); @@ -129,49 +129,50 @@ pub enum HueV2ProductArchetype { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2DeviceProductData { - model_id: String, - manufacturer_name: String, - product_name: String, - product_archetype: HueV2ProductArchetype, - certified: bool, - software_version: String, - hardware_platform_type: Option, + pub model_id: String, + pub manufacturer_name: String, + pub product_name: String, + pub product_archetype: HueV2ProductArchetype, + pub certified: bool, + pub software_version: String, + pub hardware_platform_type: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2DeviceMetadata { - name: String, - archetype: HueV2ProductArchetype, + pub name: String, + pub archetype: HueV2ProductArchetype, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ResourceIdentifier { - rid: String, - rtype: HueV2ResourceType, + pub rid: String, + pub rtype: HueV2ResourceType, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Device { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - product_data: HueV2DeviceProductData, - metadata: HueV2DeviceMetadata, - services: Vec, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub product_data: HueV2DeviceProductData, + pub metadata: HueV2DeviceMetadata, + pub services: Vec, } hue_v2_res!(HueV2Device); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2BridgeHome { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - children: Vec, - services: Vec, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub children: Vec, + pub services: Vec, } hue_v2_res!(HueV2BridgeHome); #[derive(Debug, Deserialize, Serialize, Type)] +#[serde(rename_all = "snake_case")] pub enum HueV2RoomArchetype { LivingRoom, Kitchen, @@ -217,33 +218,34 @@ pub enum HueV2RoomArchetype { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2RoomMetadata { - name: String, - archetype: HueV2RoomArchetype, + pub name: String, + pub archetype: HueV2RoomArchetype, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Room { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - children: Vec, - services: Vec, - metadata: HueV2RoomMetadata, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub children: Vec, + pub services: Vec, + pub metadata: HueV2RoomMetadata, } hue_v2_res!(HueV2Room); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Zone { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - children: Vec, - services: Vec, - metadata: HueV2RoomMetadata, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub children: Vec, + pub services: Vec, + pub metadata: HueV2RoomMetadata, } hue_v2_res!(HueV2Zone); #[derive(Debug, Deserialize, Serialize, Type)] +#[serde(rename_all = "snake_case")] pub enum HueV2LightArchetype { UnknownArchetype, ClassicBulb, @@ -297,52 +299,52 @@ pub enum HueV2LightArchetype { } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightMetadata { - name: String, - archetype: HueV2LightArchetype, - fixed_mired: Option, + pub name: String, + pub archetype: HueV2LightArchetype, + pub fixed_mired: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightOn { - on: bool, + pub on: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightDimming { - brightness: f64, - min_dim_level: Option, + pub brightness: f64, + pub min_dim_level: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColorTemperatureMirekSchema { - mirek_minimum: u32, - mirek_maximum: u32, + pub mirek_minimum: u32, + pub mirek_maximum: u32, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColorTemperature { - mirek: u32, - mirek_valid: bool, - mirek_schema: HueV2LightColorTemperatureMirekSchema, + pub mirek: u32, + pub mirek_valid: bool, + pub mirek_schema: HueV2LightColorTemperatureMirekSchema, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColorXY { - x: f64, - y: f64, + pub x: f64, + pub y: f64, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColorGamutChannel { - x: f64, - y: f64, + pub x: f64, + pub y: f64, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColorGamut { - red: HueV2LightColorGamutChannel, - green: HueV2LightColorGamutChannel, - blue: HueV2LightColorGamutChannel, + pub red: HueV2LightColorGamutChannel, + pub green: HueV2LightColorGamutChannel, + pub blue: HueV2LightColorGamutChannel, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -356,9 +358,9 @@ pub enum HueV2LightColorGamutType { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightColor { - xy: HueV2LightColorXY, - gamut: Option, - gamut_type: HueV2LightColorGamutType, + pub xy: HueV2LightColorXY, + pub gamut: Option, + pub gamut_type: HueV2LightColorGamutType, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -370,15 +372,15 @@ pub enum HueV2LightDynamicsStatus { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightDynamics { - status: HueV2LightDynamicsStatus, - status_values: Vec, - speed: f64, - speed_valid: bool, + pub status: HueV2LightDynamicsStatus, + pub status_values: Vec, + pub speed: f64, + pub speed_valid: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightAlert { - action_values: Vec, + pub action_values: Vec, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -390,13 +392,13 @@ pub enum HueV2LightSignal { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightSignalingStatus { - signal: HueV2LightSignal, - estimated_end: String, + pub signal: HueV2LightSignal, + pub estimated_end: String, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightSignaling { - status: Option, + pub status: Option, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -408,12 +410,12 @@ pub enum HueV2LightMode { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightGradientColor { - xy: HueV2LightColorXY, + pub xy: HueV2LightColorXY, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightGradientPoint { - color: HueV2LightGradientColor, + pub color: HueV2LightGradientColor, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -426,11 +428,11 @@ pub enum HueV2LightGradientMode { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightGradient { - points: Vec, - mode: HueV2LightGradientMode, - points_capable: u32, - mode_values: Vec, - pixel_count: Option, + pub points: Vec, + pub mode: HueV2LightGradientMode, + pub points_capable: u32, + pub mode_values: Vec, + pub pixel_count: Option, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -444,10 +446,10 @@ pub enum HueV2LightEffect { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightEffects { - effect: HueV2LightEffect, - status_values: Vec, - status: HueV2LightEffect, - effect_values: Vec, + pub effect: HueV2LightEffect, + pub status_values: Vec, + pub status: HueV2LightEffect, + pub effect_values: Vec, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -459,11 +461,11 @@ pub enum HueV2LightTimedEffect { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightTimedEffects { - effect: HueV2LightTimedEffect, - duration: Option, - status_values: Vec, - status: HueV2LightTimedEffect, - effect_values: Vec, + pub effect: HueV2LightTimedEffect, + pub duration: Option, + pub status_values: Vec, + pub status: HueV2LightTimedEffect, + pub effect_values: Vec, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -485,8 +487,8 @@ pub enum HueV2LightPowerupOnMode { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupOn { - mode: HueV2LightPowerupOnMode, - on: Option, + pub mode: HueV2LightPowerupOnMode, + pub on: Option, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -498,13 +500,13 @@ pub enum HueV2LightPowerupDimmingMode { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupDimmingBrightness { - brightness: f64, + pub brightness: f64, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupDimming { - mode: HueV2LightPowerupDimmingMode, - dimming: Option, + pub mode: HueV2LightPowerupDimmingMode, + pub dimming: Option, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -517,55 +519,55 @@ pub enum HueV2LightColorTemperatureMode { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupColorTemperature { - mirek: u32, + pub mirek: u32, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupColorColor { - xy: HueV2LightColorXY, + pub xy: HueV2LightColorXY, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerupColor { - mode: HueV2LightColorTemperatureMode, - color_temperature: Option, - color: Option, + pub mode: HueV2LightColorTemperatureMode, + pub color_temperature: Option, + pub color: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightPowerup { - preset: HueV2LightPowerupPreset, - configured: bool, - on: HueV2LightPowerupOn, - dimming: Option, - color: Option, + pub preset: HueV2LightPowerupPreset, + pub configured: bool, + pub on: HueV2LightPowerupOn, + pub dimming: Option, + pub color: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Light { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - metadata: HueV2LightMetadata, - on: HueV2LightOn, - dimming: Option, - color_temperature: Option, - color: Option, - dynamics: Option, - alert: Option, - signaling: Option, - mode: HueV2LightMode, - gradient: Option, - effects: Option, - timed_effects: Option, - powerup: Option, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub metadata: HueV2LightMetadata, + pub on: HueV2LightOn, + pub dimming: Option, + pub color_temperature: Option, + pub color: Option, + pub dynamics: Option, + pub alert: Option, + pub signaling: Option, + pub mode: HueV2LightMode, + pub gradient: Option, + pub effects: Option, + pub timed_effects: Option, + pub powerup: Option, } hue_v2_res!(HueV2Light); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ButtonMetadata { - control_id: u32, + pub control_id: u32, } #[derive(Debug, Deserialize, Serialize, Type)] @@ -581,17 +583,17 @@ pub enum HueV2ButtonEvent { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ButtonButton { - last_event: HueV2ButtonEvent, + pub last_event: HueV2ButtonEvent, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Button { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - metadata: HueV2ButtonMetadata, - button: HueV2ButtonButton, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub metadata: HueV2ButtonMetadata, + pub button: HueV2ButtonButton, } hue_v2_res!(HueV2Button); @@ -611,138 +613,139 @@ pub enum HueV2RelativeRotaryDirection { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2RelativeRotaryRotation { - direction: HueV2RelativeRotaryDirection, - steps: u32, - duration: u32, + pub direction: HueV2RelativeRotaryDirection, + pub steps: u32, + pub duration: u32, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2RelativeRotaryEvent { - action: HueV2RelativeRotaryAction, - rotation: HueV2RelativeRotaryRotation, + pub action: HueV2RelativeRotaryAction, + pub rotation: HueV2RelativeRotaryRotation, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2RelativeRotaryInner { - last_event: Option, + pub last_event: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2RelativeRotary { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - relative_rotary: HueV2RelativeRotaryInner, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub relative_rotary: HueV2RelativeRotaryInner, } hue_v2_res!(HueV2RelativeRotary); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2TemperatureInner { - temperature: f64, - temperature_valid: bool, + pub temperature: f64, + pub temperature_valid: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Temperature { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - enabled: bool, - temperature: HueV2TemperatureInner, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub enabled: bool, + pub temperature: HueV2TemperatureInner, } hue_v2_res!(HueV2Temperature); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightLevelInner { - light_level: u32, - light_level_valid: bool, + pub light_level: u32, + pub light_level_valid: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2LightLevel { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - enabled: bool, - light: HueV2LightLevelInner, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub enabled: bool, + pub light: HueV2LightLevelInner, } hue_v2_res!(HueV2LightLevel); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2MotionInner { - motion: bool, - motion_valid: bool, + pub motion: bool, + pub motion_valid: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Motion { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - enabled: bool, - motion: HueV2MotionInner, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub enabled: bool, + pub motion: HueV2MotionInner, } hue_v2_res!(HueV2Motion); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2EntertainmentSegment { - start: u32, - length: u32, + pub start: u32, + pub length: u32, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2EntertainmentSegments { - configurable: bool, - max_segments: u32, - segments: Vec, + pub configurable: bool, + pub max_segments: u32, + pub segments: Vec, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Entertainment { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - renderer: bool, - proxy: bool, - equalizer: bool, - max_streams: Option, - segments: Option, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub renderer: bool, + pub proxy: bool, + pub equalizer: bool, + pub max_streams: Option, + pub segments: Option, } hue_v2_res!(HueV2Entertainment); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2GroupedLightOn { - on: bool, + pub on: bool, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2GroupedLightDimming { - dimming: f64, + pub dimming: f64, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2GroupedLightAlert { - action_values: Vec, + pub action_values: Vec, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2GroupedLight { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - on: Option, - dimming: Option, - alert: Option, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub on: Option, + pub dimming: Option, + pub alert: Option, } hue_v2_res!(HueV2GroupedLight); #[derive(Debug, Deserialize, Serialize, Type)] +#[serde(rename_all = "snake_case")] pub enum HueV2DeviceBatteryState { Normal, Low, @@ -751,124 +754,343 @@ pub enum HueV2DeviceBatteryState { #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2DevicePowerState { - battery_state: Option, - battery_level: Option, + pub battery_state: Option, + pub battery_level: Option, } #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2DevicePower { - id: String, - r#type: HueV2ResourceType, - id_v1: Option, - owner: HueV2ResourceIdentifier, - power_state: HueV2DevicePowerState, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub power_state: HueV2DevicePowerState, } hue_v2_res!(HueV2DevicePower); -#[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2ZigbeeBridgeConnectivity { - string: String, +#[derive(Debug, Serialize, Deserialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2ZigbeeConnectivityStatus { + Connected, + Disconnected, + ConnectivityIssue, + UnidirectionalIncoming, } -hue_v2_res!(HueV2ZigbeeBridgeConnectivity); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ZigbeeConnectivity { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub status: HueV2ZigbeeConnectivityStatus, + pub mac_address: String, } hue_v2_res!(HueV2ZigbeeConnectivity); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ZgpConnectivity { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub status: HueV2ZigbeeConnectivityStatus, + pub source_id: String, } hue_v2_res!(HueV2ZgpConnectivity); +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2BridgeTimeZone { + pub time_zone: String, +} + #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Bridge { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub bridge_id: String, + pub time_zone: HueV2BridgeTimeZone, } hue_v2_res!(HueV2Bridge); +#[derive(Debug, Serialize, Deserialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2ZigbeeDeviceDiscoveryStatus { + Active, + Ready, +} + #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2ZigbeeDeviceDiscovery { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub owner: HueV2ResourceIdentifier, + pub status: HueV2ZigbeeDeviceDiscoveryStatus, } hue_v2_res!(HueV2ZigbeeDeviceDiscovery); +#[derive(Debug, Serialize, Deserialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2HomekitStatus { + Paired, + Pairing, + Unpaired, +} + #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Homekit { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub status: HueV2HomekitStatus, } hue_v2_res!(HueV2Homekit); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Matter { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub max_fabrics: i32, + pub has_qr_code: bool, } hue_v2_res!(HueV2Matter); +#[derive(Debug, Serialize, Deserialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2MatterFabricStatus { + Pending, + Timedout, + Paired, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2MatterFabricData { + pub label: String, + pub vendor_id: i32, +} + #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2MatterFabric { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub status: HueV2MatterFabricStatus, + pub fabric_data: Option, + pub creation_time: String, } hue_v2_res!(HueV2MatterFabric); #[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2Scene { - string: String, +pub struct HueV2SceneActionTarget { + pub rid: String, + pub rtype: HueV2ResourceType, } -hue_v2_res!(HueV2Scene); #[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2EntertainmentConfiguration { - string: String, +pub struct HueV2SceneActionOn { + pub on: bool, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionDimming { + pub brightness: f64, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionColorXY { + pub x: f64, + pub y: f64, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionColor { + pub xy: HueV2SceneActionColorXY, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionColorTemperature { + pub mirek: u32, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2SceneActionGradientMode { + InterpolatedPalette, + InterpolatedPaletteMirrored, + RandomPixelated, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionGradientPoint { + pub color: HueV2SceneActionColor, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionGradient { + pub points: Vec, + pub mode: HueV2SceneActionGradientMode, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +#[serde(rename_all = "snake_case")] +pub enum HueV2SceneActionEffect { + Sparkle, + Fire, + Candle, + NoEffect, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionEffects { + pub effect: HueV2SceneActionEffect, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionDynamics { + pub duration: Option, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneActionInner { + pub on: Option, + pub dimming: Option, + pub color: Option, + pub color_temperature: Option, + pub gradient: Option, + pub effects: Option, + pub dynamics: Option, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneAction { + pub target: HueV2SceneActionTarget, + pub action: HueV2SceneActionInner, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneImage { + pub rid: String, + pub rtype: HueV2ResourceType, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneMetadata { + pub name: String, + pub image: Option, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2SceneGroup { + pub rid: String, + pub rtype: HueV2ResourceType, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteColorInnerXY { + pub x: f64, + pub y: f64, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteColorInner { + pub xy: HueV2ScenePaletteColorInnerXY, } -hue_v2_res!(HueV2EntertainmentConfiguration); #[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2PublicImage { - string: String, +pub struct HueV2ScenePaletteColorDimming { + pub brightness: f64, } -hue_v2_res!(HueV2PublicImage); #[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2AuthV1 { - string: String, +pub struct HueV2ScenePaletteColor { + pub color: HueV2ScenePaletteColorInner, + pub dimming: HueV2ScenePaletteColorDimming, } -hue_v2_res!(HueV2AuthV1); + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteDimming { + pub brightness: f64, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteColorTemperatureInner { + pub mirek: u32, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteColorTemperatureDimming { + pub brightness: f64, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePaletteColorTemperature { + pub color_temperature: HueV2ScenePaletteColorTemperatureInner, + pub dimming: HueV2ScenePaletteColorTemperatureDimming, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2ScenePalette { + pub color: Vec, + pub dimming: Vec, + pub color_temperature: Vec, +} + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2Scene { + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub actions: Vec, + pub metadata: HueV2SceneMetadata, + pub group: HueV2SceneGroup, + pub palette: Option, + pub speed: f64, + pub auto_dynamic: bool, +} +hue_v2_res!(HueV2Scene); + +#[derive(Debug, Deserialize, Serialize, Type)] +pub struct HueV2EntertainmentConfiguration { + pub string: String, +} +hue_v2_res!(HueV2EntertainmentConfiguration); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2BehaviorScript { - string: String, + pub string: String, } hue_v2_res!(HueV2BehaviorScript); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2BehaviorInstance { - string: String, + pub string: String, } hue_v2_res!(HueV2BehaviorInstance); -#[derive(Debug, Deserialize, Serialize, Type)] -pub struct HueV2Geofence { - string: String, -} -hue_v2_res!(HueV2Geofence); - #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2GeofenceClient { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub name: String, } hue_v2_res!(HueV2GeofenceClient); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2Geolocation { - string: String, + pub id: String, + pub r#type: HueV2ResourceType, + pub id_v1: Option, + pub is_configured: bool, } hue_v2_res!(HueV2Geolocation); #[derive(Debug, Deserialize, Serialize, Type)] pub struct HueV2SmartScene { - string: String, + pub string: String, } hue_v2_res!(HueV2SmartScene); diff --git a/src-tauri/lib.rs b/src-tauri/lib.rs index 19ff273..abaf3d6 100644 --- a/src-tauri/lib.rs +++ b/src-tauri/lib.rs @@ -12,7 +12,7 @@ use tokio::{ task::{AbortHandle, JoinHandle}, }; -const HUE_BRIDGE_SERVICE_NAME: &str = "_hue._tcp.local"; +pub const HUE_BRIDGE_SERVICE_NAME: &str = "_hue._tcp.local"; const HUE_BRIDGE_SERVICE_QUERY_INTERVAL_SECONDS: u64 = 1; const HUE_BRIDGE_API_SCHEMA: &str = "https://"; const HUE_BRIDGE_API_BASE_URL: &str = "/clip/v2"; @@ -32,7 +32,7 @@ pub struct HueHueHue { pub struct HueHueHueState(pub Mutex); #[derive(Debug, thiserror::Error)] -pub enum HueHueHueError { +pub enum HueHueHueBackendError { #[error(transparent)] MdnsError(#[from] mdns::Error), #[error(transparent)] @@ -41,7 +41,7 @@ pub enum HueHueHueError { TokioError(#[from] tokio::task::JoinError), } -impl serde::Serialize for HueHueHueError { +impl serde::Serialize for HueHueHueBackendError { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -58,7 +58,7 @@ impl HueHueHue { } } - pub fn set_selected_bridge(&mut self, mdns_name: String) -> Result<(), HueHueHueError> { + pub fn set_selected_bridge(&mut self, mdns_name: String) -> Result<(), HueHueHueBackendError> { self.selected_bridge = mdns_name; self.abort_discover() @@ -75,7 +75,7 @@ impl HueHueHue { ) } - pub fn abort_discover(&mut self) -> Result<(), HueHueHueError> { + pub fn abort_discover(&mut self) -> Result<(), HueHueHueBackendError> { if let Some(handle) = &self.discovery_abort_handle { handle.abort(); } @@ -83,7 +83,7 @@ impl HueHueHue { Ok(()) } - pub fn discover(&mut self) -> JoinHandle> { + pub fn discover(&mut self) -> JoinHandle> { let addrs = self.bridges.clone(); let discovery_handle = tokio::spawn(async move { info!( diff --git a/src-tauri/main.rs b/src-tauri/main.rs index 0fbe23a..bf4adeb 100644 --- a/src-tauri/main.rs +++ b/src-tauri/main.rs @@ -4,12 +4,18 @@ use clap::{Args, Parser, Subcommand}; use huehuehue::{ bindings, core::handlers::*, huehuehue_handlers, HueHueHue, HueHueHueBackendConfig, - HueHueHueError, HueHueHueState, + HueHueHueBackendError, HueHueHueState, }; use log::info; use tauri::RunEvent; use tokio::sync::Mutex; +#[derive(Debug, thiserror::Error)] +pub enum HueHueHueError { + #[error(transparent)] + BackendError(#[from] HueHueHueBackendError), +} + #[derive(Debug, Parser)] #[command(author, version, about)] struct HueHueHueConfig { @@ -51,7 +57,11 @@ async fn command(command: &Command) -> Result { info!("running command config: {:?}", command); match command { Command::Discover(config) => { - HueHueHue::with_config(config).discover().await??; + HueHueHue::with_config(config) + .discover() + .await + .map_err(|e| Into::::into(e))??; + return Ok(true); } Command::GenerateBindings(config) => { From 89d1ddec13c6002ab15a2516e2b73c3e90a6a8f9 Mon Sep 17 00:00:00 2001 From: Cedric Schwyter Date: Sat, 22 Jul 2023 11:51:11 +0200 Subject: [PATCH 2/2] chore(clippy): address warnings --- src-tauri/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/main.rs b/src-tauri/main.rs index bf4adeb..1f0ed29 100644 --- a/src-tauri/main.rs +++ b/src-tauri/main.rs @@ -60,7 +60,7 @@ async fn command(command: &Command) -> Result { HueHueHue::with_config(config) .discover() .await - .map_err(|e| Into::::into(e))??; + .map_err(Into::::into)??; return Ok(true); }