Class: PresetJob

Inherits:
ServiceJob show all
Defined in:
app/models/preset_job.rb

Overview

== Schema Information

Table name: service_jobs
Database name: primary

id :integer not null, primary key
adaptive_start :boolean default(TRUE), not null
completed_on :date
cross_street1 :string(255)
cross_street1_direction :string(255)
cross_street2 :string(255)
cross_street2_direction :string(255)
display_format_celsius :boolean default(FALSE), not null
display_language :string
estimated_size_sqft :float
floor_load :float
floor_protection_mode :string default("laminate")
floor_temperature_max :integer default(82), not null
floor_temperature_min :integer default(41), not null
friday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
friday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
friday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
friday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
is_specified :boolean default(FALSE), not null
job_comments :string(255)
job_date :datetime
measurecomp_job_number :string(255)
measurecomp_order_number :string(255)
monday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
monday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
monday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
monday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
reference_number :string(255) not null
saturday_periods :string default(["8:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
saturday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
saturday_periods_inactive :boolean default([FALSE, TRUE, TRUE, TRUE, TRUE, FALSE]), is an Array
saturday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
serial_number :string(255)
state :string(255)
sunday_periods :string default(["8:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
sunday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
sunday_periods_inactive :boolean default([FALSE, TRUE, TRUE, TRUE, TRUE, FALSE]), is an Array
sunday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
temperature_control_mode :string default("AF"), not null
thursday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
thursday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
thursday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
thursday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
tstat_count :integer
tstat_sku :string
tuesday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
tuesday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
tuesday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
tuesday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
wednesday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
wednesday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
wednesday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
wednesday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
created_at :datetime
updated_at :datetime
address_id :integer
business_phone_contact_point_id :integer
cell_phone_contact_point_id :integer
contact_id :integer
creator_id :integer
customer_id :integer
delivery_id :integer
email_contact_point_id :integer
home_phone_contact_point_id :integer
line_item_id :integer
order_id :integer
tstat_line_item_id :integer
updater_id :integer

Indexes

index_measurecomp_jobs_on_address_id (address_id)
index_measurecomp_jobs_on_business_phone_contact_point_id (business_phone_contact_point_id)
index_measurecomp_jobs_on_cell_phone_contact_point_id (cell_phone_contact_point_id)
index_measurecomp_jobs_on_customer_id (customer_id)
index_measurecomp_jobs_on_delivery_id (delivery_id)
index_measurecomp_jobs_on_email_contact_point_id (email_contact_point_id)
index_measurecomp_jobs_on_home_phone_contact_point_id (home_phone_contact_point_id)
index_measurecomp_jobs_on_measurecomp_job_number (measurecomp_job_number)
index_measurecomp_jobs_on_order_id (order_id)
index_measurecomp_jobs_on_serial_number (serial_number)
index_service_jobs_on_contact_id (contact_id)
index_service_jobs_on_is_specified (is_specified)
index_service_jobs_on_job_date (job_date)
index_service_jobs_on_line_item_id (line_item_id)
index_service_jobs_on_state (state)

Constant Summary collapse

OJ_LANGUAGES_HASH =

validates :order, :presence => true
validates :delivery, :presence => true, if: Proc.new{|pj| pj.created_at.blank?}
validates :tstat_count, :presence => true
validates_numericality_of :tstat_count, :greater_than_or_equal_to => 1
validate :warming_periods

{ en: 'English', fr: 'Français', es: 'Español' }.freeze
FLOOR_PROTECTION_MODES_HASH =

Floor protection modes hash.

{ laminate: 'Laminate (82 F / 28 C)', tile: 'Tile (104 F / 40 C)', custom: 'Custom', disabled: 'Disabled' }.freeze
DAYS_OF_THE_WEEK =

Days of the week.

%w[monday tuesday wednesday thursday friday saturday sunday].freeze
ICON_FOR_PERIOD =

Icon for period.

['smartpreset-icon-period-1.png', 'smartpreset-icon-period-2.png', 'smartpreset-icon-period-3.png', 'smartpreset-icon-period-4.png'].freeze
ICON_FOR_TEMPERATURE =

Icon for temperature.

%w[fa-sun fa-moon fa-sun fa-moon].freeze
LEGACY_HONEYWELL_PERIOD_DEFAULTS =

Legacy honeywell period defaults.

['06:00', '08:30', '17:00', '23:00'].freeze
LEGACY_HONEYWELL_TEMP_BY_MODE_DEFAULTS_HASH =

Legacy honeywell temp by mode defaults hash.

{ F: [82, 68, 82, 68], AF: [70, 63, 70, 63], A: [70, 63, 70, 63] }.freeze
LEGACY_HONEYWELL_WEEKEND_PERIOD_DEFAULTS =

Legacy honeywell weekend period defaults.

['06:00', '08:30', '17:00', '23:00'].freeze
LEGACY_HONEYWELL_WEEKEND_TEMP_DEFAULTS_HASH =

Legacy honeywell weekend temp defaults hash.

{ F: [82, 68, 82, 68], AF: [70, 63, 70, 63], A: [70, 63, 70, 63] }.freeze
LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN =

Legacy temperature control mode human.

{ A: 'Ambient Temperature (A)', F: 'Floor Temperature (F)', AF: 'Ambient/Floor Temperature (AF)' }.freeze
TEMPERATURE_CONTROL_MODE_HUMAN =

Temperature control mode human.

{ A: 'Room Temperature', F: 'Floor Temperature', AF: 'Room/Floor Limited Temperature' }.freeze
TEMPERATURE_LABEL =

Temperature label.

{ A: 'room', F: 'floor', AF: 'room' }.freeze
DISPLAY_FORMAT =

Display format.

['Celsius/24 Hour Clock', 'Fahrenheit/12 Hour Clock'].freeze
TEMPERATURE_RANGE =

Temperature range.

{ A: [40, 86], F: [41, 104], AF: [40, 86] }.freeze
TEMPERATURE_MODE_KINDS =

Temperature mode kinds.

%w[temperature_comfort temperature_economy temperature_vacation].freeze
TEMPERATURE_MODE_ADJUSTMENTS =

Temperature mode adjustments.

[12, 5, 0].freeze
LEGACY_AMBIENT_TEMPERATURE_MODE_WARNING =

Legacy ambient temperature mode warning.

"For carpet, laminate and other engineered floors, please ensure compliance with the floor covering manufacturer's required minimum and maximum temperature limits.".freeze
AMBIENT_TEMPERATURE_MODE_WARNING =

Ambient temperature mode warning.

"For carpet, laminate and other engineered floors, you need to ensure compliance with the floor covering manufacturer's required minimum and maximum temperature limits to avoid damaging the surface.".freeze
LEGACY_TEMPERATURE_MODE_WARNINGS =

Legacy temperature mode warnings.

{
A: "WarmlyYours STRONGLY recommends using the floor temperature mode of F. If you choose this ambient temperature mode A, please ensure that the remote floor temperature sensor is NOT connected to the thermostat.  #{LEGACY_AMBIENT_TEMPERATURE_MODE_WARNING}", F: 'WarmlyYours recommends using this mode. Please ensure that the remote temperature sensor is connected to the thermostat', AF: "WarmlyYours STRONGLY recommends using the floor temperature mode of F. If you choose this ambient/floor temperature mode AF, please ensure that the remote floor temperature sensor is connected to the thermostat. #{LEGACY_AMBIENT_TEMPERATURE_MODE_WARNING}"
}.freeze
OJ_TEMPERATURE_MODE_WARNINGS =

Oj temperature mode warnings.

{
A: "WarmlyYours recommends using the floor temperature sensor application. If you want to use the room temperature sensor application with carpet, laminate and other engineered floors, please consider the room/floor limited temperature sensor application.  #{AMBIENT_TEMPERATURE_MODE_WARNING}", F: 'WarmlyYours recommends using this sensor application. Please ensure that the remote temperature sensor is connected to the thermostat', AF: "WarmlyYours recommends using the floor temperature sensor application. If you choose this room/floor limited temperature application, please ensure that the remote floor temperature sensor is connected to the thermostat. #{AMBIENT_TEMPERATURE_MODE_WARNING}"
}.freeze
WEEKDAY_TEMP_BY_MODE_DEFAULTS_HASH =

Weekday temp by mode defaults hash.

{
  'UDG4-4999' => { F: [82, 74, 82, 74, 82, 74], AF: [70, 62, 70, 62, 70, 62], A: [70, 62, 70, 62, 70, 62] },
  'UDG4-4999-WY' => { F: [82, 74, 82, 74, 82, 74], AF: [70, 62, 70, 62, 70, 62], A: [70, 62, 70, 62, 70, 62] },
  'UWG4-4999' => { F: [82, 74, 82, 74, 82, 74], AF: [70, 62, 70, 62, 70, 62], A: [70, 62, 70, 62, 70, 62] }
}.freeze
WEEKEND_TEMP_BY_MODE_DEFAULTS_HASH =

OJ Thermostat weekend temp defaults (static, no DB query needed)

{
  'UDG4-4999' => { F: [82, 74, 82, 74, 82, 74], AF: [70, 62, 70, 62, 70, 62], A: [70, 62, 70, 62, 70, 62] },
  'UWG4-4999' => { F: [82, 74, 82, 74, 82, 74], AF: [70, 62, 70, 62, 70, 62], A: [70, 62, 70, 62, 70, 62] }
}.freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary

Attributes inherited from ServiceJob

#job_comments

Belongs to collapse

Methods inherited from ServiceJob

#address, #business_phone_contact_point, #cell_phone_contact_point, #email_contact_point, #home_phone_contact_point

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServiceJob

active, #business_phone, #business_phone=, #cell_phone, #cell_phone=, complete, #email, #email=, #home_phone, #home_phone=, open_jobs, #primary_phone, #search_text, #set_best_guess_email_contact_point, #set_best_guess_home_phone_contact_point, #set_reference_number, #set_serial_number, #uploads

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.celsius_to_fahrenheit(c) ⇒ Object



422
423
424
# File 'app/models/preset_job.rb', line 422

def self.celsius_to_fahrenheit(c)
  ((1.8 * c.to_f) + 32.0).round
end

.default_floor_prot_mode_sym_hashObject



185
186
187
188
# File 'app/models/preset_job.rb', line 185

def default_floor_prot_mode_sym_hash
  build_thermostat_defaults unless @defaults_built
  @default_floor_prot_mode_sym_hash
end

.default_period_temps_hashObject



235
236
237
238
# File 'app/models/preset_job.rb', line 235

def default_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_period_temps_hash
end

.default_period_times_hashObject



230
231
232
233
# File 'app/models/preset_job.rb', line 230

def default_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_period_times_hash
end

.default_temp_mode_sym_hashObject



180
181
182
183
# File 'app/models/preset_job.rb', line 180

def default_temp_mode_sym_hash
  build_thermostat_defaults unless @defaults_built
  @default_temp_mode_sym_hash
end

.default_weekday_period_inact_hashObject



200
201
202
203
# File 'app/models/preset_job.rb', line 200

def default_weekday_period_inact_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_inact_hash
end

.default_weekday_period_temps_hashObject



195
196
197
198
# File 'app/models/preset_job.rb', line 195

def default_weekday_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_temps_hash
end

.default_weekday_period_times_hashObject



190
191
192
193
# File 'app/models/preset_job.rb', line 190

def default_weekday_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_times_hash
end

.default_weekend_period_inact_hashObject



225
226
227
228
# File 'app/models/preset_job.rb', line 225

def default_weekend_period_inact_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_inact_hash
end

.default_weekend_period_temps_hashObject



220
221
222
223
# File 'app/models/preset_job.rb', line 220

def default_weekend_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_temps_hash
end

.default_weekend_period_times_hashObject



215
216
217
218
# File 'app/models/preset_job.rb', line 215

def default_weekend_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_times_hash
end

.display_format_celsius_options_for_selectObject



409
410
411
# File 'app/models/preset_job.rb', line 409

def self.display_format_celsius_options_for_select
  [[DISPLAY_FORMAT[1].to_s, false], [DISPLAY_FORMAT[0].to_s, true]]
end

.display_language_options_for_selectObject



401
402
403
# File 'app/models/preset_job.rb', line 401

def self.display_language_options_for_select
  OJ_LANGUAGES_HASH.map { |locale, label| [label, locale.to_s] }
end

.fahrenheit_to_celsius(f) ⇒ Object



426
427
428
# File 'app/models/preset_job.rb', line 426

def self.fahrenheit_to_celsius(f)
  PresetJob.round_point5((f.to_f - 32.0) / 1.8).to_f
end

.floor_protection_mode_options_for_selectObject



405
406
407
# File 'app/models/preset_job.rb', line 405

def self.floor_protection_mode_options_for_select
  FLOOR_PROTECTION_MODES_HASH.map { |mode, label| [label, mode.to_s] }
end

.legacy_temperature_control_mode_options_for_selectObject



413
414
415
416
# File 'app/models/preset_job.rb', line 413

def self.legacy_temperature_control_mode_options_for_select
  [["A: #{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:A]} (#{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:A]})", 'A'], ["F: #{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:F]} (#{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:F]})", 'F'],
   ["AF: #{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:AF]} (#{LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[:AF]})", 'AF']]
end

.round_point5(n) ⇒ Object



430
431
432
# File 'app/models/preset_job.rb', line 430

def self.round_point5(n)
  (n * 2).round / 2.0
end

.states_for_selectObject



328
329
330
# File 'app/models/preset_job.rb', line 328

def self.states_for_select
  state_machines[:state].states.map { |s| [s.human_name, s.value] }
end

.supported_smartstat_skusObject



168
169
170
# File 'app/models/preset_job.rb', line 168

def supported_smartstat_skus
  @supported_smartstat_skus ||= Item.smartstats.pluck(:sku).uniq.sort
end

.supported_thermostat_skusObject



172
173
174
# File 'app/models/preset_job.rb', line 172

def supported_thermostat_skus
  @supported_thermostat_skus ||= (supported_smartstat_skus + Item.oj_programmable_tstats.active.available_to_public.pluck(:sku)).uniq.sort
end

.temperature_control_mode_options_for_selectObject



418
419
420
# File 'app/models/preset_job.rb', line 418

def self.temperature_control_mode_options_for_select
  [[TEMPERATURE_CONTROL_MODE_HUMAN[:A].to_s, 'A'], [TEMPERATURE_CONTROL_MODE_HUMAN[:F].to_s, 'F'], [TEMPERATURE_CONTROL_MODE_HUMAN[:AF].to_s, 'AF']]
end

.temperature_mode_warnings_hashObject



205
206
207
208
# File 'app/models/preset_job.rb', line 205

def temperature_mode_warnings_hash
  build_thermostat_defaults unless @defaults_built
  @temperature_mode_warnings_hash
end

.temperature_options_for_select(mode = :F) ⇒ Object



434
435
436
# File 'app/models/preset_job.rb', line 434

def self.temperature_options_for_select(mode = :F)
  (TEMPERATURE_RANGE[mode][0]..TEMPERATURE_RANGE[mode][1]).map { |t| ["#{t} F / #{PresetJob.fahrenheit_to_celsius(t)} C", t] }
end

.tstat_skusObject



176
177
178
# File 'app/models/preset_job.rb', line 176

def tstat_skus
  @tstat_skus ||= Item.smartstats.pluck(:sku) + Item.oj_programmable_tstats.pluck(:sku)
end

.weekday_temp_by_mode_defaults_hashObject



210
211
212
213
# File 'app/models/preset_job.rb', line 210

def weekday_temp_by_mode_defaults_hash
  build_thermostat_defaults unless @defaults_built
  @weekday_temp_by_mode_defaults_hash
end

Instance Method Details

#contactContact

Returns:

See Also:



96
# File 'app/models/preset_job.rb', line 96

belongs_to :contact, inverse_of: :preset_jobs, optional: true

#customerCustomer

Returns:

See Also:



95
# File 'app/models/preset_job.rb', line 95

belongs_to :customer, inverse_of: :preset_jobs, optional: true

#deliveryDelivery

Returns:

See Also:



98
# File 'app/models/preset_job.rb', line 98

belongs_to :delivery, inverse_of: :preset_jobs, optional: true

#display_formatObject



380
381
382
# File 'app/models/preset_job.rb', line 380

def display_format
  display_format_celsius? ? DISPLAY_FORMAT[0] : DISPLAY_FORMAT[1]
end

#display_language_labelObject



362
363
364
365
366
# File 'app/models/preset_job.rb', line 362

def display_language_label
  locale = :en
  locale = display_language.to_sym if display_language
  OJ_LANGUAGES_HASH[locale]
end

#file_nameObject



438
439
440
# File 'app/models/preset_job.rb', line 438

def file_name
  "smartpreset_form_#{reference_number}.pdf"
end

#floor_protection_mode_labelObject



368
369
370
371
372
# File 'app/models/preset_job.rb', line 368

def floor_protection_mode_label
  mode = :custom
  mode = floor_protection_mode.to_sym if floor_protection_mode
  FLOOR_PROTECTION_MODES_HASH[mode]
end

#for_smartstat?Boolean

Returns:

  • (Boolean)


446
447
448
# File 'app/models/preset_job.rb', line 446

def for_smartstat?
  self.class.supported_smartstat_skus.include?(tstat_sku)
end

#friday_periods_temperatureObject



536
537
538
# File 'app/models/preset_job.rb', line 536

def friday_periods_temperature
  periods_temperature('friday')
end

#friday_periods_temperature=(temp) ⇒ Object



569
570
571
# File 'app/models/preset_job.rb', line 569

def friday_periods_temperature=(temp)
  set_periods_temperature('friday', temp)
end

#guess_best_floor_loadObject



465
466
467
468
469
470
# File 'app/models/preset_job.rb', line 465

def guess_best_floor_load
  rc = line_item.room_configuration
  return rc.calculate_total_kilowatts if rc

  order.line_items.heating_elements.to_a.sum { |he| he.quantity * he.item.watts.to_f } / 1000.0
end

#guess_best_tstat_skuObject



450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'app/models/preset_job.rb', line 450

def guess_best_tstat_sku
  # build list of all supported tstat skus in the order, exploding out array when some line items have more than a single quantity

  tstat_skus = []
  container = line_item.room_configuration || order
  tstat_lis = container.line_items.goods.select { |li| self.class.supported_thermostat_skus.include?(li.item.sku) }
  tstat_lis.each do |tstat_li|
    tstat_li.quantity.times do
      tstat_skus << tstat_li.sku
    end
  end
  # use index to choose tstat sku
  tstat_skus[index - 1]
end

#indexObject



336
337
338
339
# File 'app/models/preset_job.rb', line 336

def index
  container = line_item.room_configuration || order
  ((container.line_items.smartpresets.map(&:id).sort.index(line_item.id) || 0) + 1)
end

#labelObject



341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'app/models/preset_job.rb', line 341

def label
  rc = line_item.room_configuration
  str = if rc
          "#{rc.name}, Plan # #{rc.reference_number}"
        elsif (opp = order.opportunity)
          "Project: #{opp.name}"
        else
          "Order # #{order.reference_number}"
        end
  number_str = ''
  number_str = " # #{index}" if index > 1
  str += ", #{thermostat_model_name}#{number_str}"
  str
end

#line_itemLineItem

Returns:

See Also:



99
# File 'app/models/preset_job.rb', line 99

belongs_to :line_item, optional: true

#monday_periods_temperatureObject



520
521
522
# File 'app/models/preset_job.rb', line 520

def monday_periods_temperature
  periods_temperature('monday')
end

#monday_periods_temperature=(temp) ⇒ Object



553
554
555
# File 'app/models/preset_job.rb', line 553

def monday_periods_temperature=(temp)
  set_periods_temperature('monday', temp)
end

#nameObject



332
333
334
# File 'app/models/preset_job.rb', line 332

def name
  reference_number || 'Not set yet'
end

#ok_to_deleteObject



378
# File 'app/models/preset_job.rb', line 378

def ok_to_delete; end

#orderOrder

Returns:

See Also:



97
# File 'app/models/preset_job.rb', line 97

belongs_to :order, inverse_of: :preset_jobs, optional: true

#periods_temperature(day_label) ⇒ Object



548
549
550
551
# File 'app/models/preset_job.rb', line 548

def periods_temperature(day_label)
  temp_label = TEMPERATURE_LABEL[temperature_control_mode.to_sym]
  send("#{day_label}_periods_#{temp_label}_temperature")
end

#public_pathObject



442
443
444
# File 'app/models/preset_job.rb', line 442

def public_path
  UrlHelper.instance.preset_job_path(self)
end

#saturday_periods_temperatureObject



540
541
542
# File 'app/models/preset_job.rb', line 540

def saturday_periods_temperature
  periods_temperature('saturday')
end

#saturday_periods_temperature=(temp) ⇒ Object



573
574
575
# File 'app/models/preset_job.rb', line 573

def saturday_periods_temperature=(temp)
  set_periods_temperature('saturday', temp)
end

#set_after_create_defaultsObject (protected)



588
589
590
591
592
593
594
595
596
597
# File 'app/models/preset_job.rb', line 588

def set_after_create_defaults
  self.address = order.shipping_address
  set_best_guess_email_contact_point
  set_best_guess_home_phone_contact_point
  set_serial_number
  self.tstat_sku = guess_best_tstat_sku
  set_thermostat_default_periods_and_temperatures
  self.floor_load = guess_best_floor_load
  save
end

#set_defaultsObject (protected)



599
600
601
# File 'app/models/preset_job.rb', line 599

def set_defaults
  self.contact_id ||= order.contact_id
end

#set_periods_temperature(day_label, temp) ⇒ Object



581
582
583
584
# File 'app/models/preset_job.rb', line 581

def set_periods_temperature(day_label, temp)
  temp_label = TEMPERATURE_LABEL[temperature_control_mode.to_sym]
  send("#{day_label}_periods_#{temp_label}_temperature=(#{temp})")
end

#set_thermostat_default_periods_and_temperaturesObject



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'app/models/preset_job.rb', line 483

def set_thermostat_default_periods_and_temperatures
  self.temperature_control_mode = self.class.default_temp_mode_sym_hash[tstat_sku].to_s
  self.floor_protection_mode = self.class.default_floor_prot_mode_sym_hash[tstat_sku].to_s
  self.monday_periods = self.class.default_weekday_period_times_hash[tstat_sku]
  self.tuesday_periods = self.class.default_weekday_period_times_hash[tstat_sku]
  self.wednesday_periods = self.class.default_weekday_period_times_hash[tstat_sku]
  self.thursday_periods = self.class.default_weekday_period_times_hash[tstat_sku]
  self.friday_periods = self.class.default_weekday_period_times_hash[tstat_sku]
  self.saturday_periods = self.class.default_weekend_period_times_hash[tstat_sku]
  self.sunday_periods = self.class.default_weekend_period_times_hash[tstat_sku]
  weekday_floor_temps = self.class.weekday_temp_by_mode_defaults_hash[tstat_sku][:F]
  WEEKEND_TEMP_BY_MODE_DEFAULTS_HASH[tstat_sku][:F]
  self.monday_periods_floor_temperature = weekday_floor_temps
  self.tuesday_periods_floor_temperature = weekday_floor_temps
  self.wednesday_periods_floor_temperature = weekday_floor_temps
  self.thursday_periods_floor_temperature = weekday_floor_temps
  self.friday_periods_floor_temperature = weekday_floor_temps
  self.saturday_periods_floor_temperature = weekday_floor_temps
  self.sunday_periods_floor_temperature = weekday_floor_temps
  weekday_room_temps = self.class.weekday_temp_by_mode_defaults_hash[tstat_sku][:AF]
  weekend_room_temps = WEEKEND_TEMP_BY_MODE_DEFAULTS_HASH[tstat_sku][:AF]
  self.monday_periods_room_temperature = weekday_room_temps
  self.tuesday_periods_room_temperature = weekday_room_temps
  self.wednesday_periods_room_temperature = weekday_room_temps
  self.thursday_periods_room_temperature = weekday_room_temps
  self.friday_periods_room_temperature = weekday_room_temps
  self.saturday_periods_room_temperature = weekend_room_temps
  self.sunday_periods_room_temperature = weekend_room_temps
  self.monday_periods_inactive = self.class.default_weekday_period_inact_hash[tstat_sku]
  self.tuesday_periods_inactive = self.class.default_weekday_period_inact_hash[tstat_sku]
  self.wednesday_periods_inactive = self.class.default_weekday_period_inact_hash[tstat_sku]
  self.thursday_periods_inactive = self.class.default_weekday_period_inact_hash[tstat_sku]
  self.friday_periods_inactive = self.class.default_weekday_period_inact_hash[tstat_sku]
  self.saturday_periods_inactive = self.class.default_weekend_period_inact_hash[tstat_sku]
  self.sunday_periods_inactive = self.class.default_weekend_period_inact_hash[tstat_sku]
end

#sunday_periods_temperatureObject



544
545
546
# File 'app/models/preset_job.rb', line 544

def sunday_periods_temperature
  periods_temperature('sunday')
end

#sunday_periods_temperature=(temp) ⇒ Object



577
578
579
# File 'app/models/preset_job.rb', line 577

def sunday_periods_temperature=(temp)
  set_periods_temperature('sunday', temp)
end

#supports_programming?(sym) ⇒ Boolean

Returns:

  • (Boolean)


472
473
474
475
476
477
478
479
480
481
# File 'app/models/preset_job.rb', line 472

def supports_programming?(sym)
  case sym
  when :display_language, :floor_load
    false if %w[UDG4-4999 UDG4-4999-WY UWG4-4999].include?(tstat_sku)
  when :floor_protection_mode
    false unless %w[UDG4-4999 UDG4-4999-WY UWG4-4999].include?(tstat_sku) && (temperature_control_mode != 'A')
  else
    true
  end
end

#temperature_control_mode_humanObject



384
385
386
# File 'app/models/preset_job.rb', line 384

def temperature_control_mode_human
  for_smartstat? ? LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN[temperature_control_mode.to_sym] : TEMPERATURE_CONTROL_MODE_HUMAN[temperature_control_mode.to_sym]
end

#temperature_human(temp) ⇒ Object



388
389
390
391
# File 'app/models/preset_job.rb', line 388

def temperature_human(temp)
  t = send(temp)
  temperature_label(t)
end

#temperature_label(t) ⇒ Object



393
394
395
# File 'app/models/preset_job.rb', line 393

def temperature_label(t)
  "#{t} F / #{PresetJob.fahrenheit_to_celsius(t)} C"
end

#temperature_mode_warningObject



374
375
376
# File 'app/models/preset_job.rb', line 374

def temperature_mode_warning
  self.class.temperature_mode_warnings_hash[tstat_sku][temperature_control_mode.to_sym]
end

#thermostat_model_nameObject



356
357
358
359
360
# File 'app/models/preset_job.rb', line 356

def thermostat_model_name
  res = 'Thermostat'
  res = Item.find_by(sku: tstat_sku).public_name if tstat_sku
  res
end

#thermostat_model_options_for_selectObject



397
398
399
# File 'app/models/preset_job.rb', line 397

def thermostat_model_options_for_select
  [[Item.find_by(sku: tstat_sku).public_name, tstat_sku]]
end

#thursday_periods_temperatureObject



532
533
534
# File 'app/models/preset_job.rb', line 532

def thursday_periods_temperature
  periods_temperature('thursday')
end

#thursday_periods_temperature=(temp) ⇒ Object



565
566
567
# File 'app/models/preset_job.rb', line 565

def thursday_periods_temperature=(temp)
  set_periods_temperature('thursday', temp)
end

#tuesday_periods_temperatureObject



524
525
526
# File 'app/models/preset_job.rb', line 524

def tuesday_periods_temperature
  periods_temperature('tuesday')
end

#tuesday_periods_temperature=(temp) ⇒ Object



557
558
559
# File 'app/models/preset_job.rb', line 557

def tuesday_periods_temperature=(temp)
  set_periods_temperature('tuesday', temp)
end

#warming_periodsObject (protected)



603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'app/models/preset_job.rb', line 603

def warming_periods
  skips_issue_days = []
  early_start_issue_days = []
  non_ascend_issue_days = []
  PresetJob::DAYS_OF_THE_WEEK.each do |day|
    skips_in_day = []
    periods_in_day = []
    monday_periods.length.times do |i|
      if (pt = send("#{day}_periods")[i]).present?
        skips_in_day << false
        periods_in_day << Time.zone.parse(pt)
      else
        skips_in_day << true
      end
    end
    num_skips_in_day = skips_in_day.sum { |p| p == true ? 1 : 0 }
    skips_issue_days << day if [1, 3].include?(num_skips_in_day)
    # From SmartStat guide: NOTE: If you intend to use only 2 periods, set periods '1 and 4' or periods '2 and 3'. Early Start will not work if you set periods '1 and 2' or periods '3 and 4'
    if for_smartstat? && adaptive_start && (num_skips_in_day == 2)
      early_start_issue_days << day unless [[false, true, true, false], [true, false, false, true]].include?(skips_in_day)
    end
    next if periods_in_day.empty?

    all_periods_ascend = true
    (periods_in_day.length - 1).times.each do |j|
      all_periods_ascend = false if periods_in_day[j + 1] <= periods_in_day[j]
    end
    non_ascend_issue_days << day unless all_periods_ascend
  end
  error_fields = []
  error_msgs = []
  skips_issue_days.each do |day|
    error_fields << :"#{day}_periods"
    error_msgs << "you can't skip only one or three periods on any given day"
  end
  early_start_issue_days.each do |day|
    error_fields << :"#{day}_periods"
    error_msgs << 'if you intend to use only 2 periods, set periods 1 and 4 or periods 2 and 3, early start mode will not work if you set periods 1 and 2 or periods 3 and 4'
  end
  non_ascend_issue_days.each do |day|
    error_fields << :"#{day}_periods"
    error_msgs << 'start time must be earlier than the end time, please correct and adjust your warming time selections'
  end
  error_msgs.each_with_index do |error_msg, i|
    errors.add(error_fields[i], error_msg)
  end
end

#wednesday_periods_temperatureObject



528
529
530
# File 'app/models/preset_job.rb', line 528

def wednesday_periods_temperature
  periods_temperature('wednesday')
end

#wednesday_periods_temperature=(temp) ⇒ Object



561
562
563
# File 'app/models/preset_job.rb', line 561

def wednesday_periods_temperature=(temp)
  set_periods_temperature('wednesday', temp)
end