1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //! GATT profiles 16 17 use crate::wrapper::{ 18 gatt_client::{CharacteristicProxy, ProfileServiceProxy}, 19 PyObjectExt, 20 }; 21 use pyo3::{intern, PyObject, PyResult, Python}; 22 23 /// Exposes the battery GATT service 24 pub struct BatteryServiceProxy(PyObject); 25 26 impl BatteryServiceProxy { 27 /// Get the battery level, if available battery_level(&self) -> PyResult<Option<CharacteristicProxy>>28 pub fn battery_level(&self) -> PyResult<Option<CharacteristicProxy>> { 29 Python::with_gil(|py| { 30 self.0 31 .getattr(py, intern!(py, "battery_level")) 32 .map(|level| level.into_option(CharacteristicProxy)) 33 }) 34 } 35 } 36 37 impl ProfileServiceProxy for BatteryServiceProxy { 38 const PROXY_CLASS_MODULE: &'static str = "bumble.profiles.battery_service"; 39 const PROXY_CLASS_NAME: &'static str = "BatteryServiceProxy"; 40 wrap(obj: PyObject) -> Self41 fn wrap(obj: PyObject) -> Self { 42 Self(obj) 43 } 44 } 45