Domotest is a small library to assist with testing file-system-based Lua scripts used by Domoticz.
I wanted to ensure that my home automation scripts were working correctly, and any changes would not break anything. That meant I wanted to have tests that could confirm the correct behaviour of the event scripts.
It turns out that getting data into a Domoticz-compatible Lua script (such as the devicechanged
, otherdevices
tables) requires a reasonable amount of boilerplate that would clutter the tests and make them harder to understand.
Enter Domotest.
Install the domotest rock:
luarocks install domotest
Require the domotest library in your test .lua
file(s):
require 'domotest'
Clone the git repository:
git clone https://github.com/NxSoftware/domotest.git
Require the domotest source as a relative path from your test .lua
file(s):
require 'src/domotest'
Use Domotest to load the appropriate Domoticz event script, passing in whatever data you need to test:
commandArray = domotest('script_device_bathroommotion.lua', {
devicechanged = { ['Bathroom Motion'] = 'On' },
timeofday = { ['Nighttime'] = true }
})
The return value is the commandArray
table as returned from your Domoticz event script.
Have a look at the examples for a more detailed look and how it can be used with the Busted test framework.
Please note that the examples are not necessarily good/recommended ways of writing event scripts and are simply intended to show how Domotest is used.