From c89f6fa1059502d03ae7d7e77be7045422f8bc90 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 31 Oct 2023 00:10:57 +0000 Subject: [PATCH] Implement base home assistant types --- shalom/src/hass_client.rs | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) diff --git a/shalom/src/hass_client.rs b/shalom/src/hass_client.rs index 8086984..84f4e05 100644 --- a/shalom/src/hass_client.rs +++ b/shalom/src/hass_client.rs @@ -194,4 +194,233 @@ pub mod responses { #[serde(borrow)] pub picture: Option>, } + + #[derive(Deserialize, Yokeable, Debug)] + pub struct DeviceRegistryList<'a>(#[serde(borrow)] pub Vec>); + + #[derive(Deserialize, Debug)] + pub struct Device<'a> { + #[serde(borrow)] + pub area_id: Option>, + #[serde(borrow)] + pub configuration_url: Option>, + #[serde(borrow)] + pub config_entries: Vec>, + #[serde(borrow)] + pub connections: Vec<(Cow<'a, str>, Cow<'a, str>)>, + #[serde(borrow)] + pub disabled_by: Option>, + #[serde(borrow)] + pub entry_type: Option>, + #[serde(borrow)] + pub hw_version: Option>, + #[serde(borrow)] + pub id: Cow<'a, str>, + #[serde(borrow)] + pub identifiers: Vec<(Cow<'a, str>, Cow<'a, str>)>, + #[serde(borrow)] + pub manufacturer: Cow<'a, str>, + #[serde(borrow)] + pub model: Option>, + #[serde(borrow)] + pub name_by_user: Option>, + #[serde(borrow)] + pub name: Cow<'a, str>, + #[serde(borrow)] + pub sw_version: Option>, + #[serde(borrow)] + pub via_device_id: Option>, + } + + #[derive(Deserialize, Yokeable, Debug)] + pub struct EntityRegistryList<'a>(#[serde(borrow)] pub Vec>); + + #[derive(Deserialize, Debug)] + pub struct Entity<'a> { + #[serde(borrow)] + pub area_id: Option>, + #[serde(borrow)] + pub config_entry_id: Cow<'a, str>, + #[serde(borrow)] + pub device_id: Option>, + #[serde(borrow)] + pub disabled_by: Option>, + #[serde(borrow)] + pub entity_category: Option>, + #[serde(borrow)] + pub entity_id: Cow<'a, str>, + pub has_entity_name: bool, + #[serde(borrow)] + pub hidden_by: Option>, + #[serde(borrow)] + pub icon: Option>, + #[serde(borrow)] + pub id: Cow<'a, str>, + #[serde(borrow)] + pub name: Option>, + #[serde(borrow)] + pub original_name: Cow<'a, str>, + #[serde(borrow)] + pub platform: Cow<'a, str>, + #[serde(borrow)] + pub translation_key: Option>, + #[serde(borrow)] + pub unique_id: Option>, + } + + #[derive(Deserialize, Yokeable, Debug)] + pub struct StatesList<'a>(#[serde(borrow)] pub Vec>); + + #[derive(Deserialize, Debug)] + pub enum State<'a> { + Sun { + #[serde(borrow)] + state: Cow<'a, str>, + attributes: StateSunAttributes, + }, + MediaPlayer { + #[serde(borrow)] + state: Cow<'a, str>, + #[serde(borrow)] + attributes: StateMediaPlayerAttributes<'a>, + }, + Camera { + #[serde(borrow)] + state: Cow<'a, str>, + #[serde(borrow)] + attributes: StateCameraAttributes<'a>, + }, + Weather { + #[serde(borrow)] + state: Cow<'a, str>, + #[serde(borrow)] + attributes: StateWeatherAttributes<'a>, + }, + Light { + #[serde(borrow)] + state: Cow<'a, str>, + #[serde(borrow)] + attributes: StateLightAttributes<'a>, + } + } + + #[derive(Deserialize, Debug)] + pub struct StateSunAttributes { + // next_dawn: time::OffsetDateTime, + // next_dusk: time::OffsetDateTime, + // next_midnight: time::OffsetDateTime, + // next_noon: time::OffsetDateTime, + // next_rising: time::OffsetDateTime, + // next_setting: time::OffsetDateTime, + elevation: f32, + azimuth: f32, + rising: bool, + } + + #[derive(Deserialize, Debug)] + pub struct StateMediaPlayerAttributes<'a> { + #[serde(borrow)] + source_list: Vec>, + #[serde(borrow)] + group_members: Vec>, + volume_level: f32, + is_volume_muted: bool, + #[serde(borrow)] + media_content_id: Cow<'a, str>, + #[serde(borrow)] + media_content_type: Cow<'a, str>, + #[serde(borrow)] + source: Cow<'a, str>, + shuffle: bool, + #[serde(borrow)] + repeat: Cow<'a, str>, + queue_position: u32, + queue_size: u32, + #[serde(borrow)] + device_class: Cow<'a, str>, + #[serde(borrow)] + friendly_name: Cow<'a, str>, + } + + #[derive(Deserialize, Debug)] + pub struct StateCameraAttributes<'a> { + #[serde(borrow)] + access_token: Cow<'a, str>, + #[serde(borrow)] + friendly_name: Cow<'a, str>, + #[serde(borrow)] + stream_source: Cow<'a, str>, + #[serde(borrow)] + still_image_url: Cow<'a, str>, + #[serde(borrow)] + name: Cow<'a, str>, + #[serde(borrow)] + id: Cow<'a, str>, + #[serde(borrow)] + entity_picture: Cow<'a, str>, + } + + #[derive(Deserialize, Debug)] + pub struct StateWeatherAttributes<'a> { + temperature: f32, + dew_point: f32, + #[serde(borrow)] + temperature_unit: Cow<'a, str>, + humidity: u8, + cloud_coverage: u8, + pressure: f32, + #[serde(borrow)] + pressure_unit: Cow<'a, str>, + wind_bearing: f32, + wind_speed: f32, + #[serde(borrow)] + wind_speed_unit: Cow<'a, str>, + #[serde(borrow)] + visibility_unit: Cow<'a, str>, + #[serde(borrow)] + precipitation_unit: Cow<'a, str>, + #[serde(borrow)] + forecast: Vec>, + } + + #[derive(Deserialize, Debug)] + pub struct StateWeatherAttributesForecast<'a> { + #[serde(borrow)] + condition: Cow<'a, str>, + // datetime: time::OffsetDateTime, + wind_bearing: f32, + temperature: f32, + #[serde(rename = "templow")] + temperature_low: f32, + wind_speed: f32, + precipitation: u8, + humidity: u8, + } + + #[derive(Deserialize, Debug)] + pub struct StateLightAttributes<'a> { + min_color_temp_kelvin: u16, + max_color_temp_kelvin: u16, + min_mireds: u16, + max_mireds: u16, + supported_color_modes: Vec, + #[serde(borrow)] + mode: Cow<'a, str>, + #[serde(borrow)] + dynamics: Cow<'a, str>, + #[serde(borrow)] + friendly_name: Cow<'a, str>, + color_mode: Option, + brightness: Option, + color_temp_kelvin: Option, + color_temp: Option, + xy_color: Option<(u8, u8)>, + } + + #[derive(Deserialize, Debug)] + #[serde(rename_all = "snake_case")] + pub enum ColorMode { + ColorTemp, + Xy, + } } -- libgit2 1.7.2