diff --git a/Cargo.lock b/Cargo.lock index 5bfbcb0..5ba0ace 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1060,9 +1060,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.6" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "chrono", @@ -1080,9 +1080,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.6" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -1090,9 +1090,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.6" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -1100,9 +1100,9 @@ dependencies = [ [[package]] name = "pyo3-log" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac84e6eec1159bc2a575c9ae6723baa6ee9d45873e9bebad1e3ad7e8d28a443" +checksum = "3eb421dc86d38d08e04b927b02424db480be71b777fa3a56f32e2f2a3a1a3b08" dependencies = [ "arc-swap", "log", @@ -1111,9 +1111,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.6" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -1123,9 +1123,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.6" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 23f057f..41815d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = ["tapo", "tapo-py"] [workspace.dependencies] anyhow = "1.0" chrono = { version = "0.4.34", default-features = false } -pyo3 = { version = "0.22" } +pyo3 = { version = "0.23" } serde = { version = "1.0" } serde_json = { version = "1.0" } tokio = { version = "1.42", default-features = false } diff --git a/tapo-py/Cargo.toml b/tapo-py/Cargo.toml index db3067b..9db328e 100644 --- a/tapo-py/Cargo.toml +++ b/tapo-py/Cargo.toml @@ -22,7 +22,7 @@ pyo3 = { workspace = true, features = [ "extension-module", "py-clone", ] } -pyo3-log = { version = "0.11" } +pyo3-log = { version = "0.12" } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true, default-features = false, features = [ diff --git a/tapo-py/src/api/hub_handler.rs b/tapo-py/src/api/hub_handler.rs index e9cf59e..b3337c4 100644 --- a/tapo-py/src/api/hub_handler.rs +++ b/tapo-py/src/api/hub_handler.rs @@ -75,30 +75,30 @@ impl PyHubHandler { )?; let results = Python::with_gil(|py| { - let results = PyList::empty_bound(py); + let results = PyList::empty(py); for child in children { match child { ChildDeviceHubResult::KE100(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::S200B(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::T100(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::T110(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::T300(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::T310(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } ChildDeviceHubResult::T315(device) => { - results.append(device.into_py(py))?; + results.append(device.into_pyobject(py)?)?; } _ => { results.append(py.None())?; diff --git a/tapo-py/src/api/power_strip_handler.rs b/tapo-py/src/api/power_strip_handler.rs index ce697b3..dd9825c 100644 --- a/tapo-py/src/api/power_strip_handler.rs +++ b/tapo-py/src/api/power_strip_handler.rs @@ -78,10 +78,10 @@ impl PyPowerStripHandler { )?; let results = Python::with_gil(|py| { - let results = PyList::empty_bound(py); + let results = PyList::empty(py); for child in children { - results.append(child.into_py(py))?; + results.append(child.into_pyobject(py)?)?; } Ok(results.into()) diff --git a/tapo-py/src/lib.rs b/tapo-py/src/lib.rs index c8c3070..852dbbf 100644 --- a/tapo-py/src/lib.rs +++ b/tapo-py/src/lib.rs @@ -43,8 +43,8 @@ fn tapo_py(py: Python, module: &Bound<'_, PyModule>) -> PyResult<()> { .install() .expect("Failed to install the logger"); - let requests = PyModule::new_bound(py, "tapo.requests")?; - let responses = PyModule::new_bound(py, "tapo.responses")?; + let requests = PyModule::new(py, "tapo.requests")?; + let responses = PyModule::new(py, "tapo.responses")?; register_handlers(module)?; register_requests(&requests)?; @@ -55,7 +55,7 @@ fn tapo_py(py: Python, module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_submodule(&requests)?; module.add_submodule(&responses)?; - let sys = py.import_bound("sys")?; + let sys = py.import("sys")?; let modules = sys.getattr("modules")?; modules.set_item("tapo.requests", requests)?; modules.set_item("tapo.responses", responses)?; diff --git a/tapo/src/python.rs b/tapo/src/python.rs index a080b5f..bb68ceb 100644 --- a/tapo/src/python.rs +++ b/tapo/src/python.rs @@ -1,12 +1,12 @@ //! Python utilities. use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods}; -use pyo3::{Py, PyResult, Python, ToPyObject}; +use pyo3::{IntoPyObjectExt, Py, PyResult, Python}; use serde_json::Value; /// Converts a serde object to a Python dictionary. pub fn serde_object_to_py_dict(py: Python, value: &Value) -> PyResult> { - let dict = PyDict::new_bound(py); + let dict = PyDict::new(py); if let Some(object) = value.as_object() { for (key, value) in object { @@ -18,28 +18,28 @@ pub fn serde_object_to_py_dict(py: Python, value: &Value) -> PyResult Ok(dict.into()) } -fn map_value(py: Python, value: &Value) -> PyResult { +fn map_value<'py>(py: Python<'py>, value: &'py Value) -> PyResult> { let mapped_value = match value { - Value::Object(_) => serde_object_to_py_dict(py, value)?.to_object(py), + Value::Object(_) => serde_object_to_py_dict(py, value)?.into_py_any(py)?, Value::Array(value) => { - let array = PyList::empty_bound(py); + let array = PyList::empty(py); for item in value { let mapped_item = map_value(py, item)?; array.append(mapped_item)?; } - array.to_object(py) + array.into_py_any(py)? } - Value::String(value) => ToPyObject::to_object(value, py), - Value::Bool(value) => ToPyObject::to_object(value, py), + Value::String(value) => IntoPyObjectExt::into_py_any(value, py)?, + Value::Bool(value) => IntoPyObjectExt::into_py_any(value, py)?, Value::Number(value) => { if let Some(ref value) = value.as_i64() { - ToPyObject::to_object(value, py) + IntoPyObjectExt::into_py_any(value, py)? } else if let Some(ref value) = value.as_u64() { - ToPyObject::to_object(value, py) + IntoPyObjectExt::into_py_any(value, py)? } else if let Some(ref value) = value.as_f64() { - ToPyObject::to_object(value, py) + IntoPyObjectExt::into_py_any(value, py)? } else { todo!() }