- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - tuya #16474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    New Components - tuya #16474
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import tuya from "../../tuya.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "tuya-list-devices", | ||
| name: "List Devices", | ||
| description: "Get a list of devices associated with a home. [See the documentation](https://developer.tuya.com/en/docs/cloud/d7ee73aadb?id=Kawfjer0wkt2a)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| tuya, | ||
| userId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "userId", | ||
| ], | ||
| }, | ||
| homeId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "homeId", | ||
| (c) => ({ | ||
| userId: c.userId, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = this.homeId | ||
| ? await this.tuya.listHomeDevices({ | ||
| homeId: this.homeId, | ||
| }) | ||
| : await this.tuya.listUserDevices({ | ||
| userId: this.userId, | ||
| }); | ||
| if (response?.result?.length) { | ||
| $.export("$summary", `Found ${response.result.length} device${response.result.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| } | ||
| return response; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import tuya from "../../tuya.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "tuya-list-homes", | ||
| name: "List Homes", | ||
| description: "Based on the user ID, query the list of homes where the specified user belongs. [See the documentation](https://developer.tuya.com/en/docs/cloud/f5dd40ed14?id=Kawfjh9hpov1n)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| tuya, | ||
| userId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "userId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.tuya.listHomes({ | ||
| userId: this.userId, | ||
| }); | ||
| if (response?.result?.length) { | ||
| $.export("$summary", `Found ${response.result.length} home${response.result.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| } | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            69 changes: 69 additions & 0 deletions
          
          69 
        
  components/tuya/actions/send-instructions-to-device/send-instructions-to-device.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import tuya from "../../tuya.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "tuya-send-instructions-to-device", | ||
| name: "Send Instructions to Device", | ||
| description: "Send an instruction to the specified device. [See the documentation](https://developer.tuya.com/en/docs/cloud/device-control?id=K95zu01ksols7#title-35-Send%20instructions%20to%20the%20device)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| tuya, | ||
| userId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "userId", | ||
| ], | ||
| }, | ||
| homeId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "homeId", | ||
| (c) => ({ | ||
| userId: c.userId, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| deviceId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "deviceId", | ||
| (c) => ({ | ||
| userId: c.userId, | ||
| homeId: c.homeId, | ||
| }), | ||
| ], | ||
| }, | ||
| instructionCode: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "instructionCode", | ||
| (c) => ({ | ||
| deviceId: c.deviceId, | ||
| }), | ||
| ], | ||
| }, | ||
| value: { | ||
| type: "string", | ||
| label: "Value", | ||
| description: "The value to set", | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.tuya.sendInstructionsToDevice({ | ||
| deviceId: this.deviceId, | ||
| data: { | ||
| commands: [ | ||
| { | ||
| code: this.instructionCode, | ||
| value: this.value, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| if (response.success) { | ||
| $.export("$summary", "Successfully sent instructions to device"); | ||
| } | ||
| return response; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/tuya", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Tuya Components", | ||
| "main": "tuya.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3", | ||
| "@tuya/tuya-connector-nodejs": "^2.1.2" | ||
| } | ||
| } | ||
| } | ||
        
          
          
            88 changes: 88 additions & 0 deletions
          
          88 
        
  components/tuya/sources/new-device-parameter-updated/new-device-parameter-updated.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import tuya from "../../tuya.app.mjs"; | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|  | ||
| export default { | ||
| key: "tuya-new-device-parameter-updated", | ||
| name: "New Device Parameter Updated", | ||
| description: "Emit new event when the specified device parameter is updated. [See the documentation](https://developer.tuya.com/en/docs/cloud/device-management?id=K9g6rfntdz78a#title-10-Get%20a%20list%20of%20devices%20under%20a%20specified%20user)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| tuya, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| userId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "userId", | ||
| ], | ||
| }, | ||
| deviceParameter: { | ||
| type: "string", | ||
| label: "Device Parameter", | ||
| description: "The device parameter to watch for updates. E.g. `switch_1`", | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| homeId: { | ||
| propDefinition: [ | ||
| tuya, | ||
| "homeId", | ||
| (c) => ({ | ||
| userId: c.userId, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getPreviousValues() { | ||
| return this.db.get("previousValues") || {}; | ||
| }, | ||
| _setPreviousValues(previousValues) { | ||
| this.db.set("previousValues", previousValues); | ||
| }, | ||
| getCurrentValue(device) { | ||
| const { status } = device; | ||
| const relevantStatus = status.find(({ code }) => code === this.deviceParameter); | ||
| return relevantStatus?.value; | ||
| }, | ||
| generateMeta(item) { | ||
| const ts = Date.now(); | ||
| return { | ||
| id: `${item.id}${ts}`, | ||
| summary: `Device Updated with ID: ${item.id}`, | ||
| ts, | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const previousValues = this._getPreviousValues(); | ||
| const newValues = {}; | ||
|  | ||
| const { result: devices } = this.homeId | ||
| ? await this.tuya.listHomeDevices({ | ||
| homeId: this.homeId, | ||
| }) | ||
| : await this.tuya.listUserDevices({ | ||
| userId: this.userId, | ||
| }); | ||
|  | ||
| for (const device of devices) { | ||
| const currentValue = this.getCurrentValue(device); | ||
| if (previousValues[device.id] !== currentValue) { | ||
| const meta = this.generateMeta(device); | ||
| this.$emit(device, meta); | ||
| } | ||
| newValues[device.id] = currentValue; | ||
| } | ||
|  | ||
| this._setPreviousValues(newValues); | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| sampleEmit, | ||
| }; | ||
        
          
          
            77 changes: 77 additions & 0 deletions
          
          77 
        
  components/tuya/sources/new-device-parameter-updated/test-event.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| export default { | ||
| "active_time": 1748632139, | ||
| "biz_type": 18, | ||
| "category": "cz", | ||
| "create_time": 1748632139, | ||
| "icon": "smart/icon/bay1599677305883cNM4/03aaf2fd77d712895eb7b8408a374ebe.png", | ||
| "id": "vdevo174863213925233", | ||
| "ip": "47.225.143.157", | ||
| "lat": "", | ||
| "local_key": ".'0k9<h@|2j7!OK9", | ||
| "lon": "", | ||
| "model": "TS-441", | ||
| "name": "Tramontina Plug-vdevo", | ||
| "online": true, | ||
| "owner_id": "250587566", | ||
| "product_id": "mjzxchzvqmxps3lf", | ||
| "product_name": "Plugue Tramontina", | ||
| "status": [ | ||
| { | ||
| "code": "switch_1", | ||
| "value": false | ||
| }, | ||
| { | ||
| "code": "countdown_1", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "code": "add_ele", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "code": "cur_current", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "code": "cur_power", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "code": "cur_voltage", | ||
| "value": 0 | ||
| }, | ||
| { | ||
| "code": "relay_status", | ||
| "value": "power_off" | ||
| }, | ||
| { | ||
| "code": "overcharge_switch", | ||
| "value": false | ||
| }, | ||
| { | ||
| "code": "light_mode", | ||
| "value": "relay" | ||
| }, | ||
| { | ||
| "code": "child_lock", | ||
| "value": false | ||
| }, | ||
| { | ||
| "code": "cycle_time", | ||
| "value": "" | ||
| }, | ||
| { | ||
| "code": "random_time", | ||
| "value": "" | ||
| }, | ||
| { | ||
| "code": "switch_inching", | ||
| "value": "" | ||
| } | ||
| ], | ||
| "sub": false, | ||
| "time_zone": "", | ||
| "uid": "az1748632127862aWriL", | ||
| "update_time": 1748632139, | ||
| "uuid": "vdevo174863213925233" | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.