Skip to main content

pca9956b_api/client/
mod.rs

1use futures;
2use futures::{Future, Stream, future, stream};
3use hyper;
4use hyper::client::HttpConnector;
5use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE};
6use hyper::{Body, Uri, Response};
7#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
8use hyper_openssl::HttpsConnector;
9use serde_json;
10use std::borrow::Cow;
11use std::convert::TryInto;
12use std::io::{Read, Error, ErrorKind};
13use std::error;
14use std::fmt;
15use std::path::Path;
16use std::sync::Arc;
17use std::str;
18use std::str::FromStr;
19use std::string::ToString;
20use swagger;
21use swagger::{ApiError, Connector, client::Service, XSpanIdString, Has, AuthData};
22use url::form_urlencoded;
23use url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET};
24
25use crate::models;
26use crate::header;
27
28url::define_encode_set! {
29    /// This encode set is used for object IDs
30    ///
31    /// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`,
32    /// the vertical bar (|) is encoded.
33    pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'}
34}
35
36use crate::{Api,
37     ClearErrorResponse,
38     GetAddrEnabledResponse,
39     GetAddrInfoResponse,
40     GetAddrValueResponse,
41     GetApiResponse,
42     GetConfigResponse,
43     GetCurrentResponse,
44     GetErrorResponse,
45     GetErrorsResponse,
46     GetFreqResponse,
47     GetGroupResponse,
48     GetLedCurrentResponse,
49     GetLedErrorResponse,
50     GetLedInfoResponse,
51     GetLedInfoAllResponse,
52     GetLedPwmResponse,
53     GetLedStateResponse,
54     GetOffsetResponse,
55     GetOutputChangeResponse,
56     GetOverTempResponse,
57     GetPwmResponse,
58     GetSleepResponse,
59     ResetResponse,
60     SetAddrEnabledResponse,
61     SetAddrValueResponse,
62     SetConfigResponse,
63     SetCurrentResponse,
64     SetFreqResponse,
65     SetGroupResponse,
66     SetLedCurrentResponse,
67     SetLedErrorResponse,
68     SetLedInfoResponse,
69     SetLedInfoAllResponse,
70     SetLedPwmResponse,
71     SetLedStateResponse,
72     SetOffsetResponse,
73     SetOutputChangeResponse,
74     SetPwmResponse,
75     SetSleepResponse
76     };
77
78/// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.
79fn into_base_path(input: &str, correct_scheme: Option<&'static str>) -> Result<String, ClientInitError> {
80    // First convert to Uri, since a base path is a subset of Uri.
81    let uri = Uri::from_str(input)?;
82
83    let scheme = uri.scheme_part().ok_or(ClientInitError::InvalidScheme)?;
84
85    // Check the scheme if necessary
86    if let Some(correct_scheme) = correct_scheme {
87        if scheme != correct_scheme {
88            return Err(ClientInitError::InvalidScheme);
89        }
90    }
91
92    let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?;
93    let port = uri.port_part().map(|x| format!(":{}", x)).unwrap_or_default();
94    Ok(format!("{}://{}{}{}", scheme, host, port, uri.path().trim_end_matches('/')))
95}
96
97/// A client that implements the API by making HTTP calls out to a server.
98pub struct Client<F>
99{
100    /// Inner service
101    client_service: Arc<Box<dyn Service<ReqBody=Body, Future=F> + Send + Sync>>,
102
103    /// Base path of the API
104    base_path: String,
105}
106
107impl<F> fmt::Debug for Client<F>
108{
109    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110        write!(f, "Client {{ base_path: {} }}", self.base_path)
111    }
112}
113
114impl<F> Clone for Client<F>
115{
116    fn clone(&self) -> Self {
117        Client {
118            client_service: self.client_service.clone(),
119            base_path: self.base_path.clone(),
120        }
121    }
122}
123
124impl Client<hyper::client::ResponseFuture>
125{
126    /// Create a client with a custom implementation of hyper::client::Connect.
127    ///
128    /// Intended for use with custom implementations of connect for e.g. protocol logging
129    /// or similar functionality which requires wrapping the transport layer. When wrapping a TCP connection,
130    /// this function should be used in conjunction with `swagger::Connector::builder()`.
131    ///
132    /// For ordinary tcp connections, prefer the use of `try_new_http`, `try_new_https`
133    /// and `try_new_https_mutual`, to avoid introducing a dependency on the underlying transport layer.
134    ///
135    /// # Arguments
136    ///
137    /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
138    /// * `protocol` - Which protocol to use when constructing the request url, e.g. `Some("http")`
139    /// * `connector` - Implementation of `hyper::client::Connect` to use for the client
140    pub fn try_new_with_connector<C>(
141        base_path: &str,
142        protocol: Option<&'static str>,
143        connector: C,
144    ) -> Result<Self, ClientInitError> where
145      C: hyper::client::connect::Connect + 'static,
146      C::Transport: 'static,
147      C::Future: 'static,
148    {
149        let client_service = Box::new(hyper::client::Client::builder().build(connector));
150
151        Ok(Client {
152            client_service: Arc::new(client_service),
153            base_path: into_base_path(base_path, protocol)?,
154        })
155    }
156
157    /// Create an HTTP client.
158    ///
159    /// # Arguments
160    /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
161    pub fn try_new_http(
162        base_path: &str,
163    ) -> Result<Self, ClientInitError> {
164        let http_connector = Connector::builder().build();
165
166        Self::try_new_with_connector(base_path, Some("http"), http_connector)
167    }
168
169    /// Create a client with a TLS connection to the server
170    ///
171    /// # Arguments
172    /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
173    pub fn try_new_https(base_path: &str) -> Result<Self, ClientInitError>
174    {
175        let https_connector = Connector::builder()
176            .https()
177            .build()
178            .map_err(|e| ClientInitError::SslError(e))?;
179        Self::try_new_with_connector(base_path, Some("https"), https_connector)
180    }
181
182    /// Create a client with a TLS connection to the server using a pinned certificate
183    ///
184    /// # Arguments
185    /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
186    /// * `ca_certificate` - Path to CA certificate used to authenticate the server
187    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
188    pub fn try_new_https_pinned<CA>(
189        base_path: &str,
190        ca_certificate: CA,
191    ) -> Result<Self, ClientInitError>
192    where
193        CA: AsRef<Path>,
194    {
195        let https_connector = Connector::builder()
196            .https()
197            .pin_server_certificate(ca_certificate)
198            .build()
199            .map_err(|e| ClientInitError::SslError(e))?;
200        Self::try_new_with_connector(base_path, Some("https"), https_connector)
201    }
202
203    /// Create a client with a mutually authenticated TLS connection to the server.
204    ///
205    /// # Arguments
206    /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com"
207    /// * `ca_certificate` - Path to CA certificate used to authenticate the server
208    /// * `client_key` - Path to the client private key
209    /// * `client_certificate` - Path to the client's public certificate associated with the private key
210    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
211    pub fn try_new_https_mutual<CA, K, D>(
212        base_path: &str,
213        ca_certificate: CA,
214        client_key: K,
215        client_certificate: D,
216    ) -> Result<Self, ClientInitError>
217    where
218        CA: AsRef<Path>,
219        K: AsRef<Path>,
220        D: AsRef<Path>,
221    {
222        let https_connector = Connector::builder()
223            .https()
224            .pin_server_certificate(ca_certificate)
225            .client_authentication(client_key, client_certificate)
226            .build()
227            .map_err(|e| ClientInitError::SslError(e))?;
228        Self::try_new_with_connector(base_path, Some("https"), https_connector)
229    }
230}
231
232impl<F> Client<F>
233{
234    /// Constructor for creating a `Client` by passing in a pre-made `swagger::Service`
235    ///
236    /// This allows adding custom wrappers around the underlying transport, for example for logging.
237    pub fn try_new_with_client_service(
238        client_service: Arc<Box<dyn Service<ReqBody=Body, Future=F> + Send + Sync>>,
239        base_path: &str,
240    ) -> Result<Self, ClientInitError> {
241        Ok(Client {
242            client_service: client_service,
243            base_path: into_base_path(base_path, None)?,
244        })
245    }
246}
247
248/// Error type failing to create a Client
249#[derive(Debug)]
250pub enum ClientInitError {
251    /// Invalid URL Scheme
252    InvalidScheme,
253
254    /// Invalid URI
255    InvalidUri(hyper::http::uri::InvalidUri),
256
257    /// Missing Hostname
258    MissingHost,
259
260    /// SSL Connection Error
261    #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))]
262    SslError(native_tls::Error),
263
264    /// SSL Connection Error
265    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
266    SslError(openssl::error::ErrorStack),
267}
268
269impl From<hyper::http::uri::InvalidUri> for ClientInitError {
270    fn from(err: hyper::http::uri::InvalidUri) -> ClientInitError {
271        ClientInitError::InvalidUri(err)
272    }
273}
274
275impl fmt::Display for ClientInitError {
276    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
277        let s: &dyn fmt::Debug = self;
278        s.fmt(f)
279    }
280}
281
282impl error::Error for ClientInitError {
283    fn description(&self) -> &str {
284        "Failed to produce a hyper client."
285    }
286}
287
288impl<C, F> Api<C> for Client<F> where
289    C: Has<XSpanIdString> ,
290    F: Future<Item=Response<Body>, Error=hyper::Error> + Send + 'static
291{
292    fn clear_error(
293        &self,
294        param_bus_id: i32,
295        param_addr: i32,
296        context: &C) -> Box<dyn Future<Item=ClearErrorResponse, Error=ApiError> + Send>
297    {
298        let mut uri = format!(
299            "{}/pca9956b/{bus_id}/{addr}/error/clear",
300            self.base_path
301            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
302            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
303        );
304
305        // Query parameters
306        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
307        let query_string_str = query_string.finish();
308        if !query_string_str.is_empty() {
309            uri += "?";
310            uri += &query_string_str;
311        }
312
313        let uri = match Uri::from_str(&uri) {
314            Ok(uri) => uri,
315            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
316        };
317
318        let mut request = match hyper::Request::builder()
319            .method("POST")
320            .uri(uri)
321            .body(Body::empty()) {
322                Ok(req) => req,
323                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
324        };
325
326        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
327        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
328            Ok(h) => h,
329            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
330        });
331
332        Box::new(self.client_service.request(request)
333                             .map_err(|e| ApiError(format!("No response received: {}", e)))
334                             .and_then(|mut response| {
335            match response.status().as_u16() {
336                200 => {
337                    let body = response.into_body();
338                    Box::new(
339                        future::ok(
340                            ClearErrorResponse::OK
341                        )
342                    ) as Box<dyn Future<Item=_, Error=_> + Send>
343                },
344                400 => {
345                    let body = response.into_body();
346                    Box::new(
347                        body
348                        .concat2()
349                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
350                        .and_then(|body|
351                        str::from_utf8(&body)
352                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
353                                             .and_then(|body|
354                                                 serde_json::from_str::<models::BadRequest>(body)
355                                                     .map_err(|e| e.into())
356                                             )
357                                 )
358                        .map(move |body| {
359                            ClearErrorResponse::BadRequest
360                            (body)
361                        })
362                    ) as Box<dyn Future<Item=_, Error=_> + Send>
363                },
364                502 => {
365                    let body = response.into_body();
366                    Box::new(
367                        body
368                        .concat2()
369                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
370                        .and_then(|body|
371                        str::from_utf8(&body)
372                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
373                                             .and_then(|body|
374                                                 serde_json::from_str::<models::OpError>(body)
375                                                     .map_err(|e| e.into())
376                                             )
377                                 )
378                        .map(move |body| {
379                            ClearErrorResponse::OperationFailed
380                            (body)
381                        })
382                    ) as Box<dyn Future<Item=_, Error=_> + Send>
383                },
384                code => {
385                    let headers = response.headers().clone();
386                    Box::new(response.into_body()
387                            .take(100)
388                            .concat2()
389                            .then(move |body|
390                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
391                                    code,
392                                    headers,
393                                    match body {
394                                        Ok(ref body) => match str::from_utf8(body) {
395                                            Ok(body) => Cow::from(body),
396                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
397                                        },
398                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
399                                    })))
400                            )
401                    ) as Box<dyn Future<Item=_, Error=_> + Send>
402                }
403            }
404        }))
405    }
406
407    fn get_addr_enabled(
408        &self,
409        param_bus_id: i32,
410        param_addr: i32,
411        param_num: i32,
412        context: &C) -> Box<dyn Future<Item=GetAddrEnabledResponse, Error=ApiError> + Send>
413    {
414        let mut uri = format!(
415            "{}/pca9956b/{bus_id}/{addr}/addr/{num}/enabled",
416            self.base_path
417            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
418            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
419            ,num=utf8_percent_encode(&param_num.to_string(), ID_ENCODE_SET)
420        );
421
422        // Query parameters
423        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
424        let query_string_str = query_string.finish();
425        if !query_string_str.is_empty() {
426            uri += "?";
427            uri += &query_string_str;
428        }
429
430        let uri = match Uri::from_str(&uri) {
431            Ok(uri) => uri,
432            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
433        };
434
435        let mut request = match hyper::Request::builder()
436            .method("GET")
437            .uri(uri)
438            .body(Body::empty()) {
439                Ok(req) => req,
440                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
441        };
442
443        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
444        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
445            Ok(h) => h,
446            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
447        });
448
449        Box::new(self.client_service.request(request)
450                             .map_err(|e| ApiError(format!("No response received: {}", e)))
451                             .and_then(|mut response| {
452            match response.status().as_u16() {
453                200 => {
454                    let body = response.into_body();
455                    Box::new(
456                        body
457                        .concat2()
458                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
459                        .and_then(|body|
460                        str::from_utf8(&body)
461                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
462                                             .and_then(|body|
463                                                 serde_json::from_str::<bool>(body)
464                                                     .map_err(|e| e.into())
465                                             )
466                                 )
467                        .map(move |body| {
468                            GetAddrEnabledResponse::OK
469                            (body)
470                        })
471                    ) as Box<dyn Future<Item=_, Error=_> + Send>
472                },
473                400 => {
474                    let body = response.into_body();
475                    Box::new(
476                        body
477                        .concat2()
478                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
479                        .and_then(|body|
480                        str::from_utf8(&body)
481                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
482                                             .and_then(|body|
483                                                 serde_json::from_str::<models::BadRequest>(body)
484                                                     .map_err(|e| e.into())
485                                             )
486                                 )
487                        .map(move |body| {
488                            GetAddrEnabledResponse::BadRequest
489                            (body)
490                        })
491                    ) as Box<dyn Future<Item=_, Error=_> + Send>
492                },
493                502 => {
494                    let body = response.into_body();
495                    Box::new(
496                        body
497                        .concat2()
498                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
499                        .and_then(|body|
500                        str::from_utf8(&body)
501                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
502                                             .and_then(|body|
503                                                 serde_json::from_str::<models::OpError>(body)
504                                                     .map_err(|e| e.into())
505                                             )
506                                 )
507                        .map(move |body| {
508                            GetAddrEnabledResponse::OperationFailed
509                            (body)
510                        })
511                    ) as Box<dyn Future<Item=_, Error=_> + Send>
512                },
513                code => {
514                    let headers = response.headers().clone();
515                    Box::new(response.into_body()
516                            .take(100)
517                            .concat2()
518                            .then(move |body|
519                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
520                                    code,
521                                    headers,
522                                    match body {
523                                        Ok(ref body) => match str::from_utf8(body) {
524                                            Ok(body) => Cow::from(body),
525                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
526                                        },
527                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
528                                    })))
529                            )
530                    ) as Box<dyn Future<Item=_, Error=_> + Send>
531                }
532            }
533        }))
534    }
535
536    fn get_addr_info(
537        &self,
538        param_bus_id: i32,
539        param_addr: i32,
540        param_num: i32,
541        context: &C) -> Box<dyn Future<Item=GetAddrInfoResponse, Error=ApiError> + Send>
542    {
543        let mut uri = format!(
544            "{}/pca9956b/{bus_id}/{addr}/addr/{num}",
545            self.base_path
546            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
547            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
548            ,num=utf8_percent_encode(&param_num.to_string(), ID_ENCODE_SET)
549        );
550
551        // Query parameters
552        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
553        let query_string_str = query_string.finish();
554        if !query_string_str.is_empty() {
555            uri += "?";
556            uri += &query_string_str;
557        }
558
559        let uri = match Uri::from_str(&uri) {
560            Ok(uri) => uri,
561            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
562        };
563
564        let mut request = match hyper::Request::builder()
565            .method("GET")
566            .uri(uri)
567            .body(Body::empty()) {
568                Ok(req) => req,
569                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
570        };
571
572        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
573        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
574            Ok(h) => h,
575            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
576        });
577
578        Box::new(self.client_service.request(request)
579                             .map_err(|e| ApiError(format!("No response received: {}", e)))
580                             .and_then(|mut response| {
581            match response.status().as_u16() {
582                200 => {
583                    let body = response.into_body();
584                    Box::new(
585                        body
586                        .concat2()
587                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
588                        .and_then(|body|
589                        str::from_utf8(&body)
590                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
591                                             .and_then(|body|
592                                                 serde_json::from_str::<models::AddrInfo>(body)
593                                                     .map_err(|e| e.into())
594                                             )
595                                 )
596                        .map(move |body| {
597                            GetAddrInfoResponse::OK
598                            (body)
599                        })
600                    ) as Box<dyn Future<Item=_, Error=_> + Send>
601                },
602                400 => {
603                    let body = response.into_body();
604                    Box::new(
605                        body
606                        .concat2()
607                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
608                        .and_then(|body|
609                        str::from_utf8(&body)
610                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
611                                             .and_then(|body|
612                                                 serde_json::from_str::<models::BadRequest>(body)
613                                                     .map_err(|e| e.into())
614                                             )
615                                 )
616                        .map(move |body| {
617                            GetAddrInfoResponse::BadRequest
618                            (body)
619                        })
620                    ) as Box<dyn Future<Item=_, Error=_> + Send>
621                },
622                502 => {
623                    let body = response.into_body();
624                    Box::new(
625                        body
626                        .concat2()
627                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
628                        .and_then(|body|
629                        str::from_utf8(&body)
630                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
631                                             .and_then(|body|
632                                                 serde_json::from_str::<models::OpError>(body)
633                                                     .map_err(|e| e.into())
634                                             )
635                                 )
636                        .map(move |body| {
637                            GetAddrInfoResponse::OperationFailed
638                            (body)
639                        })
640                    ) as Box<dyn Future<Item=_, Error=_> + Send>
641                },
642                code => {
643                    let headers = response.headers().clone();
644                    Box::new(response.into_body()
645                            .take(100)
646                            .concat2()
647                            .then(move |body|
648                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
649                                    code,
650                                    headers,
651                                    match body {
652                                        Ok(ref body) => match str::from_utf8(body) {
653                                            Ok(body) => Cow::from(body),
654                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
655                                        },
656                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
657                                    })))
658                            )
659                    ) as Box<dyn Future<Item=_, Error=_> + Send>
660                }
661            }
662        }))
663    }
664
665    fn get_addr_value(
666        &self,
667        param_bus_id: i32,
668        param_addr: i32,
669        param_num: i32,
670        context: &C) -> Box<dyn Future<Item=GetAddrValueResponse, Error=ApiError> + Send>
671    {
672        let mut uri = format!(
673            "{}/pca9956b/{bus_id}/{addr}/addr/{num}/addr",
674            self.base_path
675            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
676            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
677            ,num=utf8_percent_encode(&param_num.to_string(), ID_ENCODE_SET)
678        );
679
680        // Query parameters
681        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
682        let query_string_str = query_string.finish();
683        if !query_string_str.is_empty() {
684            uri += "?";
685            uri += &query_string_str;
686        }
687
688        let uri = match Uri::from_str(&uri) {
689            Ok(uri) => uri,
690            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
691        };
692
693        let mut request = match hyper::Request::builder()
694            .method("GET")
695            .uri(uri)
696            .body(Body::empty()) {
697                Ok(req) => req,
698                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
699        };
700
701        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
702        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
703            Ok(h) => h,
704            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
705        });
706
707        Box::new(self.client_service.request(request)
708                             .map_err(|e| ApiError(format!("No response received: {}", e)))
709                             .and_then(|mut response| {
710            match response.status().as_u16() {
711                200 => {
712                    let body = response.into_body();
713                    Box::new(
714                        body
715                        .concat2()
716                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
717                        .and_then(|body|
718                        str::from_utf8(&body)
719                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
720                                             .and_then(|body|
721                                                 serde_json::from_str::<i32>(body)
722                                                     .map_err(|e| e.into())
723                                             )
724                                 )
725                        .map(move |body| {
726                            GetAddrValueResponse::OK
727                            (body)
728                        })
729                    ) as Box<dyn Future<Item=_, Error=_> + Send>
730                },
731                400 => {
732                    let body = response.into_body();
733                    Box::new(
734                        body
735                        .concat2()
736                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
737                        .and_then(|body|
738                        str::from_utf8(&body)
739                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
740                                             .and_then(|body|
741                                                 serde_json::from_str::<models::BadRequest>(body)
742                                                     .map_err(|e| e.into())
743                                             )
744                                 )
745                        .map(move |body| {
746                            GetAddrValueResponse::BadRequest
747                            (body)
748                        })
749                    ) as Box<dyn Future<Item=_, Error=_> + Send>
750                },
751                502 => {
752                    let body = response.into_body();
753                    Box::new(
754                        body
755                        .concat2()
756                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
757                        .and_then(|body|
758                        str::from_utf8(&body)
759                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
760                                             .and_then(|body|
761                                                 serde_json::from_str::<models::OpError>(body)
762                                                     .map_err(|e| e.into())
763                                             )
764                                 )
765                        .map(move |body| {
766                            GetAddrValueResponse::OperationFailed
767                            (body)
768                        })
769                    ) as Box<dyn Future<Item=_, Error=_> + Send>
770                },
771                code => {
772                    let headers = response.headers().clone();
773                    Box::new(response.into_body()
774                            .take(100)
775                            .concat2()
776                            .then(move |body|
777                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
778                                    code,
779                                    headers,
780                                    match body {
781                                        Ok(ref body) => match str::from_utf8(body) {
782                                            Ok(body) => Cow::from(body),
783                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
784                                        },
785                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
786                                    })))
787                            )
788                    ) as Box<dyn Future<Item=_, Error=_> + Send>
789                }
790            }
791        }))
792    }
793
794    fn get_api(
795        &self,
796        context: &C) -> Box<dyn Future<Item=GetApiResponse, Error=ApiError> + Send>
797    {
798        let mut uri = format!(
799            "{}/pca9956b/api",
800            self.base_path
801        );
802
803        // Query parameters
804        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
805        let query_string_str = query_string.finish();
806        if !query_string_str.is_empty() {
807            uri += "?";
808            uri += &query_string_str;
809        }
810
811        let uri = match Uri::from_str(&uri) {
812            Ok(uri) => uri,
813            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
814        };
815
816        let mut request = match hyper::Request::builder()
817            .method("GET")
818            .uri(uri)
819            .body(Body::empty()) {
820                Ok(req) => req,
821                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
822        };
823
824        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
825        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
826            Ok(h) => h,
827            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
828        });
829
830        Box::new(self.client_service.request(request)
831                             .map_err(|e| ApiError(format!("No response received: {}", e)))
832                             .and_then(|mut response| {
833            match response.status().as_u16() {
834                200 => {
835                    let body = response.into_body();
836                    Box::new(
837                        body
838                        .concat2()
839                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
840                        .and_then(|body|
841                        str::from_utf8(&body)
842                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
843                                             .and_then(|body|
844                                                 Ok(body.to_string())
845                                             )
846                                 )
847                        .map(move |body| {
848                            GetApiResponse::OK
849                            (body)
850                        })
851                    ) as Box<dyn Future<Item=_, Error=_> + Send>
852                },
853                404 => {
854                    let body = response.into_body();
855                    Box::new(
856                        body
857                        .concat2()
858                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
859                        .and_then(|body|
860                        str::from_utf8(&body)
861                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
862                                             .and_then(|body|
863                                                 Ok(body.to_string())
864                                             )
865                                 )
866                        .map(move |body| {
867                            GetApiResponse::FileNotFound
868                            (body)
869                        })
870                    ) as Box<dyn Future<Item=_, Error=_> + Send>
871                },
872                code => {
873                    let headers = response.headers().clone();
874                    Box::new(response.into_body()
875                            .take(100)
876                            .concat2()
877                            .then(move |body|
878                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
879                                    code,
880                                    headers,
881                                    match body {
882                                        Ok(ref body) => match str::from_utf8(body) {
883                                            Ok(body) => Cow::from(body),
884                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
885                                        },
886                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
887                                    })))
888                            )
889                    ) as Box<dyn Future<Item=_, Error=_> + Send>
890                }
891            }
892        }))
893    }
894
895    fn get_config(
896        &self,
897        param_bus_id: i32,
898        param_addr: i32,
899        context: &C) -> Box<dyn Future<Item=GetConfigResponse, Error=ApiError> + Send>
900    {
901        let mut uri = format!(
902            "{}/pca9956b/{bus_id}/{addr}/config",
903            self.base_path
904            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
905            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
906        );
907
908        // Query parameters
909        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
910        let query_string_str = query_string.finish();
911        if !query_string_str.is_empty() {
912            uri += "?";
913            uri += &query_string_str;
914        }
915
916        let uri = match Uri::from_str(&uri) {
917            Ok(uri) => uri,
918            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
919        };
920
921        let mut request = match hyper::Request::builder()
922            .method("GET")
923            .uri(uri)
924            .body(Body::empty()) {
925                Ok(req) => req,
926                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
927        };
928
929        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
930        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
931            Ok(h) => h,
932            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
933        });
934
935        Box::new(self.client_service.request(request)
936                             .map_err(|e| ApiError(format!("No response received: {}", e)))
937                             .and_then(|mut response| {
938            match response.status().as_u16() {
939                200 => {
940                    let body = response.into_body();
941                    Box::new(
942                        body
943                        .concat2()
944                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
945                        .and_then(|body|
946                        str::from_utf8(&body)
947                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
948                                             .and_then(|body|
949                                                 serde_json::from_str::<models::Config>(body)
950                                                     .map_err(|e| e.into())
951                                             )
952                                 )
953                        .map(move |body| {
954                            GetConfigResponse::OK
955                            (body)
956                        })
957                    ) as Box<dyn Future<Item=_, Error=_> + Send>
958                },
959                400 => {
960                    let body = response.into_body();
961                    Box::new(
962                        body
963                        .concat2()
964                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
965                        .and_then(|body|
966                        str::from_utf8(&body)
967                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
968                                             .and_then(|body|
969                                                 serde_json::from_str::<models::BadRequest>(body)
970                                                     .map_err(|e| e.into())
971                                             )
972                                 )
973                        .map(move |body| {
974                            GetConfigResponse::BadRequest
975                            (body)
976                        })
977                    ) as Box<dyn Future<Item=_, Error=_> + Send>
978                },
979                502 => {
980                    let body = response.into_body();
981                    Box::new(
982                        body
983                        .concat2()
984                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
985                        .and_then(|body|
986                        str::from_utf8(&body)
987                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
988                                             .and_then(|body|
989                                                 serde_json::from_str::<models::OpError>(body)
990                                                     .map_err(|e| e.into())
991                                             )
992                                 )
993                        .map(move |body| {
994                            GetConfigResponse::OperationFailed
995                            (body)
996                        })
997                    ) as Box<dyn Future<Item=_, Error=_> + Send>
998                },
999                code => {
1000                    let headers = response.headers().clone();
1001                    Box::new(response.into_body()
1002                            .take(100)
1003                            .concat2()
1004                            .then(move |body|
1005                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1006                                    code,
1007                                    headers,
1008                                    match body {
1009                                        Ok(ref body) => match str::from_utf8(body) {
1010                                            Ok(body) => Cow::from(body),
1011                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1012                                        },
1013                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1014                                    })))
1015                            )
1016                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1017                }
1018            }
1019        }))
1020    }
1021
1022    fn get_current(
1023        &self,
1024        param_bus_id: i32,
1025        param_addr: i32,
1026        context: &C) -> Box<dyn Future<Item=GetCurrentResponse, Error=ApiError> + Send>
1027    {
1028        let mut uri = format!(
1029            "{}/pca9956b/{bus_id}/{addr}/current",
1030            self.base_path
1031            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1032            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1033        );
1034
1035        // Query parameters
1036        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1037        let query_string_str = query_string.finish();
1038        if !query_string_str.is_empty() {
1039            uri += "?";
1040            uri += &query_string_str;
1041        }
1042
1043        let uri = match Uri::from_str(&uri) {
1044            Ok(uri) => uri,
1045            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1046        };
1047
1048        let mut request = match hyper::Request::builder()
1049            .method("GET")
1050            .uri(uri)
1051            .body(Body::empty()) {
1052                Ok(req) => req,
1053                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1054        };
1055
1056        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1057        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1058            Ok(h) => h,
1059            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1060        });
1061
1062        Box::new(self.client_service.request(request)
1063                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1064                             .and_then(|mut response| {
1065            match response.status().as_u16() {
1066                200 => {
1067                    let body = response.into_body();
1068                    Box::new(
1069                        body
1070                        .concat2()
1071                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1072                        .and_then(|body|
1073                        str::from_utf8(&body)
1074                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1075                                             .and_then(|body|
1076                                                 serde_json::from_str::<i32>(body)
1077                                                     .map_err(|e| e.into())
1078                                             )
1079                                 )
1080                        .map(move |body| {
1081                            GetCurrentResponse::OK
1082                            (body)
1083                        })
1084                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1085                },
1086                400 => {
1087                    let body = response.into_body();
1088                    Box::new(
1089                        body
1090                        .concat2()
1091                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1092                        .and_then(|body|
1093                        str::from_utf8(&body)
1094                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1095                                             .and_then(|body|
1096                                                 serde_json::from_str::<models::BadRequest>(body)
1097                                                     .map_err(|e| e.into())
1098                                             )
1099                                 )
1100                        .map(move |body| {
1101                            GetCurrentResponse::BadRequest
1102                            (body)
1103                        })
1104                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1105                },
1106                502 => {
1107                    let body = response.into_body();
1108                    Box::new(
1109                        body
1110                        .concat2()
1111                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1112                        .and_then(|body|
1113                        str::from_utf8(&body)
1114                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1115                                             .and_then(|body|
1116                                                 serde_json::from_str::<models::OpError>(body)
1117                                                     .map_err(|e| e.into())
1118                                             )
1119                                 )
1120                        .map(move |body| {
1121                            GetCurrentResponse::OperationFailed
1122                            (body)
1123                        })
1124                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1125                },
1126                code => {
1127                    let headers = response.headers().clone();
1128                    Box::new(response.into_body()
1129                            .take(100)
1130                            .concat2()
1131                            .then(move |body|
1132                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1133                                    code,
1134                                    headers,
1135                                    match body {
1136                                        Ok(ref body) => match str::from_utf8(body) {
1137                                            Ok(body) => Cow::from(body),
1138                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1139                                        },
1140                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1141                                    })))
1142                            )
1143                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1144                }
1145            }
1146        }))
1147    }
1148
1149    fn get_error(
1150        &self,
1151        param_bus_id: i32,
1152        param_addr: i32,
1153        context: &C) -> Box<dyn Future<Item=GetErrorResponse, Error=ApiError> + Send>
1154    {
1155        let mut uri = format!(
1156            "{}/pca9956b/{bus_id}/{addr}/error",
1157            self.base_path
1158            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1159            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1160        );
1161
1162        // Query parameters
1163        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1164        let query_string_str = query_string.finish();
1165        if !query_string_str.is_empty() {
1166            uri += "?";
1167            uri += &query_string_str;
1168        }
1169
1170        let uri = match Uri::from_str(&uri) {
1171            Ok(uri) => uri,
1172            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1173        };
1174
1175        let mut request = match hyper::Request::builder()
1176            .method("GET")
1177            .uri(uri)
1178            .body(Body::empty()) {
1179                Ok(req) => req,
1180                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1181        };
1182
1183        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1184        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1185            Ok(h) => h,
1186            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1187        });
1188
1189        Box::new(self.client_service.request(request)
1190                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1191                             .and_then(|mut response| {
1192            match response.status().as_u16() {
1193                200 => {
1194                    let body = response.into_body();
1195                    Box::new(
1196                        body
1197                        .concat2()
1198                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1199                        .and_then(|body|
1200                        str::from_utf8(&body)
1201                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1202                                             .and_then(|body|
1203                                                 serde_json::from_str::<bool>(body)
1204                                                     .map_err(|e| e.into())
1205                                             )
1206                                 )
1207                        .map(move |body| {
1208                            GetErrorResponse::OK
1209                            (body)
1210                        })
1211                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1212                },
1213                400 => {
1214                    let body = response.into_body();
1215                    Box::new(
1216                        body
1217                        .concat2()
1218                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1219                        .and_then(|body|
1220                        str::from_utf8(&body)
1221                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1222                                             .and_then(|body|
1223                                                 serde_json::from_str::<models::BadRequest>(body)
1224                                                     .map_err(|e| e.into())
1225                                             )
1226                                 )
1227                        .map(move |body| {
1228                            GetErrorResponse::BadRequest
1229                            (body)
1230                        })
1231                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1232                },
1233                502 => {
1234                    let body = response.into_body();
1235                    Box::new(
1236                        body
1237                        .concat2()
1238                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1239                        .and_then(|body|
1240                        str::from_utf8(&body)
1241                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1242                                             .and_then(|body|
1243                                                 serde_json::from_str::<models::OpError>(body)
1244                                                     .map_err(|e| e.into())
1245                                             )
1246                                 )
1247                        .map(move |body| {
1248                            GetErrorResponse::OperationFailed
1249                            (body)
1250                        })
1251                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1252                },
1253                code => {
1254                    let headers = response.headers().clone();
1255                    Box::new(response.into_body()
1256                            .take(100)
1257                            .concat2()
1258                            .then(move |body|
1259                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1260                                    code,
1261                                    headers,
1262                                    match body {
1263                                        Ok(ref body) => match str::from_utf8(body) {
1264                                            Ok(body) => Cow::from(body),
1265                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1266                                        },
1267                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1268                                    })))
1269                            )
1270                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1271                }
1272            }
1273        }))
1274    }
1275
1276    fn get_errors(
1277        &self,
1278        param_bus_id: i32,
1279        param_addr: i32,
1280        context: &C) -> Box<dyn Future<Item=GetErrorsResponse, Error=ApiError> + Send>
1281    {
1282        let mut uri = format!(
1283            "{}/pca9956b/{bus_id}/{addr}/errors",
1284            self.base_path
1285            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1286            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1287        );
1288
1289        // Query parameters
1290        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1291        let query_string_str = query_string.finish();
1292        if !query_string_str.is_empty() {
1293            uri += "?";
1294            uri += &query_string_str;
1295        }
1296
1297        let uri = match Uri::from_str(&uri) {
1298            Ok(uri) => uri,
1299            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1300        };
1301
1302        let mut request = match hyper::Request::builder()
1303            .method("POST")
1304            .uri(uri)
1305            .body(Body::empty()) {
1306                Ok(req) => req,
1307                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1308        };
1309
1310        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1311        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1312            Ok(h) => h,
1313            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1314        });
1315
1316        Box::new(self.client_service.request(request)
1317                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1318                             .and_then(|mut response| {
1319            match response.status().as_u16() {
1320                200 => {
1321                    let body = response.into_body();
1322                    Box::new(
1323                        body
1324                        .concat2()
1325                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1326                        .and_then(|body|
1327                        str::from_utf8(&body)
1328                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1329                                             .and_then(|body|
1330                                                 serde_json::from_str::<models::LedErrors>(body)
1331                                                     .map_err(|e| e.into())
1332                                             )
1333                                 )
1334                        .map(move |body| {
1335                            GetErrorsResponse::OK
1336                            (body)
1337                        })
1338                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1339                },
1340                400 => {
1341                    let body = response.into_body();
1342                    Box::new(
1343                        body
1344                        .concat2()
1345                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1346                        .and_then(|body|
1347                        str::from_utf8(&body)
1348                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1349                                             .and_then(|body|
1350                                                 serde_json::from_str::<models::BadRequest>(body)
1351                                                     .map_err(|e| e.into())
1352                                             )
1353                                 )
1354                        .map(move |body| {
1355                            GetErrorsResponse::BadRequest
1356                            (body)
1357                        })
1358                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1359                },
1360                502 => {
1361                    let body = response.into_body();
1362                    Box::new(
1363                        body
1364                        .concat2()
1365                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1366                        .and_then(|body|
1367                        str::from_utf8(&body)
1368                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1369                                             .and_then(|body|
1370                                                 serde_json::from_str::<models::OpError>(body)
1371                                                     .map_err(|e| e.into())
1372                                             )
1373                                 )
1374                        .map(move |body| {
1375                            GetErrorsResponse::OperationFailed
1376                            (body)
1377                        })
1378                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1379                },
1380                code => {
1381                    let headers = response.headers().clone();
1382                    Box::new(response.into_body()
1383                            .take(100)
1384                            .concat2()
1385                            .then(move |body|
1386                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1387                                    code,
1388                                    headers,
1389                                    match body {
1390                                        Ok(ref body) => match str::from_utf8(body) {
1391                                            Ok(body) => Cow::from(body),
1392                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1393                                        },
1394                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1395                                    })))
1396                            )
1397                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1398                }
1399            }
1400        }))
1401    }
1402
1403    fn get_freq(
1404        &self,
1405        param_bus_id: i32,
1406        param_addr: i32,
1407        context: &C) -> Box<dyn Future<Item=GetFreqResponse, Error=ApiError> + Send>
1408    {
1409        let mut uri = format!(
1410            "{}/pca9956b/{bus_id}/{addr}/freq",
1411            self.base_path
1412            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1413            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1414        );
1415
1416        // Query parameters
1417        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1418        let query_string_str = query_string.finish();
1419        if !query_string_str.is_empty() {
1420            uri += "?";
1421            uri += &query_string_str;
1422        }
1423
1424        let uri = match Uri::from_str(&uri) {
1425            Ok(uri) => uri,
1426            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1427        };
1428
1429        let mut request = match hyper::Request::builder()
1430            .method("GET")
1431            .uri(uri)
1432            .body(Body::empty()) {
1433                Ok(req) => req,
1434                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1435        };
1436
1437        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1438        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1439            Ok(h) => h,
1440            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1441        });
1442
1443        Box::new(self.client_service.request(request)
1444                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1445                             .and_then(|mut response| {
1446            match response.status().as_u16() {
1447                200 => {
1448                    let body = response.into_body();
1449                    Box::new(
1450                        body
1451                        .concat2()
1452                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1453                        .and_then(|body|
1454                        str::from_utf8(&body)
1455                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1456                                             .and_then(|body|
1457                                                 serde_json::from_str::<i32>(body)
1458                                                     .map_err(|e| e.into())
1459                                             )
1460                                 )
1461                        .map(move |body| {
1462                            GetFreqResponse::OK
1463                            (body)
1464                        })
1465                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1466                },
1467                400 => {
1468                    let body = response.into_body();
1469                    Box::new(
1470                        body
1471                        .concat2()
1472                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1473                        .and_then(|body|
1474                        str::from_utf8(&body)
1475                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1476                                             .and_then(|body|
1477                                                 serde_json::from_str::<models::BadRequest>(body)
1478                                                     .map_err(|e| e.into())
1479                                             )
1480                                 )
1481                        .map(move |body| {
1482                            GetFreqResponse::BadRequest
1483                            (body)
1484                        })
1485                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1486                },
1487                502 => {
1488                    let body = response.into_body();
1489                    Box::new(
1490                        body
1491                        .concat2()
1492                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1493                        .and_then(|body|
1494                        str::from_utf8(&body)
1495                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1496                                             .and_then(|body|
1497                                                 serde_json::from_str::<models::OpError>(body)
1498                                                     .map_err(|e| e.into())
1499                                             )
1500                                 )
1501                        .map(move |body| {
1502                            GetFreqResponse::OperationFailed
1503                            (body)
1504                        })
1505                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1506                },
1507                code => {
1508                    let headers = response.headers().clone();
1509                    Box::new(response.into_body()
1510                            .take(100)
1511                            .concat2()
1512                            .then(move |body|
1513                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1514                                    code,
1515                                    headers,
1516                                    match body {
1517                                        Ok(ref body) => match str::from_utf8(body) {
1518                                            Ok(body) => Cow::from(body),
1519                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1520                                        },
1521                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1522                                    })))
1523                            )
1524                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1525                }
1526            }
1527        }))
1528    }
1529
1530    fn get_group(
1531        &self,
1532        param_bus_id: i32,
1533        param_addr: i32,
1534        context: &C) -> Box<dyn Future<Item=GetGroupResponse, Error=ApiError> + Send>
1535    {
1536        let mut uri = format!(
1537            "{}/pca9956b/{bus_id}/{addr}/group",
1538            self.base_path
1539            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1540            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1541        );
1542
1543        // Query parameters
1544        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1545        let query_string_str = query_string.finish();
1546        if !query_string_str.is_empty() {
1547            uri += "?";
1548            uri += &query_string_str;
1549        }
1550
1551        let uri = match Uri::from_str(&uri) {
1552            Ok(uri) => uri,
1553            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1554        };
1555
1556        let mut request = match hyper::Request::builder()
1557            .method("GET")
1558            .uri(uri)
1559            .body(Body::empty()) {
1560                Ok(req) => req,
1561                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1562        };
1563
1564        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1565        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1566            Ok(h) => h,
1567            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1568        });
1569
1570        Box::new(self.client_service.request(request)
1571                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1572                             .and_then(|mut response| {
1573            match response.status().as_u16() {
1574                200 => {
1575                    let body = response.into_body();
1576                    Box::new(
1577                        body
1578                        .concat2()
1579                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1580                        .and_then(|body|
1581                        str::from_utf8(&body)
1582                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1583                                             .and_then(|body|
1584                                                 serde_json::from_str::<models::Group>(body)
1585                                                     .map_err(|e| e.into())
1586                                             )
1587                                 )
1588                        .map(move |body| {
1589                            GetGroupResponse::OK
1590                            (body)
1591                        })
1592                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1593                },
1594                400 => {
1595                    let body = response.into_body();
1596                    Box::new(
1597                        body
1598                        .concat2()
1599                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1600                        .and_then(|body|
1601                        str::from_utf8(&body)
1602                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1603                                             .and_then(|body|
1604                                                 serde_json::from_str::<models::BadRequest>(body)
1605                                                     .map_err(|e| e.into())
1606                                             )
1607                                 )
1608                        .map(move |body| {
1609                            GetGroupResponse::BadRequest
1610                            (body)
1611                        })
1612                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1613                },
1614                502 => {
1615                    let body = response.into_body();
1616                    Box::new(
1617                        body
1618                        .concat2()
1619                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1620                        .and_then(|body|
1621                        str::from_utf8(&body)
1622                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1623                                             .and_then(|body|
1624                                                 serde_json::from_str::<models::OpError>(body)
1625                                                     .map_err(|e| e.into())
1626                                             )
1627                                 )
1628                        .map(move |body| {
1629                            GetGroupResponse::OperationFailed
1630                            (body)
1631                        })
1632                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1633                },
1634                code => {
1635                    let headers = response.headers().clone();
1636                    Box::new(response.into_body()
1637                            .take(100)
1638                            .concat2()
1639                            .then(move |body|
1640                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1641                                    code,
1642                                    headers,
1643                                    match body {
1644                                        Ok(ref body) => match str::from_utf8(body) {
1645                                            Ok(body) => Cow::from(body),
1646                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1647                                        },
1648                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1649                                    })))
1650                            )
1651                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1652                }
1653            }
1654        }))
1655    }
1656
1657    fn get_led_current(
1658        &self,
1659        param_bus_id: i32,
1660        param_addr: i32,
1661        param_led: i32,
1662        context: &C) -> Box<dyn Future<Item=GetLedCurrentResponse, Error=ApiError> + Send>
1663    {
1664        let mut uri = format!(
1665            "{}/pca9956b/{bus_id}/{addr}/led/{led}/current",
1666            self.base_path
1667            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1668            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1669            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
1670        );
1671
1672        // Query parameters
1673        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1674        let query_string_str = query_string.finish();
1675        if !query_string_str.is_empty() {
1676            uri += "?";
1677            uri += &query_string_str;
1678        }
1679
1680        let uri = match Uri::from_str(&uri) {
1681            Ok(uri) => uri,
1682            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1683        };
1684
1685        let mut request = match hyper::Request::builder()
1686            .method("GET")
1687            .uri(uri)
1688            .body(Body::empty()) {
1689                Ok(req) => req,
1690                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1691        };
1692
1693        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1694        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1695            Ok(h) => h,
1696            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1697        });
1698
1699        Box::new(self.client_service.request(request)
1700                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1701                             .and_then(|mut response| {
1702            match response.status().as_u16() {
1703                200 => {
1704                    let body = response.into_body();
1705                    Box::new(
1706                        body
1707                        .concat2()
1708                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1709                        .and_then(|body|
1710                        str::from_utf8(&body)
1711                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1712                                             .and_then(|body|
1713                                                 serde_json::from_str::<i32>(body)
1714                                                     .map_err(|e| e.into())
1715                                             )
1716                                 )
1717                        .map(move |body| {
1718                            GetLedCurrentResponse::OK
1719                            (body)
1720                        })
1721                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1722                },
1723                400 => {
1724                    let body = response.into_body();
1725                    Box::new(
1726                        body
1727                        .concat2()
1728                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1729                        .and_then(|body|
1730                        str::from_utf8(&body)
1731                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1732                                             .and_then(|body|
1733                                                 serde_json::from_str::<models::BadRequest>(body)
1734                                                     .map_err(|e| e.into())
1735                                             )
1736                                 )
1737                        .map(move |body| {
1738                            GetLedCurrentResponse::BadRequest
1739                            (body)
1740                        })
1741                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1742                },
1743                502 => {
1744                    let body = response.into_body();
1745                    Box::new(
1746                        body
1747                        .concat2()
1748                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1749                        .and_then(|body|
1750                        str::from_utf8(&body)
1751                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1752                                             .and_then(|body|
1753                                                 serde_json::from_str::<models::OpError>(body)
1754                                                     .map_err(|e| e.into())
1755                                             )
1756                                 )
1757                        .map(move |body| {
1758                            GetLedCurrentResponse::OperationFailed
1759                            (body)
1760                        })
1761                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1762                },
1763                code => {
1764                    let headers = response.headers().clone();
1765                    Box::new(response.into_body()
1766                            .take(100)
1767                            .concat2()
1768                            .then(move |body|
1769                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1770                                    code,
1771                                    headers,
1772                                    match body {
1773                                        Ok(ref body) => match str::from_utf8(body) {
1774                                            Ok(body) => Cow::from(body),
1775                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1776                                        },
1777                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1778                                    })))
1779                            )
1780                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1781                }
1782            }
1783        }))
1784    }
1785
1786    fn get_led_error(
1787        &self,
1788        param_bus_id: i32,
1789        param_addr: i32,
1790        param_led: i32,
1791        context: &C) -> Box<dyn Future<Item=GetLedErrorResponse, Error=ApiError> + Send>
1792    {
1793        let mut uri = format!(
1794            "{}/pca9956b/{bus_id}/{addr}/led/{led}/error",
1795            self.base_path
1796            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1797            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1798            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
1799        );
1800
1801        // Query parameters
1802        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1803        let query_string_str = query_string.finish();
1804        if !query_string_str.is_empty() {
1805            uri += "?";
1806            uri += &query_string_str;
1807        }
1808
1809        let uri = match Uri::from_str(&uri) {
1810            Ok(uri) => uri,
1811            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1812        };
1813
1814        let mut request = match hyper::Request::builder()
1815            .method("GET")
1816            .uri(uri)
1817            .body(Body::empty()) {
1818                Ok(req) => req,
1819                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1820        };
1821
1822        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1823        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1824            Ok(h) => h,
1825            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1826        });
1827
1828        Box::new(self.client_service.request(request)
1829                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1830                             .and_then(|mut response| {
1831            match response.status().as_u16() {
1832                200 => {
1833                    let body = response.into_body();
1834                    Box::new(
1835                        body
1836                        .concat2()
1837                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1838                        .and_then(|body|
1839                        str::from_utf8(&body)
1840                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1841                                             .and_then(|body|
1842                                                 serde_json::from_str::<models::LedError>(body)
1843                                                     .map_err(|e| e.into())
1844                                             )
1845                                 )
1846                        .map(move |body| {
1847                            GetLedErrorResponse::OK
1848                            (body)
1849                        })
1850                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1851                },
1852                400 => {
1853                    let body = response.into_body();
1854                    Box::new(
1855                        body
1856                        .concat2()
1857                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1858                        .and_then(|body|
1859                        str::from_utf8(&body)
1860                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1861                                             .and_then(|body|
1862                                                 serde_json::from_str::<models::BadRequest>(body)
1863                                                     .map_err(|e| e.into())
1864                                             )
1865                                 )
1866                        .map(move |body| {
1867                            GetLedErrorResponse::BadRequest
1868                            (body)
1869                        })
1870                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1871                },
1872                502 => {
1873                    let body = response.into_body();
1874                    Box::new(
1875                        body
1876                        .concat2()
1877                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1878                        .and_then(|body|
1879                        str::from_utf8(&body)
1880                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1881                                             .and_then(|body|
1882                                                 serde_json::from_str::<models::OpError>(body)
1883                                                     .map_err(|e| e.into())
1884                                             )
1885                                 )
1886                        .map(move |body| {
1887                            GetLedErrorResponse::OperationFailed
1888                            (body)
1889                        })
1890                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1891                },
1892                code => {
1893                    let headers = response.headers().clone();
1894                    Box::new(response.into_body()
1895                            .take(100)
1896                            .concat2()
1897                            .then(move |body|
1898                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
1899                                    code,
1900                                    headers,
1901                                    match body {
1902                                        Ok(ref body) => match str::from_utf8(body) {
1903                                            Ok(body) => Cow::from(body),
1904                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
1905                                        },
1906                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
1907                                    })))
1908                            )
1909                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1910                }
1911            }
1912        }))
1913    }
1914
1915    fn get_led_info(
1916        &self,
1917        param_bus_id: i32,
1918        param_addr: i32,
1919        param_led: i32,
1920        context: &C) -> Box<dyn Future<Item=GetLedInfoResponse, Error=ApiError> + Send>
1921    {
1922        let mut uri = format!(
1923            "{}/pca9956b/{bus_id}/{addr}/led/{led}",
1924            self.base_path
1925            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
1926            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
1927            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
1928        );
1929
1930        // Query parameters
1931        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
1932        let query_string_str = query_string.finish();
1933        if !query_string_str.is_empty() {
1934            uri += "?";
1935            uri += &query_string_str;
1936        }
1937
1938        let uri = match Uri::from_str(&uri) {
1939            Ok(uri) => uri,
1940            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
1941        };
1942
1943        let mut request = match hyper::Request::builder()
1944            .method("GET")
1945            .uri(uri)
1946            .body(Body::empty()) {
1947                Ok(req) => req,
1948                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
1949        };
1950
1951        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
1952        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
1953            Ok(h) => h,
1954            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
1955        });
1956
1957        Box::new(self.client_service.request(request)
1958                             .map_err(|e| ApiError(format!("No response received: {}", e)))
1959                             .and_then(|mut response| {
1960            match response.status().as_u16() {
1961                200 => {
1962                    let body = response.into_body();
1963                    Box::new(
1964                        body
1965                        .concat2()
1966                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1967                        .and_then(|body|
1968                        str::from_utf8(&body)
1969                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1970                                             .and_then(|body|
1971                                                 serde_json::from_str::<models::LedInfo>(body)
1972                                                     .map_err(|e| e.into())
1973                                             )
1974                                 )
1975                        .map(move |body| {
1976                            GetLedInfoResponse::OK
1977                            (body)
1978                        })
1979                    ) as Box<dyn Future<Item=_, Error=_> + Send>
1980                },
1981                400 => {
1982                    let body = response.into_body();
1983                    Box::new(
1984                        body
1985                        .concat2()
1986                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1987                        .and_then(|body|
1988                        str::from_utf8(&body)
1989                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
1990                                             .and_then(|body|
1991                                                 serde_json::from_str::<models::BadRequest>(body)
1992                                                     .map_err(|e| e.into())
1993                                             )
1994                                 )
1995                        .map(move |body| {
1996                            GetLedInfoResponse::BadRequest
1997                            (body)
1998                        })
1999                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2000                },
2001                502 => {
2002                    let body = response.into_body();
2003                    Box::new(
2004                        body
2005                        .concat2()
2006                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2007                        .and_then(|body|
2008                        str::from_utf8(&body)
2009                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2010                                             .and_then(|body|
2011                                                 serde_json::from_str::<models::OpError>(body)
2012                                                     .map_err(|e| e.into())
2013                                             )
2014                                 )
2015                        .map(move |body| {
2016                            GetLedInfoResponse::OperationFailed
2017                            (body)
2018                        })
2019                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2020                },
2021                code => {
2022                    let headers = response.headers().clone();
2023                    Box::new(response.into_body()
2024                            .take(100)
2025                            .concat2()
2026                            .then(move |body|
2027                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2028                                    code,
2029                                    headers,
2030                                    match body {
2031                                        Ok(ref body) => match str::from_utf8(body) {
2032                                            Ok(body) => Cow::from(body),
2033                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2034                                        },
2035                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2036                                    })))
2037                            )
2038                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2039                }
2040            }
2041        }))
2042    }
2043
2044    fn get_led_info_all(
2045        &self,
2046        param_bus_id: i32,
2047        param_addr: i32,
2048        context: &C) -> Box<dyn Future<Item=GetLedInfoAllResponse, Error=ApiError> + Send>
2049    {
2050        let mut uri = format!(
2051            "{}/pca9956b/{bus_id}/{addr}/led",
2052            self.base_path
2053            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2054            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2055        );
2056
2057        // Query parameters
2058        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2059        let query_string_str = query_string.finish();
2060        if !query_string_str.is_empty() {
2061            uri += "?";
2062            uri += &query_string_str;
2063        }
2064
2065        let uri = match Uri::from_str(&uri) {
2066            Ok(uri) => uri,
2067            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2068        };
2069
2070        let mut request = match hyper::Request::builder()
2071            .method("GET")
2072            .uri(uri)
2073            .body(Body::empty()) {
2074                Ok(req) => req,
2075                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2076        };
2077
2078        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2079        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2080            Ok(h) => h,
2081            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2082        });
2083
2084        Box::new(self.client_service.request(request)
2085                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2086                             .and_then(|mut response| {
2087            match response.status().as_u16() {
2088                200 => {
2089                    let body = response.into_body();
2090                    Box::new(
2091                        body
2092                        .concat2()
2093                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2094                        .and_then(|body|
2095                        str::from_utf8(&body)
2096                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2097                                             .and_then(|body|
2098                                                 serde_json::from_str::<models::LedInfoArray>(body)
2099                                                     .map_err(|e| e.into())
2100                                             )
2101                                 )
2102                        .map(move |body| {
2103                            GetLedInfoAllResponse::OK
2104                            (body)
2105                        })
2106                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2107                },
2108                400 => {
2109                    let body = response.into_body();
2110                    Box::new(
2111                        body
2112                        .concat2()
2113                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2114                        .and_then(|body|
2115                        str::from_utf8(&body)
2116                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2117                                             .and_then(|body|
2118                                                 serde_json::from_str::<models::BadRequest>(body)
2119                                                     .map_err(|e| e.into())
2120                                             )
2121                                 )
2122                        .map(move |body| {
2123                            GetLedInfoAllResponse::BadRequest
2124                            (body)
2125                        })
2126                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2127                },
2128                502 => {
2129                    let body = response.into_body();
2130                    Box::new(
2131                        body
2132                        .concat2()
2133                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2134                        .and_then(|body|
2135                        str::from_utf8(&body)
2136                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2137                                             .and_then(|body|
2138                                                 serde_json::from_str::<models::OpError>(body)
2139                                                     .map_err(|e| e.into())
2140                                             )
2141                                 )
2142                        .map(move |body| {
2143                            GetLedInfoAllResponse::OperationFailed
2144                            (body)
2145                        })
2146                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2147                },
2148                code => {
2149                    let headers = response.headers().clone();
2150                    Box::new(response.into_body()
2151                            .take(100)
2152                            .concat2()
2153                            .then(move |body|
2154                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2155                                    code,
2156                                    headers,
2157                                    match body {
2158                                        Ok(ref body) => match str::from_utf8(body) {
2159                                            Ok(body) => Cow::from(body),
2160                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2161                                        },
2162                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2163                                    })))
2164                            )
2165                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2166                }
2167            }
2168        }))
2169    }
2170
2171    fn get_led_pwm(
2172        &self,
2173        param_bus_id: i32,
2174        param_addr: i32,
2175        param_led: i32,
2176        context: &C) -> Box<dyn Future<Item=GetLedPwmResponse, Error=ApiError> + Send>
2177    {
2178        let mut uri = format!(
2179            "{}/pca9956b/{bus_id}/{addr}/led/{led}/pwm",
2180            self.base_path
2181            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2182            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2183            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
2184        );
2185
2186        // Query parameters
2187        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2188        let query_string_str = query_string.finish();
2189        if !query_string_str.is_empty() {
2190            uri += "?";
2191            uri += &query_string_str;
2192        }
2193
2194        let uri = match Uri::from_str(&uri) {
2195            Ok(uri) => uri,
2196            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2197        };
2198
2199        let mut request = match hyper::Request::builder()
2200            .method("GET")
2201            .uri(uri)
2202            .body(Body::empty()) {
2203                Ok(req) => req,
2204                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2205        };
2206
2207        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2208        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2209            Ok(h) => h,
2210            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2211        });
2212
2213        Box::new(self.client_service.request(request)
2214                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2215                             .and_then(|mut response| {
2216            match response.status().as_u16() {
2217                200 => {
2218                    let body = response.into_body();
2219                    Box::new(
2220                        body
2221                        .concat2()
2222                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2223                        .and_then(|body|
2224                        str::from_utf8(&body)
2225                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2226                                             .and_then(|body|
2227                                                 serde_json::from_str::<i32>(body)
2228                                                     .map_err(|e| e.into())
2229                                             )
2230                                 )
2231                        .map(move |body| {
2232                            GetLedPwmResponse::OK
2233                            (body)
2234                        })
2235                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2236                },
2237                400 => {
2238                    let body = response.into_body();
2239                    Box::new(
2240                        body
2241                        .concat2()
2242                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2243                        .and_then(|body|
2244                        str::from_utf8(&body)
2245                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2246                                             .and_then(|body|
2247                                                 serde_json::from_str::<models::BadRequest>(body)
2248                                                     .map_err(|e| e.into())
2249                                             )
2250                                 )
2251                        .map(move |body| {
2252                            GetLedPwmResponse::BadRequest
2253                            (body)
2254                        })
2255                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2256                },
2257                502 => {
2258                    let body = response.into_body();
2259                    Box::new(
2260                        body
2261                        .concat2()
2262                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2263                        .and_then(|body|
2264                        str::from_utf8(&body)
2265                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2266                                             .and_then(|body|
2267                                                 serde_json::from_str::<models::OpError>(body)
2268                                                     .map_err(|e| e.into())
2269                                             )
2270                                 )
2271                        .map(move |body| {
2272                            GetLedPwmResponse::OperationFailed
2273                            (body)
2274                        })
2275                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2276                },
2277                code => {
2278                    let headers = response.headers().clone();
2279                    Box::new(response.into_body()
2280                            .take(100)
2281                            .concat2()
2282                            .then(move |body|
2283                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2284                                    code,
2285                                    headers,
2286                                    match body {
2287                                        Ok(ref body) => match str::from_utf8(body) {
2288                                            Ok(body) => Cow::from(body),
2289                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2290                                        },
2291                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2292                                    })))
2293                            )
2294                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2295                }
2296            }
2297        }))
2298    }
2299
2300    fn get_led_state(
2301        &self,
2302        param_bus_id: i32,
2303        param_addr: i32,
2304        param_led: i32,
2305        context: &C) -> Box<dyn Future<Item=GetLedStateResponse, Error=ApiError> + Send>
2306    {
2307        let mut uri = format!(
2308            "{}/pca9956b/{bus_id}/{addr}/led/{led}/state",
2309            self.base_path
2310            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2311            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2312            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
2313        );
2314
2315        // Query parameters
2316        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2317        let query_string_str = query_string.finish();
2318        if !query_string_str.is_empty() {
2319            uri += "?";
2320            uri += &query_string_str;
2321        }
2322
2323        let uri = match Uri::from_str(&uri) {
2324            Ok(uri) => uri,
2325            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2326        };
2327
2328        let mut request = match hyper::Request::builder()
2329            .method("GET")
2330            .uri(uri)
2331            .body(Body::empty()) {
2332                Ok(req) => req,
2333                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2334        };
2335
2336        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2337        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2338            Ok(h) => h,
2339            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2340        });
2341
2342        Box::new(self.client_service.request(request)
2343                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2344                             .and_then(|mut response| {
2345            match response.status().as_u16() {
2346                200 => {
2347                    let body = response.into_body();
2348                    Box::new(
2349                        body
2350                        .concat2()
2351                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2352                        .and_then(|body|
2353                        str::from_utf8(&body)
2354                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2355                                             .and_then(|body|
2356                                                 serde_json::from_str::<models::LedState>(body)
2357                                                     .map_err(|e| e.into())
2358                                             )
2359                                 )
2360                        .map(move |body| {
2361                            GetLedStateResponse::OK
2362                            (body)
2363                        })
2364                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2365                },
2366                400 => {
2367                    let body = response.into_body();
2368                    Box::new(
2369                        body
2370                        .concat2()
2371                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2372                        .and_then(|body|
2373                        str::from_utf8(&body)
2374                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2375                                             .and_then(|body|
2376                                                 serde_json::from_str::<models::BadRequest>(body)
2377                                                     .map_err(|e| e.into())
2378                                             )
2379                                 )
2380                        .map(move |body| {
2381                            GetLedStateResponse::BadRequest
2382                            (body)
2383                        })
2384                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2385                },
2386                502 => {
2387                    let body = response.into_body();
2388                    Box::new(
2389                        body
2390                        .concat2()
2391                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2392                        .and_then(|body|
2393                        str::from_utf8(&body)
2394                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2395                                             .and_then(|body|
2396                                                 serde_json::from_str::<models::OpError>(body)
2397                                                     .map_err(|e| e.into())
2398                                             )
2399                                 )
2400                        .map(move |body| {
2401                            GetLedStateResponse::OperationFailed
2402                            (body)
2403                        })
2404                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2405                },
2406                code => {
2407                    let headers = response.headers().clone();
2408                    Box::new(response.into_body()
2409                            .take(100)
2410                            .concat2()
2411                            .then(move |body|
2412                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2413                                    code,
2414                                    headers,
2415                                    match body {
2416                                        Ok(ref body) => match str::from_utf8(body) {
2417                                            Ok(body) => Cow::from(body),
2418                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2419                                        },
2420                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2421                                    })))
2422                            )
2423                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2424                }
2425            }
2426        }))
2427    }
2428
2429    fn get_offset(
2430        &self,
2431        param_bus_id: i32,
2432        param_addr: i32,
2433        context: &C) -> Box<dyn Future<Item=GetOffsetResponse, Error=ApiError> + Send>
2434    {
2435        let mut uri = format!(
2436            "{}/pca9956b/{bus_id}/{addr}/offset",
2437            self.base_path
2438            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2439            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2440        );
2441
2442        // Query parameters
2443        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2444        let query_string_str = query_string.finish();
2445        if !query_string_str.is_empty() {
2446            uri += "?";
2447            uri += &query_string_str;
2448        }
2449
2450        let uri = match Uri::from_str(&uri) {
2451            Ok(uri) => uri,
2452            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2453        };
2454
2455        let mut request = match hyper::Request::builder()
2456            .method("GET")
2457            .uri(uri)
2458            .body(Body::empty()) {
2459                Ok(req) => req,
2460                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2461        };
2462
2463        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2464        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2465            Ok(h) => h,
2466            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2467        });
2468
2469        Box::new(self.client_service.request(request)
2470                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2471                             .and_then(|mut response| {
2472            match response.status().as_u16() {
2473                200 => {
2474                    let body = response.into_body();
2475                    Box::new(
2476                        body
2477                        .concat2()
2478                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2479                        .and_then(|body|
2480                        str::from_utf8(&body)
2481                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2482                                             .and_then(|body|
2483                                                 serde_json::from_str::<i32>(body)
2484                                                     .map_err(|e| e.into())
2485                                             )
2486                                 )
2487                        .map(move |body| {
2488                            GetOffsetResponse::OK
2489                            (body)
2490                        })
2491                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2492                },
2493                400 => {
2494                    let body = response.into_body();
2495                    Box::new(
2496                        body
2497                        .concat2()
2498                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2499                        .and_then(|body|
2500                        str::from_utf8(&body)
2501                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2502                                             .and_then(|body|
2503                                                 serde_json::from_str::<models::BadRequest>(body)
2504                                                     .map_err(|e| e.into())
2505                                             )
2506                                 )
2507                        .map(move |body| {
2508                            GetOffsetResponse::BadRequest
2509                            (body)
2510                        })
2511                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2512                },
2513                502 => {
2514                    let body = response.into_body();
2515                    Box::new(
2516                        body
2517                        .concat2()
2518                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2519                        .and_then(|body|
2520                        str::from_utf8(&body)
2521                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2522                                             .and_then(|body|
2523                                                 serde_json::from_str::<models::OpError>(body)
2524                                                     .map_err(|e| e.into())
2525                                             )
2526                                 )
2527                        .map(move |body| {
2528                            GetOffsetResponse::OperationFailed
2529                            (body)
2530                        })
2531                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2532                },
2533                code => {
2534                    let headers = response.headers().clone();
2535                    Box::new(response.into_body()
2536                            .take(100)
2537                            .concat2()
2538                            .then(move |body|
2539                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2540                                    code,
2541                                    headers,
2542                                    match body {
2543                                        Ok(ref body) => match str::from_utf8(body) {
2544                                            Ok(body) => Cow::from(body),
2545                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2546                                        },
2547                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2548                                    })))
2549                            )
2550                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2551                }
2552            }
2553        }))
2554    }
2555
2556    fn get_output_change(
2557        &self,
2558        param_bus_id: i32,
2559        param_addr: i32,
2560        context: &C) -> Box<dyn Future<Item=GetOutputChangeResponse, Error=ApiError> + Send>
2561    {
2562        let mut uri = format!(
2563            "{}/pca9956b/{bus_id}/{addr}/outputChange",
2564            self.base_path
2565            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2566            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2567        );
2568
2569        // Query parameters
2570        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2571        let query_string_str = query_string.finish();
2572        if !query_string_str.is_empty() {
2573            uri += "?";
2574            uri += &query_string_str;
2575        }
2576
2577        let uri = match Uri::from_str(&uri) {
2578            Ok(uri) => uri,
2579            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2580        };
2581
2582        let mut request = match hyper::Request::builder()
2583            .method("GET")
2584            .uri(uri)
2585            .body(Body::empty()) {
2586                Ok(req) => req,
2587                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2588        };
2589
2590        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2591        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2592            Ok(h) => h,
2593            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2594        });
2595
2596        Box::new(self.client_service.request(request)
2597                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2598                             .and_then(|mut response| {
2599            match response.status().as_u16() {
2600                200 => {
2601                    let body = response.into_body();
2602                    Box::new(
2603                        body
2604                        .concat2()
2605                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2606                        .and_then(|body|
2607                        str::from_utf8(&body)
2608                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2609                                             .and_then(|body|
2610                                                 serde_json::from_str::<models::OutputChange>(body)
2611                                                     .map_err(|e| e.into())
2612                                             )
2613                                 )
2614                        .map(move |body| {
2615                            GetOutputChangeResponse::OK
2616                            (body)
2617                        })
2618                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2619                },
2620                400 => {
2621                    let body = response.into_body();
2622                    Box::new(
2623                        body
2624                        .concat2()
2625                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2626                        .and_then(|body|
2627                        str::from_utf8(&body)
2628                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2629                                             .and_then(|body|
2630                                                 serde_json::from_str::<models::BadRequest>(body)
2631                                                     .map_err(|e| e.into())
2632                                             )
2633                                 )
2634                        .map(move |body| {
2635                            GetOutputChangeResponse::BadRequest
2636                            (body)
2637                        })
2638                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2639                },
2640                502 => {
2641                    let body = response.into_body();
2642                    Box::new(
2643                        body
2644                        .concat2()
2645                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2646                        .and_then(|body|
2647                        str::from_utf8(&body)
2648                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2649                                             .and_then(|body|
2650                                                 serde_json::from_str::<models::OpError>(body)
2651                                                     .map_err(|e| e.into())
2652                                             )
2653                                 )
2654                        .map(move |body| {
2655                            GetOutputChangeResponse::OperationFailed
2656                            (body)
2657                        })
2658                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2659                },
2660                code => {
2661                    let headers = response.headers().clone();
2662                    Box::new(response.into_body()
2663                            .take(100)
2664                            .concat2()
2665                            .then(move |body|
2666                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2667                                    code,
2668                                    headers,
2669                                    match body {
2670                                        Ok(ref body) => match str::from_utf8(body) {
2671                                            Ok(body) => Cow::from(body),
2672                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2673                                        },
2674                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2675                                    })))
2676                            )
2677                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2678                }
2679            }
2680        }))
2681    }
2682
2683    fn get_over_temp(
2684        &self,
2685        param_bus_id: i32,
2686        param_addr: i32,
2687        context: &C) -> Box<dyn Future<Item=GetOverTempResponse, Error=ApiError> + Send>
2688    {
2689        let mut uri = format!(
2690            "{}/pca9956b/{bus_id}/{addr}/overTemp",
2691            self.base_path
2692            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2693            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2694        );
2695
2696        // Query parameters
2697        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2698        let query_string_str = query_string.finish();
2699        if !query_string_str.is_empty() {
2700            uri += "?";
2701            uri += &query_string_str;
2702        }
2703
2704        let uri = match Uri::from_str(&uri) {
2705            Ok(uri) => uri,
2706            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2707        };
2708
2709        let mut request = match hyper::Request::builder()
2710            .method("GET")
2711            .uri(uri)
2712            .body(Body::empty()) {
2713                Ok(req) => req,
2714                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2715        };
2716
2717        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2718        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2719            Ok(h) => h,
2720            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2721        });
2722
2723        Box::new(self.client_service.request(request)
2724                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2725                             .and_then(|mut response| {
2726            match response.status().as_u16() {
2727                200 => {
2728                    let body = response.into_body();
2729                    Box::new(
2730                        body
2731                        .concat2()
2732                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2733                        .and_then(|body|
2734                        str::from_utf8(&body)
2735                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2736                                             .and_then(|body|
2737                                                 serde_json::from_str::<bool>(body)
2738                                                     .map_err(|e| e.into())
2739                                             )
2740                                 )
2741                        .map(move |body| {
2742                            GetOverTempResponse::OK
2743                            (body)
2744                        })
2745                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2746                },
2747                400 => {
2748                    let body = response.into_body();
2749                    Box::new(
2750                        body
2751                        .concat2()
2752                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2753                        .and_then(|body|
2754                        str::from_utf8(&body)
2755                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2756                                             .and_then(|body|
2757                                                 serde_json::from_str::<models::BadRequest>(body)
2758                                                     .map_err(|e| e.into())
2759                                             )
2760                                 )
2761                        .map(move |body| {
2762                            GetOverTempResponse::BadRequest
2763                            (body)
2764                        })
2765                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2766                },
2767                502 => {
2768                    let body = response.into_body();
2769                    Box::new(
2770                        body
2771                        .concat2()
2772                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2773                        .and_then(|body|
2774                        str::from_utf8(&body)
2775                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2776                                             .and_then(|body|
2777                                                 serde_json::from_str::<models::OpError>(body)
2778                                                     .map_err(|e| e.into())
2779                                             )
2780                                 )
2781                        .map(move |body| {
2782                            GetOverTempResponse::OperationFailed
2783                            (body)
2784                        })
2785                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2786                },
2787                code => {
2788                    let headers = response.headers().clone();
2789                    Box::new(response.into_body()
2790                            .take(100)
2791                            .concat2()
2792                            .then(move |body|
2793                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2794                                    code,
2795                                    headers,
2796                                    match body {
2797                                        Ok(ref body) => match str::from_utf8(body) {
2798                                            Ok(body) => Cow::from(body),
2799                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2800                                        },
2801                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2802                                    })))
2803                            )
2804                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2805                }
2806            }
2807        }))
2808    }
2809
2810    fn get_pwm(
2811        &self,
2812        param_bus_id: i32,
2813        param_addr: i32,
2814        context: &C) -> Box<dyn Future<Item=GetPwmResponse, Error=ApiError> + Send>
2815    {
2816        let mut uri = format!(
2817            "{}/pca9956b/{bus_id}/{addr}/pwm",
2818            self.base_path
2819            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2820            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2821        );
2822
2823        // Query parameters
2824        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2825        let query_string_str = query_string.finish();
2826        if !query_string_str.is_empty() {
2827            uri += "?";
2828            uri += &query_string_str;
2829        }
2830
2831        let uri = match Uri::from_str(&uri) {
2832            Ok(uri) => uri,
2833            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2834        };
2835
2836        let mut request = match hyper::Request::builder()
2837            .method("GET")
2838            .uri(uri)
2839            .body(Body::empty()) {
2840                Ok(req) => req,
2841                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2842        };
2843
2844        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2845        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2846            Ok(h) => h,
2847            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2848        });
2849
2850        Box::new(self.client_service.request(request)
2851                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2852                             .and_then(|mut response| {
2853            match response.status().as_u16() {
2854                200 => {
2855                    let body = response.into_body();
2856                    Box::new(
2857                        body
2858                        .concat2()
2859                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2860                        .and_then(|body|
2861                        str::from_utf8(&body)
2862                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2863                                             .and_then(|body|
2864                                                 serde_json::from_str::<i32>(body)
2865                                                     .map_err(|e| e.into())
2866                                             )
2867                                 )
2868                        .map(move |body| {
2869                            GetPwmResponse::OK
2870                            (body)
2871                        })
2872                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2873                },
2874                400 => {
2875                    let body = response.into_body();
2876                    Box::new(
2877                        body
2878                        .concat2()
2879                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2880                        .and_then(|body|
2881                        str::from_utf8(&body)
2882                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2883                                             .and_then(|body|
2884                                                 serde_json::from_str::<models::BadRequest>(body)
2885                                                     .map_err(|e| e.into())
2886                                             )
2887                                 )
2888                        .map(move |body| {
2889                            GetPwmResponse::BadRequest
2890                            (body)
2891                        })
2892                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2893                },
2894                502 => {
2895                    let body = response.into_body();
2896                    Box::new(
2897                        body
2898                        .concat2()
2899                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2900                        .and_then(|body|
2901                        str::from_utf8(&body)
2902                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2903                                             .and_then(|body|
2904                                                 serde_json::from_str::<models::OpError>(body)
2905                                                     .map_err(|e| e.into())
2906                                             )
2907                                 )
2908                        .map(move |body| {
2909                            GetPwmResponse::OperationFailed
2910                            (body)
2911                        })
2912                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2913                },
2914                code => {
2915                    let headers = response.headers().clone();
2916                    Box::new(response.into_body()
2917                            .take(100)
2918                            .concat2()
2919                            .then(move |body|
2920                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
2921                                    code,
2922                                    headers,
2923                                    match body {
2924                                        Ok(ref body) => match str::from_utf8(body) {
2925                                            Ok(body) => Cow::from(body),
2926                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
2927                                        },
2928                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
2929                                    })))
2930                            )
2931                    ) as Box<dyn Future<Item=_, Error=_> + Send>
2932                }
2933            }
2934        }))
2935    }
2936
2937    fn get_sleep(
2938        &self,
2939        param_bus_id: i32,
2940        param_addr: i32,
2941        context: &C) -> Box<dyn Future<Item=GetSleepResponse, Error=ApiError> + Send>
2942    {
2943        let mut uri = format!(
2944            "{}/pca9956b/{bus_id}/{addr}/sleep",
2945            self.base_path
2946            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
2947            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
2948        );
2949
2950        // Query parameters
2951        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
2952        let query_string_str = query_string.finish();
2953        if !query_string_str.is_empty() {
2954            uri += "?";
2955            uri += &query_string_str;
2956        }
2957
2958        let uri = match Uri::from_str(&uri) {
2959            Ok(uri) => uri,
2960            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
2961        };
2962
2963        let mut request = match hyper::Request::builder()
2964            .method("GET")
2965            .uri(uri)
2966            .body(Body::empty()) {
2967                Ok(req) => req,
2968                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
2969        };
2970
2971        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
2972        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
2973            Ok(h) => h,
2974            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
2975        });
2976
2977        Box::new(self.client_service.request(request)
2978                             .map_err(|e| ApiError(format!("No response received: {}", e)))
2979                             .and_then(|mut response| {
2980            match response.status().as_u16() {
2981                200 => {
2982                    let body = response.into_body();
2983                    Box::new(
2984                        body
2985                        .concat2()
2986                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
2987                        .and_then(|body|
2988                        str::from_utf8(&body)
2989                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
2990                                             .and_then(|body|
2991                                                 serde_json::from_str::<bool>(body)
2992                                                     .map_err(|e| e.into())
2993                                             )
2994                                 )
2995                        .map(move |body| {
2996                            GetSleepResponse::OK
2997                            (body)
2998                        })
2999                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3000                },
3001                400 => {
3002                    let body = response.into_body();
3003                    Box::new(
3004                        body
3005                        .concat2()
3006                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3007                        .and_then(|body|
3008                        str::from_utf8(&body)
3009                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3010                                             .and_then(|body|
3011                                                 serde_json::from_str::<models::BadRequest>(body)
3012                                                     .map_err(|e| e.into())
3013                                             )
3014                                 )
3015                        .map(move |body| {
3016                            GetSleepResponse::BadRequest
3017                            (body)
3018                        })
3019                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3020                },
3021                502 => {
3022                    let body = response.into_body();
3023                    Box::new(
3024                        body
3025                        .concat2()
3026                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3027                        .and_then(|body|
3028                        str::from_utf8(&body)
3029                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3030                                             .and_then(|body|
3031                                                 serde_json::from_str::<models::OpError>(body)
3032                                                     .map_err(|e| e.into())
3033                                             )
3034                                 )
3035                        .map(move |body| {
3036                            GetSleepResponse::OperationFailed
3037                            (body)
3038                        })
3039                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3040                },
3041                code => {
3042                    let headers = response.headers().clone();
3043                    Box::new(response.into_body()
3044                            .take(100)
3045                            .concat2()
3046                            .then(move |body|
3047                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3048                                    code,
3049                                    headers,
3050                                    match body {
3051                                        Ok(ref body) => match str::from_utf8(body) {
3052                                            Ok(body) => Cow::from(body),
3053                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3054                                        },
3055                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3056                                    })))
3057                            )
3058                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3059                }
3060            }
3061        }))
3062    }
3063
3064    fn reset(
3065        &self,
3066        param_bus_id: i32,
3067        context: &C) -> Box<dyn Future<Item=ResetResponse, Error=ApiError> + Send>
3068    {
3069        let mut uri = format!(
3070            "{}/pca9956b/{bus_id}/reset",
3071            self.base_path
3072            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3073        );
3074
3075        // Query parameters
3076        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3077        let query_string_str = query_string.finish();
3078        if !query_string_str.is_empty() {
3079            uri += "?";
3080            uri += &query_string_str;
3081        }
3082
3083        let uri = match Uri::from_str(&uri) {
3084            Ok(uri) => uri,
3085            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3086        };
3087
3088        let mut request = match hyper::Request::builder()
3089            .method("POST")
3090            .uri(uri)
3091            .body(Body::empty()) {
3092                Ok(req) => req,
3093                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3094        };
3095
3096        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3097        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3098            Ok(h) => h,
3099            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3100        });
3101
3102        Box::new(self.client_service.request(request)
3103                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3104                             .and_then(|mut response| {
3105            match response.status().as_u16() {
3106                200 => {
3107                    let body = response.into_body();
3108                    Box::new(
3109                        future::ok(
3110                            ResetResponse::OK
3111                        )
3112                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3113                },
3114                400 => {
3115                    let body = response.into_body();
3116                    Box::new(
3117                        body
3118                        .concat2()
3119                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3120                        .and_then(|body|
3121                        str::from_utf8(&body)
3122                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3123                                             .and_then(|body|
3124                                                 serde_json::from_str::<models::BadRequest>(body)
3125                                                     .map_err(|e| e.into())
3126                                             )
3127                                 )
3128                        .map(move |body| {
3129                            ResetResponse::BadRequest
3130                            (body)
3131                        })
3132                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3133                },
3134                502 => {
3135                    let body = response.into_body();
3136                    Box::new(
3137                        body
3138                        .concat2()
3139                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3140                        .and_then(|body|
3141                        str::from_utf8(&body)
3142                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3143                                             .and_then(|body|
3144                                                 serde_json::from_str::<models::OpError>(body)
3145                                                     .map_err(|e| e.into())
3146                                             )
3147                                 )
3148                        .map(move |body| {
3149                            ResetResponse::OperationFailed
3150                            (body)
3151                        })
3152                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3153                },
3154                code => {
3155                    let headers = response.headers().clone();
3156                    Box::new(response.into_body()
3157                            .take(100)
3158                            .concat2()
3159                            .then(move |body|
3160                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3161                                    code,
3162                                    headers,
3163                                    match body {
3164                                        Ok(ref body) => match str::from_utf8(body) {
3165                                            Ok(body) => Cow::from(body),
3166                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3167                                        },
3168                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3169                                    })))
3170                            )
3171                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3172                }
3173            }
3174        }))
3175    }
3176
3177    fn set_addr_enabled(
3178        &self,
3179        param_bus_id: i32,
3180        param_addr: i32,
3181        param_num: i32,
3182        param_enabled: bool,
3183        context: &C) -> Box<dyn Future<Item=SetAddrEnabledResponse, Error=ApiError> + Send>
3184    {
3185        let mut uri = format!(
3186            "{}/pca9956b/{bus_id}/{addr}/addr/{num}/enabled/{enabled}",
3187            self.base_path
3188            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3189            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3190            ,num=utf8_percent_encode(&param_num.to_string(), ID_ENCODE_SET)
3191            ,enabled=utf8_percent_encode(&param_enabled.to_string(), ID_ENCODE_SET)
3192        );
3193
3194        // Query parameters
3195        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3196        let query_string_str = query_string.finish();
3197        if !query_string_str.is_empty() {
3198            uri += "?";
3199            uri += &query_string_str;
3200        }
3201
3202        let uri = match Uri::from_str(&uri) {
3203            Ok(uri) => uri,
3204            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3205        };
3206
3207        let mut request = match hyper::Request::builder()
3208            .method("POST")
3209            .uri(uri)
3210            .body(Body::empty()) {
3211                Ok(req) => req,
3212                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3213        };
3214
3215        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3216        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3217            Ok(h) => h,
3218            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3219        });
3220
3221        Box::new(self.client_service.request(request)
3222                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3223                             .and_then(|mut response| {
3224            match response.status().as_u16() {
3225                200 => {
3226                    let body = response.into_body();
3227                    Box::new(
3228                        future::ok(
3229                            SetAddrEnabledResponse::OK
3230                        )
3231                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3232                },
3233                400 => {
3234                    let body = response.into_body();
3235                    Box::new(
3236                        body
3237                        .concat2()
3238                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3239                        .and_then(|body|
3240                        str::from_utf8(&body)
3241                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3242                                             .and_then(|body|
3243                                                 serde_json::from_str::<models::BadRequest>(body)
3244                                                     .map_err(|e| e.into())
3245                                             )
3246                                 )
3247                        .map(move |body| {
3248                            SetAddrEnabledResponse::BadRequest
3249                            (body)
3250                        })
3251                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3252                },
3253                502 => {
3254                    let body = response.into_body();
3255                    Box::new(
3256                        body
3257                        .concat2()
3258                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3259                        .and_then(|body|
3260                        str::from_utf8(&body)
3261                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3262                                             .and_then(|body|
3263                                                 serde_json::from_str::<models::OpError>(body)
3264                                                     .map_err(|e| e.into())
3265                                             )
3266                                 )
3267                        .map(move |body| {
3268                            SetAddrEnabledResponse::OperationFailed
3269                            (body)
3270                        })
3271                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3272                },
3273                code => {
3274                    let headers = response.headers().clone();
3275                    Box::new(response.into_body()
3276                            .take(100)
3277                            .concat2()
3278                            .then(move |body|
3279                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3280                                    code,
3281                                    headers,
3282                                    match body {
3283                                        Ok(ref body) => match str::from_utf8(body) {
3284                                            Ok(body) => Cow::from(body),
3285                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3286                                        },
3287                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3288                                    })))
3289                            )
3290                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3291                }
3292            }
3293        }))
3294    }
3295
3296    fn set_addr_value(
3297        &self,
3298        param_bus_id: i32,
3299        param_addr: i32,
3300        param_num: i32,
3301        param_addr_val: i32,
3302        context: &C) -> Box<dyn Future<Item=SetAddrValueResponse, Error=ApiError> + Send>
3303    {
3304        let mut uri = format!(
3305            "{}/pca9956b/{bus_id}/{addr}/addr/{num}/addr/{addr_val}",
3306            self.base_path
3307            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3308            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3309            ,num=utf8_percent_encode(&param_num.to_string(), ID_ENCODE_SET)
3310            ,addr_val=utf8_percent_encode(&param_addr_val.to_string(), ID_ENCODE_SET)
3311        );
3312
3313        // Query parameters
3314        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3315        let query_string_str = query_string.finish();
3316        if !query_string_str.is_empty() {
3317            uri += "?";
3318            uri += &query_string_str;
3319        }
3320
3321        let uri = match Uri::from_str(&uri) {
3322            Ok(uri) => uri,
3323            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3324        };
3325
3326        let mut request = match hyper::Request::builder()
3327            .method("POST")
3328            .uri(uri)
3329            .body(Body::empty()) {
3330                Ok(req) => req,
3331                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3332        };
3333
3334        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3335        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3336            Ok(h) => h,
3337            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3338        });
3339
3340        Box::new(self.client_service.request(request)
3341                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3342                             .and_then(|mut response| {
3343            match response.status().as_u16() {
3344                200 => {
3345                    let body = response.into_body();
3346                    Box::new(
3347                        future::ok(
3348                            SetAddrValueResponse::OK
3349                        )
3350                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3351                },
3352                400 => {
3353                    let body = response.into_body();
3354                    Box::new(
3355                        body
3356                        .concat2()
3357                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3358                        .and_then(|body|
3359                        str::from_utf8(&body)
3360                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3361                                             .and_then(|body|
3362                                                 serde_json::from_str::<models::BadRequest>(body)
3363                                                     .map_err(|e| e.into())
3364                                             )
3365                                 )
3366                        .map(move |body| {
3367                            SetAddrValueResponse::BadRequest
3368                            (body)
3369                        })
3370                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3371                },
3372                502 => {
3373                    let body = response.into_body();
3374                    Box::new(
3375                        body
3376                        .concat2()
3377                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3378                        .and_then(|body|
3379                        str::from_utf8(&body)
3380                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3381                                             .and_then(|body|
3382                                                 serde_json::from_str::<models::OpError>(body)
3383                                                     .map_err(|e| e.into())
3384                                             )
3385                                 )
3386                        .map(move |body| {
3387                            SetAddrValueResponse::OperationFailed
3388                            (body)
3389                        })
3390                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3391                },
3392                code => {
3393                    let headers = response.headers().clone();
3394                    Box::new(response.into_body()
3395                            .take(100)
3396                            .concat2()
3397                            .then(move |body|
3398                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3399                                    code,
3400                                    headers,
3401                                    match body {
3402                                        Ok(ref body) => match str::from_utf8(body) {
3403                                            Ok(body) => Cow::from(body),
3404                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3405                                        },
3406                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3407                                    })))
3408                            )
3409                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3410                }
3411            }
3412        }))
3413    }
3414
3415    fn set_config(
3416        &self,
3417        param_bus_id: i32,
3418        param_addr: i32,
3419        param_config: models::Config,
3420        context: &C) -> Box<dyn Future<Item=SetConfigResponse, Error=ApiError> + Send>
3421    {
3422        let mut uri = format!(
3423            "{}/pca9956b/{bus_id}/{addr}/config",
3424            self.base_path
3425            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3426            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3427        );
3428
3429        // Query parameters
3430        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3431        let query_string_str = query_string.finish();
3432        if !query_string_str.is_empty() {
3433            uri += "?";
3434            uri += &query_string_str;
3435        }
3436
3437        let uri = match Uri::from_str(&uri) {
3438            Ok(uri) => uri,
3439            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3440        };
3441
3442        let mut request = match hyper::Request::builder()
3443            .method("POST")
3444            .uri(uri)
3445            .body(Body::empty()) {
3446                Ok(req) => req,
3447                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3448        };
3449
3450        let body = serde_json::to_string(&param_config).expect("impossible to fail to serialize");
3451                *request.body_mut() = Body::from(body);
3452
3453        let header = "application/json";
3454        request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
3455            Ok(h) => h,
3456            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create header: {} - {}", header, e))))
3457        });
3458        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3459        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3460            Ok(h) => h,
3461            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3462        });
3463
3464        Box::new(self.client_service.request(request)
3465                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3466                             .and_then(|mut response| {
3467            match response.status().as_u16() {
3468                200 => {
3469                    let body = response.into_body();
3470                    Box::new(
3471                        future::ok(
3472                            SetConfigResponse::OK
3473                        )
3474                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3475                },
3476                400 => {
3477                    let body = response.into_body();
3478                    Box::new(
3479                        body
3480                        .concat2()
3481                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3482                        .and_then(|body|
3483                        str::from_utf8(&body)
3484                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3485                                             .and_then(|body|
3486                                                 serde_json::from_str::<models::BadRequest>(body)
3487                                                     .map_err(|e| e.into())
3488                                             )
3489                                 )
3490                        .map(move |body| {
3491                            SetConfigResponse::BadRequest
3492                            (body)
3493                        })
3494                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3495                },
3496                502 => {
3497                    let body = response.into_body();
3498                    Box::new(
3499                        body
3500                        .concat2()
3501                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3502                        .and_then(|body|
3503                        str::from_utf8(&body)
3504                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3505                                             .and_then(|body|
3506                                                 serde_json::from_str::<models::OpError>(body)
3507                                                     .map_err(|e| e.into())
3508                                             )
3509                                 )
3510                        .map(move |body| {
3511                            SetConfigResponse::OperationFailed
3512                            (body)
3513                        })
3514                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3515                },
3516                code => {
3517                    let headers = response.headers().clone();
3518                    Box::new(response.into_body()
3519                            .take(100)
3520                            .concat2()
3521                            .then(move |body|
3522                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3523                                    code,
3524                                    headers,
3525                                    match body {
3526                                        Ok(ref body) => match str::from_utf8(body) {
3527                                            Ok(body) => Cow::from(body),
3528                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3529                                        },
3530                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3531                                    })))
3532                            )
3533                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3534                }
3535            }
3536        }))
3537    }
3538
3539    fn set_current(
3540        &self,
3541        param_bus_id: i32,
3542        param_addr: i32,
3543        param_current: i32,
3544        context: &C) -> Box<dyn Future<Item=SetCurrentResponse, Error=ApiError> + Send>
3545    {
3546        let mut uri = format!(
3547            "{}/pca9956b/{bus_id}/{addr}/current/{current}",
3548            self.base_path
3549            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3550            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3551            ,current=utf8_percent_encode(&param_current.to_string(), ID_ENCODE_SET)
3552        );
3553
3554        // Query parameters
3555        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3556        let query_string_str = query_string.finish();
3557        if !query_string_str.is_empty() {
3558            uri += "?";
3559            uri += &query_string_str;
3560        }
3561
3562        let uri = match Uri::from_str(&uri) {
3563            Ok(uri) => uri,
3564            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3565        };
3566
3567        let mut request = match hyper::Request::builder()
3568            .method("POST")
3569            .uri(uri)
3570            .body(Body::empty()) {
3571                Ok(req) => req,
3572                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3573        };
3574
3575        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3576        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3577            Ok(h) => h,
3578            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3579        });
3580
3581        Box::new(self.client_service.request(request)
3582                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3583                             .and_then(|mut response| {
3584            match response.status().as_u16() {
3585                200 => {
3586                    let body = response.into_body();
3587                    Box::new(
3588                        future::ok(
3589                            SetCurrentResponse::OK
3590                        )
3591                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3592                },
3593                400 => {
3594                    let body = response.into_body();
3595                    Box::new(
3596                        body
3597                        .concat2()
3598                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3599                        .and_then(|body|
3600                        str::from_utf8(&body)
3601                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3602                                             .and_then(|body|
3603                                                 serde_json::from_str::<models::BadRequest>(body)
3604                                                     .map_err(|e| e.into())
3605                                             )
3606                                 )
3607                        .map(move |body| {
3608                            SetCurrentResponse::BadRequest
3609                            (body)
3610                        })
3611                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3612                },
3613                502 => {
3614                    let body = response.into_body();
3615                    Box::new(
3616                        body
3617                        .concat2()
3618                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3619                        .and_then(|body|
3620                        str::from_utf8(&body)
3621                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3622                                             .and_then(|body|
3623                                                 serde_json::from_str::<models::OpError>(body)
3624                                                     .map_err(|e| e.into())
3625                                             )
3626                                 )
3627                        .map(move |body| {
3628                            SetCurrentResponse::OperationFailed
3629                            (body)
3630                        })
3631                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3632                },
3633                code => {
3634                    let headers = response.headers().clone();
3635                    Box::new(response.into_body()
3636                            .take(100)
3637                            .concat2()
3638                            .then(move |body|
3639                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3640                                    code,
3641                                    headers,
3642                                    match body {
3643                                        Ok(ref body) => match str::from_utf8(body) {
3644                                            Ok(body) => Cow::from(body),
3645                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3646                                        },
3647                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3648                                    })))
3649                            )
3650                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3651                }
3652            }
3653        }))
3654    }
3655
3656    fn set_freq(
3657        &self,
3658        param_bus_id: i32,
3659        param_addr: i32,
3660        param_freq: i32,
3661        context: &C) -> Box<dyn Future<Item=SetFreqResponse, Error=ApiError> + Send>
3662    {
3663        let mut uri = format!(
3664            "{}/pca9956b/{bus_id}/{addr}/freq/{freq}",
3665            self.base_path
3666            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3667            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3668            ,freq=utf8_percent_encode(&param_freq.to_string(), ID_ENCODE_SET)
3669        );
3670
3671        // Query parameters
3672        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3673        let query_string_str = query_string.finish();
3674        if !query_string_str.is_empty() {
3675            uri += "?";
3676            uri += &query_string_str;
3677        }
3678
3679        let uri = match Uri::from_str(&uri) {
3680            Ok(uri) => uri,
3681            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3682        };
3683
3684        let mut request = match hyper::Request::builder()
3685            .method("POST")
3686            .uri(uri)
3687            .body(Body::empty()) {
3688                Ok(req) => req,
3689                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3690        };
3691
3692        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3693        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3694            Ok(h) => h,
3695            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3696        });
3697
3698        Box::new(self.client_service.request(request)
3699                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3700                             .and_then(|mut response| {
3701            match response.status().as_u16() {
3702                200 => {
3703                    let body = response.into_body();
3704                    Box::new(
3705                        future::ok(
3706                            SetFreqResponse::OK
3707                        )
3708                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3709                },
3710                400 => {
3711                    let body = response.into_body();
3712                    Box::new(
3713                        body
3714                        .concat2()
3715                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3716                        .and_then(|body|
3717                        str::from_utf8(&body)
3718                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3719                                             .and_then(|body|
3720                                                 serde_json::from_str::<models::BadRequest>(body)
3721                                                     .map_err(|e| e.into())
3722                                             )
3723                                 )
3724                        .map(move |body| {
3725                            SetFreqResponse::BadRequest
3726                            (body)
3727                        })
3728                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3729                },
3730                502 => {
3731                    let body = response.into_body();
3732                    Box::new(
3733                        body
3734                        .concat2()
3735                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3736                        .and_then(|body|
3737                        str::from_utf8(&body)
3738                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3739                                             .and_then(|body|
3740                                                 serde_json::from_str::<models::OpError>(body)
3741                                                     .map_err(|e| e.into())
3742                                             )
3743                                 )
3744                        .map(move |body| {
3745                            SetFreqResponse::OperationFailed
3746                            (body)
3747                        })
3748                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3749                },
3750                code => {
3751                    let headers = response.headers().clone();
3752                    Box::new(response.into_body()
3753                            .take(100)
3754                            .concat2()
3755                            .then(move |body|
3756                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3757                                    code,
3758                                    headers,
3759                                    match body {
3760                                        Ok(ref body) => match str::from_utf8(body) {
3761                                            Ok(body) => Cow::from(body),
3762                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3763                                        },
3764                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3765                                    })))
3766                            )
3767                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3768                }
3769            }
3770        }))
3771    }
3772
3773    fn set_group(
3774        &self,
3775        param_bus_id: i32,
3776        param_addr: i32,
3777        param_group: models::Group,
3778        context: &C) -> Box<dyn Future<Item=SetGroupResponse, Error=ApiError> + Send>
3779    {
3780        let mut uri = format!(
3781            "{}/pca9956b/{bus_id}/{addr}/group/{group}",
3782            self.base_path
3783            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3784            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3785            ,group=utf8_percent_encode(&param_group.to_string(), ID_ENCODE_SET)
3786        );
3787
3788        // Query parameters
3789        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3790        let query_string_str = query_string.finish();
3791        if !query_string_str.is_empty() {
3792            uri += "?";
3793            uri += &query_string_str;
3794        }
3795
3796        let uri = match Uri::from_str(&uri) {
3797            Ok(uri) => uri,
3798            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3799        };
3800
3801        let mut request = match hyper::Request::builder()
3802            .method("POST")
3803            .uri(uri)
3804            .body(Body::empty()) {
3805                Ok(req) => req,
3806                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3807        };
3808
3809        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3810        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3811            Ok(h) => h,
3812            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3813        });
3814
3815        Box::new(self.client_service.request(request)
3816                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3817                             .and_then(|mut response| {
3818            match response.status().as_u16() {
3819                200 => {
3820                    let body = response.into_body();
3821                    Box::new(
3822                        future::ok(
3823                            SetGroupResponse::OK
3824                        )
3825                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3826                },
3827                400 => {
3828                    let body = response.into_body();
3829                    Box::new(
3830                        body
3831                        .concat2()
3832                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3833                        .and_then(|body|
3834                        str::from_utf8(&body)
3835                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3836                                             .and_then(|body|
3837                                                 serde_json::from_str::<models::BadRequest>(body)
3838                                                     .map_err(|e| e.into())
3839                                             )
3840                                 )
3841                        .map(move |body| {
3842                            SetGroupResponse::BadRequest
3843                            (body)
3844                        })
3845                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3846                },
3847                502 => {
3848                    let body = response.into_body();
3849                    Box::new(
3850                        body
3851                        .concat2()
3852                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3853                        .and_then(|body|
3854                        str::from_utf8(&body)
3855                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3856                                             .and_then(|body|
3857                                                 serde_json::from_str::<models::OpError>(body)
3858                                                     .map_err(|e| e.into())
3859                                             )
3860                                 )
3861                        .map(move |body| {
3862                            SetGroupResponse::OperationFailed
3863                            (body)
3864                        })
3865                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3866                },
3867                code => {
3868                    let headers = response.headers().clone();
3869                    Box::new(response.into_body()
3870                            .take(100)
3871                            .concat2()
3872                            .then(move |body|
3873                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3874                                    code,
3875                                    headers,
3876                                    match body {
3877                                        Ok(ref body) => match str::from_utf8(body) {
3878                                            Ok(body) => Cow::from(body),
3879                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3880                                        },
3881                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
3882                                    })))
3883                            )
3884                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3885                }
3886            }
3887        }))
3888    }
3889
3890    fn set_led_current(
3891        &self,
3892        param_bus_id: i32,
3893        param_addr: i32,
3894        param_led: i32,
3895        param_current: i32,
3896        context: &C) -> Box<dyn Future<Item=SetLedCurrentResponse, Error=ApiError> + Send>
3897    {
3898        let mut uri = format!(
3899            "{}/pca9956b/{bus_id}/{addr}/led/{led}/current/{current}",
3900            self.base_path
3901            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
3902            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
3903            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
3904            ,current=utf8_percent_encode(&param_current.to_string(), ID_ENCODE_SET)
3905        );
3906
3907        // Query parameters
3908        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
3909        let query_string_str = query_string.finish();
3910        if !query_string_str.is_empty() {
3911            uri += "?";
3912            uri += &query_string_str;
3913        }
3914
3915        let uri = match Uri::from_str(&uri) {
3916            Ok(uri) => uri,
3917            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
3918        };
3919
3920        let mut request = match hyper::Request::builder()
3921            .method("POST")
3922            .uri(uri)
3923            .body(Body::empty()) {
3924                Ok(req) => req,
3925                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
3926        };
3927
3928        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
3929        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
3930            Ok(h) => h,
3931            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
3932        });
3933
3934        Box::new(self.client_service.request(request)
3935                             .map_err(|e| ApiError(format!("No response received: {}", e)))
3936                             .and_then(|mut response| {
3937            match response.status().as_u16() {
3938                200 => {
3939                    let body = response.into_body();
3940                    Box::new(
3941                        future::ok(
3942                            SetLedCurrentResponse::OK
3943                        )
3944                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3945                },
3946                400 => {
3947                    let body = response.into_body();
3948                    Box::new(
3949                        body
3950                        .concat2()
3951                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3952                        .and_then(|body|
3953                        str::from_utf8(&body)
3954                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3955                                             .and_then(|body|
3956                                                 serde_json::from_str::<models::BadRequest>(body)
3957                                                     .map_err(|e| e.into())
3958                                             )
3959                                 )
3960                        .map(move |body| {
3961                            SetLedCurrentResponse::BadRequest
3962                            (body)
3963                        })
3964                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3965                },
3966                502 => {
3967                    let body = response.into_body();
3968                    Box::new(
3969                        body
3970                        .concat2()
3971                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
3972                        .and_then(|body|
3973                        str::from_utf8(&body)
3974                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
3975                                             .and_then(|body|
3976                                                 serde_json::from_str::<models::OpError>(body)
3977                                                     .map_err(|e| e.into())
3978                                             )
3979                                 )
3980                        .map(move |body| {
3981                            SetLedCurrentResponse::OperationFailed
3982                            (body)
3983                        })
3984                    ) as Box<dyn Future<Item=_, Error=_> + Send>
3985                },
3986                code => {
3987                    let headers = response.headers().clone();
3988                    Box::new(response.into_body()
3989                            .take(100)
3990                            .concat2()
3991                            .then(move |body|
3992                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
3993                                    code,
3994                                    headers,
3995                                    match body {
3996                                        Ok(ref body) => match str::from_utf8(body) {
3997                                            Ok(body) => Cow::from(body),
3998                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
3999                                        },
4000                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4001                                    })))
4002                            )
4003                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4004                }
4005            }
4006        }))
4007    }
4008
4009    fn set_led_error(
4010        &self,
4011        param_bus_id: i32,
4012        param_addr: i32,
4013        param_led: i32,
4014        param_error: models::LedError,
4015        context: &C) -> Box<dyn Future<Item=SetLedErrorResponse, Error=ApiError> + Send>
4016    {
4017        let mut uri = format!(
4018            "{}/pca9956b/{bus_id}/{addr}/led/{led}/error/{error}",
4019            self.base_path
4020            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4021            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4022            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
4023            ,error=utf8_percent_encode(&param_error.to_string(), ID_ENCODE_SET)
4024        );
4025
4026        // Query parameters
4027        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4028        let query_string_str = query_string.finish();
4029        if !query_string_str.is_empty() {
4030            uri += "?";
4031            uri += &query_string_str;
4032        }
4033
4034        let uri = match Uri::from_str(&uri) {
4035            Ok(uri) => uri,
4036            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4037        };
4038
4039        let mut request = match hyper::Request::builder()
4040            .method("POST")
4041            .uri(uri)
4042            .body(Body::empty()) {
4043                Ok(req) => req,
4044                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4045        };
4046
4047        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4048        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4049            Ok(h) => h,
4050            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4051        });
4052
4053        Box::new(self.client_service.request(request)
4054                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4055                             .and_then(|mut response| {
4056            match response.status().as_u16() {
4057                200 => {
4058                    let body = response.into_body();
4059                    Box::new(
4060                        future::ok(
4061                            SetLedErrorResponse::OK
4062                        )
4063                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4064                },
4065                400 => {
4066                    let body = response.into_body();
4067                    Box::new(
4068                        body
4069                        .concat2()
4070                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4071                        .and_then(|body|
4072                        str::from_utf8(&body)
4073                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4074                                             .and_then(|body|
4075                                                 serde_json::from_str::<models::BadRequest>(body)
4076                                                     .map_err(|e| e.into())
4077                                             )
4078                                 )
4079                        .map(move |body| {
4080                            SetLedErrorResponse::BadRequest
4081                            (body)
4082                        })
4083                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4084                },
4085                502 => {
4086                    let body = response.into_body();
4087                    Box::new(
4088                        body
4089                        .concat2()
4090                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4091                        .and_then(|body|
4092                        str::from_utf8(&body)
4093                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4094                                             .and_then(|body|
4095                                                 serde_json::from_str::<models::OpError>(body)
4096                                                     .map_err(|e| e.into())
4097                                             )
4098                                 )
4099                        .map(move |body| {
4100                            SetLedErrorResponse::OperationFailed
4101                            (body)
4102                        })
4103                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4104                },
4105                code => {
4106                    let headers = response.headers().clone();
4107                    Box::new(response.into_body()
4108                            .take(100)
4109                            .concat2()
4110                            .then(move |body|
4111                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4112                                    code,
4113                                    headers,
4114                                    match body {
4115                                        Ok(ref body) => match str::from_utf8(body) {
4116                                            Ok(body) => Cow::from(body),
4117                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4118                                        },
4119                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4120                                    })))
4121                            )
4122                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4123                }
4124            }
4125        }))
4126    }
4127
4128    fn set_led_info(
4129        &self,
4130        param_bus_id: i32,
4131        param_addr: i32,
4132        param_led: i32,
4133        param_led_info: models::LedInfo,
4134        context: &C) -> Box<dyn Future<Item=SetLedInfoResponse, Error=ApiError> + Send>
4135    {
4136        let mut uri = format!(
4137            "{}/pca9956b/{bus_id}/{addr}/led/{led}",
4138            self.base_path
4139            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4140            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4141            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
4142        );
4143
4144        // Query parameters
4145        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4146        let query_string_str = query_string.finish();
4147        if !query_string_str.is_empty() {
4148            uri += "?";
4149            uri += &query_string_str;
4150        }
4151
4152        let uri = match Uri::from_str(&uri) {
4153            Ok(uri) => uri,
4154            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4155        };
4156
4157        let mut request = match hyper::Request::builder()
4158            .method("POST")
4159            .uri(uri)
4160            .body(Body::empty()) {
4161                Ok(req) => req,
4162                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4163        };
4164
4165        let body = serde_json::to_string(&param_led_info).expect("impossible to fail to serialize");
4166                *request.body_mut() = Body::from(body);
4167
4168        let header = "application/json";
4169        request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
4170            Ok(h) => h,
4171            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create header: {} - {}", header, e))))
4172        });
4173        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4174        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4175            Ok(h) => h,
4176            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4177        });
4178
4179        Box::new(self.client_service.request(request)
4180                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4181                             .and_then(|mut response| {
4182            match response.status().as_u16() {
4183                200 => {
4184                    let body = response.into_body();
4185                    Box::new(
4186                        future::ok(
4187                            SetLedInfoResponse::OK
4188                        )
4189                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4190                },
4191                400 => {
4192                    let body = response.into_body();
4193                    Box::new(
4194                        body
4195                        .concat2()
4196                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4197                        .and_then(|body|
4198                        str::from_utf8(&body)
4199                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4200                                             .and_then(|body|
4201                                                 serde_json::from_str::<models::BadRequest>(body)
4202                                                     .map_err(|e| e.into())
4203                                             )
4204                                 )
4205                        .map(move |body| {
4206                            SetLedInfoResponse::BadRequest
4207                            (body)
4208                        })
4209                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4210                },
4211                502 => {
4212                    let body = response.into_body();
4213                    Box::new(
4214                        body
4215                        .concat2()
4216                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4217                        .and_then(|body|
4218                        str::from_utf8(&body)
4219                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4220                                             .and_then(|body|
4221                                                 serde_json::from_str::<models::OpError>(body)
4222                                                     .map_err(|e| e.into())
4223                                             )
4224                                 )
4225                        .map(move |body| {
4226                            SetLedInfoResponse::OperationFailed
4227                            (body)
4228                        })
4229                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4230                },
4231                code => {
4232                    let headers = response.headers().clone();
4233                    Box::new(response.into_body()
4234                            .take(100)
4235                            .concat2()
4236                            .then(move |body|
4237                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4238                                    code,
4239                                    headers,
4240                                    match body {
4241                                        Ok(ref body) => match str::from_utf8(body) {
4242                                            Ok(body) => Cow::from(body),
4243                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4244                                        },
4245                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4246                                    })))
4247                            )
4248                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4249                }
4250            }
4251        }))
4252    }
4253
4254    fn set_led_info_all(
4255        &self,
4256        param_bus_id: i32,
4257        param_addr: i32,
4258        param_led_info_array: models::LedInfoArray,
4259        context: &C) -> Box<dyn Future<Item=SetLedInfoAllResponse, Error=ApiError> + Send>
4260    {
4261        let mut uri = format!(
4262            "{}/pca9956b/{bus_id}/{addr}/led",
4263            self.base_path
4264            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4265            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4266        );
4267
4268        // Query parameters
4269        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4270        let query_string_str = query_string.finish();
4271        if !query_string_str.is_empty() {
4272            uri += "?";
4273            uri += &query_string_str;
4274        }
4275
4276        let uri = match Uri::from_str(&uri) {
4277            Ok(uri) => uri,
4278            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4279        };
4280
4281        let mut request = match hyper::Request::builder()
4282            .method("POST")
4283            .uri(uri)
4284            .body(Body::empty()) {
4285                Ok(req) => req,
4286                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4287        };
4288
4289        let body = serde_json::to_string(&param_led_info_array).expect("impossible to fail to serialize");
4290                *request.body_mut() = Body::from(body);
4291
4292        let header = "application/json";
4293        request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(header) {
4294            Ok(h) => h,
4295            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create header: {} - {}", header, e))))
4296        });
4297        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4298        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4299            Ok(h) => h,
4300            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4301        });
4302
4303        Box::new(self.client_service.request(request)
4304                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4305                             .and_then(|mut response| {
4306            match response.status().as_u16() {
4307                200 => {
4308                    let body = response.into_body();
4309                    Box::new(
4310                        future::ok(
4311                            SetLedInfoAllResponse::OK
4312                        )
4313                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4314                },
4315                400 => {
4316                    let body = response.into_body();
4317                    Box::new(
4318                        body
4319                        .concat2()
4320                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4321                        .and_then(|body|
4322                        str::from_utf8(&body)
4323                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4324                                             .and_then(|body|
4325                                                 serde_json::from_str::<models::BadRequest>(body)
4326                                                     .map_err(|e| e.into())
4327                                             )
4328                                 )
4329                        .map(move |body| {
4330                            SetLedInfoAllResponse::BadRequest
4331                            (body)
4332                        })
4333                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4334                },
4335                502 => {
4336                    let body = response.into_body();
4337                    Box::new(
4338                        body
4339                        .concat2()
4340                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4341                        .and_then(|body|
4342                        str::from_utf8(&body)
4343                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4344                                             .and_then(|body|
4345                                                 serde_json::from_str::<models::OpError>(body)
4346                                                     .map_err(|e| e.into())
4347                                             )
4348                                 )
4349                        .map(move |body| {
4350                            SetLedInfoAllResponse::OperationFailed
4351                            (body)
4352                        })
4353                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4354                },
4355                code => {
4356                    let headers = response.headers().clone();
4357                    Box::new(response.into_body()
4358                            .take(100)
4359                            .concat2()
4360                            .then(move |body|
4361                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4362                                    code,
4363                                    headers,
4364                                    match body {
4365                                        Ok(ref body) => match str::from_utf8(body) {
4366                                            Ok(body) => Cow::from(body),
4367                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4368                                        },
4369                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4370                                    })))
4371                            )
4372                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4373                }
4374            }
4375        }))
4376    }
4377
4378    fn set_led_pwm(
4379        &self,
4380        param_bus_id: i32,
4381        param_addr: i32,
4382        param_led: i32,
4383        param_pwm: i32,
4384        context: &C) -> Box<dyn Future<Item=SetLedPwmResponse, Error=ApiError> + Send>
4385    {
4386        let mut uri = format!(
4387            "{}/pca9956b/{bus_id}/{addr}/led/{led}/pwm/{pwm}",
4388            self.base_path
4389            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4390            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4391            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
4392            ,pwm=utf8_percent_encode(&param_pwm.to_string(), ID_ENCODE_SET)
4393        );
4394
4395        // Query parameters
4396        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4397        let query_string_str = query_string.finish();
4398        if !query_string_str.is_empty() {
4399            uri += "?";
4400            uri += &query_string_str;
4401        }
4402
4403        let uri = match Uri::from_str(&uri) {
4404            Ok(uri) => uri,
4405            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4406        };
4407
4408        let mut request = match hyper::Request::builder()
4409            .method("POST")
4410            .uri(uri)
4411            .body(Body::empty()) {
4412                Ok(req) => req,
4413                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4414        };
4415
4416        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4417        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4418            Ok(h) => h,
4419            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4420        });
4421
4422        Box::new(self.client_service.request(request)
4423                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4424                             .and_then(|mut response| {
4425            match response.status().as_u16() {
4426                200 => {
4427                    let body = response.into_body();
4428                    Box::new(
4429                        future::ok(
4430                            SetLedPwmResponse::OK
4431                        )
4432                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4433                },
4434                400 => {
4435                    let body = response.into_body();
4436                    Box::new(
4437                        body
4438                        .concat2()
4439                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4440                        .and_then(|body|
4441                        str::from_utf8(&body)
4442                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4443                                             .and_then(|body|
4444                                                 serde_json::from_str::<models::BadRequest>(body)
4445                                                     .map_err(|e| e.into())
4446                                             )
4447                                 )
4448                        .map(move |body| {
4449                            SetLedPwmResponse::BadRequest
4450                            (body)
4451                        })
4452                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4453                },
4454                502 => {
4455                    let body = response.into_body();
4456                    Box::new(
4457                        body
4458                        .concat2()
4459                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4460                        .and_then(|body|
4461                        str::from_utf8(&body)
4462                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4463                                             .and_then(|body|
4464                                                 serde_json::from_str::<models::OpError>(body)
4465                                                     .map_err(|e| e.into())
4466                                             )
4467                                 )
4468                        .map(move |body| {
4469                            SetLedPwmResponse::OperationFailed
4470                            (body)
4471                        })
4472                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4473                },
4474                code => {
4475                    let headers = response.headers().clone();
4476                    Box::new(response.into_body()
4477                            .take(100)
4478                            .concat2()
4479                            .then(move |body|
4480                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4481                                    code,
4482                                    headers,
4483                                    match body {
4484                                        Ok(ref body) => match str::from_utf8(body) {
4485                                            Ok(body) => Cow::from(body),
4486                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4487                                        },
4488                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4489                                    })))
4490                            )
4491                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4492                }
4493            }
4494        }))
4495    }
4496
4497    fn set_led_state(
4498        &self,
4499        param_bus_id: i32,
4500        param_addr: i32,
4501        param_led: i32,
4502        param_state: models::LedState,
4503        context: &C) -> Box<dyn Future<Item=SetLedStateResponse, Error=ApiError> + Send>
4504    {
4505        let mut uri = format!(
4506            "{}/pca9956b/{bus_id}/{addr}/led/{led}/state/{state}",
4507            self.base_path
4508            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4509            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4510            ,led=utf8_percent_encode(&param_led.to_string(), ID_ENCODE_SET)
4511            ,state=utf8_percent_encode(&param_state.to_string(), ID_ENCODE_SET)
4512        );
4513
4514        // Query parameters
4515        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4516        let query_string_str = query_string.finish();
4517        if !query_string_str.is_empty() {
4518            uri += "?";
4519            uri += &query_string_str;
4520        }
4521
4522        let uri = match Uri::from_str(&uri) {
4523            Ok(uri) => uri,
4524            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4525        };
4526
4527        let mut request = match hyper::Request::builder()
4528            .method("POST")
4529            .uri(uri)
4530            .body(Body::empty()) {
4531                Ok(req) => req,
4532                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4533        };
4534
4535        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4536        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4537            Ok(h) => h,
4538            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4539        });
4540
4541        Box::new(self.client_service.request(request)
4542                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4543                             .and_then(|mut response| {
4544            match response.status().as_u16() {
4545                200 => {
4546                    let body = response.into_body();
4547                    Box::new(
4548                        future::ok(
4549                            SetLedStateResponse::OK
4550                        )
4551                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4552                },
4553                400 => {
4554                    let body = response.into_body();
4555                    Box::new(
4556                        body
4557                        .concat2()
4558                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4559                        .and_then(|body|
4560                        str::from_utf8(&body)
4561                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4562                                             .and_then(|body|
4563                                                 serde_json::from_str::<models::BadRequest>(body)
4564                                                     .map_err(|e| e.into())
4565                                             )
4566                                 )
4567                        .map(move |body| {
4568                            SetLedStateResponse::BadRequest
4569                            (body)
4570                        })
4571                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4572                },
4573                502 => {
4574                    let body = response.into_body();
4575                    Box::new(
4576                        body
4577                        .concat2()
4578                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4579                        .and_then(|body|
4580                        str::from_utf8(&body)
4581                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4582                                             .and_then(|body|
4583                                                 serde_json::from_str::<models::OpError>(body)
4584                                                     .map_err(|e| e.into())
4585                                             )
4586                                 )
4587                        .map(move |body| {
4588                            SetLedStateResponse::OperationFailed
4589                            (body)
4590                        })
4591                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4592                },
4593                code => {
4594                    let headers = response.headers().clone();
4595                    Box::new(response.into_body()
4596                            .take(100)
4597                            .concat2()
4598                            .then(move |body|
4599                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4600                                    code,
4601                                    headers,
4602                                    match body {
4603                                        Ok(ref body) => match str::from_utf8(body) {
4604                                            Ok(body) => Cow::from(body),
4605                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4606                                        },
4607                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4608                                    })))
4609                            )
4610                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4611                }
4612            }
4613        }))
4614    }
4615
4616    fn set_offset(
4617        &self,
4618        param_bus_id: i32,
4619        param_addr: i32,
4620        param_offset: i32,
4621        context: &C) -> Box<dyn Future<Item=SetOffsetResponse, Error=ApiError> + Send>
4622    {
4623        let mut uri = format!(
4624            "{}/pca9956b/{bus_id}/{addr}/offset/{offset}",
4625            self.base_path
4626            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4627            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4628            ,offset=utf8_percent_encode(&param_offset.to_string(), ID_ENCODE_SET)
4629        );
4630
4631        // Query parameters
4632        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4633        let query_string_str = query_string.finish();
4634        if !query_string_str.is_empty() {
4635            uri += "?";
4636            uri += &query_string_str;
4637        }
4638
4639        let uri = match Uri::from_str(&uri) {
4640            Ok(uri) => uri,
4641            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4642        };
4643
4644        let mut request = match hyper::Request::builder()
4645            .method("POST")
4646            .uri(uri)
4647            .body(Body::empty()) {
4648                Ok(req) => req,
4649                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4650        };
4651
4652        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4653        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4654            Ok(h) => h,
4655            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4656        });
4657
4658        Box::new(self.client_service.request(request)
4659                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4660                             .and_then(|mut response| {
4661            match response.status().as_u16() {
4662                200 => {
4663                    let body = response.into_body();
4664                    Box::new(
4665                        future::ok(
4666                            SetOffsetResponse::OK
4667                        )
4668                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4669                },
4670                400 => {
4671                    let body = response.into_body();
4672                    Box::new(
4673                        body
4674                        .concat2()
4675                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4676                        .and_then(|body|
4677                        str::from_utf8(&body)
4678                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4679                                             .and_then(|body|
4680                                                 serde_json::from_str::<models::BadRequest>(body)
4681                                                     .map_err(|e| e.into())
4682                                             )
4683                                 )
4684                        .map(move |body| {
4685                            SetOffsetResponse::BadRequest
4686                            (body)
4687                        })
4688                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4689                },
4690                502 => {
4691                    let body = response.into_body();
4692                    Box::new(
4693                        body
4694                        .concat2()
4695                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4696                        .and_then(|body|
4697                        str::from_utf8(&body)
4698                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4699                                             .and_then(|body|
4700                                                 serde_json::from_str::<models::OpError>(body)
4701                                                     .map_err(|e| e.into())
4702                                             )
4703                                 )
4704                        .map(move |body| {
4705                            SetOffsetResponse::OperationFailed
4706                            (body)
4707                        })
4708                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4709                },
4710                code => {
4711                    let headers = response.headers().clone();
4712                    Box::new(response.into_body()
4713                            .take(100)
4714                            .concat2()
4715                            .then(move |body|
4716                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4717                                    code,
4718                                    headers,
4719                                    match body {
4720                                        Ok(ref body) => match str::from_utf8(body) {
4721                                            Ok(body) => Cow::from(body),
4722                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4723                                        },
4724                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4725                                    })))
4726                            )
4727                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4728                }
4729            }
4730        }))
4731    }
4732
4733    fn set_output_change(
4734        &self,
4735        param_bus_id: i32,
4736        param_addr: i32,
4737        param_output_change: models::OutputChange,
4738        context: &C) -> Box<dyn Future<Item=SetOutputChangeResponse, Error=ApiError> + Send>
4739    {
4740        let mut uri = format!(
4741            "{}/pca9956b/{bus_id}/{addr}/outputChange/{output_change}",
4742            self.base_path
4743            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4744            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4745            ,output_change=utf8_percent_encode(&param_output_change.to_string(), ID_ENCODE_SET)
4746        );
4747
4748        // Query parameters
4749        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4750        let query_string_str = query_string.finish();
4751        if !query_string_str.is_empty() {
4752            uri += "?";
4753            uri += &query_string_str;
4754        }
4755
4756        let uri = match Uri::from_str(&uri) {
4757            Ok(uri) => uri,
4758            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4759        };
4760
4761        let mut request = match hyper::Request::builder()
4762            .method("POST")
4763            .uri(uri)
4764            .body(Body::empty()) {
4765                Ok(req) => req,
4766                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4767        };
4768
4769        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4770        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4771            Ok(h) => h,
4772            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4773        });
4774
4775        Box::new(self.client_service.request(request)
4776                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4777                             .and_then(|mut response| {
4778            match response.status().as_u16() {
4779                200 => {
4780                    let body = response.into_body();
4781                    Box::new(
4782                        future::ok(
4783                            SetOutputChangeResponse::OK
4784                        )
4785                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4786                },
4787                400 => {
4788                    let body = response.into_body();
4789                    Box::new(
4790                        body
4791                        .concat2()
4792                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4793                        .and_then(|body|
4794                        str::from_utf8(&body)
4795                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4796                                             .and_then(|body|
4797                                                 serde_json::from_str::<models::BadRequest>(body)
4798                                                     .map_err(|e| e.into())
4799                                             )
4800                                 )
4801                        .map(move |body| {
4802                            SetOutputChangeResponse::BadRequest
4803                            (body)
4804                        })
4805                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4806                },
4807                502 => {
4808                    let body = response.into_body();
4809                    Box::new(
4810                        body
4811                        .concat2()
4812                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4813                        .and_then(|body|
4814                        str::from_utf8(&body)
4815                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4816                                             .and_then(|body|
4817                                                 serde_json::from_str::<models::OpError>(body)
4818                                                     .map_err(|e| e.into())
4819                                             )
4820                                 )
4821                        .map(move |body| {
4822                            SetOutputChangeResponse::OperationFailed
4823                            (body)
4824                        })
4825                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4826                },
4827                code => {
4828                    let headers = response.headers().clone();
4829                    Box::new(response.into_body()
4830                            .take(100)
4831                            .concat2()
4832                            .then(move |body|
4833                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4834                                    code,
4835                                    headers,
4836                                    match body {
4837                                        Ok(ref body) => match str::from_utf8(body) {
4838                                            Ok(body) => Cow::from(body),
4839                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4840                                        },
4841                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4842                                    })))
4843                            )
4844                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4845                }
4846            }
4847        }))
4848    }
4849
4850    fn set_pwm(
4851        &self,
4852        param_bus_id: i32,
4853        param_addr: i32,
4854        param_pwm: i32,
4855        context: &C) -> Box<dyn Future<Item=SetPwmResponse, Error=ApiError> + Send>
4856    {
4857        let mut uri = format!(
4858            "{}/pca9956b/{bus_id}/{addr}/pwm/{pwm}",
4859            self.base_path
4860            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4861            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4862            ,pwm=utf8_percent_encode(&param_pwm.to_string(), ID_ENCODE_SET)
4863        );
4864
4865        // Query parameters
4866        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4867        let query_string_str = query_string.finish();
4868        if !query_string_str.is_empty() {
4869            uri += "?";
4870            uri += &query_string_str;
4871        }
4872
4873        let uri = match Uri::from_str(&uri) {
4874            Ok(uri) => uri,
4875            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4876        };
4877
4878        let mut request = match hyper::Request::builder()
4879            .method("POST")
4880            .uri(uri)
4881            .body(Body::empty()) {
4882                Ok(req) => req,
4883                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
4884        };
4885
4886        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
4887        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
4888            Ok(h) => h,
4889            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
4890        });
4891
4892        Box::new(self.client_service.request(request)
4893                             .map_err(|e| ApiError(format!("No response received: {}", e)))
4894                             .and_then(|mut response| {
4895            match response.status().as_u16() {
4896                200 => {
4897                    let body = response.into_body();
4898                    Box::new(
4899                        future::ok(
4900                            SetPwmResponse::OK
4901                        )
4902                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4903                },
4904                400 => {
4905                    let body = response.into_body();
4906                    Box::new(
4907                        body
4908                        .concat2()
4909                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4910                        .and_then(|body|
4911                        str::from_utf8(&body)
4912                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4913                                             .and_then(|body|
4914                                                 serde_json::from_str::<models::BadRequest>(body)
4915                                                     .map_err(|e| e.into())
4916                                             )
4917                                 )
4918                        .map(move |body| {
4919                            SetPwmResponse::BadRequest
4920                            (body)
4921                        })
4922                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4923                },
4924                502 => {
4925                    let body = response.into_body();
4926                    Box::new(
4927                        body
4928                        .concat2()
4929                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
4930                        .and_then(|body|
4931                        str::from_utf8(&body)
4932                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
4933                                             .and_then(|body|
4934                                                 serde_json::from_str::<models::OpError>(body)
4935                                                     .map_err(|e| e.into())
4936                                             )
4937                                 )
4938                        .map(move |body| {
4939                            SetPwmResponse::OperationFailed
4940                            (body)
4941                        })
4942                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4943                },
4944                code => {
4945                    let headers = response.headers().clone();
4946                    Box::new(response.into_body()
4947                            .take(100)
4948                            .concat2()
4949                            .then(move |body|
4950                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
4951                                    code,
4952                                    headers,
4953                                    match body {
4954                                        Ok(ref body) => match str::from_utf8(body) {
4955                                            Ok(body) => Cow::from(body),
4956                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
4957                                        },
4958                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
4959                                    })))
4960                            )
4961                    ) as Box<dyn Future<Item=_, Error=_> + Send>
4962                }
4963            }
4964        }))
4965    }
4966
4967    fn set_sleep(
4968        &self,
4969        param_bus_id: i32,
4970        param_addr: i32,
4971        param_sleep: bool,
4972        context: &C) -> Box<dyn Future<Item=SetSleepResponse, Error=ApiError> + Send>
4973    {
4974        let mut uri = format!(
4975            "{}/pca9956b/{bus_id}/{addr}/sleep/{sleep}",
4976            self.base_path
4977            ,bus_id=utf8_percent_encode(&param_bus_id.to_string(), ID_ENCODE_SET)
4978            ,addr=utf8_percent_encode(&param_addr.to_string(), ID_ENCODE_SET)
4979            ,sleep=utf8_percent_encode(&param_sleep.to_string(), ID_ENCODE_SET)
4980        );
4981
4982        // Query parameters
4983        let mut query_string = url::form_urlencoded::Serializer::new("".to_owned());
4984        let query_string_str = query_string.finish();
4985        if !query_string_str.is_empty() {
4986            uri += "?";
4987            uri += &query_string_str;
4988        }
4989
4990        let uri = match Uri::from_str(&uri) {
4991            Ok(uri) => uri,
4992            Err(err) => return Box::new(future::err(ApiError(format!("Unable to build URI: {}", err)))),
4993        };
4994
4995        let mut request = match hyper::Request::builder()
4996            .method("POST")
4997            .uri(uri)
4998            .body(Body::empty()) {
4999                Ok(req) => req,
5000                Err(e) => return Box::new(future::err(ApiError(format!("Unable to create request: {}", e))))
5001        };
5002
5003        let header = HeaderValue::from_str((context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str());
5004        request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
5005            Ok(h) => h,
5006            Err(e) => return Box::new(future::err(ApiError(format!("Unable to create X-Span ID header value: {}", e))))
5007        });
5008
5009        Box::new(self.client_service.request(request)
5010                             .map_err(|e| ApiError(format!("No response received: {}", e)))
5011                             .and_then(|mut response| {
5012            match response.status().as_u16() {
5013                200 => {
5014                    let body = response.into_body();
5015                    Box::new(
5016                        future::ok(
5017                            SetSleepResponse::OK
5018                        )
5019                    ) as Box<dyn Future<Item=_, Error=_> + Send>
5020                },
5021                400 => {
5022                    let body = response.into_body();
5023                    Box::new(
5024                        body
5025                        .concat2()
5026                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
5027                        .and_then(|body|
5028                        str::from_utf8(&body)
5029                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
5030                                             .and_then(|body|
5031                                                 serde_json::from_str::<models::BadRequest>(body)
5032                                                     .map_err(|e| e.into())
5033                                             )
5034                                 )
5035                        .map(move |body| {
5036                            SetSleepResponse::BadRequest
5037                            (body)
5038                        })
5039                    ) as Box<dyn Future<Item=_, Error=_> + Send>
5040                },
5041                502 => {
5042                    let body = response.into_body();
5043                    Box::new(
5044                        body
5045                        .concat2()
5046                        .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
5047                        .and_then(|body|
5048                        str::from_utf8(&body)
5049                                             .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))
5050                                             .and_then(|body|
5051                                                 serde_json::from_str::<models::OpError>(body)
5052                                                     .map_err(|e| e.into())
5053                                             )
5054                                 )
5055                        .map(move |body| {
5056                            SetSleepResponse::OperationFailed
5057                            (body)
5058                        })
5059                    ) as Box<dyn Future<Item=_, Error=_> + Send>
5060                },
5061                code => {
5062                    let headers = response.headers().clone();
5063                    Box::new(response.into_body()
5064                            .take(100)
5065                            .concat2()
5066                            .then(move |body|
5067                                future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}",
5068                                    code,
5069                                    headers,
5070                                    match body {
5071                                        Ok(ref body) => match str::from_utf8(body) {
5072                                            Ok(body) => Cow::from(body),
5073                                            Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)),
5074                                        },
5075                                        Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
5076                                    })))
5077                            )
5078                    ) as Box<dyn Future<Item=_, Error=_> + Send>
5079                }
5080            }
5081        }))
5082    }
5083
5084}