format
This commit is contained in:
parent
868999bce8
commit
f43322d841
2 changed files with 12 additions and 9 deletions
|
@ -2,7 +2,10 @@ use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use crate::api::{
|
use crate::api::{
|
||||||
internal::{RegisterReq, RegisterResponse, RegisterSuccess},
|
internal::{RegisterReq, RegisterResponse, RegisterSuccess},
|
||||||
ApiError, Group, Light, UpdateStatus,
|
ApiError,
|
||||||
|
Group,
|
||||||
|
Light,
|
||||||
|
UpdateStatus,
|
||||||
};
|
};
|
||||||
use miette::Diagnostic;
|
use miette::Diagnostic;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
@ -50,7 +53,8 @@ impl<T> ActionStatus<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bridge {
|
impl Bridge {
|
||||||
/// tries to register a new user at the given bridge endpoint with a given username.
|
/// tries to register a new user at the given bridge endpoint with a given
|
||||||
|
/// username.
|
||||||
pub async fn register(
|
pub async fn register(
|
||||||
http: Arc<Client>,
|
http: Arc<Client>,
|
||||||
devicetype: &str,
|
devicetype: &str,
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -1,6 +1,5 @@
|
||||||
use std::sync::Arc;
|
|
||||||
use miette::Diagnostic;
|
use miette::Diagnostic;
|
||||||
use std::{io, time::Duration};
|
use std::{io, sync::Arc, time::Duration};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -24,8 +23,9 @@ pub enum DiscoverError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Looks for hue bridges in the local network using the SSDP protocol.
|
/// Looks for hue bridges in the local network using the SSDP protocol.
|
||||||
/// A reqwest client is required, to fetch the device's description, which is needed to make sure a
|
/// A reqwest client is required, to fetch the device's description, which is
|
||||||
/// device is a hue bridge. If a bridge is found, it's URL is returned.
|
/// needed to make sure a device is a hue bridge. If a bridge is found, it's URL
|
||||||
|
/// is returned.
|
||||||
pub async fn discover_bridge(
|
pub async fn discover_bridge(
|
||||||
reqwest_client: Arc<reqwest::Client>,
|
reqwest_client: Arc<reqwest::Client>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
|
@ -38,8 +38,8 @@ pub async fn discover_bridge(
|
||||||
if resp.location().ends_with("/description.xml") {
|
if resp.location().ends_with("/description.xml") {
|
||||||
let mut url = Url::parse(resp.location())?;
|
let mut url = Url::parse(resp.location())?;
|
||||||
|
|
||||||
// this check is needed so we don't think that all devices that use description.xml are
|
// this check is needed so we don't think that all devices that use
|
||||||
// hue bridges.
|
// description.xml are hue bridges.
|
||||||
if reqwest_client
|
if reqwest_client
|
||||||
.get(url.clone())
|
.get(url.clone())
|
||||||
.send()
|
.send()
|
||||||
|
@ -64,4 +64,3 @@ pub enum Error {
|
||||||
#[error("JSON error")]
|
#[error("JSON error")]
|
||||||
JsonError(#[from] serde_json::Error),
|
JsonError(#[from] serde_json::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue