// WARNING: Please don't edit this file. It was generated by Python/WinRT v2.1.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 != nullptr)
        {
            py::set_invalid_kwd_args_error();
            return nullptr;
        }

        auto arg_count = PyTuple_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
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SlaveAddress"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert(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 == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SlaveAddress"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

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

            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
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SharingMode"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert(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 == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"SharingMode"))
            {
                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);

            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
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"BusSpeed"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert(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 == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cConnectionSettings", L"BusSpeed"))
            {
                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);

            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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetControllersAsync", 1))
                {
                    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(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_Size(args);

        if (arg_count == 0)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetDefaultAsync", 0))
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert(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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cController", L"GetDevice", 1))
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

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

                return py::convert(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_Size(args);

        if (arg_count == 0)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Close", 0))
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                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_Size(args);

        if (arg_count == 2)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"FromIdAsync", 2))
                {
                    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(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_Size(args);

        if (arg_count == 0)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"GetDeviceSelector", 0))
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert(winrt::Windows::Devices::I2c::I2cDevice::GetDeviceSelector());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"GetDeviceSelector", 1))
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

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

                return py::convert(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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Read", 0))
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

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

                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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"ReadPartial", 0))
                {
                    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(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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"Write", 1))
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

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

                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_Size(args);

        if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WritePartial", 1))
                {
                    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(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_Size(args);

        if (arg_count == 2)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WriteRead", 1))
                {
                    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);

                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_Size(args);

        if (arg_count == 2)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.I2cDevice", L"WriteReadPartial", 1))
                {
                    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(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
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cDevice", L"ConnectionSettings"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert(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
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.I2c.I2cDevice", L"DeviceId"))
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert(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
        {
            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 },
        { }
    };

    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 --------------------

    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;
    }

    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_Size(args);

        if (arg_count == 2)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"FromIdAsync", 2))
                {
                    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(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_Size(args);

        if (arg_count == 0)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"GetDeviceSelector", 0))
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert(self->obj.GetDeviceSelector());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 1)
        {
            try
            {
                if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.I2c.II2cDeviceStatics", L"GetDeviceSelector", 1))
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

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

                return py::convert(self->obj.GetDeviceSelector(param0));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    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 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 },
        { "_assign_array_", _assign_array_II2cDeviceStatics, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_II2cDeviceStatics), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_II2cDeviceStatics[] = {
        { }
    };

    static PyType_Slot _type_slots_II2cDeviceStatics[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_II2cDeviceStatics) },
        { 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,
        _type_slots_II2cDeviceStatics};

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

    winrt_struct_wrapper<winrt::Windows::Devices::I2c::I2cTransferResult>* _new_I2cTransferResult(PyTypeObject* subclass, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        auto self = reinterpret_cast<winrt_struct_wrapper<winrt::Windows::Devices::I2c::I2cTransferResult>*>(subclass->tp_alloc(subclass, 0));

        if (!self)
        {
            return nullptr;
        }

        std::construct_at(&self->obj);

        return self;
    }

    int _init_I2cTransferResult(winrt_struct_wrapper<winrt::Windows::Devices::I2c::I2cTransferResult>* self, PyObject* args, PyObject* kwds) noexcept
    {
        auto tuple_size = PyTuple_Size(args);

        if ((tuple_size == 0) && (kwds == nullptr))
        {
            self->obj = {};
            return 0;
        }

        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 -1;
        }

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

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

    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;
    }

    static PyMethodDef _methods_I2cTransferResult[] = {
        { "_assign_array_", _assign_array_I2cTransferResult, METH_O | METH_STATIC, 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 int I2cTransferResult_set_Status(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            self->obj.Status = py::converter<winrt::Windows::Devices::I2c::I2cTransferStatus>::convert_to(arg);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    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 int I2cTransferResult_set_BytesTransferred(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            self->obj.BytesTransferred = py::converter<uint32_t>::convert_to(arg);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

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

    static PyObject* _richcompare_I2cTransferResult(py::wrapper::Windows::Devices::I2c::I2cTransferResult* self, PyObject* other, int op) noexcept
    {
        try
        {
            auto _other = py::converter<winrt::Windows::Devices::I2c::I2cTransferResult>::convert_to(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 PyType_Slot _type_slots_I2cTransferResult[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_I2cTransferResult) },
        { Py_tp_init, reinterpret_cast<void*>(_init_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) },
        { }
    };

    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 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;
    }

    if (py::register_python_type(module.get(), &type_spec_I2cConnectionSettings, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }

    py::pyobj_handle type_I2cController_Static{PyType_FromSpec(&type_spec_I2cController_Static)};
    if (!type_I2cController_Static)
    {
        return nullptr;
    }

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

    py::pyobj_handle type_I2cDevice_Static{PyType_FromSpec(&type_spec_I2cDevice_Static)};
    if (!type_I2cDevice_Static)
    {
        return nullptr;
    }

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

    if (py::register_python_type(module.get(), &type_spec_II2cDeviceStatics, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }

    if (py::register_python_type(module.get(), &type_spec_I2cTransferResult, nullptr, nullptr) == -1)
    {
        return nullptr;
    }


    return module.detach();
}
