تم إيقاف إجراءات المحادثات نهائيًا في 13 حزيران (يونيو) 2023. لمزيد من المعلومات، يُرجى الاطّلاع على
إنهاء إجراءات المحادثة.
إضافة المزيد من السمات والمعالجات
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكنك إضافة أي عدد تريده من السمات إلى طراز جهازك. هذه السمات
غير مرتبطة بنوع جهاز واحد فقط، فيمكنك استخدامها حسب اختيارك.
هذه هي عملية إضافة أي سمة والتعامل مع الأمر الوارد:
تحديد السمة التي تريدها
لإضافتها.
افتح ملف pushtotalk.py
.
cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc
nano pushtotalk.py
أضِف مجموعة الرموز التالية ضمن المجموعة الحالية التي
تعالج الأمر action.devices.commands.OnOff
(لا تحذف الأمر
مجموعة رموز).
@device_handler.command('action.devices.commands.command-name')
def my-function(parameter-name):
if conditional:
logging.info('Something happened.')
else:
logging.info('Something else happened.')
ابحث عن المعلومات التي تحتاجها لكل متغير في مجموعة الرموز أعلاه.
command-name | انتقل إلى صفحة السمات المحددة من
الخطوة 1 (على سبيل المثال، ColorTemperature)
استخدم أمرًا من جدول أوامر الأجهزة. |
my-function | أدخِل اسمًا لوظيفة المعالِج كما تريد. |
parameter-name | انظر مرة أخرى إلى أوامر الجهاز.
جدول في صفحة السمات. لكل أمر معلمة واحدة أو أكثر
المرتبطة بها. هذه الخيارات مدرجة تحت "params" في التنفيذ
لطلب JSON. استخدِم اسم المَعلمة بالضبط. لاحظ أن بعض هذه
والمعلَمات هي كائنات تحتوي على معلَمات أخرى - ما عليك سوى استخدام
من عنصر المستوى الأعلى.
|
conditional | لا تحتاج بشدة إلى استخدام شرطي
في التعليمات البرمجية للمعالج، ولكن قد يساعدك في تمييز كيفية تنفيذ
على الجهاز. |
في ما يلي بعض الأمثلة على سمات السطوع
وColorTemperature:
@device_handler.command('action.devices.commands.BrightnessAbsolute')
def brightnessCheck(brightness):
if brightness > 50:
logging.info('brightness > 50')
else:
logging.info('brightness <= 50')
@device_handler.command('action.devices.commands.ColorAbsolute')
def color(color):
if color.get('name') == "blue":
logging.info('color is blue')
else:
logging.info('color is not blue')
تحديث طراز الجهاز
بالسمة التي أضفتها في الخطوة 1.
شغِّل رمز المصدر المُعدَّل.
cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc
python pushtotalk.py
اضغط على مفتاح Enter وجرِّب أحد طلبات البحث.
على سبيل المثال:
ضبط مستوى السطوع على %65
اختيار اللون الأزرق:
الخطوة التالية
تسجيل إجراءات الجهاز المخصّصة
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eYou can freely add numerous traits to your device model, independent of device type.\u003c/p\u003e\n"],["\u003cp\u003eThe process to add a trait involves updating the \u003ccode\u003epushtotalk.py\u003c/code\u003e file with a new code block to handle the incoming command and then updating the device model.\u003c/p\u003e\n"],["\u003cp\u003eEach added trait requires specific command details that can be found on the relevant trait documentation page.\u003c/p\u003e\n"],["\u003cp\u003eOnce implemented, the code can be tested by running \u003ccode\u003epushtotalk.py\u003c/code\u003e and using voice commands corresponding to the added trait.\u003c/p\u003e\n"]]],[],null,["# Add More Traits and Handlers\n\nYou can add as many traits to your device model as you wish. These traits are\nnot tied to just one device type, you can use them as you choose.\n\nThis is the process to add any trait and handle the incoming command:\n\n1. Determine which [trait](/assistant/sdk/reference/traits) you want\n to add.\n\n2. Open the `pushtotalk.py` file.\n\n ```\n cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc\n ``` \n\n ```\n nano pushtotalk.py\n ```\n3. Add the following code block under the existing one that\n handles the `action.devices.commands.OnOff` command (don't delete the existing\n code block).\n\n ```\n @device_handler.command('action.devices.commands.command-name')\n def my-function(parameter-name):\n if conditional:\n logging.info('Something happened.')\n else:\n logging.info('Something else happened.')\n ```\n4. Find the information you need for each variable in the above code block.\n\n |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | `command-name` | Go to the specific trait page from Step 1 (for example, [ColorTemperature](/assistant/sdk/reference/traits/colortemperature)). Use a command from the **Device COMMANDS** table. |\n | `my-function` | Name your handler function whatever you want. |\n | `parameter-name` | Look again at the **Device COMMANDS** table on the trait page. Each command has one or more parameters associated with it. These are listed under `\"params\"` in the EXECUTE request JSON. Use the exact parameter name. Note that some of these parameters are objects that contain other parameters - just use the top-level object. |\n | `conditional` | You don't strictly need to use a conditional in your handler code, but it may help to differentiate how you execute the command on the device. |\n\n Here are some examples for traits [Brightness](/assistant/sdk/reference/traits/brightness)\n and [ColorTemperature](/assistant/sdk/reference/traits/colortemperature): \n\n ```python\n @device_handler.command('action.devices.commands.BrightnessAbsolute')\n def brightnessCheck(brightness):\n if brightness \u003e 50:\n logging.info('brightness \u003e 50')\n else:\n logging.info('brightness \u003c= 50')\n\n @device_handler.command('action.devices.commands.ColorAbsolute')\n def color(color):\n if color.get('name') == \"blue\":\n logging.info('color is blue')\n else:\n logging.info('color is not blue')\n ```\n5. [Update the device model](/assistant/sdk/guides/service/python/extend/register-device-traits)\n with the trait you added in Step 1.\n\n6. Run the modified source code.\n\n ```\n cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc\n ``` \n\n ```\n python pushtotalk.py\n ```\n7. Press the Enter key and try a query.\n\n For example:\n\n *Set brightness to 65%.*\n\n *Make it blue.*\n\nNext step\n---------\n\n[Register Custom Device Actions](/assistant/sdk/guides/service/python/extend/custom-actions)"]]