pub struct KlafsClient { /* private fields */ }Expand description
Klafs API client
Handles authentication and maintains session state for communicating with the Klafs sauna control API.
§Example
use klafs_api::KlafsClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = KlafsClient::new()?;
client.login("user@example.com", "password").await?;
let status = client.get_status("sauna-uuid").await?;
println!("Temperature: {}°C", status.current_temperature);
Ok(())
}Implementations§
Source§impl KlafsClient
impl KlafsClient
Sourcepub fn with_config(config: ClientConfig) -> Result<Self>
pub fn with_config(config: ClientConfig) -> Result<Self>
Create a new Klafs client with custom configuration
Sourcepub fn debugger(&self) -> &HttpDebugger
pub fn debugger(&self) -> &HttpDebugger
Get the debugger for accessing traffic logs
Sourcepub fn enable_debug(&self)
pub fn enable_debug(&self)
Enable debug logging at runtime
Sourcepub fn disable_debug(&self)
pub fn disable_debug(&self)
Disable debug logging at runtime
Sourcepub async fn login(&self, username: &str, password: &str) -> Result<()>
pub async fn login(&self, username: &str, password: &str) -> Result<()>
Login to the Klafs API
This authenticates with the Klafs server and establishes a session. The session cookie is stored automatically for subsequent requests.
§Arguments
username- Email address for the Klafs accountpassword- Password for the Klafs account
§Errors
Returns KlafsError::AuthenticationFailed if credentials are invalid.
Returns KlafsError::AccountLocked if too many failed attempts.
§Warning
Klafs locks accounts after 3 failed login attempts!
Sourcepub async fn get_status(&self, sauna_id: &str) -> Result<SaunaStatus>
pub async fn get_status(&self, sauna_id: &str) -> Result<SaunaStatus>
Get the current status of a sauna
Sourcepub async fn list_saunas(&self) -> Result<Vec<SaunaInfo>>
pub async fn list_saunas(&self) -> Result<Vec<SaunaInfo>>
List all saunas registered to the account
Sourcepub async fn power_on(
&self,
sauna_id: &str,
pin: &str,
schedule: Option<(i32, i32)>,
) -> Result<()>
pub async fn power_on( &self, sauna_id: &str, pin: &str, schedule: Option<(i32, i32)>, ) -> Result<()>
Power on the sauna immediately or at a scheduled time
§Arguments
sauna_id- UUID of the saunapin- PIN code for power controlschedule- Optional (hour, minute) to schedule start instead of immediate
Sourcepub async fn set_mode(&self, sauna_id: &str, mode: SaunaMode) -> Result<()>
pub async fn set_mode(&self, sauna_id: &str, mode: SaunaMode) -> Result<()>
Set the operating mode
§Arguments
sauna_id- UUID of the saunamode- The mode to set (Sauna, Sanarium, or Infrared)
Sourcepub async fn set_temperature(
&self,
sauna_id: &str,
temperature: i32,
) -> Result<()>
pub async fn set_temperature( &self, sauna_id: &str, temperature: i32, ) -> Result<()>
Set the target temperature
§Arguments
sauna_id- UUID of the saunatemperature- Target temperature in °C- Sauna mode: 10-100°C
- Sanarium mode: 40-75°C
Sourcepub async fn set_humidity(&self, sauna_id: &str, level: i32) -> Result<()>
pub async fn set_humidity(&self, sauna_id: &str, level: i32) -> Result<()>
Set the humidity level (Sanarium mode only)
§Arguments
sauna_id- UUID of the saunalevel- Humidity level (1-10)
Sourcepub async fn set_start_time(
&self,
sauna_id: &str,
hour: i32,
minute: i32,
) -> Result<()>
pub async fn set_start_time( &self, sauna_id: &str, hour: i32, minute: i32, ) -> Result<()>
Set the scheduled start time
§Arguments
sauna_id- UUID of the saunahour- Start hour (0-23)minute- Start minute (0-59)
Sourcepub async fn set_selected_time(
&self,
sauna_id: &str,
time: Option<(i32, i32)>,
) -> Result<()>
pub async fn set_selected_time( &self, sauna_id: &str, time: Option<(i32, i32)>, ) -> Result<()>
Set or clear the scheduled start time without starting the sauna
This uses the SetSelectedTime endpoint to configure scheduling without immediately powering on the sauna.
§Arguments
sauna_id- UUID of the saunatime-Some((hour, minute))to set schedule,Noneto clear
Sourcepub async fn set_light(
&self,
sauna_id: &str,
on: bool,
brightness: Option<i32>,
) -> Result<()>
pub async fn set_light( &self, sauna_id: &str, on: bool, brightness: Option<i32>, ) -> Result<()>
Control the main cabin light
§Arguments
sauna_id- UUID of the saunaon- Whether to turn the light on or offbrightness- Brightness level (1-10), only used when turning on
Sourcepub async fn set_sunset(
&self,
sauna_id: &str,
on: bool,
brightness: Option<i32>,
) -> Result<()>
pub async fn set_sunset( &self, sauna_id: &str, on: bool, brightness: Option<i32>, ) -> Result<()>
Control the sunset light
§Arguments
sauna_id- UUID of the saunaon- Whether to turn the light on or offbrightness- Brightness level (1-10), only used when turning on
Sourcepub async fn configure(
&self,
sauna_id: &str,
sauna_temperature: Option<i32>,
sanarium_temperature: Option<i32>,
humidity_level: Option<i32>,
hour: Option<i32>,
minute: Option<i32>,
) -> Result<()>
pub async fn configure( &self, sauna_id: &str, sauna_temperature: Option<i32>, sanarium_temperature: Option<i32>, humidity_level: Option<i32>, hour: Option<i32>, minute: Option<i32>, ) -> Result<()>
Configure multiple settings in a single API call
This uses the PostConfigChange endpoint to set multiple parameters at once.
Only the parameters that are Some will be included in the request.
§Arguments
sauna_id- UUID of the saunasauna_temperature- Target temperature for sauna mode (10-100°C)sanarium_temperature- Target temperature for sanarium mode (40-75°C)humidity_level- Humidity level for sanarium mode (1-10)hour- Scheduled start hour (0-23)minute- Scheduled start minute (0-59)
Sourcepub fn is_logged_in(&self) -> bool
pub fn is_logged_in(&self) -> bool
Check if the client has an active session