thomas-ghysbrecht-thermostat-exercise 0.1.2.pre.a → 0.1.2

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
  SHA1:
3
- metadata.gz: bd2a9d561838ec347e9472ce9d99afe78a35eb1e
4
- data.tar.gz: e0700576bdd5ac5d5517bf80da662684f01b669a
3
+ metadata.gz: fbe18aaf520766500ca3e4f98f43e7f28616bb10
4
+ data.tar.gz: 7551566136956b7b54db73a35658bc1105febe24
5
5
  SHA512:
6
- metadata.gz: 57a6b7915f5f8622ae6fa79b82f78675daff5c0fac8b3a80344cd1e382b90d4087437affc966cbd6f42cf10c621a7709e62cd49427bc095d268954715a50c8e9
7
- data.tar.gz: daacfb7593ebb0a02906a0d1a4c8ef86108be863fee0beb57756272b89d27d726b2591f7920f6110d8e19f4a6998c987bc0679d517b46d08d868d3c4de130f26
6
+ metadata.gz: 3d7e46e99a39b1e789bf8fec5b8f0639ad881d739d1b560b795296e54272aeb596ef33133b48294501cf844db5e34bcb31d6759a8c74ba514b7d6ca38d604a83
7
+ data.tar.gz: d47b192613da1c968ad37507682c8a22aafdb1fa1a5ddf3e20a3c7d21befe1b79d402c0641ddf31e025eadbe6d8d6ed79e459e4cad86549a61a4c2bc2d35dda6
@@ -1,9 +1,5 @@
1
- # The Httpsvalue returns a value on a webpage.
2
- #
3
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
4
1
  class Httpsvalue
5
2
  require "open-uri"
6
- # Get a value fromt this url
7
3
  def get_value(url)
8
4
  data = URI.parse(url).read
9
5
  end
@@ -1,18 +1,13 @@
1
1
  require 'date'
2
2
 
3
- # The ThermoLoger class logs the thermos object's status in a file.
4
- #
5
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
6
3
  class ThermoLogger
7
4
 
8
- # Logs a message to a file
9
5
  def log_message(message)
10
6
  open('log.txt', 'a') do |f|
11
7
  f.puts message
12
8
  end
13
9
  end
14
10
 
15
- # Logs the thermos class to a file
16
11
  def log_event(thermos)
17
12
  current_time = DateTime.now
18
13
  log_message("-------------------------------------------------------")
@@ -1,27 +1,19 @@
1
1
  require 'mqtt'
2
2
 
3
- # Mqtt class that makes it possible to receive and send values via mqtt.
4
- #
5
- # You can attach a block of code to run when a value is received. Also you can
6
- # send the led hex value via mqtt to a specified topic.
7
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
8
3
  class Mqtttemp
9
4
 
10
- # Set up the class with the brokere server address
11
5
  def initialize(server)
12
6
  @server = server;
13
7
  end
14
8
 
15
- # Attachach a codeblock that will be executed when a value is received
16
9
  def on_change &block
17
10
  @on_change_block = block
18
11
  end
19
12
 
20
- # Enable a thread that executes the on_change block when something is
21
- # received on the topic given via the argument.
22
13
  def enable_thread(mqtt_topic)
23
14
  Thread.new do
24
15
  MQTT::Client.connect(@server) do |c|
16
+ # If you pass a block to the get method, then it will loop
25
17
  c.get(mqtt_topic) do |topic,message|
26
18
  if(isValidJson(message))
27
19
  @on_change_block.call(JSON.parse(message)["temperature"]) unless @on_change_block.nil?
@@ -39,10 +31,6 @@ class Mqtttemp
39
31
  return false
40
32
  end
41
33
 
42
- # Send a hex value via MQTT to a topic.
43
- # Argumens:
44
- # hex (string) : The hex value that needs to be sent in format "FFAA33".
45
- # topic (string) : The topic where to send the hex value to.
46
34
  def send_led_hex(hex, topic)
47
35
  MQTT::Client.connect(@server) do |c|
48
36
  data = '{"color":"'+ hex +'"}'
@@ -2,9 +2,6 @@ require 'optparse'
2
2
 
3
3
  Options = Struct.new(:kelvin, :celcius, :target, :fahrenheit, :range, :httplink, :mqtt, :json, :subscribe, :publish )
4
4
 
5
- # Parser class using optparse, this makes it possible to easly use this
6
- # app as an CLI app.
7
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
8
5
  class Parser
9
6
  def parse(options)
10
7
  args = Options.new()
@@ -1,8 +1,4 @@
1
- # Status class that prints out the themos object's status
2
- #
3
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
4
1
  class Status
5
- # Prints out the current status in the console
6
2
  def get_status(nest)
7
3
  puts "----------------------------------------------------------------------------------------"
8
4
  puts "+-------------------------+"
@@ -1,7 +1,4 @@
1
- # Temperature class with multiple temperature compatibility
2
- #
3
- # The Temperature class stores a temperature. And decides the led color and relais.
4
- # @author Thomas Ghysbrecht <ghysbrecht@hotmail.com>
1
+
5
2
  class Thermos
6
3
 
7
4
  attr_accessor :target
@@ -14,10 +11,7 @@ class Thermos
14
11
  attr_reader :relaisHeater
15
12
  attr_reader :temperature
16
13
 
17
- # Initializes the class with a target and range
18
- # Arguments:
19
- # - target (float) : The target temperature
20
- # - range (float) : What temperatures are acceptable around the target
14
+
21
15
  def initialize(target, range)
22
16
  @target = target
23
17
  @range = range
@@ -26,24 +20,18 @@ class Thermos
26
20
  @relaisHeater = false;
27
21
  end
28
22
 
29
- # Sets the temperature with a Celcius value.
30
- # This method also reset and sets the leds.
31
23
  def set_celcius (temperature)
32
24
  @temperature = temperature
33
25
  reset_leds
34
26
  set_leds
35
27
  end
36
28
 
37
- # Sets the temperature with a Kelvin value
38
- # This method also reset and sets the leds.
39
29
  def set_kelvin (temperature)
40
30
  @temperature = temperature - 273.15
41
31
  reset_leds
42
32
  set_leds
43
33
  end
44
34
 
45
- # Sets the temperature with a Fahrenheit value
46
- # This method also reset and sets the leds.
47
35
  def set_fahrenheit (temperature)
48
36
  @temperature = (temperature - 32)/1.8
49
37
  reset_leds
@@ -56,7 +44,6 @@ class Thermos
56
44
  @blue = 0.0
57
45
  end
58
46
 
59
-
60
47
  def set_leds
61
48
  if(@temperature < (@target - @range))
62
49
  multiplier = ( (@target - @temperature) / (5 * @range)) #5 times the range from the target is very blue
@@ -82,7 +69,6 @@ class Thermos
82
69
  end
83
70
  end
84
71
 
85
- # Return the led status in hex format -> FF88AA
86
72
  def get_hex_leds
87
73
  "%02x%02x%02x" % [@red,@green,@blue]
88
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thomas-ghysbrecht-thermostat-exercise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.pre.a
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Ghysbrecht
@@ -39,9 +39,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ">"
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 1.3.1
44
+ version: '0'
45
45
  requirements: []
46
46
  rubyforge_project:
47
47
  rubygems_version: 2.5.2