कैमरा डिवाइस टाइप को दो ट्रेट का इस्तेमाल करके लागू किया जाता है:
PushAvStreamTransport,
यह पुश-आधारित प्रोटोकॉल का इस्तेमाल करके, ऑडियो और वीडियो स्ट्रीम को ट्रांसफ़र करता है. साथ ही,
WebRtcLiveView,
यह लाइव स्ट्रीम और टॉकबैक को कंट्रोल करने की सुविधा देता है.
किसी भी सुविधा का इस्तेमाल करने या एट्रिब्यूट अपडेट करने से पहले, हमेशा यह जांच करें कि डिवाइस के लिए एट्रिब्यूट और कमांड काम करती हैं या नहीं. ज़्यादा जानकारी के लिए, Androidपर डिवाइसों को कंट्रोल करना लेख पढ़ें.
| Home APIs डिवाइस टाइप | विशेषताएं | Kotlin सैंपल ऐप्लिकेशन | इस्तेमाल का उदाहरण |
|---|---|---|---|
|
कैमरा
ऐसा डिवाइस जो फ़ोटो या वीडियो रिकॉर्ड करता है. कैमरों में, सुलभ लाइवस्ट्रीम, बातचीत करने की सुविधा या गतिविधियों का पता लगाने की सुविधा हो सकती है. |
ज़रूरी एट्रिब्यूट google PushAvStreamTransport google WebRtcLiveView |
कैमरा |
किसी डिवाइस के बारे में बुनियादी जानकारी पाना
BasicInformation
ट्रेट में वेंडर का नाम, वेंडर आईडी, प्रॉडक्ट आईडी, प्रॉडक्ट का नाम (इसमें मॉडल की जानकारी शामिल होती है), सॉफ़्टवेयर वर्शन, और डिवाइस का सीरियल नंबर जैसी जानकारी शामिल होती है:
// Get device basic information. All general information traits are on the RootNodeDevice type. device.type(RootNodeDevice).first().standardTraits.basicInformation?.let { basicInformation -> println("vendorName ${basicInformation.vendorName}") println("vendorId ${basicInformation.vendorId}") println("productId ${basicInformation.productId}") println("productName ${basicInformation.productName}") println("softwareVersion ${basicInformation.softwareVersion}") println("serialNumber ${basicInformation.serialNumber}") }
डिवाइस के क्लाउड से कनेक्ट होने का सबसे हाल ही का समय पाना
डिवाइस का क्लाउड से संपर्क कब हुआ था, इसकी जानकारी पाने के लिए, ExtendedGeneralDiagnostics ट्रेट के lastContactTimestamp एट्रिब्यूट का इस्तेमाल करें:
fun getLastContactTimeStamp(trait: ExtendedGeneralDiagnostics): java.time.Instant { val timestamp = trait.lastContactTimestamp return Instant.ofEpochSecond(timestamp.toLong()) }
किसी डिवाइस के लिए कनेक्टिविटी की जांच करना
किसी डिवाइस के लिए कनेक्टिविटी की जांच, डिवाइस टाइप के लेवल पर की जाती है. ऐसा इसलिए, क्योंकि कुछ डिवाइस कई तरह के डिवाइस टाइप के साथ काम करते हैं. जवाब में, उस डिवाइस पर मौजूद सभी सुविधाओं के लिए कनेक्टिविटी की स्थितियों का कॉम्बिनेशन दिखाया जाता है.
val lightConnectivity = dimmableLightDevice.metadata.sourceConnectivity.connectivityState
इंटरनेट कनेक्टिविटी न होने पर, अलग-अलग तरह के डिवाइसों में PARTIALLY_ONLINE दिख सकता है.
लोकल राउटिंग की वजह से, Matter की स्टैंडर्ड सुविधाएं अब भी ऑनलाइन हो सकती हैं. हालांकि, क्लाउड पर आधारित सुविधाएं ऑफ़लाइन हो जाएंगी.
लाइव स्ट्रीम शुरू करना
लाइव स्ट्रीम शुरू करने के लिए, सेशन डिस्क्रिप्शन प्रोटोकॉल (एसडीपी) स्ट्रिंग को WebRtcLiveView ट्रेट के startLiveView() तरीके पर भेजें. इससे WebRtcLiveViewTrait.StartLiveViewCommand.Response मिलता है, जिसमें ये तीन वैल्यू होती हैं:
- सेशन के लिए एसडीपी.
- सत्र की अवधि, सेकंड में.
- यह सेशन आईडी है. इसका इस्तेमाल सेशन को बढ़ाने या खत्म करने के लिए किया जा सकता है.
suspend fun getWebRtcLiveViewTrait(cameraDevice: HomeDevice) { return cameraDevice.type(GoogleCameraDevice).trait(WebRtcLiveView).first { it?.metadata?.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE } } // Start the live view suspend fun startCameraStream(trait: WebRtcLiveView, offerSdp: String) { val response = trait.startLiveView(offerSdp) // Response contains three fields (see below) return response } ... // This is used to manage the WebRTC connection val peerConnection: RTCPeerConnection = ... ... val startResponse = startCameraStream(sdp) val answerSdp = startResponse?.answerSdp val sessionDuration = startResponse?.liveSessionDurationSeconds val mediaSessionId = startResponse?.mediaSessionId peerConnection.setRemoteDescription(SessionDescription.Type.ANSWER, answerSdp)
लाइव स्ट्रीम की अवधि बढ़ाना
लाइव स्ट्रीम की अवधि पहले से तय होती है. इसके बाद, वे खत्म हो जाती हैं. चालू स्ट्रीम की अवधि बढ़ाने के लिए, WebRtcLiveView.extendLiveView() तरीके का इस्तेमाल करके, अवधि बढ़ाने का अनुरोध करें:
// Assuming camera stream has just been started suspend fun scheduleExtension(trait: WebRtcLiveView, mediaSessionId: String, liveSessionDurationSeconds: UShort ) { delay(liveSessionDurationSeconds - BUFFER_SECONDS * 1000) val response = trait.extendLiveView(mediaSessionId) // returns how long the session will be live for return response.liveSessionDurationSeconds }
TalkBack को चालू और बंद करना
TalkBack की सुविधा शुरू करने के लिए, WebRtcLiveView
ट्रेट के startTalkback()
तरीके को कॉल करें. इसे बंद करने के लिए, stopTalkback() का इस्तेमाल करें.
// Make sure camera stream is on suspend fun setTalkback(isOn: Boolean, trait: WebRtcLiveView, mediaSessionId: String) { if(isOn) { trait.startTalkback(mediaSessionId) } else { trait.stopTalkback(mediaSessionId) } }
रिकॉर्डिंग की सुविधा को चालू और बंद करना
कैमरे की रिकॉर्डिंग की सुविधा चालू करने के लिए, PushAvStreamTransport ट्रेट के setTransportStatus() तरीके में TransportStatusEnum.Active पास करें. रिकॉर्डिंग की सुविधा बंद करने के लिए, इसे TransportStatusEnum.Inactive पर सेट करें.
यहां दिए गए उदाहरण में, हमने इन कॉल को एक ही कॉल में रैप किया है. इसमें रिकॉर्डिंग की सुविधा को टॉगल करने के लिए, Boolean का इस्तेमाल किया गया है:
// Start or stop recording for all connections. suspend fun setCameraRecording(trait: PushAvStreamTransport, isOn: Boolean) { if(isOn) { trait.setTransportStatus(TransportStatusEnum.Active) } else { trait.setTransportStatus(TransportStatusEnum.Inactive) } }
कैमरे की रिकॉर्डिंग की सुविधा को चालू या बंद करने का मतलब है कि कैमरे का वीडियो चालू या बंद करना. जब कैमरे का वीडियो चालू होता है, तब वह रिकॉर्डिंग कर रहा होता है. ऐसा इवेंट और उनसे जुड़ी क्लिप के लिए किया जाता है.
जब रिकॉर्डिंग की सुविधा बंद हो (कैमरे का वीडियो बंद हो):
connectivityStateडिवाइस टाइप के हिसाब से, कैमरा अब भी ऑनलाइन दिख सकता है.- लाइव स्ट्रीम को ऐक्सेस नहीं किया जा सकता. साथ ही, कैमरा किसी भी क्लाउड इवेंट का पता नहीं लगाता.
देखें कि रिकॉर्डिंग की सुविधा चालू है या नहीं
यह पता लगाने के लिए कि कैमरे की रिकॉर्डिंग की सुविधा चालू है या नहीं, देखें कि कोई कनेक्शन चालू है या नहीं. यहां दिए गए उदाहरण में, ऐसा करने के लिए दो फ़ंक्शन तय किए गए हैं:
// Get the on/off state suspend fun onOffState(pushAvStreamTransport: PushAvStreamTransport) { return pushAvStreamTransport .currentConnections?.any { it.transportStatus == TransportStatusEnum.Active } ?: false } // Check if the camera's recording capability is enabled fun PushAvStreamTransport.recordModeActive(): Boolean { return currentConnections?.any { it.transportStatus == TransportStatusEnum.Active } ?: false }
जांच करने का एक और तरीका है. इसके लिए, प्रेडिकेट के साथ findTransport() फ़ंक्शन का इस्तेमाल करें:
// Fetch the current connections suspend fun queryRecordModeState(trait: PushAvStreamTransport) { return trait.findTransport().let { it.transportConfigurations.any { it.transportStatus == TransportStatusEnum.Active } }
बैटरी की सेटिंग
Home API की मदद से, बैटरी से जुड़ी कई सेटिंग कंट्रोल की जा सकती हैं.
बैटरी खर्च करने की प्राथमिकता सेट करना
एनर्जी बैलेंस सेट करने से, किसी डिवाइस की बैटरी लाइफ़ और परफ़ॉर्मेंस के बीच तालमेल बिठाया जा सकता है. "बैटरी सेवर", "बैलेंस", और "परफ़ॉर्मेंस" जैसी अलग-अलग बैटरी प्रोफ़ाइलें बनाई जा सकती हैं. साथ ही, इनके बीच स्विच किया जा सकता है.
इस सुविधा को लागू करने के लिए, EnergyPreference ट्रेट के currentEnergyBalance एट्रिब्यूट को अपडेट किया जाता है. इस एट्रिब्यूट के लिए, पूर्णांक इंडेक्स स्वीकार किया जाता है. यह इंडेक्स, डिवाइस की energyBalances सूची में तय की गई किसी प्रोफ़ाइल से मेल खाता है. उदाहरण के लिए, EXTENDED के लिए 0, BALANCED के लिए 1, और PERFORMANCE के लिए 2.
currentEnergyBalance के लिए null वैल्यू से पता चलता है कि डिवाइस, कस्टम प्रोफ़ाइल का इस्तेमाल कर रहा है. यह सिर्फ़ पढ़ने के लिए है.
यहां currentEnergyBalance एट्रिब्यूट के इस्तेमाल का एक उदाहरण दिया गया है. इसके बाद, एट्रिब्यूट का इस्तेमाल करने वाला कोड स्निपेट दिया गया है.
// Example energyBalances list energy_balances: [ { step: 0, label: "EXTENDED" }, { step: 50, label: "BALANCED" }, { step: 100, label: "PERFORMANCE" } ]
// The index parameter must be within the UByte range (0-255). suspend fun setEnergyBalance(trait: EnergyPreference, index: Int) { trait.update { setCurrentEnergyBalance(index.toUByte()) } } // Setting the battery usage to more recording ie performance setEnergyBalance(energyPreference, 2)
बैटरी सेवर अपने-आप चालू होने की सुविधा चालू करना
इस सुविधा को कॉन्फ़िगर करने के लिए, EnergyPreference ट्रेट के currentLowPowerModeSensitivity एट्रिब्यूट की वैल्यू अपडेट करें. इस एट्रिब्यूट में इंडेक्स का इस्तेमाल करके, संवेदनशीलता का लेवल चुना जाता है. इसमें 0 का मतलब आम तौर पर Disabled होता है और 1 का मतलब Enabled या Automatic होता है.
suspend fun setAutomaticBatterySaver(enable: Boolean, trait: EnergyPreference) { // 0 is Disabled, 1 is Enabled val value = if (enable) 1.toUByte() else 0.toUByte() trait.update { setCurrentLowPowerModeSensitivity(value) } }
बैटरी चार्ज होने की स्थिति पाना
डिवाइस की मौजूदा चार्जिंग की स्थिति (चार्ज हो रहा है, पूरी तरह से चार्ज हो गया है या चार्ज नहीं हो रहा है) की जानकारी पाने के लिए, PowerSource ट्रेट के batChargeState एट्रिब्यूट का इस्तेमाल करें.
// Get the battery charging state val batteryChargeState = powerSource.batChargeState when (batteryChargeState) { PowerSourceTrait.BatChargeStateEnum.IsCharging -> "Charging" PowerSourceTrait.BatChargeStateEnum.IsAtFullCharge -> "Full" PowerSourceTrait.BatChargeStateEnum.IsNotCharging -> "Not Charging" else -> "Unknown" }
बैटरी लेवल की जानकारी पाना
बैटरी का मौजूदा लेवल पाने के लिए, PowerSource ट्रेट के batChargeLevel एट्रिब्यूट का इस्तेमाल करें. यह लेवल OK, Warning (कम) या Critical में से कोई एक है.
// Get the battery charge level val batteryLevel = powerSourceTrait.batChargeLevel when (batteryLevel) { PowerSourceTrait.BatChargeLevelEnum.OK -> "OK" PowerSourceTrait.BatChargeLevelEnum.Warning -> "Warning" PowerSourceTrait.BatChargeLevelEnum.Critical -> "Critical" else -> "Unknown" }
पावर सोर्स की जानकारी पाना
डिवाइस के पावर सोर्स का पता लगाने के लिए, PowerSource ट्रेट के BatPresent और wiredPresent एट्रिब्यूट का इस्तेमाल करें.
val trait: PowerSource val isWired = trait.wiredPresent val hasBattery = trait.batPresent
ऑडियो सेटिंग
Home APIs की मदद से, ऑडियो की अलग-अलग सेटिंग कंट्रोल की जा सकती हैं.
माइक्रोफ़ोन चालू या बंद करना
डिवाइस के माइक्रोफ़ोन को चालू या बंद करने के लिए, CameraAvStreamManagement ट्रेट के microphoneMuted एट्रिब्यूट को अपडेट करें. इसके लिए, पहले से मौजूद setMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn the device's microphone on or off suspend fun turnOffMicrophone(disableMicrophone: Boolean, trait: CameraAvStreamManagement) { trait.update { setMicrophoneMuted(disableMicrophone) } }
ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करना
डिवाइस के लिए ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करने के लिए, CameraAvStreamManagement ट्रेट के recordingMicrophoneMuted एट्रिब्यूट को अपडेट करें. इसके लिए, setRecordingMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn audio recording on or off for the device suspend fun turnOffAudioRecording(disableAudioRecording: Boolean, trait: CameraAvStreamManagement) { trait.update { setRecordingMicrophoneMuted(disableAudioRecording) } }
स्पीकर की आवाज़ कम या ज़्यादा करना
डिवाइस के स्पीकर का वॉल्यूम घटाने या बढ़ाने के लिए, CameraAvStreamManagement ट्रेट के speakerVolumeLevel एट्रिब्यूट को अपडेट करें. इसके लिए, setSpeakerVolumeLevel Kotlin फ़ंक्शन का इस्तेमाल करें:
// Adjust the camera speaker volume suspend fun adjustSpeakerVolume(volume: Int, trait: CameraAvStreamManagement) { trait.update { setSpeakerVolumeLevel(volume.toUbyte()) } }
ऐक्टिविटी ज़ोन की सेटिंग
ZoneManagement ट्रेट, कैमरे और दरवाज़े की घंटी वाले डिवाइसों पर, दिलचस्पी वाले कस्टम क्षेत्रों (गतिविधि ज़ोन) को मैनेज करने के लिए एक इंटरफ़ेस उपलब्ध कराती है.
इन ज़ोन का इस्तेमाल, डिवाइस के फ़ील्ड ऑफ़ व्यू में मौजूद किसी खास जगह पर इवेंट का पता लगाने के लिए किया जाता है. जैसे, किसी व्यक्ति या वाहन की गतिविधि.
ऐक्टिविटी ज़ोन को उपयोगकर्ता, पार्टनर ऐप्लिकेशन में कॉन्फ़िगर करता है. इससे वह कैमरे के फ़ील्ड ऑफ़ व्यू में मौजूद खास जगहों पर ज़ोन बना पाता है. इसके बाद, उपयोगकर्ता के तय किए गए इन ज़ोन को इस ट्रेट में इस्तेमाल किए गए स्ट्रक्चर में बदल दिया जाता है. ऐक्टिविटी ज़ोन के काम करने के तरीके के बारे में ज़्यादा जानने के लिए, ऐक्टिविटी ज़ोन सेट अप करना और उनका इस्तेमाल करना लेख पढ़ें.
गतिविधि वाले ज़ोन आम तौर पर, 2D कार्टेशियन कोऑर्डिनेट का इस्तेमाल करके तय किए जाते हैं.
यह ट्रेट, वर्टेक्स के लिए TwoDCartesianVertexStruct और ज़ोन की परिभाषा के लिए TwoDCartesianZoneStruct उपलब्ध कराती है. ज़ोन की परिभाषा में नाम, वर्टेक्स, रंग, और इस्तेमाल शामिल होता है.
ऐक्टिविटी ज़ोन की जांच करना
गतिविधि वाले ज़ोन दिखाने के लिए, ZoneManagement ट्रेट के zones एट्रिब्यूट की वैल्यू देखें.
// 1. Obtain the trait flow from the device private val zoneManagementFlow: Flow= device.type(CAMERA_TYPE).flatMapLatest { it.trait(ZoneManagement) } // 2. Map the flow to the list of zone structures val activityZones: Flow<List<ZoneManagementTrait.ZoneInformationStruct>> = zoneManagementFlow.map { trait -> trait.zones ?: emptyList() }
गतिविधि ज़ोन जोड़ना
नया ज़ोन बनाने के लिए, createTwoDCartesianZone कमांड का इस्तेमाल करें. इस कमांड में TwoDCartesianZoneStruct का इस्तेमाल किया जाता है. इससे ज़ोन का नाम, वर्टेक्स, रंग, और इस्तेमाल तय होता है.
नीचे दिए गए उदाहरण में, "Front Porch" नाम का एक ज़ोन बनाने का तरीका दिखाया गया है. इसमें चार वर्टेक्स हैं, इसका रंग सैल्मन (#F439A0) है, और इसका इस्तेमाल मोशन का पता लगाने के लिए किया जाता है.
import com.google.home.google.ZoneManagement import com.google.home.google.ZoneManagementTrait import com.google.home.matter.serialization.OptionalValue /** * Creates a custom activity zone named "Front Porch" with a salmon color * configured for motion detection. */ suspend fun createFrontPorchZone(zoneManagement: ZoneManagement) { // 1. Define the vertices for the zone (2D Cartesian coordinates) // Values are typically scaled to a maximum defined by the device's twoDCartesianMax attribute. val vertices = listOf( ZoneManagementTrait.TwoDCartesianVertexStruct(x = 260u, y = 422u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 1049u, y = 0u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 2048u, y = 0u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 2048u, y = 950u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 1630u, y = 1349u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 880u, y = 2048u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 0u, y = 2048u), ZoneManagementTrait.TwoDCartesianVertexStruct(x = 638u, y = 1090u) ) // 2. Define the zone structure val newZone = ZoneManagementTrait.TwoDCartesianZoneStruct( name = "Front Porch", vertices = vertices, // Usage defines what the zone filters (for example, Motion, Person, Vehicle) use = listOf(ZoneManagementTrait.ZoneUseEnum.Motion), // Color is typically a hex string (for example, Salmon/Pink) color = OptionalValue.present("#F439A0") ) try { // 3. Execute the command to add the zone to the device zoneManagement.createTwoDCartesianZone(newZone) println("Successfully created activity zone.") } catch (e: Exception) { // Handle potential HomeException or Timeout println("Failed to create activity zone: ${e.message}") } }
गतिविधि वाले ज़ोन की जानकारी अपडेट करना
किसी मौजूदा ज़ोन को अपडेट करने के लिए, updateTwoDCartesianZone कमांड का इस्तेमाल करें. इस निर्देश के लिए, zoneId और अपडेट किया गया TwoDCartesianZoneStruct ज़रूरी है.
private suspend fun ZoneManagement.updateZone( zoneId: UShort, zone: ZoneManagementTrait.TwoDCartesianZoneStruct ) { // Execute the command to update the zone this.updateTwoDCartesianZone(zoneId = zoneId, zone = zone) }
गतिविधि ज़ोन मिटाना
किसी ज़ोन को हटाने के लिए, removeZone कमांड के साथ zoneId का इस्तेमाल करें.
private suspend fun ZoneManagement.deleteZone(zoneId: UShort) { // Execute the command to remove the zone this.removeZone(zoneId = zoneId) }
साउंड इवेंट ट्रिगर
AvStreamAnalysis ट्रेट, कैमरे और दरवाज़े की घंटी वाले डिवाइसों पर, रिकॉर्ड की गई गतिविधि का पता लगाने की सुविधा को मैनेज करने के लिए इंटरफ़ेस उपलब्ध कराती है. विज़न पर आधारित ट्रिगर (जैसे, लोग या वाहन) किसी ज़ोन के हिसाब से सेट किए जा सकते हैं. हालांकि, आवाज़ से जुड़े ट्रिगर आम तौर पर डिवाइस के लेवल पर कॉन्फ़िगर किए जाते हैं.
EventTriggerTypeEnum के साथ आवाज़ का पता लगाने के लिए, ये ट्रिगर टाइप उपलब्ध हैं:
| मोड | इनम वैल्यू | ब्यौरा |
|---|---|---|
| आवाज़ | Sound |
आवाज़ का पता लगाने की सामान्य सुविधा. |
| बातचीत करने की आवाज़ | PersonTalking |
आवाज़ का पता लगाता है. |
| कुत्ते के भौंकने की आवाज़ | DogBark |
यह कुत्ते के भौंकने की आवाज़ का पता लगाता है. |
| कांच टूटने की आवाज़ | GlassBreak |
कांच टूटने की आवाज़ का पता लगाता है. |
| धुएं का अलार्म | SmokeAlarm |
धुएं के अलार्म का पता लगाता है. इसकी पहचान अक्सर T3 के सुनाई देने वाले पैटर्न से होती है. इसमें तीन छोटी बीप के बाद कुछ देर का ठहराव होता है. |
| कार्बन मोनोऑक्साइड का अलार्म | CoAlarm |
यह कार्बन मोनोऑक्साइड (CO) के अलार्म का पता लगाता है. आम तौर पर, इसकी पहचान T4 के सुनाई देने वाले पैटर्न से होती है. इसमें चार छोटी बीप के बाद कुछ देर का ठहराव होता है. |
आवाज़ पहचानने की सुविधा की स्थिति देखना
उपयोगकर्ता को आवाज़ का पता लगाने की सुविधा की मौजूदा स्थिति दिखाने के लिए, आपको यह देखना होगा कि डिवाइस पर कौनसी सुविधाएं काम करती हैं और डिवाइस के हार्डवेयर में कौनसी सुविधाएं चालू हैं. इन दो एट्रिब्यूट की जांच की जानी चाहिए:
Kotlin फ़्लो का इस्तेमाल करके Android डेवलपमेंट में, आम तौर पर HomeDevice से AvStreamAnalysis ट्रेट को देखा जाता है.
// Example structure to store the data class EventTriggerAttribute(val type: EventTriggerTypeEnum, val enabled: Boolean) // 1. Obtain the trait flow from the device private val avStreamAnalysisFlow: Flow<AvStreamAnalysis> = device.traitFromType(AvStreamAnalysis, CAMERA_TYPES.first { device.has(it) }) // 2. Map the flow to a list of sound event attributes val soundEventTriggersState: Flow<List<EventTriggerAttribute>> = avStreamAnalysisFlow.map { trait -> // Get raw lists from the trait attributes val supported = trait.supportedEventTriggers ?: emptyList() val enabled = trait.enabledEventTriggers ?: emptyList() // Define sound-specific triggers to filter for val soundTypes = setOf( EventTriggerTypeEnum.Sound, EventTriggerTypeEnum.PersonTalking, EventTriggerTypeEnum.DogBark, EventTriggerTypeEnum.GlassBreak, EventTriggerTypeEnum.SmokeAlarm, EventTriggerTypeEnum.CoAlarm, ) // Filter and associate status supported .filter { soundTypes.contains(it) } .map { type -> EventTriggerAttribute( type = type, enabled = enabled.contains(type) ) } }
चालू किए गए ट्रिगर के सेट को अपडेट करना
चालू किए गए ट्रिगर के सेट को अपडेट करने के लिए, SetOrUpdateEventDetectionTriggers कमांड का इस्तेमाल करें. यह कमांड, EventTriggerEnablement स्ट्रक्चर की सूची लेती है.
private suspend fun AvStreamAnalysis.updateEventTriggers( eventTriggers: List<EventTriggerAttribute> ) { val toUpdate = eventTriggers.map { EventTriggerEnablement( eventTriggerType = it.type, enablementStatus = if (it.enabled) { EnablementStatusEnum.Enabled } else { EnablementStatusEnum.Disabled }, ) } // Execute the command on the device setOrUpdateEventDetectionTriggers(toUpdate) }
रिकॉर्डिंग मोड
RecordingMode ट्रेट, कैमरा और दरवाज़े की घंटी वाले डिवाइसों पर वीडियो और इमेज रिकॉर्डिंग के व्यवहार को मैनेज करने के लिए एक इंटरफ़ेस उपलब्ध कराती है. इससे उपयोगकर्ताओं को लगातार रिकॉर्डिंग, इवेंट के आधार पर रिकॉर्डिंग या रिकॉर्डिंग की सुविधा को पूरी तरह से बंद करने (सिर्फ़ लाइव व्यू के लिए) का विकल्प मिलता है.
RecordingModeEnum
से, रिकॉर्डिंग की उपलब्ध रणनीतियों के बारे में पता चलता है:
| मोड | इनम वैल्यू | ब्यौरा |
|---|---|---|
| बंद है | Disabled |
रिकॉर्डिंग की सुविधा पूरी तरह से बंद है. इसका इस्तेमाल मुख्य रूप से लेगसी डिवाइसों के लिए किया जाता है. |
| सीवीआर (लगातार वीडियो रिकॉर्डिंग) | Cvr |
वीडियो को हर समय रिकॉर्ड किया जाता है. सदस्यता लेना ज़रूरी है (उदाहरण के लिए, Google Google Home Premium. |
| ईबीआर (इवेंट के आधार पर रिकॉर्डिंग) | Ebr |
रिकॉर्डिंग, इवेंट (व्यक्ति, गति) के हिसाब से ट्रिगर होती है. वीडियो की अवधि, इवेंट की अवधि और सदस्यता पर निर्भर करती है. |
| ETR (इवेंट ट्रिगर होने पर रिकॉर्डिंग शुरू होना) | Etr |
इवेंट से ट्रिगर होने वाली, कम समय की झलक दिखाने वाली रिकॉर्डिंग (उदाहरण के लिए, 10 सेकंड). |
| लाइव व्यू | LiveView |
रिकॉर्डिंग की सुविधा बंद है. हालांकि, उपयोगकर्ता अब भी लाइव स्ट्रीम को ऐक्सेस कर सकते हैं. |
| स्टिल इमेज | Images |
इवेंट होने पर, वीडियो के बजाय स्नैपशॉट रिकॉर्ड किए जाते हैं. |
रिकॉर्डिंग मोड देखना
मौजूदा रिकॉर्डिंग कॉन्फ़िगरेशन दिखाने के लिए, RecordingMode ट्रेट के एट्रिब्यूट देखें:
supportedRecordingModes- सभी संभावित मोडavailableRecordingModes- चुने जा सकने वाले मोडselectedRecordingMode- ऐक्टिव मोड
// 1. Obtain the trait flow from the device private val recordingModeTraitFlow: Flow= device.traitFromType(RecordingMode, CAMERA_TYPES.first { device.has(it) }) // 2. Map the flow to recording mode options data class RecordingModeOptions( val recordingMode: RecordingModeTrait.RecordingModeEnum, val index: Int, val available: Boolean, val readableString: String, ) private val recordingModeOptions: Flow<List > = recordingModeTraitFlow.map { trait -> val supported = trait.supportedRecordingModes?.map { it.recordingMode } ?: emptyList() val available = trait.availableRecordingModes?.map { it.toInt() } ?: emptyList() supported.withIndex().map { (index, mode) -> RecordingModeOptions( recordingMode = mode, index = index, available = available.contains(index), readableString = mode.toReadableString(), ) } }
रिकॉर्डिंग का मोड बदलना
अपडेट करने से पहले, पक्का करें कि supportedRecordingModes एट्रिब्यूट में चुना गया इंडेक्स, availableRecordingModes एट्रिब्यूट में मौजूद हो.
चुने गए मोड को अपडेट करने के लिए, setSelectedRecordingMode फ़ंक्शन का इस्तेमाल करें. इसमें चुने गए मोड का इंडेक्स पास करें:
private suspend fun RecordingMode.updateRecordingMode(index: Int) { // Execute the command to update the selected mode this.setSelectedRecordingMode(index.toUByte()) }
अन्य सेटिंग
Home API की मदद से, कई अन्य सेटिंग कंट्रोल की जा सकती हैं.
इमेज का ओरिएंटेशन बदलना
कैमरे की इमेज (वीडियो) के ओरिएंटेशन को घुमाया जा सकता है. वीडियो को सिर्फ़ 180 डिग्री घुमाया जा सकता है.
कैमरे की इमेज ओरिएंटेशन बदलने के लिए, पहले से मौजूद setImageRotation Kotlin फ़ंक्शन का इस्तेमाल करके, CameraAvStreamManagement ट्रेट के imageRotation एट्रिब्यूट को अपडेट करें:
// Change the camera's image orientation val isRotated = false cameraAvStreamManagement.update { setImageRotation(if (isRotated) 180.toUShort() else 0.toUShort()) }
नाइट विज़न मोड को चालू या बंद करना
कैमरे के लिए नाइट विज़न की सुविधा चालू या बंद करने के लिए, TriStateAutoEnum का इस्तेमाल करके CameraAvStreamManagement ट्रेट के nightVision एट्रिब्यूट को अपडेट करें. इसके लिए, setNightVision Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn night vision on cameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.On) } // Turn night vision off CameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.Off) }
स्टेटस एलईडी की चमक बदलना
स्टेटस एलईडी की चमक बदलने के लिए, ThreeLevelAutoEnum का इस्तेमाल करें. इससे CameraAvStreamManagement ट्रेट के statusLightBrightness एट्रिब्यूट को अपडेट किया जा सकता है. इसके लिए, setStatusLightBrightness Kotlin फ़ंक्शन का इस्तेमाल करें:
// Set the LED brightness to high cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.High) } // Set the LED brightness to low cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.Low) }
कैमरे का व्यूपोर्ट बदलना
कैमरे का व्यू पोर्ट, ज़ूम और क्रॉप करने की सुविधा जैसा ही होता है. इस सुविधा के बारे में, Nest Cam के वीडियो को ज़ूम और बेहतर बनाएं सहायता लेख में बताया गया है.
व्यूपोर्ट को ViewportStruct में तय किया जाता है. इसमें चार वैल्यू होती हैं. इनका इस्तेमाल व्यूपोर्ट के निर्देशांकों के तौर पर किया जाता है. कोऑर्डिनेट इस तरह तय किए जाते हैं:
(x1,y1) -- (x2,y1) | | (x1,y2) -- (x2,y2)
ViewportStruct के लिए वैल्यू तय करना, ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) और कैमरे को लागू करने के तरीके पर निर्भर करता है. कैमरे के वीडियो का व्यूपोर्ट सेट करने के लिए, CameraAvStreamManagement ट्रेट के viewport एट्रिब्यूट को ViewportStruct से अपडेट करें. इसके लिए, setViewport Kotlin के बिल्ट-इन फ़ंक्शन का इस्तेमाल करें:
cameraAvStreamManagement .update { setViewport( CameraAvStreamManagementTrait.ViewportStruct( x1 = horizontalRange.rangeStart.roundToInt().toUShort(), x2 = horizontalRange.rangeEnd.roundToInt().toUShort(), y1 = verticalRange.rangeStart.roundToInt().toUShort(), y2 = verticalRange.rangeEnd.roundToInt().toUShort(), ) ) }
डिवाइस के वेक-अप होने की सेंसिटिविटी को अडजस्ट करना
डिवाइस के वेक-अप सेंसर की संवेदनशीलता का इस्तेमाल, बैटरी बचाने के लिए किया जाता है. इसके लिए, डिवाइस की उस रेंज को कम किया जाता है जिसमें वह गतिविधि का पता लगा सकता है. साथ ही, गतिविधि का पता लगाने के बाद, डिवाइस को वेक अप करने के समय को बढ़ाया जाता है.
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionSensitivity प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
डिवाइस को जगाने की सुविधा के लिए, संवेदनशीलता को सिर्फ़ इन वैल्यू पर सेट किया जा सकता है:
- 1 = कम
- 5 = मीडियम
- 10 = ज़्यादा
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, नई संवेदनशीलता वैल्यू के साथ कॉन्फ़िगरेशन में बदलाव करें:
// Create a struct with the new wake-up sensitivity val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionSensitivity = OptionalValue.present(wakeUpSensitivity.toUByte()) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }
इवेंट की ज़्यादा से ज़्यादा अवधि में बदलाव करना
इवेंट की ज़्यादा से ज़्यादा अवधि का मतलब है कि कैमरा किसी इवेंट के लिए, कितने समय तक क्लिप रिकॉर्ड करेगा. होम एपीआई के ज़रिए, इसे हर डिवाइस के लिए कॉन्फ़िगर किया जा सकता है. इसके लिए, GHA के बराबर समयसीमा तय की जा सकती है. यह समयसीमा सेकंड के हिसाब से तय की जाती है:
- 10 सेकंड
- 15 सेकंड
- 30 सेकंड
- 60 सेकंड (एक मिनट)
- 120 सेकंड (2 मिनट)
- 180 सेकंड (3 मिनट)
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionTimeControl प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, कॉन्फ़िगरेशन में इवेंट की नई अवधि की वैल्यू में बदलाव करें:
// Create a struct with the new max event length // where maxDuration is the length in seconds val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionTimeControl = OptionalValue.present( TransportMotionTriggerTimeControlStruct(maxDuration = it.toUInt()) ) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }
Analytics को चालू या बंद करना
हर डिवाइस, Google Home क्लाउड को आंकड़ों का ज़्यादा डेटा भेजने के लिए अलग-अलग ऑप्ट-इन कर सकता है. इसके लिए, Home API के लिए क्लाउड मॉनिटरिंग देखें.
किसी डिवाइस के लिए आंकड़ों को इकट्ठा करने की सुविधा चालू करने के लिए, ExtendedGeneralDiagnosticsTrait की analyticsEnabled प्रॉपर्टी को true पर सेट करें. analyticsEnabled को सेट करने पर, logUploadEnabled प्रॉपर्टी अपने-आप true पर सेट हो जाती है. इससे, Google Home क्लाउड पर आंकड़ों की लॉग फ़ाइलें अपलोड की जा सकती हैं.
// Enable analytics extendedGeneralDiagnostics.update { setAnalyticsEnabled(true) } // Disable analytics extendedGeneralDiagnostics.update { setAnalyticsEnabled(false) }