|
1 |
| -# SmartThingsEdgeDrivers |
| 1 | +# SmartThingsEdgeDrivers |
| 2 | + |
| 3 | +## Documentation |
| 4 | + |
| 5 | +Check out the [SmartThings developer docs](https://developer-preview.smartthings.com/) for a bunch of guides and |
| 6 | +reference documentation about SmartThings Edge Drivers. |
| 7 | + |
| 8 | +## Setting up your development environment |
| 9 | + |
| 10 | +### LUA_PATH |
| 11 | + |
| 12 | +When running lua code it is necessary for you have a `LUA_PATH` environment variable that informs your system of where |
| 13 | +to find code that can be used via a Lua `require` call. For any driver it is going to be necessary that you use the |
| 14 | +SmartThings Lua libraries to provide the functionality needed to interact with the system and devices. You should have |
| 15 | +a LUA_PATH that looks something like: |
| 16 | + |
| 17 | +``` |
| 18 | +LUA_PATH=/path/to/lua_libs-api_vX/?.lua;/path/to/lua_libs-api_vX/?/init.lua;./?.lua;./?/init.lua;; |
| 19 | +``` |
| 20 | + |
| 21 | +This assumes that the `lua_libs-api_vX` folder is the folder included in the API releases. NOTE: this is the internal |
| 22 | +folder of this name, not a top level folder you potentially created when unzipping (i.e. it should not include the docs |
| 23 | +folder). This will make all the SmartThings Lua library functionality available under the same paths it will be |
| 24 | +available when executing in the SmartThings sandbox, as well as allow any working directory folders and files to be |
| 25 | +available (as they will be for files provided in the `src/` directory of your driver). |
| 26 | + |
| 27 | +If you've installed `luasocket` using `luarocks` you will also need to make sure you include the luarocks include |
| 28 | +folders in this path. You can do this semi-automatically with `eval $(luarocks path --append)` after configuring the |
| 29 | +`LUA_PATH` for the lua_libs folder. |
| 30 | + |
| 31 | +### IDE and Auto-completion |
| 32 | + |
| 33 | +The lua libraries are tagged with EmmyLua comments to describe the types and functions that are |
| 34 | +available within the libraries. These can be very helpful with IDE support to allow for powerful auto-completion and |
| 35 | +suggestions. Setting this up will be IDE specific, but following are a few options: |
| 36 | + |
| 37 | +#### IntelliJ |
| 38 | + |
| 39 | +1) Install the EmmyLua IntelliJ plugin (Not the Lua plugin) |
| 40 | +2) Download the API release version [from github](https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases) |
| 41 | + that you will be developing against |
| 42 | +3) Extract the contents into the git repo directory for this project (the 2 extracted folders should be .gitignored by |
| 43 | + default) |
| 44 | +4) Navigate to the settings and add the `lua_libs-api_vX` extracted directory as a "Lua Additional Sources Root" under |
| 45 | + the EmmyLua settings |
| 46 | + |
| 47 | +At this point IntelliJ should run an indexing task and the auto-completion and type hints should be available while |
| 48 | +developing. However in order to run an individual test file (the only way to "run" your driver outside the context of |
| 49 | +the sandbox on a SmartThings hub), you need to set up the run configuration. |
| 50 | + |
| 51 | +1) Open the run configurations in your IDE |
| 52 | +2) Create a new Lua Application (or edit an existing one) |
| 53 | +3) Set the working directory to `path/to/your-driver/src` |
| 54 | +4) Set the entry file to `path/to/your-driver/src/test/test_file.lua` |
| 55 | +5) Set an environment variable for the `LUA_PATH` described in this document |
| 56 | + |
| 57 | +From here you should be able to "run" the configuration and see the test output in your IDE. |
| 58 | + |
| 59 | +#### VSCode |
| 60 | + |
| 61 | +1. Install the [Lua Language Server](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) VSCode plugin |
| 62 | +1. Download the API release version [from github](https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases) |
| 63 | + that you will be developing against |
| 64 | +1. Extract the contents into the git repo directory for this project (the 2 extracted folders should be .gitignored by |
| 65 | + default) |
| 66 | + |
| 67 | +Alternatively, you can extract the API release to a location of your choice and add the folder path as a Workspace |
| 68 | +Library source in the Lua Language Server [settings](https://github.com/sumneko/lua-language-server#setting). **NOTE**: |
| 69 | +this is the internal folder, not a top level folder you potentially created when unzipping (i.e. it should not include |
| 70 | +the docs folder). |
0 commit comments