co2-notify 0.4.0 → 0.4.3
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
- data/lib/co2-notify/config.rb +5 -2
- data/lib/co2-notify/hipchat_client.rb +1 -1
- data/lib/co2-notify/notifier.rb +2 -2
- data/lib/co2-notify/status.rb +32 -17
- data/lib/co2-notify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0898262a63f0164a54f0c5b7bbb08d347313804
|
4
|
+
data.tar.gz: e56659a2bd9e16205d9b822c3aa2d61b0e1cd877
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d8227a661bc931192432f35448b1c7d8fb429231bdcf847b132b674fd63c086d5889f7533e8a3423ac5dc0fcc47513e269169bace208ad0e9de7289e1f9e4ae
|
7
|
+
data.tar.gz: 2beb06bb5b919344a9d8d2def12ea496e3cbcc0a6805211dfa3644df532e9e70b24a3faae468de7c07d151241fabd5eda8f3cf50d88c7b51b7098c48613550df
|
data/lib/co2-notify/config.rb
CHANGED
@@ -8,6 +8,7 @@ class Co2Notify::Config < OpenStruct
|
|
8
8
|
DEFAULT_VERY_HIGH_LEVEL = 1200.freeze
|
9
9
|
DEFAULT_START_TIME = "12:00".freeze
|
10
10
|
DEFAULT_STOP_TIME = "19:00".freeze
|
11
|
+
DEFAULR_PING_TIMEOUT = 10.freeze
|
11
12
|
|
12
13
|
def self.get
|
13
14
|
new YAML.load_file(config_file)
|
@@ -27,9 +28,11 @@ class Co2Notify::Config < OpenStruct
|
|
27
28
|
h["timeout"] = STDIN.gets.chomp.presence || DEFAULT_TIMEOUT
|
28
29
|
print "Cooldown (default: #{DEFAULT_COOLDOWN} mins): "
|
29
30
|
h["cooldown"] = STDIN.gets.chomp.presence || DEFAULT_COOLDOWN
|
30
|
-
print "
|
31
|
+
print "Ping timeout (default: #{DEFAULT_PING_TIMEOUT} mins): "
|
32
|
+
h["ping_timeout"] = STDIN.gets.chomp.presence || DEFAULT_PING_TIMEOUT
|
33
|
+
print "High CO₂ level (default: #{DEFAULT_HIGH_LEVEL}): "
|
31
34
|
h["high_level"] = STDIN.gets.chomp.presence || DEFAULT_HIGH_LEVEL
|
32
|
-
print "Very High
|
35
|
+
print "Very High CO₂ level (default: #{DEFAULT_VERY_HIGH_LEVEL}): "
|
33
36
|
h["very_high_level"] = STDIN.gets.chomp.presence || DEFAULT_VERY_HIGH_LEVEL
|
34
37
|
print "Start time (default: #{DEFAULT_START_TIME}): "
|
35
38
|
h["start_time"] = STDIN.gets.chomp.presence || DEFAULT_START_TIME
|
@@ -8,6 +8,6 @@ class Co2Notify::HipchatClient
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def send(status)
|
11
|
-
client[room].send("
|
11
|
+
client[room].send("#{location}", status.message, color: status.color, message_format: "text")
|
12
12
|
end
|
13
13
|
end
|
data/lib/co2-notify/notifier.rb
CHANGED
@@ -9,7 +9,7 @@ class Co2Notify::Notifier
|
|
9
9
|
def initialize(config)
|
10
10
|
@config = config
|
11
11
|
@client = Co2Notify::HipchatClient.new(config)
|
12
|
-
@status = Co2Notify::Status::Empty.new(config)
|
12
|
+
@status = Co2Notify::Status::Empty.new(config, Time.now)
|
13
13
|
end
|
14
14
|
|
15
15
|
def start
|
@@ -32,7 +32,7 @@ class Co2Notify::Notifier
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def notify
|
35
|
-
new_status = Co2Notify::Status.build(get_data, config, status)
|
35
|
+
new_status = Co2Notify::Status.build(get_data, Time.now, config, status)
|
36
36
|
|
37
37
|
if status.changed?(new_status)
|
38
38
|
client.send(new_status)
|
data/lib/co2-notify/status.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Co2Notify::Status
|
2
2
|
class Base
|
3
|
-
attr_reader :co2, :config, :previous
|
4
|
-
delegate :timeout, :cooldown, :mention, :user, to: :config
|
3
|
+
attr_reader :co2, :config, :previous, :time
|
4
|
+
delegate :timeout, :cooldown, :mention, :user, :ping_timeout, to: :config
|
5
5
|
|
6
|
-
def initialize(config, previous = nil, co2 = nil)
|
7
|
-
@config, @co2, @previous = config, co2, previous
|
6
|
+
def initialize(config, time, previous = nil, co2 = nil)
|
7
|
+
@config, @co2, @previous, @time = config, co2, previous, time
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
@@ -20,7 +20,7 @@ class Co2Notify::Status
|
|
20
20
|
|
21
21
|
class VeryHigh < Base
|
22
22
|
def message
|
23
|
-
"#{hc_mention}
|
23
|
+
"#{hc_mention}CO₂ level is very high - #{co2}. Please open the windows!"
|
24
24
|
end
|
25
25
|
|
26
26
|
def color
|
@@ -28,7 +28,9 @@ class Co2Notify::Status
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def changed?(new_status)
|
31
|
-
new_status.is_a?(Empty) ||
|
31
|
+
new_status.is_a?(Empty) ||
|
32
|
+
new_status.is_a?(Normal) ||
|
33
|
+
(new_status.is_a?(VeryHigh) && new_status.co2 > co2)
|
32
34
|
end
|
33
35
|
|
34
36
|
def timeout
|
@@ -38,7 +40,7 @@ class Co2Notify::Status
|
|
38
40
|
|
39
41
|
class High < Base
|
40
42
|
def message
|
41
|
-
"#{hc_mention}
|
43
|
+
"#{hc_mention}CO₂ level is high - #{co2}. Please open the windows!"
|
42
44
|
end
|
43
45
|
|
44
46
|
def color
|
@@ -46,7 +48,10 @@ class Co2Notify::Status
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def changed?(new_status)
|
49
|
-
new_status.is_a?(Empty) ||
|
51
|
+
new_status.is_a?(Empty) ||
|
52
|
+
new_status.is_a?(Normal) ||
|
53
|
+
(new_status.is_a?(High) && new_status.co2 > co2) ||
|
54
|
+
new_status.is_a?(VeryHigh)
|
50
55
|
end
|
51
56
|
|
52
57
|
def timeout
|
@@ -56,7 +61,11 @@ class Co2Notify::Status
|
|
56
61
|
|
57
62
|
class Normal < Base
|
58
63
|
def message
|
59
|
-
|
64
|
+
if previous.is_a?(Normal) || previous.is_a?(Empty)
|
65
|
+
"CO₂ level is normal - #{co2}."
|
66
|
+
else
|
67
|
+
"#{hc_mention}CO₂ level is normalized - #{co2}. You can close the windows."
|
68
|
+
end
|
60
69
|
end
|
61
70
|
|
62
71
|
def color
|
@@ -64,7 +73,10 @@ class Co2Notify::Status
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def changed?(new_status)
|
67
|
-
new_status.is_a?(Empty) ||
|
76
|
+
new_status.is_a?(Empty) ||
|
77
|
+
new_status.is_a?(High) ||
|
78
|
+
new_status.is_a?(VeryHigh) ||
|
79
|
+
(new_status.is_a?(Normal) && new_status.time >= time + ping_timeout * 60)
|
68
80
|
end
|
69
81
|
|
70
82
|
def timeout
|
@@ -74,7 +86,7 @@ class Co2Notify::Status
|
|
74
86
|
|
75
87
|
class Empty < Base
|
76
88
|
def message
|
77
|
-
"#{hc_user}Please check that
|
89
|
+
"#{hc_user}Please check that CO₂ monitor is connected."
|
78
90
|
end
|
79
91
|
|
80
92
|
def color
|
@@ -82,20 +94,23 @@ class Co2Notify::Status
|
|
82
94
|
end
|
83
95
|
|
84
96
|
def changed?(new_status)
|
85
|
-
new_status.is_a?(Empty) ||
|
97
|
+
new_status.is_a?(Empty) ||
|
98
|
+
new_status.is_a?(High) ||
|
99
|
+
new_status.is_a?(VeryHigh) ||
|
100
|
+
new_status.is_a?(Normal)
|
86
101
|
end
|
87
102
|
end
|
88
103
|
|
89
|
-
def self.build(co2, config, previous = nil)
|
104
|
+
def self.build(co2, time, config, previous = nil)
|
90
105
|
case co2
|
91
106
|
when 1..config.high_level
|
92
|
-
Normal.new(config, previous, co2)
|
107
|
+
Normal.new(config, time, previous, co2)
|
93
108
|
when config.high_level..config.very_high_level
|
94
|
-
High.new(config, previous, co2)
|
109
|
+
High.new(config, time, previous, co2)
|
95
110
|
when proc { |n| n >= config.very_high_level }
|
96
|
-
VeryHigh.new(config, previous, co2)
|
111
|
+
VeryHigh.new(config, time, previous, co2)
|
97
112
|
else
|
98
|
-
Empty.new(config)
|
113
|
+
Empty.new(config, time)
|
99
114
|
end
|
100
115
|
end
|
101
116
|
end
|
data/lib/co2-notify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co2-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Butermanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|