// WARNING: Please don't edit this file. It was generated by Python/WinRT v3.2.0

#include "py.Windows.Devices.I2c.h"

namespace py::cpp::Windows::Devices::I2c
{
    // ----- I2cConnectionSettings class --------------------

    static PyObject* _new_I2cConnectionSettings(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept
    {
        if (kwds)
        {
            py::set_invalid_kwd_args_error();
            return nullptr;
        }

        auto arg_count = PyTuple_GET_SIZE(args);
        if (arg_count == 1)
        {
            try
            {
                auto param0 = py::convert_to<int32_t>(args, 0);

                winrt::Windows::Devices::I2c::I2cConnectionSettings instance{param0};
                return py::wrap(instance, type);
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static void _dealloc_I2cConnectionSettings(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* I2cConnectionSettings_get_SlaveAddress(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SlaveAddress");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.SlaveAddress();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int I2cConnectionSettings_put_SlaveAddress(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SlaveAddress");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<int32_t>(arg);

            {
                auto _gil = release_gil();
                self->obj.SlaveAddress(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* I2cConnectionSettings_get_SharingMode(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SharingMode");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.SharingMode();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int I2cConnectionSettings_put_SharingMode(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SharingMode");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Devices::I2c::I2cSharingMode>(arg);

            {
                auto _gil = release_gil();
                self->obj.SharingMode(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* I2cConnectionSettings_get_BusSpeed(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"BusSpeed");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.BusSpeed();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int I2cConnectionSettings_put_BusSpeed(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"BusSpeed");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Devices::I2c::I2cBusSpeed>(arg);

            {
                auto _gil = release_gil();
                self->obj.BusSpeed(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* _assign_array_I2cConnectionSettings(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::I2c::I2cConnectionSettings>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_I2cConnectionSettings(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::I2c::I2cConnectionSettings>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_I2cConnectionSettings[] = {
        { "_assign_array_", _assign_array_I2cConnectionSettings, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_I2cConnectionSettings), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_I2cConnectionSettings[] = {
        { "slave_address", reinterpret_cast<getter>(I2cConnectionSettings_get_SlaveAddress), reinterpret_cast<setter>(I2cConnectionSettings_put_SlaveAddress), nullptr, nullptr },
        { "sharing_mode", reinterpret_cast<getter>(I2cConnectionSettings_get_SharingMode), reinterpret_cast<setter>(I2cConnectionSettings_put_SharingMode), nullptr, nullptr },
        { "bus_speed", reinterpret_cast<getter>(I2cConnectionSettings_get_BusSpeed), reinterpret_cast<setter>(I2cConnectionSettings_put_BusSpeed), nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_I2cConnectionSettings[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_I2cConnectionSettings) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_I2cConnectionSettings) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_I2cConnectionSettings) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_I2cConnectionSettings) },
        { }};

    static PyType_Spec type_spec_I2cConnectionSettings = {
        "winrt._winrt_windows_devices_i2c.I2cConnectionSettings",
        sizeof(py::wrapper::Windows::Devices::I2c::I2cConnectionSettings),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_I2cConnectionSettings};

    // ----- I2cController class --------------------

    static PyObject* _new_I2cController(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::I2c::I2cController>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::I2c::I2cController>::type_name);
        return nullptr;
    }

    static void _dealloc_I2cController(py::wrapper::Windows::Devices::I2c::I2cController* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* I2cController_GetControllersAsync(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetControllersAsync", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::Windows::Devices::I2c::Provider::II2cProvider>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::I2c::I2cController::GetControllersAsync(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cController_GetDefaultAsync(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetDefaultAsync", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::I2c::I2cController::GetDefaultAsync();
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cController_GetDevice(py::wrapper::Windows::Devices::I2c::I2cController* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetDevice", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::Windows::Devices::I2c::I2cConnectionSettings>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.GetDevice(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* _assign_array_I2cController(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::I2c::I2cController>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_I2cController(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::I2c::I2cController>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_I2cController[] = {
        { "get_device", reinterpret_cast<PyCFunction>(I2cController_GetDevice), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_I2cController, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_I2cController), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_I2cController[] = {
        { }};

    static PyType_Slot _type_slots_I2cController[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_I2cController) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_I2cController) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_I2cController) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_I2cController) },
        { }};

    static PyType_Spec type_spec_I2cController = {
        "winrt._winrt_windows_devices_i2c.I2cController",
        sizeof(py::wrapper::Windows::Devices::I2c::I2cController),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_I2cController};

    static PyGetSetDef getset_I2cController_Static[] = {
        { }};

    static PyMethodDef methods_I2cController_Static[] = {
        { "get_controllers_async", reinterpret_cast<PyCFunction>(I2cController_GetControllersAsync), METH_VARARGS, nullptr },
        { "get_default_async", reinterpret_cast<PyCFunction>(I2cController_GetDefaultAsync), METH_VARARGS, nullptr },
        { }};

    static PyType_Slot type_slots_I2cController_Static[] = 
    {
        { Py_tp_base, reinterpret_cast<void*>(&PyType_Type) },
        { Py_tp_getset, reinterpret_cast<void*>(getset_I2cController_Static) },
        { Py_tp_methods, reinterpret_cast<void*>(methods_I2cController_Static) },
        { }
    };

    static PyType_Spec type_spec_I2cController_Static = {
        "winrt._winrt_windows_devices_i2c.I2cController_Static",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT,
        type_slots_I2cController_Static};

    // ----- I2cDevice class --------------------

    static PyObject* _new_I2cDevice(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::I2c::I2cDevice>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::I2c::I2cDevice>::type_name);
        return nullptr;
    }

    static void _dealloc_I2cDevice(py::wrapper::Windows::Devices::I2c::I2cDevice* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* I2cDevice_Close(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Close", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                {
                    auto _gil = release_gil();
                    self->obj.Close();
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_FromIdAsync(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"FromIdAsync", 2);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(2);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Devices::I2c::I2cConnectionSettings>(args, 1);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::I2c::I2cDevice::FromIdAsync(param0, param1);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_GetDeviceSelector(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"GetDeviceSelector", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::I2c::I2cDevice::GetDeviceSelector();
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_GetDeviceSelectorFromFriendlyName(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"GetDeviceSelector", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::I2c::I2cDevice::GetDeviceSelector(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_Read(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Read", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 0);

                {
                    auto _gil = release_gil();
                    self->obj.Read(param0);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_ReadPartial(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"ReadPartial", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.ReadPartial(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_Write(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Write", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);

                {
                    auto _gil = release_gil();
                    self->obj.Write(param0);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_WritePartial(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WritePartial", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.WritePartial(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_WriteRead(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WriteRead", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);
                auto param1 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 1);

                {
                    auto _gil = release_gil();
                    self->obj.WriteRead(param0, param1);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_WriteReadPartial(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WriteReadPartial", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);
                auto param1 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 1);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.WriteReadPartial(param0, param1);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* I2cDevice_get_ConnectionSettings(py::wrapper::Windows::Devices::I2c::I2cDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cDevice", L"ConnectionSettings");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.ConnectionSettings();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* I2cDevice_get_DeviceId(py::wrapper::Windows::Devices::I2c::I2cDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cDevice", L"DeviceId");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.DeviceId();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_I2cDevice(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::I2c::I2cDevice>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_I2cDevice(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::I2c::I2cDevice>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _enter_I2cDevice(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* /*unused*/) noexcept
    {
        return Py_NewRef(self);
    }

    static PyObject* _exit_I2cDevice(py::wrapper::Windows::Devices::I2c::I2cDevice* self, PyObject* /*unused*/) noexcept
    {
        try
        {
            {
                auto _gil = py::release_gil();
                self->obj.Close();
            }

            Py_RETURN_FALSE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_I2cDevice[] = {
        { "close", reinterpret_cast<PyCFunction>(I2cDevice_Close), METH_VARARGS, nullptr },
        { "read", reinterpret_cast<PyCFunction>(I2cDevice_Read), METH_VARARGS, nullptr },
        { "read_partial", reinterpret_cast<PyCFunction>(I2cDevice_ReadPartial), METH_VARARGS, nullptr },
        { "write", reinterpret_cast<PyCFunction>(I2cDevice_Write), METH_VARARGS, nullptr },
        { "write_partial", reinterpret_cast<PyCFunction>(I2cDevice_WritePartial), METH_VARARGS, nullptr },
        { "write_read", reinterpret_cast<PyCFunction>(I2cDevice_WriteRead), METH_VARARGS, nullptr },
        { "write_read_partial", reinterpret_cast<PyCFunction>(I2cDevice_WriteReadPartial), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_I2cDevice, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_I2cDevice), METH_O | METH_STATIC, nullptr },
        { "__enter__", reinterpret_cast<PyCFunction>(_enter_I2cDevice), METH_NOARGS, nullptr },
        { "__exit__", reinterpret_cast<PyCFunction>(_exit_I2cDevice), METH_VARARGS, nullptr },
        { }};

    static PyGetSetDef _getset_I2cDevice[] = {
        { "connection_settings", reinterpret_cast<getter>(I2cDevice_get_ConnectionSettings), nullptr, nullptr, nullptr },
        { "device_id", reinterpret_cast<getter>(I2cDevice_get_DeviceId), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_I2cDevice[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_I2cDevice) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_I2cDevice) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_I2cDevice) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_I2cDevice) },
        { }};

    static PyType_Spec type_spec_I2cDevice = {
        "winrt._winrt_windows_devices_i2c.I2cDevice",
        sizeof(py::wrapper::Windows::Devices::I2c::I2cDevice),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_I2cDevice};

    static PyGetSetDef getset_I2cDevice_Static[] = {
        { }};

    static PyMethodDef methods_I2cDevice_Static[] = {
        { "from_id_async", reinterpret_cast<PyCFunction>(I2cDevice_FromIdAsync), METH_VARARGS, nullptr },
        { "get_device_selector", reinterpret_cast<PyCFunction>(I2cDevice_GetDeviceSelector), METH_VARARGS, nullptr },
        { "get_device_selector_from_friendly_name", reinterpret_cast<PyCFunction>(I2cDevice_GetDeviceSelectorFromFriendlyName), METH_VARARGS, nullptr },
        { }};

    static PyType_Slot type_slots_I2cDevice_Static[] = 
    {
        { Py_tp_base, reinterpret_cast<void*>(&PyType_Type) },
        { Py_tp_getset, reinterpret_cast<void*>(getset_I2cDevice_Static) },
        { Py_tp_methods, reinterpret_cast<void*>(methods_I2cDevice_Static) },
        { }
    };

    static PyType_Spec type_spec_I2cDevice_Static = {
        "winrt._winrt_windows_devices_i2c.I2cDevice_Static",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT,
        type_slots_I2cDevice_Static};

    // ----- II2cDeviceStatics interface --------------------

    #if PY_VERSION_HEX < 0x030A0000
    static PyObject* _new_II2cDeviceStatics(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::I2c::II2cDeviceStatics>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::I2c::II2cDeviceStatics>::type_name);
        return nullptr;
    }
    #endif

    static void _dealloc_II2cDeviceStatics(py::wrapper::Windows::Devices::I2c::II2cDeviceStatics* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* II2cDeviceStatics_FromIdAsync(py::wrapper::Windows::Devices::I2c::II2cDeviceStatics* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"FromIdAsync", 2);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(2);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Devices::I2c::I2cConnectionSettings>(args, 1);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.FromIdAsync(param0, param1);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* II2cDeviceStatics_GetDeviceSelector(py::wrapper::Windows::Devices::I2c::II2cDeviceStatics* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"GetDeviceSelector", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.GetDeviceSelector();
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* II2cDeviceStatics_GetDeviceSelectorFromFriendlyName(py::wrapper::Windows::Devices::I2c::II2cDeviceStatics* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"GetDeviceSelector", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return self->obj.GetDeviceSelector(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyMethodDef _methods_II2cDeviceStatics[] = {
        { "from_id_async", reinterpret_cast<PyCFunction>(II2cDeviceStatics_FromIdAsync), METH_VARARGS, nullptr },
        { "get_device_selector", reinterpret_cast<PyCFunction>(II2cDeviceStatics_GetDeviceSelector), METH_VARARGS, nullptr },
        { "get_device_selector_from_friendly_name", reinterpret_cast<PyCFunction>(II2cDeviceStatics_GetDeviceSelectorFromFriendlyName), METH_VARARGS, nullptr },
        { }};

    static PyGetSetDef _getset_II2cDeviceStatics[] = {
        { }};

    static PyType_Slot _type_slots_II2cDeviceStatics[] = {
        #if PY_VERSION_HEX < 0x030A0000
        { Py_tp_new, reinterpret_cast<void*>(_new_II2cDeviceStatics) },
        #endif
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_II2cDeviceStatics) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_II2cDeviceStatics) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_II2cDeviceStatics) },
        { }};

    static PyType_Spec type_spec_II2cDeviceStatics = {
        "winrt._winrt_windows_devices_i2c._II2cDeviceStatics",
        sizeof(py::wrapper::Windows::Devices::I2c::II2cDeviceStatics),
        0,
        Py_TPFLAGS_DEFAULT
        #if PY_VERSION_HEX >= 0x030A0000
        | Py_TPFLAGS_DISALLOW_INSTANTIATION
        #endif
        ,
        _type_slots_II2cDeviceStatics};

    struct ImplementsII2cDeviceStatics : py::ImplementsInterfaceT<ImplementsII2cDeviceStatics, winrt::Windows::Devices::I2c::II2cDeviceStatics>
    {
        ImplementsII2cDeviceStatics() = delete;
        ImplementsII2cDeviceStatics(PyObject* py_obj, winrt::impl::inspectable_abi* runtime_class) : py::ImplementsInterfaceT<ImplementsII2cDeviceStatics, winrt::Windows::Devices::I2c::II2cDeviceStatics>(py_obj, runtime_class)
        {
        }

        auto FromIdAsync(winrt::hstring const& param0, winrt::Windows::Devices::I2c::I2cConnectionSettings const& param1)
        {
            try
            {
                py::pyobj_handle self{this->get_py_obj()};

                py::pyobj_handle method{PyObject_GetAttrString(self.get(), "from_id_async")};
                if (!method)
                {
                    throw python_exception();
                }

                py::pyobj_handle py_param0{py::convert(param0)};
                if (!py_param0)
                {
                    throw python_exception();
                }

                py::pyobj_handle py_param1{py::convert(param1)};
                if (!py_param1)
                {
                    throw python_exception();
                }

                py::pyobj_handle args{PyTuple_Pack(2, py_param0.get(), py_param1.get())};
                if (!args)
                {
                    throw python_exception();
                }

                py::pyobj_handle return_value{PyObject_CallObject(method.get(), args.get())};
                if (!return_value)
                {
                    throw python_exception();
                }

                return py::convert_to<winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Devices::I2c::I2cDevice>>(return_value.get());
            }
            catch (python_exception)
            {
                py::write_unraisable_and_throw();
            }
        }

        auto GetDeviceSelector()
        {
            try
            {
                py::pyobj_handle self{this->get_py_obj()};

                py::pyobj_handle method{PyObject_GetAttrString(self.get(), "get_device_selector")};
                if (!method)
                {
                    throw python_exception();
                }

                py::pyobj_handle return_value{PyObject_CallNoArgs(method.get())};
                if (!return_value)
                {
                    throw python_exception();
                }

                return py::convert_to<winrt::hstring>(return_value.get());
            }
            catch (python_exception)
            {
                py::write_unraisable_and_throw();
            }
        }

        auto GetDeviceSelector(winrt::hstring const& param0)
        {
            try
            {
                py::pyobj_handle self{this->get_py_obj()};

                py::pyobj_handle method{PyObject_GetAttrString(self.get(), "get_device_selector_from_friendly_name")};
                if (!method)
                {
                    throw python_exception();
                }

                py::pyobj_handle py_param0{py::convert(param0)};
                if (!py_param0)
                {
                    throw python_exception();
                }

                py::pyobj_handle return_value{PyObject_CallOneArg(method.get(), py_param0.get())};
                if (!return_value)
                {
                    throw python_exception();
                }

                return py::convert_to<winrt::hstring>(return_value.get());
            }
            catch (python_exception)
            {
                py::write_unraisable_and_throw();
            }
        }
    };

    static PyObject* _assign_array_II2cDeviceStatics(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::I2c::II2cDeviceStatics>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_II2cDeviceStatics(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::I2c::II2cDeviceStatics>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _guid_ImplementsII2cDeviceStatics(PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        try
        {
            return py::convert(winrt::guid_of<winrt::Windows::Devices::I2c::II2cDeviceStatics>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _make_ImplementsII2cDeviceStatics(PyObject* /*unused*/, PyObject* args) noexcept
    {
        try
        {
            PyObject* py_obj;
            winrt::impl::inspectable_abi* runtime_class;

            if (!PyArg_ParseTuple(args, "On", &py_obj, &runtime_class))
            {
                return nullptr;
            }

            auto iface{std::make_unique<ImplementsII2cDeviceStatics>(py_obj, runtime_class)};

            return PyLong_FromVoidPtr(iface.release());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef methods_ImplementsII2cDeviceStatics[] = {
        { "_assign_array_", _assign_array_II2cDeviceStatics, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_II2cDeviceStatics), METH_O | METH_STATIC, nullptr },
        { "_guid_", reinterpret_cast<PyCFunction>(_guid_ImplementsII2cDeviceStatics), METH_NOARGS | METH_STATIC, nullptr },
        { "_make_", reinterpret_cast<PyCFunction>(_make_ImplementsII2cDeviceStatics), METH_VARARGS | METH_STATIC, nullptr },
        { }};

    static PyType_Slot type_slots_ImplementsII2cDeviceStatics[] = {
        { Py_tp_methods, reinterpret_cast<void*>(methods_ImplementsII2cDeviceStatics) },
        { }};

    static PyType_Spec type_spec_ImplementsII2cDeviceStatics = {
        "winrt._winrt_windows_devices_i2c.II2cDeviceStatics",
        0,
        0,
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
        #if PY_VERSION_HEX >= 0x030A0000
        | Py_TPFLAGS_DISALLOW_INSTANTIATION
        #endif
        ,
        type_slots_ImplementsII2cDeviceStatics};

    // ----- I2cTransferResult struct --------------------

    winrt::Windows::Devices::I2c::I2cTransferResult I2cTransferResult_from_tuple(PyObject* tuple)
    {
        if (PyTuple_GET_SIZE(tuple) != 2)
        {
            PyErr_SetString(PyExc_TypeError, "Incorrect number of fields");
            throw python_exception();
        }

        winrt::Windows::Devices::I2c::I2cTransferResult result{};

        result.Status = py::convert_to<winrt::Windows::Devices::I2c::I2cTransferStatus>(tuple, 0);
        result.BytesTransferred = py::convert_to<uint32_t>(tuple, 1);

        return result;
    }

    PyObject* _new_I2cTransferResult(PyTypeObject* subclass, PyObject* args, PyObject* kwds) noexcept
    {
        pyobj_handle self_obj{(subclass->tp_alloc(subclass, 0))};
        if (!self_obj)
        {
            return nullptr;
        }

        auto self = reinterpret_cast<winrt_struct_wrapper<winrt::Windows::Devices::I2c::I2cTransferResult>*>(self_obj.get());
        std::construct_at(&self->obj);

        auto tuple_size = PyTuple_GET_SIZE(args);
        if ((tuple_size == 0) && (!kwds))
        {
            return self_obj.detach();
        }

        int32_t _Status{};
        uint32_t _BytesTransferred{};

        static const char* kwlist[] = {"status", "bytes_transferred", nullptr};
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iI", const_cast<char**>(kwlist), &_Status, &_BytesTransferred))
        {
            return nullptr;
        }

        try
        {
            self->obj.Status = static_cast<winrt::Windows::Devices::I2c::I2cTransferStatus>(_Status);
            self->obj.BytesTransferred = _BytesTransferred;

            return self_obj.detach();
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static void _dealloc_I2cTransferResult(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* _assign_array_I2cTransferResult(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::I2c::I2cTransferResult>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    PyObject* _replace_I2cTransferResult(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* args, PyObject* kwds) noexcept
    {
        try
        {
            int32_t _Status{static_cast<int32_t>(self->obj.Status)};
            uint32_t _BytesTransferred{self->obj.BytesTransferred};

            static const char* kwlist[] = {"status", "bytes_transferred", nullptr};
            if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$iI", const_cast<char**>(kwlist), &_Status, &_BytesTransferred))
            {
                return nullptr;
            }

            auto copy = self->obj;
            copy.Status = static_cast<winrt::Windows::Devices::I2c::I2cTransferStatus>(_Status);
            copy.BytesTransferred = _BytesTransferred;

            return convert(copy);
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    PyObject* unpack_I2cTransferResult(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* /*unused*/) noexcept
    {
        py::pyobj_handle Status{convert(self->obj.Status)};
        if (!Status)
        {
            return nullptr;
        }

        py::pyobj_handle BytesTransferred{convert(self->obj.BytesTransferred)};
        if (!BytesTransferred)
        {
            return nullptr;
        }

        pyobj_handle tuple{PyTuple_New(2)};
        if (!tuple)
        {
            return nullptr;
        }

        PyTuple_SET_ITEM(tuple.get(), 0, Status.detach());
        PyTuple_SET_ITEM(tuple.get(), 1, BytesTransferred.detach());

        return tuple.detach();
    }

    static PyMethodDef _methods_I2cTransferResult[] = {
        { "_assign_array_", _assign_array_I2cTransferResult, METH_O | METH_STATIC, nullptr },
        { "__replace__", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(_replace_I2cTransferResult)), METH_VARARGS | METH_KEYWORDS, nullptr },
        { "unpack", reinterpret_cast<PyCFunction>(unpack_I2cTransferResult), METH_NOARGS, nullptr },
        { }};

    static PyObject* I2cTransferResult_get_Status(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, void* /*unused*/) noexcept
    {
        try
        {
            return py::convert(self->obj.Status);
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* I2cTransferResult_get_BytesTransferred(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, void* /*unused*/) noexcept
    {
        try
        {
            return py::convert(self->obj.BytesTransferred);
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyGetSetDef _getset_I2cTransferResult[] = {
        { "status", reinterpret_cast<getter>(I2cTransferResult_get_Status), nullptr, nullptr, nullptr },
        { "bytes_transferred", reinterpret_cast<getter>(I2cTransferResult_get_BytesTransferred), nullptr, nullptr, nullptr },
        { }};

    static PyObject* _richcompare_I2cTransferResult(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* other, int op) noexcept
    {
        try
        {
            auto _other = py::convert_to<winrt::Windows::Devices::I2c::I2cTransferResult>(other);

            if (op == Py_EQ)
            {
                if (self->obj == _other)
                {
                    Py_RETURN_TRUE;
                }

                Py_RETURN_FALSE;
            }

            if (op == Py_NE)
            {
                if (self->obj != _other)
                {
                    Py_RETURN_TRUE;
                }

                Py_RETURN_FALSE;
            }

            Py_RETURN_NOTIMPLEMENTED;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _repr_I2cTransferResult(PyObject* self) noexcept
    {
        py::pyobj_handle Status{PyObject_GetAttrString(self, "status")};
        if (!Status)
        {
            return nullptr;
        }

        py::pyobj_handle BytesTransferred{PyObject_GetAttrString(self, "bytes_transferred")};
        if (!BytesTransferred)
        {
            return nullptr;
        }

        return PyUnicode_FromFormat("I2cTransferResult(status=%R, bytes_transferred=%R)", Status.get(), BytesTransferred.get());
    }

    static PyType_Slot _type_slots_I2cTransferResult[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_I2cTransferResult) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_I2cTransferResult) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_I2cTransferResult) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_I2cTransferResult) },
        { Py_tp_richcompare, reinterpret_cast<void*>(_richcompare_I2cTransferResult) },
        { Py_tp_repr, reinterpret_cast<void*>(_repr_I2cTransferResult) },
        { }};

    static PyType_Spec type_spec_I2cTransferResult = {
        "winrt._winrt_windows_devices_i2c.I2cTransferResult",
        sizeof(py::wrapper::Windows::Devices::I2c::I2cTransferResult),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_I2cTransferResult};

    // ----- Windows.Devices.I2c Initialization --------------------

    PyDoc_STRVAR(module_doc, "Windows.Devices.I2c");

    static PyModuleDef module_def = {
        PyModuleDef_HEAD_INIT,
        "_winrt_windows_devices_i2c",
        module_doc,
        0,
        nullptr,
        nullptr,
        nullptr,
        nullptr,
        nullptr};
} // py::cpp::Windows::Devices::I2c

PyMODINIT_FUNC PyInit__winrt_windows_devices_i2c(void) noexcept
{
    using namespace py::cpp::Windows::Devices::I2c;

    if (py::import_winrt_runtime() == -1)
    {
        return nullptr;
    }

    py::pyobj_handle module{PyModule_Create(&module_def)};

    if (!module)
    {
        return nullptr;
    }

    auto inspectable_meta_type = py::get_inspectable_meta_type();
    if (!inspectable_meta_type)
    {
        return nullptr;
    }

    auto object_type = py::get_object_type();
    if (!object_type)
    {
        return nullptr;
    }

    py::pyobj_handle object_bases{PyTuple_Pack(1, object_type)};

    if (!object_bases)
    {
        return nullptr;
    }

    py::pytype_handle I2cConnectionSettings_type{py::register_python_type(module.get(), &type_spec_I2cConnectionSettings, object_bases.get(), inspectable_meta_type)};
    if (!I2cConnectionSettings_type)
    {
        return nullptr;
    }

    py::pyobj_handle I2cController_Static_bases{PyTuple_Pack(1, reinterpret_cast<PyObject*>(inspectable_meta_type))};
    if (!I2cController_Static_bases)
    {
        return nullptr;
    }

    py::pyobj_handle type_I2cController_Static{PyType_FromSpecWithBases(&type_spec_I2cController_Static, I2cController_Static_bases.get())};
    if (!type_I2cController_Static)
    {
        return nullptr;
    }

    py::pytype_handle I2cController_type{py::register_python_type(module.get(), &type_spec_I2cController, object_bases.get(), reinterpret_cast<PyTypeObject*>(type_I2cController_Static.get()))};
    if (!I2cController_type)
    {
        return nullptr;
    }

    py::pyobj_handle I2cDevice_Static_bases{PyTuple_Pack(1, reinterpret_cast<PyObject*>(inspectable_meta_type))};
    if (!I2cDevice_Static_bases)
    {
        return nullptr;
    }

    py::pyobj_handle type_I2cDevice_Static{PyType_FromSpecWithBases(&type_spec_I2cDevice_Static, I2cDevice_Static_bases.get())};
    if (!type_I2cDevice_Static)
    {
        return nullptr;
    }

    py::pytype_handle I2cDevice_type{py::register_python_type(module.get(), &type_spec_I2cDevice, object_bases.get(), reinterpret_cast<PyTypeObject*>(type_I2cDevice_Static.get()))};
    if (!I2cDevice_type)
    {
        return nullptr;
    }

    py::pytype_handle II2cDeviceStatics_type{py::register_python_type(module.get(), &type_spec_II2cDeviceStatics, object_bases.get(), nullptr)};
    if (!II2cDeviceStatics_type)
    {
        return nullptr;
    }

    py::pytype_handle ImplementsII2cDeviceStatics_type{py::register_python_type(module.get(), &type_spec_ImplementsII2cDeviceStatics, nullptr, inspectable_meta_type)};
    if (!ImplementsII2cDeviceStatics_type)
    {
        return nullptr;
    }

    if (PyModule_AddType(module.get(), ImplementsII2cDeviceStatics_type.get()) == -1)
    {
        return nullptr;
    }

    py::pytype_handle I2cTransferResult_type{py::register_python_type(module.get(), &type_spec_I2cTransferResult, nullptr, nullptr)};
    if (!I2cTransferResult_type)
    {
        return nullptr;
    }

    py::pyobj_handle I2cTransferResult_from_tuple_capsule{PyCapsule_New(reinterpret_cast<void*>(I2cTransferResult_from_tuple),"winrt._winrt_windows_devices_i2c.I2cTransferResult_from_tuple", nullptr)};
    if (!I2cTransferResult_from_tuple_capsule)
    {
        return nullptr;
    }

    if (PyModule_AddObjectRef(module.get(), "I2cTransferResult_from_tuple", I2cTransferResult_from_tuple_capsule.get()) == -1)
    {
        return nullptr;
    }

    return module.detach();
}
