-
Notifications
You must be signed in to change notification settings - Fork 14
move subscription retrying into connect_and_subscribe_sensor(); simplify #11
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
Conversation
33f7016 to
f50b6b5
Compare
publish-mqtt/src/main.rs
Outdated
|
|
||
| let mut backoff = ExponentialBackoff::default(); | ||
| backoff.max_elapsed_time = | ||
| Some(SENSOR_CONNECT_RESERVATION_TIMEOUT - 2 * DBUS_METHOD_CALL_TIMEOUT); |
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'd rather this just be a constant which is enough small enough than SENSOR_CONNECT_RESERVATION_TIMEOUT, rather than making DBUS_METHOD_CALL_TIMEOUT public.
publish-mqtt/src/main.rs
Outdated
| Some(SENSOR_CONNECT_RESERVATION_TIMEOUT - 2 * DBUS_METHOD_CALL_TIMEOUT); | ||
|
|
||
| (|| session.start_notify_sensor(id).map_err(Into::into)) | ||
| .retry(backoff) |
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.
Use UFCS for this retry call, as it is confusing for the trait to be added to the closure.
| impl SensorStore for Vec<Sensor> { | ||
| fn get_by_id(&self, id: &DeviceId) -> Option<&Sensor> { | ||
| self.iter().find(|s| &s.id == id) | ||
| } |
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.
Nit: Blank line between methods?
mijia/src/lib.rs
Outdated
| /// 500 in little-endian | ||
| const CONNECTION_INTERVAL_500_MS: [u8; 3] = [0xF4, 0x01, 0x00]; | ||
| const DBUS_METHOD_CALL_TIMEOUT: Duration = Duration::from_secs(30); | ||
| pub const DBUS_METHOD_CALL_TIMEOUT: Duration = Duration::from_secs(30); |
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'd prefer this not be public.
| sensor.name, sensor.connection_status, e | ||
| ); | ||
| } | ||
| let SensorState { sensors, homie, .. } = state.deref_mut(); |
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 destructuring thing isn't actually needed, you can just use the `let state = &mut *state.lock().await;" trick that we use elsewhere.
adding extension traits to closures is a bit non-obvious.
fb14632 to
1a45d5a
Compare
This allows us to delete the SubscribingFailedOnce state, because it is folded into Connecting.
There are also some meanderings about using id rather than idx to identify sensors. Once we stop caring about the ConnectionStatus while connecting. Mijia only cares about the id, so if we can also only care about the id then we are only holding a single piece of state across the connection attempt, which feels quite elegant.