Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ruby:2.1

# RUN apk add --no-cache alpine-sdk

COPY ./ /app
WORKDIR /app

RUN bundle install

CMD ruby app.rb
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ gem "rb-inotify"
gem "domotics-core"

# Database
#gem "redis"
#gem "hiredis"
gem "redis"
gem "hiredis"
#gem "mongo"
#gem "bson_ext"

Expand Down
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
bson (1.9.2)
bson_ext (1.9.2)
bson (~> 1.9.2)
bson (1.10.0)
bson_ext (1.10.0)
bson (~> 1.10.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.7.0)
daemons (1.1.9)
domotics-arduino (0.3.8)
serialport
domotics-core (0.2.2)
domotics-core (0.2.8)
bson_ext
domotics-arduino
em-websocket
Expand All @@ -25,11 +25,11 @@ GEM
http_parser.rb (~> 0.5.3)
eventmachine (1.0.3)
execjs (2.0.2)
ffi (1.9.3)
ffi (1.13.1)
hiredis (0.5.1)
http_parser.rb (0.5.3)
mongo (1.9.2)
bson (~> 1.9.2)
mongo (1.10.0)
bson (~> 1.10.0)
rack (1.5.2)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
Expand All @@ -52,7 +52,9 @@ PLATFORMS
DEPENDENCIES
coffee-script
domotics-core
hiredis
rb-inotify
redis
sass
slim
thin
2 changes: 1 addition & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

Domotics::Core::WsServer.new(:host => 'localhost', :port => 8080, :secure_proxy => true).run
Domotics::Core::Setup.new IO.read(conf)
Domotics::Core::Server.run(:Host => 'localhost', :Port => 9292)
Domotics::Core::Server.run(:Host => 'localhost', :Port => 9292)
2 changes: 1 addition & 1 deletion conf/app.conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Domotics::Core::Setup.logger.formatter = proc do |severity, datetime, progname, msg|
"#{severity} #{msg}#{$/}"
end
Domotics::Core::Element.data = Domotics::Core::DataRedis.new
Domotics::Core::Element.data = Domotics::Core::DataRedis.new(host: ENV["REDIS_HOST"] || "redis")
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.8"
services:
domotics:
image: dom
volumes:
- ./conf/:/app/conf/
devices:
- /dev/ttyNano
links:
- redis
redis:
image: redis
18 changes: 17 additions & 1 deletion rooms/bathroom.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
class Bathroom < Domotics::Core::Room
def event_handler(msg = {})
event, element = msg[:event], msg[:element]
case element.state
when :tap
bath_light.toggle
when :long_tap
bath_light.toggle
when :move
# bath_light.delay_on 0
when :open
bath_light.on
when :close
#wc_light.delay_off(12) { motion.state == :no_move }
end
bath_light.on? ? light_switch_indicator.on : light_switch_indicator.off
super
end
end

10 changes: 10 additions & 0 deletions rooms/hall.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
class Hall < Domotics::Core::Room

def event_handler(msg = {})
event, element = msg[:event], msg[:element]
case element.state
when :tap then hall_light.toggle
when :long_tap then bath.bath_light.toggle
end
super
end

end
4 changes: 2 additions & 2 deletions rooms/home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class Home < Domotics::Core::Room
def light(action = :off)
case action
when :off
[play, live].each { |room| room.light :off }
[play, live, hall].each { |room| room.light :off }
end
end

def verbose_state
[play, live].reduce(Hash.new) { |st, room| st.merge! room.verbose_state }
[play, live, hall].reduce(Hash.new) { |st, room| st.merge! room.verbose_state }
end
end
11 changes: 11 additions & 0 deletions rooms/kitchen.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
class Kitchen < Domotics::Core::Room

def event_handler(msg = {})
event, element = msg[:event], msg[:element]
case element.state
when :tap then main_light.toggle
when :long_tap then bath.bath_light.toggle
end
super
end


end
11 changes: 7 additions & 4 deletions rooms/living_room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ class LivingRoom < Domotics::Core::Room
def light(action = :toggle)
case action
when :up
return board_light.on if short_side_light.on?
return short_side_light.on if board_sofa_light.on?

board_sofa_light.on
[
board_sofa_light,
short_side_light,
board_tv_light,
window_side_light,
door_side_light,
].select(&:off?).first.on rescue light :off
when :down
return board_window_light.off unless board_window_light.off?
return long_side_light.off unless long_side_light.off?
Expand Down
11 changes: 5 additions & 6 deletions rooms/playroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ def light(action = :toggle)
when :off
rgb_strip.off
when :up
return center_light.on if corner_light.on?
return corner_light.on if center_light.on?

return door_side_light.on unless door_side_light.on?
window_side_light.on
[
window_side_light,
door_side_light,
].select(&:off?).first.on rescue light :off
when :down
return center_light.off unless center_light.off?
#return center_light.off unless center_light.off?
return window_side_light.off unless window_side_light.off?
door_side_light.off
end
Expand Down
22 changes: 13 additions & 9 deletions rooms/wc.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
class Wc < Domotics::Core::Room
def event_handler(msg)
event, element = *msg
def event_handler(msg = {})
event, element = msg[:event], msg[:element]
case element.state
when :tap
wc_light.toggle
when :long_tap
wc_light.toggle
when :move
light.on if door.close?
when :no_move
nil
wc_light.delay_on 0
when :open
light.on 30
wc_light.on
# wc_light.delay_off 12
wc_light.delay_off 10
when :close
light.delay_off 10
else
nil
wc_light.delay_off(11) { motion.state == :no_move }
end
wc_light.on? ? light_switch_indicator.on : light_switch_indicator.off
super
end
end