Buttplug sex toy control library
20
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implemented a deserializer for the battery field.

The battery field needs to be able to handle when the JSON field for it is null.

Because when a toy connects, Lovense Connect will send null in the battery field
until the toy has been fully initialized im guessing?

In my opinion Lovense Connect should just send 0 instead of sending null when a toy isnt fully initialized.

However the bug behaviour is:
1. Connect a ButtplugClient
2. Start Lovense connect
3. Connect toy to Lovense Connect
4. Call ButtplugClient::start_scanning()
5. The json deserialization will fail and will not parse the incoming connected toy.
6. Scan again and you will get the battery number.

authored by

SutekhVRC and committed by qdot.tngl.sh 5aa44a15 48d2a7d2

+19 -2
+19 -2
buttplug/src/server/device/hardware/communication/lovense_connect_service/lovense_connect_service_comm_manager.rs
··· 19 19 use async_trait::async_trait; 20 20 use dashmap::DashSet; 21 21 use reqwest::StatusCode; 22 - use serde::Deserialize; 22 + use serde::{Deserialize, Deserializer}; 23 23 use serde_aux::prelude::*; 24 24 use std::{collections::HashMap, time::Duration}; 25 25 use tokio::sync::mpsc; ··· 39 39 deserialize_with = "deserialize_number_from_string" 40 40 )] 41 41 pub _version: i32, 42 - #[serde(deserialize_with = "deserialize_number_from_string")] 42 + /* ~ Sutekh 43 + * Implemented a deserializer for the battery field. 44 + * The battery field needs to be able to handle when the JSON field for it is null. 45 + */ 46 + #[serde(deserialize_with = "parse_battery")] 43 47 pub battery: i8, 48 + } 49 + 50 + /* ~ Sutekh 51 + * Parse the LovenseServiceToyInfo battery field to handle incoming JSON null values from the Lovense Connect app. 52 + * This deserializer will check if we received an i8 or null. 53 + * If the value is null it will set the battery level to 0. 54 + */ 55 + fn parse_battery<'de, D>(d: D) -> Result<i8, D::Error> 56 + where D: Deserializer<'de> { 57 + Deserialize::deserialize(d) 58 + .map(|b: Option<_>| { 59 + b.unwrap_or(0) 60 + }) 44 61 } 45 62 46 63 #[derive(Deserialize, Debug)]