-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MTW sentence parser #77
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your fist-time contribution 🎉
I have left a few notes on the PR, I'm eager to merge it asap 😊
src/sentences/mtw.rs
Outdated
let (i, temperature_value) = opt(float)(i)?; | ||
let (i, unit) = opt(preceded(char(','), one_of("C")))(i)?; | ||
let unit = unit.map(|ch| match ch { | ||
'C' => MtwUnit::Celcius, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other options apart from Celsius
? I didn't find anything else, so maybe it's a good idea to just remove the field from the MtwData
. The documentation can be specific for the field - only Celsius.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had searched for this but it's kinda strange, it's described as a field in the documentation (and implemented as is in other libs) but this field seems to can only be celsius. Also didn't find any example with something else, so i assume we can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
src/sentences/mtw.rs
Outdated
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum MtwUnit { | ||
Celcius, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually a small typo, should be Celsius
with an s
src/sentences/mtw.rs
Outdated
pub temperature: Option<f32>, | ||
pub temperature_unit: Option<MtwUnit>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's just leave
temperature
and add a documentation block///
that it is only "degrees Celsius" - use
double
(f64) instead. We've discussed this before and we should unify the api to always usef64
.
src/sentences/mtw.rs
Outdated
assert_eq!(s.checksum, 0x20); | ||
let mtw_data = parse_mtw(s).unwrap(); | ||
assert_eq!(Some(17.9), mtw_data.temperature); | ||
assert_eq!(None, mtw_data.temperature_unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should cause an error instead of Option::None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you again for your contribution
#54