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' }
FLOOR_PROTECTION_MODES_HASH =
{ laminate: 'Laminate (82 F / 28 C)', tile: 'Tile (104 F / 40 C)', custom: 'Custom', disabled: 'Disabled' }
DAYS_OF_THE_WEEK =
%w[monday tuesday wednesday thursday friday saturday sunday]
ICON_FOR_PERIOD =
['smartpreset-icon-period-1.png', 'smartpreset-icon-period-2.png', 'smartpreset-icon-period-3.png', 'smartpreset-icon-period-4.png']
ICON_FOR_TEMPERATURE =
%w[fa-sun fa-moon fa-sun fa-moon]
LEGACY_HONEYWELL_PERIOD_DEFAULTS =
['06:00', '08:30', '17:00', '23:00']
LEGACY_HONEYWELL_TEMP_BY_MODE_DEFAULTS_HASH =
{ F: [82, 68, 82, 68], AF: [70, 63, 70, 63], A: [70, 63, 70, 63] }
LEGACY_HONEYWELL_WEEKEND_PERIOD_DEFAULTS =
['06:00', '08:30', '17:00', '23:00']
LEGACY_HONEYWELL_WEEKEND_TEMP_DEFAULTS_HASH =
{ F: [82, 68, 82, 68], AF: [70, 63, 70, 63], A: [70, 63, 70, 63] }
LEGACY_TEMPERATURE_CONTROL_MODE_HUMAN =
{ A: 'Ambient Temperature (A)', F: 'Floor Temperature (F)', AF: 'Ambient/Floor Temperature (AF)' }
TEMPERATURE_CONTROL_MODE_HUMAN =
{ A: 'Room Temperature', F: 'Floor Temperature', AF: 'Room/Floor Limited Temperature' }
TEMPERATURE_LABEL =
{ A: 'room', F: 'floor', AF: 'room' }
DISPLAY_FORMAT =
['Celsius/24 Hour Clock', 'Fahrenheit/12 Hour Clock']
TEMPERATURE_RANGE =
{ A: [40, 86], F: [41, 104], AF: [40, 86] }
TEMPERATURE_MODE_KINDS =
%w[temperature_comfort temperature_economy temperature_vacation]
TEMPERATURE_MODE_ADJUSTMENTS =
[12, 5, 0]
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."
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."
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}"
}
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}"
}
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] },
}
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

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 Models::EventPublishable

#publish_event

Class Method Details

.celsius_to_fahrenheit(c) ⇒ Object



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

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

.default_floor_prot_mode_sym_hashObject



164
165
166
167
# File 'app/models/preset_job.rb', line 164

def default_floor_prot_mode_sym_hash
  build_thermostat_defaults unless @defaults_built
  @default_floor_prot_mode_sym_hash
end

.default_period_temps_hashObject



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

def default_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_period_temps_hash
end

.default_period_times_hashObject



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

def default_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_period_times_hash
end

.default_temp_mode_sym_hashObject



159
160
161
162
# File 'app/models/preset_job.rb', line 159

def default_temp_mode_sym_hash
  build_thermostat_defaults unless @defaults_built
  @default_temp_mode_sym_hash
end

.default_weekday_period_inact_hashObject



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

def default_weekday_period_inact_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_inact_hash
end

.default_weekday_period_temps_hashObject



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

def default_weekday_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_temps_hash
end

.default_weekday_period_times_hashObject



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

def default_weekday_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekday_period_times_hash
end

.default_weekend_period_inact_hashObject



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

def default_weekend_period_inact_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_inact_hash
end

.default_weekend_period_temps_hashObject



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

def default_weekend_period_temps_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_temps_hash
end

.default_weekend_period_times_hashObject



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

def default_weekend_period_times_hash
  build_thermostat_defaults unless @defaults_built
  @default_weekend_period_times_hash
end

.display_format_celsius_options_for_selectObject



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

def self.display_format_celsius_options_for_select
  [["#{DISPLAY_FORMAT[1]}", false], ["#{DISPLAY_FORMAT[0]}", true]]
end

.display_language_options_for_selectObject



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

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

.fahrenheit_to_celsius(f) ⇒ Object



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

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



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

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



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

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



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

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

.states_for_selectObject



307
308
309
# File 'app/models/preset_job.rb', line 307

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

.supported_smartstat_skusObject



147
148
149
# File 'app/models/preset_job.rb', line 147

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

.supported_thermostat_skusObject



151
152
153
# File 'app/models/preset_job.rb', line 151

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



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

def self.temperature_control_mode_options_for_select
  [["#{TEMPERATURE_CONTROL_MODE_HUMAN[:A]}", 'A'], ["#{TEMPERATURE_CONTROL_MODE_HUMAN[:F]}", 'F'], ["#{TEMPERATURE_CONTROL_MODE_HUMAN[:AF]}", 'AF']]
end

.temperature_mode_warnings_hashObject



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

def temperature_mode_warnings_hash
  build_thermostat_defaults unless @defaults_built
  @temperature_mode_warnings_hash
end

.temperature_options_for_select(mode = :F) ⇒ Object



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

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



155
156
157
# File 'app/models/preset_job.rb', line 155

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

.weekday_temp_by_mode_defaults_hashObject



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

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:



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

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

#customerCustomer

Returns:

See Also:



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

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

#deliveryDelivery

Returns:

See Also:



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

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

#display_formatObject



360
361
362
# File 'app/models/preset_job.rb', line 360

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

#display_language_labelObject



341
342
343
344
345
# File 'app/models/preset_job.rb', line 341

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

#file_nameObject



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

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

#floor_protection_mode_labelObject



347
348
349
350
351
# File 'app/models/preset_job.rb', line 347

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)


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

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

#friday_periods_temperatureObject



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

def friday_periods_temperature
  periods_temperature('friday')
end

#friday_periods_temperature=(temp) ⇒ Object



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

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

#guess_best_floor_loadObject



450
451
452
453
454
455
# File 'app/models/preset_job.rb', line 450

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



435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'app/models/preset_job.rb', line 435

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



315
316
317
318
# File 'app/models/preset_job.rb', line 315

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

#labelObject



320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'app/models/preset_job.rb', line 320

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:



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

belongs_to :line_item, optional: true

#monday_periods_temperatureObject



505
506
507
# File 'app/models/preset_job.rb', line 505

def monday_periods_temperature
  periods_temperature('monday')
end

#monday_periods_temperature=(temp) ⇒ Object



538
539
540
# File 'app/models/preset_job.rb', line 538

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

#nameObject



311
312
313
# File 'app/models/preset_job.rb', line 311

def name
  reference_number || 'Not set yet'
end

#ok_to_deleteObject



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

def ok_to_delete
end

#orderOrder

Returns:

See Also:



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

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

#periods_temperature(day_label) ⇒ Object



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

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

#public_pathObject



422
423
424
425
426
427
428
429
# File 'app/models/preset_job.rb', line 422

def public_path
  # disabling authenticated links for now
  # return nil unless a.present?
  UrlHelper.instance.preset_job_path(self)
  # if self.customer.account.auth_token_required?
  #   path = self.customer.account.append_token(path, persist=true)
  # end
end

#saturday_periods_temperatureObject



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

def saturday_periods_temperature
  periods_temperature('saturday')
end

#saturday_periods_temperature=(temp) ⇒ Object



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

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

#set_after_create_defaultsObject (protected)



573
574
575
576
577
578
579
580
581
582
# File 'app/models/preset_job.rb', line 573

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)



584
585
586
# File 'app/models/preset_job.rb', line 584

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

#set_periods_temperature(day_label, temp) ⇒ Object



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

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



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'app/models/preset_job.rb', line 468

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_floor_temps = 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



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

def sunday_periods_temperature
  periods_temperature('sunday')
end

#sunday_periods_temperature=(temp) ⇒ Object



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

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

#supports_programming?(sym) ⇒ Boolean

Returns:

  • (Boolean)


457
458
459
460
461
462
463
464
465
466
# File 'app/models/preset_job.rb', line 457

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) and temperature_control_mode != 'A'
  else
    true
  end
end

#temperature_control_mode_humanObject



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

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



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

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

#temperature_label(t) ⇒ Object



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

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

#temperature_mode_warningObject



353
354
355
# File 'app/models/preset_job.rb', line 353

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

#thermostat_model_nameObject



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

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



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

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

#thursday_periods_temperatureObject



517
518
519
# File 'app/models/preset_job.rb', line 517

def thursday_periods_temperature
  periods_temperature('thursday')
end

#thursday_periods_temperature=(temp) ⇒ Object



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

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

#tuesday_periods_temperatureObject



509
510
511
# File 'app/models/preset_job.rb', line 509

def tuesday_periods_temperature
  periods_temperature('tuesday')
end

#tuesday_periods_temperature=(temp) ⇒ Object



542
543
544
# File 'app/models/preset_job.rb', line 542

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

#warming_periodsObject (protected)



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
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
# File 'app/models/preset_job.rb', line 588

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? and adaptive_start and 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



513
514
515
# File 'app/models/preset_job.rb', line 513

def wednesday_periods_temperature
  periods_temperature('wednesday')
end

#wednesday_periods_temperature=(temp) ⇒ Object



546
547
548
# File 'app/models/preset_job.rb', line 546

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