projectsimulator 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/projectsimulator.rb +113 -14
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d6d7ab7020d9059697cd4a5d7e681cf876f560cc1837e74bd3eb0e896004a9c
|
|
4
|
+
data.tar.gz: d1c40af5df514a3a41b82d03610c3fd89c8938f27b87ade37518c3295e4f65b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ff10c8255f576a0bdd80920108ad6ef2e07ded1be62b84dae5a1beac65d8836ad80c21fb73fcc51c7e328dfb1f38621c60f28d05210a19953a588ee1261e73f
|
|
7
|
+
data.tar.gz: 20f8991ea5a55153acf1c1ef584c3063de630d64704fc174c2e99587fc8c24d0e8b589491d86577dab0d9c00650c2561917fef44e9a59a2276f714fe69ac9442
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/lib/projectsimulator.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# file: projectsimulator.rb
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
require 'easydom'
|
|
6
7
|
require 'app-routes'
|
|
7
8
|
|
|
@@ -11,18 +12,30 @@ module ProjectSimulator
|
|
|
11
12
|
class Model
|
|
12
13
|
include AppRoutes
|
|
13
14
|
|
|
14
|
-
def initialize()
|
|
15
|
+
def initialize(obj=nil, root: 'building1')
|
|
15
16
|
|
|
16
|
-
super()
|
|
17
|
+
super()
|
|
18
|
+
@root = root
|
|
19
|
+
@location = nil
|
|
20
|
+
build(obj, root: root) if obj
|
|
17
21
|
|
|
18
22
|
end
|
|
19
23
|
|
|
20
|
-
def build(raw_requests, root:
|
|
24
|
+
def build(raw_requests, root: @root)
|
|
21
25
|
|
|
22
26
|
@ed = EasyDom.new(debug: false, root: root)
|
|
23
27
|
raw_requests.lines.each {|line| request(line) }
|
|
24
28
|
|
|
25
29
|
end
|
|
30
|
+
|
|
31
|
+
def get_device(h)
|
|
32
|
+
|
|
33
|
+
a = h[:location].split(/ /)
|
|
34
|
+
a << h[:device]
|
|
35
|
+
status = a.inject(@ed) {|r,x| r.send(x)}.send(h[:action])
|
|
36
|
+
"The %s %s is %s." % [h[:location], h[:device], status]
|
|
37
|
+
|
|
38
|
+
end
|
|
26
39
|
|
|
27
40
|
def op()
|
|
28
41
|
@ed
|
|
@@ -31,6 +44,24 @@ module ProjectSimulator
|
|
|
31
44
|
def query(s)
|
|
32
45
|
@ed.e.element(s)
|
|
33
46
|
end
|
|
47
|
+
|
|
48
|
+
def request(s)
|
|
49
|
+
|
|
50
|
+
params = {request: s}
|
|
51
|
+
requests(params)
|
|
52
|
+
h = find_request(s)
|
|
53
|
+
|
|
54
|
+
method(h.first[-1]).call(h)
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def set_device(h)
|
|
59
|
+
|
|
60
|
+
a = h[:location].split(/ /)
|
|
61
|
+
a << h[:device]
|
|
62
|
+
a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value])
|
|
63
|
+
|
|
64
|
+
end
|
|
34
65
|
|
|
35
66
|
def to_sliml()
|
|
36
67
|
@ed.to_sliml
|
|
@@ -44,28 +75,96 @@ module ProjectSimulator
|
|
|
44
75
|
|
|
45
76
|
def requests(params)
|
|
46
77
|
|
|
78
|
+
# e.g. switch the livingroom gas_fire off
|
|
79
|
+
#
|
|
47
80
|
get /(?:switch|turn) the ([^ ]+) +([^ ]+) +(on|off)$/ do |location, device, onoff|
|
|
48
|
-
{action: 'switch=', location: location, device: device, value: onoff}
|
|
81
|
+
{type: :set_device, action: 'switch=', location: location, device: device, value: onoff}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# e.g. switch the gas _fire off
|
|
85
|
+
#
|
|
86
|
+
get /(?:switch|turn) the ([^ ]+) +(on|off)$/ do |device, onoff|
|
|
87
|
+
location = dev_location(device)
|
|
88
|
+
{type: :set_device, action: 'switch=', location: location, device: device, value: onoff}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# e.g. is the livingroom gas_fire on?
|
|
92
|
+
#
|
|
93
|
+
get /is the ([^ ]+) +([^ ]+) +(?:on|off)\??$/ do |location, device|
|
|
94
|
+
{type: :get_device, action: 'switch', location: location, device: device}
|
|
49
95
|
end
|
|
50
96
|
|
|
97
|
+
# e.g. is the gas_fire on?
|
|
98
|
+
#
|
|
99
|
+
get /is the ([^ ]+) +(?:on|off)\??$/ do |device|
|
|
100
|
+
location = dev_location(device)
|
|
101
|
+
{type: :get_device, action: 'switch', location: location, device: device}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# e.g. fetch the livingroom temperature reading
|
|
105
|
+
#
|
|
106
|
+
get /fetch the ([^ ]+) +([^ ]+) +(?:reading)$/ do |location, device|
|
|
107
|
+
{type: :get_device, action: 'reading', location: location, device: device}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# e.g. fetch the temperature reading
|
|
111
|
+
#
|
|
112
|
+
get /fetch the ([^ ]+) +(?:reading)$/ do |device|
|
|
113
|
+
location = dev_location(device)
|
|
114
|
+
{type: :get_device, action: 'reading', location: location, device: device}
|
|
115
|
+
end
|
|
116
|
+
|
|
51
117
|
end
|
|
52
118
|
|
|
53
119
|
private
|
|
54
120
|
|
|
55
|
-
def
|
|
121
|
+
def dev_location(device)
|
|
122
|
+
a = query('//'+ device).backtrack.to_xpath.split('/')
|
|
123
|
+
a[1..-2].join(' ')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
alias find_request run_route
|
|
56
127
|
|
|
57
|
-
|
|
58
|
-
requests(@params)
|
|
59
|
-
h = find_request(s)
|
|
128
|
+
end
|
|
60
129
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
130
|
+
class Controller
|
|
131
|
+
|
|
132
|
+
attr_reader :macros
|
|
133
|
+
attr_accessor :title
|
|
64
134
|
|
|
65
|
-
|
|
135
|
+
def initialize(mcs, debug: false)
|
|
136
|
+
|
|
137
|
+
@debug = debug
|
|
138
|
+
@syslog = []
|
|
139
|
+
|
|
140
|
+
@macros = mcs.macros
|
|
66
141
|
|
|
67
|
-
|
|
142
|
+
end
|
|
68
143
|
|
|
144
|
+
|
|
145
|
+
def trigger(name, detail={})
|
|
146
|
+
|
|
147
|
+
macros = @macros.select do |macro|
|
|
148
|
+
|
|
149
|
+
puts 'macro: ' + macro.inspect if @debug
|
|
150
|
+
|
|
151
|
+
valid_trigger = macro.match?(name, detail)
|
|
152
|
+
|
|
153
|
+
puts 'valid_trigger: ' + valid_trigger.inspect if @debug
|
|
154
|
+
|
|
155
|
+
if valid_trigger then
|
|
156
|
+
@syslog << [Time.now, :trigger, name]
|
|
157
|
+
@syslog << [Time.now, :macro, macro.title]
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
valid_trigger
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
puts 'macros: ' + macros.inspect if @debug
|
|
165
|
+
|
|
166
|
+
macros.flat_map(&:run)
|
|
167
|
+
end
|
|
69
168
|
|
|
70
|
-
end
|
|
169
|
+
end
|
|
71
170
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: projectsimulator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Robertson
|
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
|
35
35
|
2GrtfOXGVOS+2jvmCQC6vU+ew9WBxiDUbebI95TeTwMs2o0cs3IASXX5rIn4TPcz
|
|
36
36
|
SCccB3fVg2yfsy5DivaWaZwg
|
|
37
37
|
-----END CERTIFICATE-----
|
|
38
|
-
date: 2020-
|
|
38
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
|
39
39
|
dependencies:
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: easydom
|
metadata.gz.sig
CHANGED
|
Binary file
|