User Tools

Site Tools


action_sendraw
sendraw.lua
--
-- Copyright (C) 2018 Fritz Elfert
--
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
--
 
local M = {}
 
function M.check(parameters)
	local _to = nil;
	if parameters['CODE'] == nil then
		error("sendraw action is missing a \"CODE\" statement");
	end
	if #parameters['CODE']['value'] ~= 1 or parameters['CODE']['value'][2] ~= nil then
		error("sendraw action \"CODE\" only takes one argument");
	end
	local code = parameters['CODE']['value'][1];
	if type(code) ~= 'string' then
		error("sendraw action \"CODE\" must be a string");
	end
	if code ~= '' and string.match(code, "^[%d%s]+$") ~= code then
		error("sendraw action \"CODE\" must contain only digits and spaces");
	end
	return 1;
end
 
function M.run(parameters)
	local code = parameters['CODE']['value'][1];
	if code ~= '' then
		os.execute("pilight-send -p raw -c \"" .. code .. "\"");
	end
	return 1;
end
 
function M.parameters()
	return "CODE";
end
 
function M.info()
	return {
		name = "sendraw",
		version = "1.0",
		reqversion = "8.1.2",
		reqcommit = "23"
	}
end
 
return M;
action_sendraw.txt · Last modified: 2018/10/20 13:48 by felfert