Applied clippy rules

This commit is contained in:
2023-04-10 01:29:48 +02:00
parent 7d5ce71e5b
commit 839c0a1c57
17 changed files with 139 additions and 53 deletions

View File

@@ -23,7 +23,7 @@ pub trait GoogleHomeDevice: AsOnOff + AsScene {
fn sync(&self) -> response::sync::Device {
let name = self.get_device_name();
let mut device = response::sync::Device::new(&self.get_id(), &name.name, self.get_device_type());
let mut device = response::sync::Device::new(self.get_id(), &name.name, self.get_device_type());
device.name = name;
device.will_report_state = self.will_report_state();
@@ -49,7 +49,7 @@ pub trait GoogleHomeDevice: AsOnOff + AsScene {
device.traits = traits;
return device;
device
}
fn query(&self) -> response::query::Device {
@@ -65,7 +65,7 @@ pub trait GoogleHomeDevice: AsOnOff + AsScene {
.ok();
}
return device;
device
}
fn execute(&mut self, command: &CommandType) -> Result<(), ErrorCode> {
@@ -84,7 +84,7 @@ pub trait GoogleHomeDevice: AsOnOff + AsScene {
},
}
return Ok(());
Ok(())
}
}

View File

@@ -21,16 +21,16 @@ impl GoogleHome {
Self { user_id: user_id.into() }
}
pub fn handle_request(&self, request: Request, mut devices: &mut HashMap<&str, &mut dyn GoogleHomeDevice>) -> Result<Response, FullfillmentError> {
pub fn handle_request(&self, request: Request, devices: &mut HashMap<&str, &mut dyn GoogleHomeDevice>) -> Result<Response, FullfillmentError> {
// TODO: What do we do if we actually get more then one thing in the input array, right now
// we only respond to the first thing
let payload = request
.inputs
.into_iter()
.map(|input| match input {
Intent::Sync => ResponsePayload::Sync(self.sync(&devices)),
Intent::Query(payload) => ResponsePayload::Query(self.query(payload, &devices)),
Intent::Execute(payload) => ResponsePayload::Execute(self.execute(payload, &mut devices)),
Intent::Sync => ResponsePayload::Sync(self.sync(devices)),
Intent::Query(payload) => ResponsePayload::Query(self.query(payload, devices)),
Intent::Execute(payload) => ResponsePayload::Execute(self.execute(payload, devices)),
}).next();
payload
@@ -45,7 +45,7 @@ impl GoogleHome {
.map(|(_, device)| device.sync())
.collect::<Vec<_>>();
return resp_payload;
resp_payload
}
fn query(&self, payload: request::query::Payload, devices: &HashMap<&str, &mut dyn GoogleHomeDevice>) -> query::Payload {
@@ -63,10 +63,10 @@ impl GoogleHome {
device
}, |device| device.query());
return (id, device);
(id, device)
}).collect();
return resp_payload;
resp_payload
}
@@ -100,9 +100,9 @@ impl GoogleHome {
// TODO: We only get one error not all errors
if let Err(err) = results {
return (id, Err(err));
(id, Err(err))
} else {
return (id, Ok(true));
(id, Ok(true))
}
})
}).for_each(|(id, state)| {
@@ -126,7 +126,7 @@ impl GoogleHome {
}
});
return resp_payload;
resp_payload
}
}
@@ -157,11 +157,11 @@ mod tests {
name.add_default_name("Outlet");
name.add_nickname("Nightlight");
return name;
name
}
fn get_id(&self) -> &str {
return &self.name;
&self.name
}
fn is_online(&self) -> bool {
@@ -212,7 +212,7 @@ mod tests {
}
fn get_id(&self) -> &str {
return "living/party_mode";
"living/party_mode"
}
fn is_online(&self) -> bool {

View File

@@ -96,7 +96,7 @@ mod tests {
assert_eq!(payload.commands[0].devices[1].id, "456");
assert_eq!(payload.commands[0].execution.len(), 1);
match payload.commands[0].execution[0] {
CommandType::OnOff{on} => assert_eq!(on, true),
CommandType::OnOff{on} => assert!(on),
_ => panic!("Expected OnOff")
}
},

View File

@@ -24,6 +24,12 @@ impl Payload {
}
}
impl Default for Payload {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Command {
@@ -78,8 +84,7 @@ mod tests {
fn serialize() {
let mut execute_resp = Payload::new();
let mut state = State::default();
state.on = Some(true);
let state = State { on: Some(true) };
let mut command = Command::new(Status::Success);
command.states = Some(States {
online: true,

View File

@@ -24,6 +24,12 @@ impl Payload {
}
}
impl Default for Payload {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Status {
@@ -64,6 +70,12 @@ impl Device {
}
}
impl Default for Device {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;