这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@alsuren
Copy link
Owner

@alsuren alsuren commented Sep 26, 2020

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.

@alsuren alsuren changed the title move subscription retrying into connect_and_subscribe_sensor() move subscription retrying into connect_and_subscribe_sensor(); simplify Sep 26, 2020

let mut backoff = ExponentialBackoff::default();
backoff.max_elapsed_time =
Some(SENSOR_CONNECT_RESERVATION_TIMEOUT - 2 * DBUS_METHOD_CALL_TIMEOUT);
Copy link
Collaborator

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.

Some(SENSOR_CONNECT_RESERVATION_TIMEOUT - 2 * DBUS_METHOD_CALL_TIMEOUT);

(|| session.start_notify_sensor(id).map_err(Into::into))
.retry(backoff)
Copy link
Collaborator

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)
}
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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.

@qwandor-google qwandor-google merged commit 1a45d5a into master Sep 29, 2020
@qwandor-google qwandor-google deleted the retry-subscribe branch September 29, 2020 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants