Fix tibber handler
This commit is contained in:
parent
38cc9facc6
commit
51bfe0ab4b
1 changed files with 28 additions and 52 deletions
|
@ -65,63 +65,36 @@ impl TibberHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn current_prices(&self) -> Result<Vec<(House, PriceInfo)>> {
|
pub async fn current_prices(&self) -> Result<Vec<(House, PriceInfo)>> {
|
||||||
let mut v = Vec::new();
|
self.get_data(|session, home_id| {
|
||||||
|
session.get_current_price(home_id).map_err(|err| {
|
||||||
for (home_id, house) in self.homes.iter() {
|
Error::msg(format!(
|
||||||
v.push((
|
"TibberHandler: failed getting current price: {err:?}"
|
||||||
house.clone(),
|
))
|
||||||
tokio::task::spawn_blocking(move || {
|
})
|
||||||
self.session.get_current_price(home_id).map_err(|err| {
|
})
|
||||||
Error::msg(format!(
|
.await
|
||||||
"TibberHandler: failed getting current price: {err:?}"
|
|
||||||
))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn prices_today(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
pub async fn prices_today(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
||||||
let mut v = Vec::new();
|
self.get_data(|session, home_id| {
|
||||||
|
session.get_prices_today(home_id).map_err(|err| {
|
||||||
for (home_id, house) in self.homes.iter() {
|
Error::msg(format!(
|
||||||
v.push((
|
"TibberHandler: failed getting prices of today: {err:?}"
|
||||||
house.clone(),
|
))
|
||||||
tokio::task::spawn_blocking(move || {
|
})
|
||||||
self.session.get_prices_today(home_id).map_err(|err| {
|
})
|
||||||
Error::msg(format!(
|
.await
|
||||||
"TibberHandler: failed getting prices of today: {err:?}"
|
|
||||||
))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn prices_tomorrow(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
pub async fn prices_tomorrow(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
||||||
let mut v = Vec::new();
|
self.get_data(|session, home_id| {
|
||||||
|
session.get_prices_tomorrow(home_id).map_err(|err| {
|
||||||
for (home_id, house) in self.homes.iter() {
|
Error::msg(format!(
|
||||||
v.push((
|
"TibberHandler: failed getting prices for tomorrow: {err:?}"
|
||||||
house.clone(),
|
))
|
||||||
tokio::task::spawn_blocking(move || {
|
})
|
||||||
self.session.get_prices_tomorrow(home_id).map_err(|err| {
|
})
|
||||||
Error::msg(format!(
|
.await
|
||||||
"TibberHandler: failed getting prices for tomorrow: {err:?}"
|
|
||||||
))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn consumption(
|
pub async fn consumption(
|
||||||
|
@ -166,7 +139,10 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_connection() -> Result<()> {
|
async fn test_connection() -> Result<()> {
|
||||||
TibberHandler::new(fs::read_to_string("tibber_token.txt")?).await?;
|
let tibber = TibberHandler::new(fs::read_to_string("tibber_token.txt")?).await?;
|
||||||
|
let current_prices = tibber.current_prices().await?;
|
||||||
|
|
||||||
|
println!("{current_prices:?}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue