Class: Sunscout::SolarLog::SolarLog
- Inherits:
-
Object
- Object
- Sunscout::SolarLog::SolarLog
- Defined in:
- lib/sunscout/solar_log/solar_log.rb
Overview
High-level binding to the SolarLog HTTP API
Instance Attribute Summary collapse
-
#consumption_ac ⇒ Fixnum
readonly
Current consumption in W.
-
#consumption_day ⇒ Fixnum
readonly
Today’s consumption in Wh.
-
#consumption_month ⇒ Fixnum
readonly
This month’s consumption in Wh.
-
#consumption_total ⇒ Fixnum
readonly
Total consumption in Wh.
-
#consumption_year ⇒ Fixnum
readonly
This year’s consumption in Wh.
-
#consumption_yesterday ⇒ Fixnum
readonly
Yesterday’s consumption in Wh.
-
#power_ac ⇒ Fixnum
readonly
AC power in W.
-
#power_dc ⇒ Fixnum
readonly
DC power in W.
-
#power_total ⇒ Fixnum
readonly
Maximum DC power in W.
-
#time ⇒ DateTime
readonly
Timestamp of the data.
-
#voltage_ac ⇒ Fixnum
readonly
AC voltage in V.
-
#voltage_dc ⇒ Fixnum
readonly
DC voltage in V.
-
#yield_day ⇒ Fixnum
readonly
Today’s yield in Wh.
-
#yield_month ⇒ Fixnum
readonly
This month’s yield in Wh.
-
#yield_total ⇒ Fixnum
readonly
Total yield in Wh.
-
#yield_year ⇒ Fixnum
readonly
This year’s yield in Wh.
-
#yield_yesterday ⇒ Fixnum
readonly
Yesterday’s yield in WH.
Instance Method Summary collapse
-
#alternator_loss ⇒ Fixnum
Loss of DC to AC conversion.
-
#capacity ⇒ Float
Capacity of peak power generation.
-
#efficiency ⇒ Float
Efficiency of DC to AC conversion.
-
#initialize(host, timezone: '+0000') ⇒ SolarLog
constructor
Initialize a new instance of the class.
-
#power_available ⇒ Fixnum
Surplus AC power.
-
#usage ⇒ Float
Usage of AC power.
Constructor Details
#initialize(host, timezone: '+0000') ⇒ SolarLog
Initialize a new instance of the class.
This also immediately queries data from the SolarLog API.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 77 def initialize(host, timezone: '+0000') client = Sunscout::SolarLog::Client.new(host) data = client.get_data # SolarLog returns the time a) without a timezone indicator and b) as whatever the station is configured. # Hence, the user has to specify what timezone it is in - otherwise we'll just fall back to UTC. time = "#{ data.fetch(:time) } #{ timezone }" @time = DateTime.strptime(time, '%d.%m.%y %H:%M:%s %Z') @power_ac = data.fetch :power_ac @power_dc = data.fetch :power_dc @power_total = data.fetch :power_total @voltage_ac = data.fetch :voltage_ac @voltage_dc = data.fetch :voltage_dc @yield_day = data.fetch :yield_day @yield_yesterday = data.fetch :yield_yesterday @yield_month = data.fetch :yield_month @yield_year = data.fetch :yield_year @yield_total = data.fetch :yield_total @consumption_ac = data.fetch :consumption_ac @consumption_day = data.fetch :consumption_day @consumption_yesterday = data.fetch :consumption_yesterday @consumption_month = data.fetch :consumption_month @consumption_year = data.fetch :consumption_year @consumption_total = data.fetch :consumption_total end |
Instance Attribute Details
#consumption_ac ⇒ Fixnum (readonly)
Current consumption in W
53 54 55 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 53 def consumption_ac @consumption_ac end |
#consumption_day ⇒ Fixnum (readonly)
Today’s consumption in Wh
56 57 58 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 56 def consumption_day @consumption_day end |
#consumption_month ⇒ Fixnum (readonly)
This month’s consumption in Wh
62 63 64 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 62 def consumption_month @consumption_month end |
#consumption_total ⇒ Fixnum (readonly)
Total consumption in Wh
68 69 70 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 68 def consumption_total @consumption_total end |
#consumption_year ⇒ Fixnum (readonly)
This year’s consumption in Wh
65 66 67 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 65 def consumption_year @consumption_year end |
#consumption_yesterday ⇒ Fixnum (readonly)
Yesterday’s consumption in Wh
59 60 61 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 59 def consumption_yesterday @consumption_yesterday end |
#power_ac ⇒ Fixnum (readonly)
AC power in W
20 21 22 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 20 def power_ac @power_ac end |
#power_dc ⇒ Fixnum (readonly)
DC power in W
23 24 25 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 23 def power_dc @power_dc end |
#power_total ⇒ Fixnum (readonly)
Maximum DC power in W
26 27 28 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 26 def power_total @power_total end |
#time ⇒ DateTime (readonly)
Timestamp of the data.
16 17 18 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 16 def time @time end |
#voltage_ac ⇒ Fixnum (readonly)
AC voltage in V
30 31 32 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 30 def voltage_ac @voltage_ac end |
#voltage_dc ⇒ Fixnum (readonly)
DC voltage in V
33 34 35 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 33 def voltage_dc @voltage_dc end |
#yield_day ⇒ Fixnum (readonly)
Today’s yield in Wh
37 38 39 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 37 def yield_day @yield_day end |
#yield_month ⇒ Fixnum (readonly)
This month’s yield in Wh
43 44 45 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 43 def yield_month @yield_month end |
#yield_total ⇒ Fixnum (readonly)
Total yield in Wh
49 50 51 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 49 def yield_total @yield_total end |
#yield_year ⇒ Fixnum (readonly)
This year’s yield in Wh
46 47 48 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 46 def yield_year @yield_year end |
#yield_yesterday ⇒ Fixnum (readonly)
Yesterday’s yield in WH
40 41 42 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 40 def yield_yesterday @yield_yesterday end |
Instance Method Details
#alternator_loss ⇒ Fixnum
Loss of DC to AC conversion.
126 127 128 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 126 def alternator_loss power_dc - power_ac end |
#capacity ⇒ Float
Capacity of peak power generation.
170 171 172 173 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 170 def capacity return 0 if power_total == 0 power_dc / power_total end |
#efficiency ⇒ Float
Efficiency of DC to AC conversion.
114 115 116 117 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 114 def efficiency return 0 if @power_dc == 0 power_ac.to_f / power_dc end |
#power_available ⇒ Fixnum
Surplus AC power.
159 160 161 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 159 def power_available power_ac - consumption_ac end |
#usage ⇒ Float
Usage of AC power.
142 143 144 145 |
# File 'lib/sunscout/solar_log/solar_log.rb', line 142 def usage return 0 if @power_ac == 0 consumption_ac.to_f / power_ac end |