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)>> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
for (home_id, house) in self.homes.iter() {
|
||||
v.push((
|
||||
house.clone(),
|
||||
tokio::task::spawn_blocking(move || {
|
||||
self.session.get_current_price(home_id).map_err(|err| {
|
||||
self.get_data(|session, home_id| {
|
||||
session.get_current_price(home_id).map_err(|err| {
|
||||
Error::msg(format!(
|
||||
"TibberHandler: failed getting current price: {err:?}"
|
||||
))
|
||||
})
|
||||
})
|
||||
.await?,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(v)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn prices_today(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
for (home_id, house) in self.homes.iter() {
|
||||
v.push((
|
||||
house.clone(),
|
||||
tokio::task::spawn_blocking(move || {
|
||||
self.session.get_prices_today(home_id).map_err(|err| {
|
||||
self.get_data(|session, home_id| {
|
||||
session.get_prices_today(home_id).map_err(|err| {
|
||||
Error::msg(format!(
|
||||
"TibberHandler: failed getting prices of today: {err:?}"
|
||||
))
|
||||
})
|
||||
})
|
||||
.await?,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(v)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn prices_tomorrow(&self) -> Result<Vec<(House, Vec<PriceInfo>)>> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
for (home_id, house) in self.homes.iter() {
|
||||
v.push((
|
||||
house.clone(),
|
||||
tokio::task::spawn_blocking(move || {
|
||||
self.session.get_prices_tomorrow(home_id).map_err(|err| {
|
||||
self.get_data(|session, home_id| {
|
||||
session.get_prices_tomorrow(home_id).map_err(|err| {
|
||||
Error::msg(format!(
|
||||
"TibberHandler: failed getting prices for tomorrow: {err:?}"
|
||||
))
|
||||
})
|
||||
})
|
||||
.await?,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(v)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn consumption(
|
||||
|
@ -166,7 +139,10 @@ mod test {
|
|||
|
||||
#[tokio::test]
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue