domotics-core 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/domotics/core/device/file_camera_device.rb +22 -20
- data/lib/domotics/core/device.rb +3 -2
- data/lib/domotics/core/element.rb +1 -0
- data/lib/domotics/core/version.rb +1 -1
- data/lib/domotics/core.rb +7 -5
- data/lib/domotics/file_camera/camera_element.rb +16 -0
- data/test/test_devices.rb +32 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74cbeb6f3ebcc02fddd4fdd6a4b980aad204da2a
|
4
|
+
data.tar.gz: 9d7c8c5d0fbeb9bdb9c8f4e7e4042c420fca3af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d210cd402ee0601e23168fb037b19650e5a570737aa82f5ec1fcbcb315fc40d6978478fa7ad1a1b1b74b6adaddde42770cfb54637bd4f682447842d6e1a9686d
|
7
|
+
data.tar.gz: 0ade937876a477a4a3594875766b19a2f32a0ce01e09004f1bf822f0f4efc1b17a0725dc2004410eda8ef61a7f134364c1ef714e19b69037d3acf5bc04c82e2d
|
@@ -1,14 +1,13 @@
|
|
1
1
|
module Domotics::Core
|
2
2
|
class FileCameraDevice < Device #__as__ :file_camera
|
3
|
+
attr_accessor :mode
|
4
|
+
attr_reader :current_file_name, :camera_element
|
3
5
|
def initialize(args = {})
|
4
|
-
@
|
6
|
+
@current_file_name = nil
|
7
|
+
@mode = args[:mode] || :watch
|
5
8
|
# Emulate element
|
6
|
-
|
7
|
-
|
8
|
-
image_lambda = lambda { s.current_link }
|
9
|
-
file_lambda = lambda { |*args| s.current_file }
|
10
|
-
@camera_element.eigenclass.send :define_method, :image, image_lambda
|
11
|
-
@camera_element.eigenclass.send :define_method, :file, file_lambda
|
9
|
+
args[:device] = self
|
10
|
+
@camera_element = Domotics::FileCamera::CameraElement.new args
|
12
11
|
# Path to shots
|
13
12
|
@path = args[:path] || "/tmp"
|
14
13
|
@path.chop! if @path[-1] == "/"
|
@@ -26,25 +25,28 @@ module Domotics::Core
|
|
26
25
|
super
|
27
26
|
end
|
28
27
|
def event_handler(event)
|
29
|
-
|
30
|
-
@current_name = "#{@path}/#{Time.now.to_i}#{@file_ext}"
|
28
|
+
return if File.extname(event.name) != @file_ext
|
31
29
|
# Wait untill close file and rename it
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
sleep 0.25
|
31
|
+
case @mode
|
32
|
+
when :save
|
33
|
+
dir_name = Time.now.strftime("%Y%m%d")
|
34
|
+
FileUtils.mkdir_p "#{@path}/#{dir_name}"
|
35
|
+
@current_file_name = "#{@path}/#{dir_name}/#{Time.now.to_i}#{@file_ext}"
|
36
|
+
File.rename "#{@path}/#{event.name}", @current_file_name
|
37
|
+
when :watch
|
38
|
+
@current_file_name = "#{@path}/current#{@file_ext}"
|
39
|
+
File.rename "#{@path}/#{event.name}", @current_file_name
|
40
|
+
else #:delete
|
41
|
+
@current_file_name = nil
|
42
|
+
FileUtils.rm "#{@path}/#{event.name}"
|
43
|
+
end
|
42
44
|
end
|
43
45
|
def current_link
|
44
46
|
"#{@camera_element.room.name}/#{@camera_element.name}/file/#{Time.now.to_i}#{@file_ext}"
|
45
47
|
end
|
46
48
|
def current_file
|
47
|
-
IO.read @
|
49
|
+
IO.read @current_file_name if @current_file_name
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
data/lib/domotics/core/device.rb
CHANGED
@@ -3,8 +3,9 @@ module Domotics::Core
|
|
3
3
|
@@devices = {}
|
4
4
|
attr_reader :name, :type
|
5
5
|
def initialize(args = {})
|
6
|
-
|
7
|
-
@
|
6
|
+
@name = args[:name] || SecureRandom.hex
|
7
|
+
@@devices[@name] = self
|
8
|
+
@type = args[:type] || "undefined"
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.[](symbol = nil)
|
data/lib/domotics/core.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
+
# From arduino_board
|
3
|
+
#require "../domotics-arduino/lib/domotics/arduino"
|
4
|
+
require 'domotics/arduino'
|
2
5
|
# From data_mongo
|
3
6
|
require 'mongo'
|
4
7
|
# From data_redis
|
5
8
|
require 'redis'
|
6
9
|
require 'hiredis'
|
7
|
-
# From
|
8
|
-
|
9
|
-
require 'domotics/arduino'
|
10
|
-
# From server
|
11
|
-
require 'json'
|
10
|
+
# From device
|
11
|
+
require 'securerandom'
|
12
12
|
# From file_camera_device
|
13
13
|
require 'rb-inotify'
|
14
|
+
# From server
|
15
|
+
require 'json'
|
14
16
|
|
15
17
|
module Domotics
|
16
18
|
module Core
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Domotics
|
2
|
+
module FileCamera
|
3
|
+
class CameraElement < Domotics::Core::Element
|
4
|
+
def image
|
5
|
+
@device.current_link
|
6
|
+
end
|
7
|
+
def file
|
8
|
+
@device.current_file
|
9
|
+
end
|
10
|
+
def mode(param)
|
11
|
+
@device.mode = param
|
12
|
+
set_state param
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_devices.rb
CHANGED
@@ -7,5 +7,36 @@ Domotics::Core::TestHelper.init
|
|
7
7
|
|
8
8
|
class DomoticsDevicesTestCase < Test::Unit::TestCase
|
9
9
|
def test_file_camera
|
10
|
+
# General
|
11
|
+
cam = Domotics::Core::Device[:cam]
|
12
|
+
assert_equal "cam", cam.name.to_s
|
13
|
+
assert_equal "test/cam/file/#{Time.now.to_i}.jpg", cam.current_link
|
14
|
+
# Watch mode (default)
|
15
|
+
%x{echo "[test foto content]" > /tmp/test_foto_1.jpg}
|
16
|
+
sleep 0.5
|
17
|
+
assert_equal "/tmp/current.jpg", cam.current_file_name
|
18
|
+
assert_equal "[test foto content]", cam.current_file.chomp
|
19
|
+
# Save mode
|
20
|
+
cam.mode = :save
|
21
|
+
dir_name = Time.now.strftime("%Y%m%d")
|
22
|
+
%x{rm -rf /tmp/#{dir_name}}
|
23
|
+
%x{echo "[test foto content]" > /tmp/test_foto_2.jpg}
|
24
|
+
name = Time.now.to_i
|
25
|
+
sleep 0.5
|
26
|
+
assert_match /\/tmp\/#{dir_name}\/#{name/100}\d{2}.jpg/, cam.current_file_name
|
27
|
+
assert_equal "[test foto content]", cam.current_file.chomp
|
28
|
+
# Delete mode
|
29
|
+
cam.mode = :delete
|
30
|
+
%x{echo "[test foto content]" > /tmp/test_foto_3.jpg}
|
31
|
+
sleep 0.5
|
32
|
+
assert_nil cam.current_file_name
|
33
|
+
assert_nil cam.current_file
|
34
|
+
# Test CameraElement
|
35
|
+
assert_equal "test/cam/file/#{Time.now.to_i}.jpg", cam.camera_element.image
|
36
|
+
cam.camera_element.mode :watch
|
37
|
+
assert_equal :watch, cam.camera_element.state
|
38
|
+
%x{echo "[test foto content]" > /tmp/test_foto_4.jpg}
|
39
|
+
sleep 0.5
|
40
|
+
assert_equal "[test foto content]", cam.camera_element.file.chomp
|
10
41
|
end
|
11
|
-
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domotics-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goredar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: domotics-arduino
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- lib/domotics/core/server.rb
|
198
198
|
- lib/domotics/core/setup.rb
|
199
199
|
- lib/domotics/core/version.rb
|
200
|
+
- lib/domotics/file_camera/camera_element.rb
|
200
201
|
- lib/domotics/file_camera/digital_sensor.rb
|
201
202
|
- test/config.test.rb
|
202
203
|
- test/test_devices.rb
|