parent
644965d12c
commit
b323b08e4e
@ -0,0 +1,165 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
### config
|
||||
user=""
|
||||
pass=""
|
||||
ip="192.168.x.x"
|
||||
|
||||
### No need to change anything below
|
||||
require "httparty"
|
||||
|
||||
url="http://#{user}:#{pass}@#{ip}/white"
|
||||
|
||||
## funkce
|
||||
def rgbwstatus(url,channel=0)
|
||||
page_data = HTTParty.get("#{url}/#{channel}")
|
||||
responses = page_data.parsed_response
|
||||
return responses
|
||||
end
|
||||
|
||||
def rgbwtoggle(url,channel=0)
|
||||
if rgbwstatus(url,channel)["ison"] == true then
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=off")
|
||||
status = page_data.parsed_response
|
||||
else
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=on")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
end
|
||||
|
||||
def rgbwbrup(url,channel=0)
|
||||
brightness = rgbwstatus(url,channel)["brightness"].to_i
|
||||
brightness = brightness+5
|
||||
|
||||
if brightness > 100 then brightness=100 end
|
||||
if brightness < 5 then brightness=5 end
|
||||
|
||||
page_data = HTTParty.get("#{url}/#{channel}?brightness=#{brightness}")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
|
||||
def rgbwbrdown(url,channel=0)
|
||||
|
||||
brightness = rgbwstatus(url,channel)["brightness"].to_i
|
||||
brightness = brightness-5
|
||||
|
||||
if brightness > 100 then brightness=100 end
|
||||
if brightness < 5 then brightness=5 end
|
||||
|
||||
page_data = HTTParty.get("#{url}/#{channel}?brightness=#{brightness}")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
|
||||
def rgbwbright(url,brightness,channel=0)
|
||||
brightness=brightness.to_i
|
||||
if brightness > 100 then
|
||||
brightness=100
|
||||
end
|
||||
if brightness < 5 then
|
||||
brightness=5
|
||||
end
|
||||
|
||||
page_data = HTTParty.get("#{url}/#{channel}?brightness=#{brightness}")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
|
||||
def rgbwtoggle(url,channel=0)
|
||||
if rgbwstatus(url,channel)["ison"] == true then
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=off")
|
||||
status = page_data.parsed_response
|
||||
else
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=on")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
end
|
||||
|
||||
def rgbwoff(url,channel=0)
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=off")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
|
||||
def rgbwon(url,channel=0)
|
||||
page_data = HTTParty.get("#{url}/#{channel}?turn=on")
|
||||
status = page_data.parsed_response
|
||||
end
|
||||
|
||||
## Ovladani
|
||||
command, *parametry = ARGV
|
||||
|
||||
case command
|
||||
when "on"
|
||||
if ! parametry[0].nil? then
|
||||
channel = parametry[0].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwon(url,channel)
|
||||
else
|
||||
rgbwon(url)
|
||||
end
|
||||
when "off"
|
||||
if ! parametry[0].nil? then
|
||||
channel = parametry[0].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwoff(url,channel)
|
||||
else
|
||||
rgbwoff(url)
|
||||
end
|
||||
when "toggle"
|
||||
if ! parametry[0].nil? then
|
||||
channel = parametry[0].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwtoggle(url,channel)
|
||||
else
|
||||
rgbwtoggle(url)
|
||||
end
|
||||
when "up"
|
||||
if ! parametry[0].nil? then
|
||||
channel = parametry[0].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwbrup(url,channel)
|
||||
else
|
||||
rgbwbrup(url)
|
||||
end
|
||||
when "down"
|
||||
if ! parametry[0].nil? then
|
||||
channel = parametry[0].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwbrdown(url,channel)
|
||||
else
|
||||
rgbwbrdown(url)
|
||||
end
|
||||
when "brightness"
|
||||
if parametry[0].nil? then
|
||||
puts "Musite zadat hodnotu intenzity v procentech (5-100)"
|
||||
exit 1
|
||||
else
|
||||
brightness=parametry[0].to_i
|
||||
end
|
||||
if ! parametry[1].nil? then
|
||||
channel = parametry[1].to_i
|
||||
if ! channel.between?(0,3) then
|
||||
puts "Neplatny kanal, hodnota musi byt v rozsahu 0 - 3"
|
||||
exit
|
||||
end
|
||||
rgbwbright(url,brightness,channel)
|
||||
else
|
||||
rgbwbright(url,brightness)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in new issue