@@ -43,13 +43,17 @@ pub async fn get_data(state: web::Data<Arc<AppState>>) -> HttpResponse {
4343 ( status = 200 , description = "Server-sent events stream of Hue device changes" )
4444 )
4545) ]
46- pub async fn events_sse ( state : web:: Data < Arc < AppState > > ) -> sse:: Sse < impl futures_util:: Stream < Item = Result < sse:: Event , std:: convert:: Infallible > > > {
46+ pub async fn events_sse (
47+ state : web:: Data < Arc < AppState > > ,
48+ ) -> sse:: Sse < impl futures_util:: Stream < Item = Result < sse:: Event , std:: convert:: Infallible > > > {
4749 let rx = subscribe ( & state. hue_events_tx ) ;
4850 let stream = BroadcastStream :: new ( rx) . filter_map ( |result| async move {
4951 match result {
5052 Ok ( event) => {
5153 let json = serde_json:: to_string ( & event) . ok ( ) ?;
52- Some ( Ok :: < _ , std:: convert:: Infallible > ( sse:: Event :: Data ( sse:: Data :: new ( json) ) ) )
54+ Some ( Ok :: < _ , std:: convert:: Infallible > ( sse:: Event :: Data (
55+ sse:: Data :: new ( json) ,
56+ ) ) )
5357 }
5458 Err ( _) => None ,
5559 }
@@ -86,10 +90,7 @@ pub struct PairResponse {
8690 ( status = 400 , description = "Pairing failed" )
8791 )
8892) ]
89- pub async fn pair (
90- state : web:: Data < Arc < AppState > > ,
91- body : web:: Json < PairRequest > ,
92- ) -> HttpResponse {
93+ pub async fn pair ( state : web:: Data < Arc < AppState > > , body : web:: Json < PairRequest > ) -> HttpResponse {
9394 let bridge_ip = body
9495 . bridge_ip
9596 . clone ( )
@@ -114,16 +115,14 @@ pub async fn pair(
114115 let res = match state. hue_client . post ( & url) . json ( & payload) . send ( ) . await {
115116 Ok ( r) => r,
116117 Err ( e) => {
117- return HttpResponse :: BadRequest ( )
118- . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
118+ return HttpResponse :: BadRequest ( ) . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
119119 }
120120 } ;
121121
122122 let entries: Vec < serde_json:: Value > = match res. json ( ) . await {
123123 Ok ( v) => v,
124124 Err ( e) => {
125- return HttpResponse :: BadRequest ( )
126- . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
125+ return HttpResponse :: BadRequest ( ) . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
127126 }
128127 } ;
129128
@@ -133,8 +132,7 @@ pub async fn pair(
133132 . get ( "description" )
134133 . and_then ( |d| d. as_str ( ) )
135134 . unwrap_or ( "Pairing failed" ) ;
136- return HttpResponse :: BadRequest ( )
137- . json ( serde_json:: json!( { "error" : desc} ) ) ;
135+ return HttpResponse :: BadRequest ( ) . json ( serde_json:: json!( { "error" : desc} ) ) ;
138136 }
139137
140138 if let Some ( success) = entry. get ( "success" ) {
@@ -184,8 +182,7 @@ pub async fn toggle_group(
184182 Ok ( res) => res,
185183 Err ( e) => {
186184 tracing:: error!( "Failed to get group {group_id}: {e}" ) ;
187- return HttpResponse :: BadGateway ( )
188- . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
185+ return HttpResponse :: BadGateway ( ) . json ( serde_json:: json!( { "error" : e. to_string( ) } ) ) ;
189186 }
190187 } ;
191188
@@ -202,8 +199,7 @@ pub async fn toggle_group(
202199 Ok ( ( ) ) => HttpResponse :: Ok ( ) . finish ( ) ,
203200 Err ( e) => {
204201 tracing:: error!( "Failed to toggle group {group_id}: {e}" ) ;
205- HttpResponse :: BadGateway ( )
206- . json ( serde_json:: json!( { "error" : e. to_string( ) } ) )
202+ HttpResponse :: BadGateway ( ) . json ( serde_json:: json!( { "error" : e. to_string( ) } ) )
207203 }
208204 }
209205}
0 commit comments