thermostat_AYTHON_HOUTTEKIER 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/app.rb +20 -0
- data/lib/json_thermostat.rb +25 -0
- data/lib/thermostat.rb +32 -0
- data/lib/unit.rb +64 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c1d46bce21f770714c6463421aaab3fb8a1001ab2cde99b03c77364176ed6e3
|
4
|
+
data.tar.gz: bbf85a7270f22c78cf852997e155f5c0d28f396ba79d71eea3bb4f4d78c23d68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0eb51addc5ea6b3a77a8edc949a5d98a9078a3421cf41c51be10dd2c6d7e6fdb7751420b4b8eadfefc7772e7ce5140ec8696c13eb5801433ed68e7a974fc48fc
|
7
|
+
data.tar.gz: 6c098f8fe9c614ce162eb8f4a107d2567c230254b7e361fd44d370eb2ef6cf67c1e9264bfd9709b1eb1a5fdc643e901a3a08fb1268e0375c441a465acdeb8715
|
data/lib/app.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'thermostat.rb'
|
2
|
+
|
3
|
+
class ThermostatApplication
|
4
|
+
|
5
|
+
def run
|
6
|
+
thermostat = Thermostat.new(20.51)
|
7
|
+
# thermostat.currentValue = rand(15..25)
|
8
|
+
# thermostat.wantedValue = 21.0
|
9
|
+
puts "current temp: #{thermostat.current} °C"
|
10
|
+
puts "wanted temp: #{thermostat.wanted} °C"
|
11
|
+
puts "range: #{thermostat.range} °C"
|
12
|
+
puts "cooling: #{thermostat.cooling?}"
|
13
|
+
puts "heating: #{thermostat.heating?}"
|
14
|
+
puts thermostat.state
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
app = ThermostatApplication.new
|
20
|
+
app.run
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'thermostat.rb'
|
3
|
+
require 'unit.rb'
|
4
|
+
|
5
|
+
class JSONThermostat
|
6
|
+
def initialize(json)
|
7
|
+
@value = JSON.parse(json)
|
8
|
+
end
|
9
|
+
|
10
|
+
def update(json)
|
11
|
+
@jsonvalue = JSON.parse(json)
|
12
|
+
@jsonvalue['unit'] = 'celsius' if @jsonvalue['unit'].nil?
|
13
|
+
@value['unit'] = 'celsius' if @value['unit'].nil?
|
14
|
+
@uni = @value['unit']
|
15
|
+
converten
|
16
|
+
end
|
17
|
+
|
18
|
+
def converten
|
19
|
+
cur = ConvertTemp.new @jsonvalue['temperature'], @jsonvalue['unit']
|
20
|
+
wan = ConvertTemp.new @value['temperature'], @value['unit']
|
21
|
+
ran = ConvertTemp.new @value['range'], @value['unit']
|
22
|
+
thermostat = Thermostat.new(cur.conv(@uni), wan.conv(@uni), ran.conv(@uni))
|
23
|
+
thermostat.state
|
24
|
+
end
|
25
|
+
end
|
data/lib/thermostat.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class Thermostat
|
4
|
+
attr_accessor :current, :wanted, :range
|
5
|
+
|
6
|
+
def initialize(current, wanted = 20.0, range = 1.0)
|
7
|
+
@current = current
|
8
|
+
@wanted = wanted
|
9
|
+
@range = range
|
10
|
+
end
|
11
|
+
|
12
|
+
def heating?
|
13
|
+
@wanted > (@current + @range / 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
def cooling?
|
17
|
+
@wanted < (@current - @range / 2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def state
|
21
|
+
if heating?
|
22
|
+
puts JSON.generate(cooling: false, heating: true)
|
23
|
+
JSON.generate(cooling: false, heating: true)
|
24
|
+
elsif cooling?
|
25
|
+
puts JSON.generate(cooling: true, heating: false)
|
26
|
+
JSON.generate(cooling: true, heating: false)
|
27
|
+
else
|
28
|
+
puts JSON.generate(cooling: false, heating: false)
|
29
|
+
JSON.generate(cooling: false, heating: false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/unit.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'thermostat.rb'
|
2
|
+
|
3
|
+
class ConvertTemp
|
4
|
+
attr_accessor :temperature, :current_unit
|
5
|
+
|
6
|
+
KELVIN_SHIFT = 273.15
|
7
|
+
FAHRENHEIT_OFFSET = 32.0
|
8
|
+
FAHRENHEIT_S = Rational(9, 5)
|
9
|
+
|
10
|
+
def initialize(temperature, current_unit = 'celsius')
|
11
|
+
@temperature = temperature
|
12
|
+
@current_unit = current_unit
|
13
|
+
end
|
14
|
+
|
15
|
+
def conv(unit)
|
16
|
+
@unit = unit
|
17
|
+
if @current_unit == 'celsius'
|
18
|
+
case_celsius
|
19
|
+
elsif @current_unit == 'fahrenheit'
|
20
|
+
case_fahrenheit
|
21
|
+
elsif @current_unit == 'kelvin'
|
22
|
+
case_kelvin
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def case_celsius
|
27
|
+
case @unit
|
28
|
+
when 'fahrenheit'
|
29
|
+
@temperature = (temperature * FAHRENHEIT_S) + FAHRENHEIT_OFFSET
|
30
|
+
when 'kelvin'
|
31
|
+
@temperature = temperature + KELVIN_SHIFT
|
32
|
+
else
|
33
|
+
@temperature
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def case_fahrenheit
|
38
|
+
case @unit
|
39
|
+
when 'celsius'
|
40
|
+
@temperature = fahrenheit_to_celcius
|
41
|
+
when 'kelvin'
|
42
|
+
@temperature = fahrenheit_to_celcius + KELVIN_SHIFT
|
43
|
+
else @temperature
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def case_kelvin
|
48
|
+
case @unit
|
49
|
+
when 'fahrenheit'
|
50
|
+
@temperature = (kelvin_to_celcius * FAHRENHEIT_S) + FAHRENHEIT_OFFSET
|
51
|
+
when 'celsius'
|
52
|
+
@temperature = kelvin_to_celcius
|
53
|
+
else @temperature
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def fahrenheit_to_celcius
|
58
|
+
@temperature = (temperature - FAHRENHEIT_OFFSET) / FAHRENHEIT_S
|
59
|
+
end
|
60
|
+
|
61
|
+
def kelvin_to_celcius
|
62
|
+
@temperature = temperature - KELVIN_SHIFT
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thermostat_AYTHON_HOUTTEKIER
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aython Houttekier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Thermostat application
|
14
|
+
email: aython.houttekier@student.vives.be
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/app.rb
|
20
|
+
- lib/json_thermostat.rb
|
21
|
+
- lib/thermostat.rb
|
22
|
+
- lib/unit.rb
|
23
|
+
homepage: https://github.com/vives-softwareengineering-2019/thermostat-aythonhouttekier
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.0.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Thermostat
|
46
|
+
test_files: []
|