From 4743520aefc9c774924c7f8f98ec9817c637a671 Mon Sep 17 00:00:00 2001 From: Vitaliy Sazonenko Date: Sat, 10 Oct 2020 17:04:22 +0300 Subject: [PATCH 1/2] [none] (backport) store changes from server --- Dockerfile | 10 ++++++++++ Gemfile | 4 ++-- Gemfile.lock | 12 ++++++------ app.rb | 2 +- conf/app.conf.rb | 2 +- docker-compose.yml | 12 ++++++++++++ rooms/bathroom.rb | 18 +++++++++++++++++- rooms/hall.rb | 10 ++++++++++ rooms/home.rb | 4 ++-- rooms/kitchen.rb | 11 +++++++++++ rooms/living_room.rb | 11 +++++++---- rooms/playroom.rb | 11 +++++------ rooms/wc.rb | 22 +++++++++++++--------- 13 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3c9a0cc --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Gemfile b/Gemfile index baf4bad..329a407 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,8 @@ gem "rb-inotify" gem "domotics-core" # Database -#gem "redis" -#gem "hiredis" +gem "redis" +gem "hiredis" #gem "mongo" #gem "bson_ext" diff --git a/Gemfile.lock b/Gemfile.lock index 2156026..0966673 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ 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 @@ -11,7 +11,7 @@ GEM 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 @@ -28,8 +28,8 @@ GEM ffi (1.9.3) 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) diff --git a/app.rb b/app.rb index 1ce601c..0dd5657 100755 --- a/app.rb +++ b/app.rb @@ -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) \ No newline at end of file +Domotics::Core::Server.run(:Host => 'localhost', :Port => 9292) diff --git a/conf/app.conf.rb b/conf/app.conf.rb index 7b71555..f8a6153 100644 --- a/conf/app.conf.rb +++ b/conf/app.conf.rb @@ -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 \ No newline at end of file +Domotics::Core::Element.data = Domotics::Core::DataRedis.new(host: ENV["REDIS_HOST"] || "redis") diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f5377db --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.8" +services: + domotics: + image: dom + volumes: + - ./conf/:/app/conf/ + devices: + - /dev/ttyNano + links: + - redis + redis: + image: redis diff --git a/rooms/bathroom.rb b/rooms/bathroom.rb index fa431f4..42a4a09 100644 --- a/rooms/bathroom.rb +++ b/rooms/bathroom.rb @@ -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 - diff --git a/rooms/hall.rb b/rooms/hall.rb index 9124900..b2bc260 100644 --- a/rooms/hall.rb +++ b/rooms/hall.rb @@ -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 diff --git a/rooms/home.rb b/rooms/home.rb index e5780bc..d6bdf5a 100644 --- a/rooms/home.rb +++ b/rooms/home.rb @@ -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 diff --git a/rooms/kitchen.rb b/rooms/kitchen.rb index 42226e1..c159c77 100644 --- a/rooms/kitchen.rb +++ b/rooms/kitchen.rb @@ -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 diff --git a/rooms/living_room.rb b/rooms/living_room.rb index c6fecce..676a202 100644 --- a/rooms/living_room.rb +++ b/rooms/living_room.rb @@ -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? diff --git a/rooms/playroom.rb b/rooms/playroom.rb index bf450fe..199a061 100644 --- a/rooms/playroom.rb +++ b/rooms/playroom.rb @@ -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 diff --git a/rooms/wc.rb b/rooms/wc.rb index 423e247..13e89a3 100644 --- a/rooms/wc.rb +++ b/rooms/wc.rb @@ -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 From 4fd7d87b1387d6e6d7ceef40eb2ffa218aad9f23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2020 08:02:29 +0000 Subject: [PATCH 2/2] Bump ffi from 1.9.3 to 1.13.1 Bumps [ffi](https://github.com/ffi/ffi) from 1.9.3 to 1.13.1. - [Release notes](https://github.com/ffi/ffi/releases) - [Changelog](https://github.com/ffi/ffi/blob/master/CHANGELOG.md) - [Commits](https://github.com/ffi/ffi/compare/1.9.3...1.13.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0966673..d14dcd4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,7 +25,7 @@ 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.10.0) @@ -52,7 +52,9 @@ PLATFORMS DEPENDENCIES coffee-script domotics-core + hiredis rb-inotify + redis sass slim thin