thermostat_Elise_DeSmet 0.0.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 +7 -0
- data/lib/convert.rb +8 -0
- data/lib/json_thermostat.rb +27 -0
- data/lib/thermostat.rb +40 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32e4d2b6d3920e8ae9059d8aa6cee4b38a2888b0
|
4
|
+
data.tar.gz: 1da68595d89fd641bc7b0c2db069d152d6ec00b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f434062dd0cada2d273ae0c8e610aa89d6cdb575fc5e3936d350b844592dbee0e5ab2d55ef4d8c28a419253dfd5e8ceda4ed08cfe4934c24a17126475ea2b78
|
7
|
+
data.tar.gz: 906a2f30afb86632333d480aba5f5e74012714ee14b54826d1caa38cd284b2af84e8c1c9ea175550298514f84df05f276a702cf906e6a452d45d83d9ece54749
|
data/lib/convert.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'thermostat.rb'
|
3
|
+
require 'convert.rb'
|
4
|
+
|
5
|
+
class JSONThermostat
|
6
|
+
attr_reader :thermostat, :convert
|
7
|
+
def initialize(settings = ' ')
|
8
|
+
obj = JSON.parse(settings)
|
9
|
+
convert = Convert.new
|
10
|
+
temperature = convert.convert(obj['temperature'], obj['unit'])
|
11
|
+
@thermostat = Thermostat.new(temperature, temperature, obj['range'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(json = ' ')
|
15
|
+
obj = JSON.parse(json)
|
16
|
+
temperature = obj['temperature']
|
17
|
+
unit = obj['unit']
|
18
|
+
convert = Convert.new
|
19
|
+
temperature = convert.convert(obj['temperature'], obj['unit'])
|
20
|
+
@thermostat.put_temperature(temperature)
|
21
|
+
@thermostat.check
|
22
|
+
end
|
23
|
+
|
24
|
+
def generateJson
|
25
|
+
JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heating)
|
26
|
+
end
|
27
|
+
end
|
data/lib/thermostat.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Thermostat
|
2
|
+
attr_accessor :current_value, :wanted_value, :range, :heating, :airco
|
3
|
+
def initialize(current_value = 0.0, wanted_value = 0.0, range = 0.0)
|
4
|
+
@current_value = current_value
|
5
|
+
@wanted_value = wanted_value
|
6
|
+
@range = range / 2
|
7
|
+
end
|
8
|
+
|
9
|
+
def heat
|
10
|
+
@heating = true
|
11
|
+
@airco = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def cool
|
15
|
+
@heating = false
|
16
|
+
@airco = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def off
|
20
|
+
@heating = false
|
21
|
+
@airco = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def check
|
25
|
+
if @current_value > (@wanted_value + @range)
|
26
|
+
cool
|
27
|
+
puts 'Turning on airco.'
|
28
|
+
elsif @current_value < (@wanted_value - @range)
|
29
|
+
heat
|
30
|
+
puts 'Turning on heating.'
|
31
|
+
else
|
32
|
+
off
|
33
|
+
puts 'Temperature has been reached.'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def put_temperature(temperature)
|
38
|
+
@current_value = temperature
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thermostat_Elise_DeSmet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elise De Smet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Software solution that acts as a thermostat.
|
14
|
+
email: elise.desmet2@student.vives.be
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/convert.rb
|
20
|
+
- lib/json_thermostat.rb
|
21
|
+
- lib/thermostat.rb
|
22
|
+
homepage: http://rubygems.org/gems/thermostat_Elise_DeSmet
|
23
|
+
licenses:
|
24
|
+
- Apache-2.0
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Thermostat
|
46
|
+
test_files: []
|