C# .NET Standard Library للتحكم في مصابيح LID Smart LED على السحابة
هذا المشروع عبارة عن مكتبة غلاف تحتوي على وظائف من واجهة برمجة تطبيقات LIFX الرسمية https://api.developer.lifx.com/reference/introduction
قم بإنشاء مثيل من فئة LifxBulbs من خلال توفير Tokenapikey واسم تسمية لمبة LED كمعلمات.
using LifxLibrary ;
LifxBulbs bedroom = new LifxBulbs ( "tokenKey" , "Bedroom" ) ;
//synchronous
bedroom . LightToggle ( 3 ) ; //toggle with 3 seconds duration
//async
await bedroom . LightToggleAsync ( 3 ) ; //async toggle with 3 seconds durationليس من الضروري تحديد اسم تسمية في مُنشئ الفئة عند استخدام أساليب SweepToggle. ستنفذ هذه الطرق عملية تبديل عامة عبر جميع الأجهزة المتصلة.
using LifxLibrary ;
LifxBulbs devices = new LifxBulbs ( "tokenKey" ) ;
//synchronous
devices . SweepToggle ( ) ;
//async
await devices . SweepToggleAsync ( ) ; تتيح لك أساليب PutPower تغيير حالة المصابيح ، ووضعها على on أو off ، وتوفير معلمة وقت مدة اختيارية تتراوح من 0 إلى 100 ثانية.
using LifxLibrary ;
LifxBulbs bedroom = new LifxBulbs ( "tokenKey" , "Bedroom" ) ;
//synchronous
bedroom . PutPower ( "on" ) ;
bedroom . PutPower ( "off" ) ;
bedroom . PutPower ( "on" , 5 ) ; //with 5 seconds duration time
//async
await bedroom . PutPowerAsync ( "off" ) ; تأخذ طرق PutBrightness معلمة عدد صحيح تتراوح من 0 إلى 100 لتعيين شدة السطوع.
using LifxLibrary ;
LifxBulbs bedroom = new LifxBulbs ( "tokenKey" , "Bedroom" ) ;
//synchronous
bedroom . PutBrightness ( 50 ) ; //set the brightness at 50%
//async
await bedroom . PutBrightnessAsync ( 50 ) ; يمكن أن تتلقى طرق PutColor سلسلة من قيم السلسلة كمعلمة لتحديد اللون والسطوع والتشبع والسمات الأخرى.
using LifxLibrary ;
LifxBulbs bedroom = new LifxBulbs ( "tokenKey" , "Bedroom" ) ;
//hexadecimal
bedroom . PutColor ( "#0000FF" ) ; //blue color
//RGB
bedroom . PutColor ( "rgb:255,0,0" ) ; //red color
//plain text
bedroom . PutColor ( "white" ) ; //white color
//async
await bedroom . PutColorAsync ( "hue:120 saturation:1.0 brightness:0.5" ) ; //Deep green 50% brightnessللحصول على دليل أكثر تفصيلاً حول تحديد الألوان ، يرجى زيارة وثائق API الرسمية LIFX على https://api.developer.lifx.com/Reference/Colors.
تقبل الطرق متعددة الاستخدامات مجموعة من المعلمات الاختيارية لتنفيذ إجراءات متنوعة على مصابيح LED ، مثل تغيير color brightness power duration time وتفعيل fast mode .
يقوم الوضع السريع بتنفيذ الاستعلام بسرعة ، دون فحوصات الحالة الأولية وانتظر عدم وجود نتائج.
using LifxLibrary ;
LifxBulbs bedroom = new LifxBulbs ( "tokenKey" , "Bedroom" ) ;
//synchronous
bedroom . MultiUse ( "on" , "blue" , 50 , 6 , true ) ; //power on, color blue, 50% brightness, 6 seconds duration with fast mode activated
//other ways to use it
bedroom . MultiUse ( power : "on" , color : "blue" , brightness : 100 , duration : 6 , fast : true ) ;
//duration time is 0 by default and fast mode is false by default
bedroom . MultiUse ( power : "on" , color : "white" , brightness : 80 ) ;
//async
await bedroom . MultiUseAsync ( "off" ) ;
await bedroom . MultiUseAsync ( "on" , "orange" ) ; فئة LightSearcher هي فئة ثابتة تحتوي على أساليب غير متزامنة ثابتة تساعد على اكتشاف مصابيح LED واسترداد خصائصها مثل LED bulb name ، power status ، connection status ، brightness level ، saturation level والمزيد.
تُرجع طريقة ShowConnectedDevicesAsync قائمة كائن سلسلة بأسماء التسمية لجميع الأجهزة المتصلة.
using LifxLibrary ;
//set the tokenkey
LightSearcher . SetTokenKey ( "tokenkey" ) ;
var devices = await LightSearcher . ShowConnectedDevicesAsync ( ) ;
foreach ( var device in devices )
{
Console . WriteLine ( device ) ;
} تقوم طريقة GetNamesAsync بإرجاع قائمة كائن السلسلة بأسماء التسمية لجميع الأجهزة المرتبطة بحسابك ، بغض النظر عن حالة اتصالها أو حالة الطاقة.
using LifxLibrary ;
//set the tokenkey
LightSearcher . SetTokenKey ( "tokenkey" ) ;
var devices = await LightSearcher . GetNamesAsync ( ) ;
foreach ( var device in devices )
{
Console . WriteLine ( device ) ;
} تقوم طريقة ShowStateAsync بإرجاع كائن BulbState مع power status ، connection status ، LED label name ، brightness level ، saturation level ، و UUID ، و ID ، و HUE .
using LifxLibrary ;
//set the tokenkey
LightSearcher . SetTokenKey ( "tokenkey" ) ;
BulbState bedroom = await LightSearcher . ShowStateAsync ( "Bedroom" ) ;
Console . WriteLine ( bedroom . Power ) ; //the response would be off or on
Console . WriteLine ( bedroom . Connected ) ; //the response would be true or false
Console . WriteLine ( bedroom . Brightness ) ; //brightness level
Console . WriteLine ( bedroom . Saturation ) ; //saturation level
Console . WriteLine ( bedroom . Id ) ; //bulb ID تحتوي فئة LightGroup على طرق للتحكم في مجموعة من مصابيح LED التي تنتمي إلى مجموعة معينة.
الأساليب غير المتزامنة والمتزامنة في فئة LightGroup .
Toggle methods Brightness methods Color methods MultiUse methods
using LifxLibrary ;
LightGroup bulbs = new LightGroup ( "tokenKey" , "Kitchen" ) ; //tokenKey and group name
bulbs . SweepToggle ( ) ;
await bulbs . PutColorAsync ( "blue" ) ;