Skip to content

Commit

Permalink
Feature/skip internal (#7)
Browse files Browse the repository at this point in the history
* Updated uom to compile

* Skipped internal fields

Sys.type has been missing from the response suddenly

* Fixups from clippy
  • Loading branch information
RadekDvorak authored Nov 29, 2021
1 parent cad878d commit 5220991
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde_derive = "^1.0"
serde_json = "^1.0"
structopt = { version = "^0.3.11" }
tokio = { version = "^0.2", features = ["full"] }
uom = "^0.27.0"
uom = "^0.31.1"
url = "^2.1.1"
sloggers = "^0.3.5"
slog = "^2.5.2"
Expand Down
18 changes: 9 additions & 9 deletions src/app/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ impl<'a> Temperature<'a> {

pub fn from_publishing_args(args: &'a dyn PublishingInfo) -> Self {
Self::new(
&args.get_prefix(),
&args.get_device_name(),
&args.get_channel_thermometer(),
args.get_prefix(),
args.get_device_name(),
args.get_channel_thermometer(),
)
}
}
Expand Down Expand Up @@ -65,9 +65,9 @@ impl<'a> Pressure<'a> {

pub fn from_publishing_args(args: &'a dyn PublishingInfo) -> Self {
Self::new(
&args.get_prefix(),
&args.get_device_name(),
&args.get_channel_barometer(),
args.get_prefix(),
args.get_device_name(),
args.get_channel_barometer(),
)
}
}
Expand Down Expand Up @@ -100,9 +100,9 @@ impl<'a> Humidity<'a> {

pub fn from_publishing_args(args: &'a dyn PublishingInfo) -> Self {
Self::new(
&args.get_prefix(),
&args.get_device_name(),
&args.get_channel_hygrometer(),
args.get_prefix(),
args.get_device_name(),
args.get_channel_hygrometer(),
)
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Args {
#[structopt(env)]
pub city_id: u32,

#[structopt(short, long, env, default_value = & Units::CELSIUS.value().unwrap(), possible_values = & Units::variants())]
#[structopt(short, long, env, default_value = & Units::Celsius.value().unwrap(), possible_values = & Units::variants())]
pub units: Units,

#[structopt(flatten)]
Expand Down Expand Up @@ -122,25 +122,25 @@ impl PublishingInfo for MqttPublishingArgs {

#[derive(Debug)]
pub enum Units {
KELVIN,
FAHRENHEIT,
CELSIUS,
Kelvin,
Fahrenheit,
Celsius,
}

impl Units {
pub fn convert_temperature(&self, temperature: ThermodynamicTemperature) -> f32 {
match *self {
Units::KELVIN => temperature.get::<thermodynamic_temperature::kelvin>(),
Units::FAHRENHEIT => temperature.get::<thermodynamic_temperature::degree_fahrenheit>(),
Units::CELSIUS => temperature.get::<thermodynamic_temperature::degree_celsius>(),
Units::Kelvin => temperature.get::<thermodynamic_temperature::kelvin>(),
Units::Fahrenheit => temperature.get::<thermodynamic_temperature::degree_fahrenheit>(),
Units::Celsius => temperature.get::<thermodynamic_temperature::degree_celsius>(),
}
}

pub fn value(&self) -> Option<&'static str> {
match *self {
Units::CELSIUS => Some("celsius"),
Units::FAHRENHEIT => Some("fahrenheit"),
Units::KELVIN => None,
Units::Celsius => Some("celsius"),
Units::Fahrenheit => Some("fahrenheit"),
Units::Kelvin => None,
}
}

Expand All @@ -153,9 +153,9 @@ impl FromStr for Units {
type Err = ParseError;
fn from_str(day: &str) -> Result<Self, Self::Err> {
match day {
"celsius" => Ok(Units::CELSIUS),
"fahrenheit" => Ok(Units::FAHRENHEIT),
"kelvin" => Ok(Units::KELVIN),
"celsius" => Ok(Units::Celsius),
"fahrenheit" => Ok(Units::Fahrenheit),
"kelvin" => Ok(Units::Kelvin),
_ => unreachable!(),
}
}
Expand All @@ -166,9 +166,9 @@ pub struct ApiKey {
value: String,
}

impl Into<String> for ApiKey {
fn into(self) -> String {
self.value
impl From<ApiKey> for String {
fn from(k: ApiKey) -> Self {
k.value
}
}

Expand All @@ -193,9 +193,9 @@ impl FromStr for User {
}
}

impl Into<String> for User {
fn into(self) -> String {
self.0
impl From<User> for String {
fn from(u: User) -> Self {
u.0
}
}

Expand All @@ -210,8 +210,8 @@ impl FromStr for Password {
}
}

impl Into<String> for Password {
fn into(self) -> String {
self.0
impl From<Password> for String {
fn from(p: Password) -> Self {
p.0
}
}
2 changes: 1 addition & 1 deletion src/domain/current_weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Humidity {
#[allow(dead_code)]
pub fn is_valid(humidity: f32) -> bool {
let rounded = Self::round(humidity);
rounded >= 0.0 && rounded <= 100.0
(0.0..=100.0).contains(&rounded)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/location_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ impl<'a> LocationSpecifier<'a> {
pub fn format(&'a self) -> Vec<(String, String)> {
match &self {
LocationSpecifier::CityAndCountryName { city, country } => {
if *country == "" {
return vec![("q".to_string(), (*city).to_string())];
return if country.is_empty() {
vec![("q".to_string(), (*city).to_string())]
} else {
return vec![("q".to_string(), format!("{},{}", city, country))];
vec![("q".to_string(), format!("{},{}", city, country))]
}
}
LocationSpecifier::CityId(id) => {
Expand All @@ -53,10 +53,10 @@ impl<'a> LocationSpecifier<'a> {
];
}
LocationSpecifier::ZipCode { zip, country } => {
if *country == "" {
return vec![("zip".to_string(), (*zip).to_string())];
return if country.is_empty() {
vec![("zip".to_string(), (*zip).to_string())]
} else {
return vec![("zip".to_string(), format!("{},{}", zip, country))];
vec![("zip".to_string(), format!("{},{}", zip, country))]
}
}
LocationSpecifier::BoundingBox {
Expand Down
2 changes: 1 addition & 1 deletion src/weather_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
{
pub fn new(location_specifier: LocationSpecifier<'a>, api_key: T) -> Self {
let default_base_url = "https://api.openweathermap.org/data/2.5/";
let base_url: Url = Url::parse(&default_base_url)
let base_url: Url = Url::parse(default_base_url)
.unwrap_or_else(|_| panic!("Broken default hardcoded base URL {}", &default_base_url));

OpenWeatherMapClientBuilder {
Expand Down
5 changes: 4 additions & 1 deletion src/weather_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ pub struct ErrorReport {

#[derive(Serialize, Deserialize, Debug)]
pub struct Sys {
#[serde(rename = "type")]
#[serde(rename = "type", skip_deserializing)]
pub message_type: u32,
#[serde(skip_deserializing)]
pub id: u32,
#[serde(skip_deserializing)]
pub message: Option<f32>,
pub country: String,
pub sunrise: u64,
Expand All @@ -80,5 +82,6 @@ pub struct WeatherReportCurrent {
pub sys: Sys,
pub id: u64,
pub name: String,
#[serde(skip_deserializing)]
pub cod: u16,
}

0 comments on commit 5220991

Please sign in to comment.