mochizuki 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8d9cbce9004854c3a808ac1ac24e60190933b6b3b60130d10ea3cfabf2babd
4
- data.tar.gz: 1ea2feed70b54549c218b5bba77ba36d75d7920c64a9603dc945e00b933b8492
3
+ metadata.gz: 45a1c70f5392c04f591f9867ce4fcd119bef28702e90ffe66d5eea1de5cdfa37
4
+ data.tar.gz: e6681852d0a5b1ab7f72991403728fdcd36b5afee94d3f657e39d6ef5b3ad002
5
5
  SHA512:
6
- metadata.gz: c2b00aa3c1b336f349da73d9dea769aed8741691ac6bd49508c4181da0be8855ee5a4cd8df104ffb2111949655da62e749f59c68d7df20a63bdb931cac313b80
7
- data.tar.gz: 1535e88b1c499b77a92966beb6da3813c881ad78f07ef4097ac512a4536895953e8fea49c931d7c26ca29fa2a55a3c13bbe3516af77abb6cafb3ebf971b160fe
6
+ metadata.gz: a9b75c553d835b499be5936fa9b3d065713b33bfc5d080486aebc8e0ca61d0f9ab55b1489f097a4f41df6ff0f1729477fa596b7a68fba6a4535bb65d1267658f
7
+ data.tar.gz: 3fbad4d706c73818f05c354c96828ad368916fe49002c3c5d5f61d84226c42957f47e940238f97f1b3dc620f59a4a66e9059bf789a7a5d98abc3c52e87366b2e
data/README.md CHANGED
@@ -19,7 +19,16 @@ gem install mochizuki
19
19
 
20
20
  **Recommended**
21
21
 
22
- See [mochizuki-docker](https://github.com/DarkKowalski/mochizuki-docker)
22
+ ```bash
23
+ docker pull darkkowalski/mochizuki
24
+ ```
25
+
26
+ ```bash
27
+ docker run --name mochizuki \
28
+ --restart=always \
29
+ -v /path/to/mochizuki.conf:/app/mochizuki.conf \
30
+ -d -it darkkowalski/mochizuki
31
+ ```
23
32
 
24
33
  ## Configuration
25
34
 
@@ -1,7 +1,7 @@
1
1
  #!/bin/ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require'mochizuki'
4
+ require 'mochizuki'
5
5
 
6
6
  load('mochizuki.conf')
7
7
  Mochizuki::Bot.new.start
@@ -16,9 +16,10 @@ module Mochizuki
16
16
  scheduler.every @config.query_interval.to_s do
17
17
  power = Mochizuki::Fetcher.new.fetch
18
18
  @logger.info "Auto query, #{power} kWh remaining"
19
- if Mochizuki.status.auto_alarm_enabled?
19
+ if Mochizuki.status.auto_alarm_triggered?
20
20
  yield(power)
21
21
  Mochizuki.status.alarmed_before = true
22
+ @logger.info 'Auto alarm is suppressed for now'
22
23
  end
23
24
  end
24
25
  end
@@ -31,6 +31,7 @@ module Mochizuki
31
31
  end
32
32
 
33
33
  def fetch
34
+ @logger.info 'Try to query'
34
35
  fetch_viewstate
35
36
  fetch_cookie
36
37
  power = fetch_power
@@ -18,14 +18,14 @@ module Mochizuki
18
18
  def update_status(power)
19
19
  last = Mochizuki.status.below_threshold
20
20
  current = power.to_f < @config.alarm_threshold.to_f
21
- @logger.info "Status, @below_threshold, last: #{last}, current: #{current}"
21
+ @logger.info "Update status, @below_threshold, last: #{last}, current: #{current}"
22
22
 
23
23
  Mochizuki.status.below_threshold = current
24
24
 
25
25
  return unless !current && last # re-enabled auto alarm
26
26
 
27
27
  Mochizuki.status.alarmed_before = false
28
- @logger.info "Status, @alarmed_before, #{@alarmed_before}, auto alarm enabled"
28
+ @logger.info 'Auto alarm enabled'
29
29
  end
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ module Mochizuki
38
38
  @alarmed_before = false
39
39
  end
40
40
 
41
- def auto_alarm_enabled?
41
+ def auto_alarm_triggered?
42
42
  if @below_threshold.nil?
43
43
  @logger.error "Unable to check status, @below_threshold can't be nil"
44
44
  raise Mochizuki::Error, 'Invalid @below_threshold'
@@ -14,17 +14,18 @@ module Mochizuki
14
14
  Mochizuki::AutoQuery.new.alarm do |power|
15
15
  bot.api.send_message(chat_id: @config.channel,
16
16
  text: "Dorm: #{@config.dorm}: #{power} kWh, " \
17
- "lower than threshold #{@config.alarm_threshold}")
17
+ "lower than threshold #{@config.alarm_threshold} kWh")
18
18
  end
19
19
  @logger.info 'Auto query enabled'
20
20
 
21
21
  bot.listen do |msg|
22
+ @logger.info "ID: #{msg.chat.id} uses #{msg}"
22
23
  case msg.text
23
24
  when '/start'
25
+ send_msg = 'I am a telegram bot written in ruby, '\
26
+ 'details at https://github.com/DarkKowalski/mochizuki'
24
27
  bot.api.send_message(chat_id: msg.chat.id,
25
- text: 'I am a telegram bot written in ruby, '\
26
- 'details at https://github.com/DarkKowalski/mochizuki-bot')
27
- @logger.info "ID: #{msg.chat.id} uses /start"
28
+ text: send_msg)
28
29
  when '/query'
29
30
  dorm = @config.dorm
30
31
  begin
@@ -34,9 +35,12 @@ module Mochizuki
34
35
  send_msg = 'Failed to query.'
35
36
  end
36
37
  bot.api.send_message(chat_id: msg.chat.id, text: send_msg)
38
+ when '/status'
39
+ send_msg = "Bot status: auto alarm is suppressed -> #{Mochizuki.status.alarmed_before}"
40
+ bot.api.send_message(chat_id: msg.chat.id, text: send_msg)
37
41
  else
42
+ @logger.warn "Unknown command #{msg}"
38
43
  bot.api.send_message(chat_id: msg.chat.id, text: "Use '/query' to get remaining power")
39
- @logger.warn "ID: #{msg.chat.id} uses #{msg.text}"
40
44
  end
41
45
  end
42
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mochizuki
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mochizuki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kowalski Dark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday