module MaxCube::Messages::TCP::Serializer::MessageS

Message to send command to Cube.

Constants

COMMANDS
DEFAULT_RF_FLAGS
KEYS

Mandatory hash keys.

OPT_KEYS

Optional hash keys.

Private Instance Methods

serialize_tcp_s(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 83
def serialize_tcp_s(hash)
  @io = StringIO.new('', 'wb')

  cmd = serialize_tcp_s_head(hash)
  send('serialize_tcp_s_' << cmd.to_s, hash)

  encode(@io.string)
end
serialize_tcp_s_config_valve(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 189
def serialize_tcp_s_config_valve(hash)
  boost_duration =
    [7, to_int(0, 'boost duration', hash[:boost_duration]) / 5].min
  valve_opening = to_float('valve opening', hash[:valve_opening])
                  .round / 5
  boost = boost_duration << 5 | valve_opening

  decalcification_day = day_of_week_id(hash[:decalcification_day])
  decalcification = decalcification_day << 5 |
                    to_int(0, 'decalcification hour',
                           hash[:decalcification_hour])

  percent = %i[max_valve_setting valve_offset]
            .map { |k| (to_float(k, hash[k]) * 2.55).round }

  write(to_int(0, 'room ID', hash[:room_id]),
        boost, decalcification, *percent, esize: 1)
end
serialize_tcp_s_display_temperature(hash) click to toggle source

Works only on wall thermostats

# File lib/maxcube/messages/tcp/type/s.rb, line 237
def serialize_tcp_s_display_temperature(hash)
  display_settings = Hash.new(0)
                         .merge!(measured: 4, configured: 0)
                         .freeze
  display = display_settings[hash.fetch(:display_temperature, 'x')
                                 .to_sym]
  write(to_int(0, 'room ID', hash[:room_id]), display, esize: 1)
end
serialize_tcp_s_group_address(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 224
def serialize_tcp_s_group_address(hash)
  write(0, to_int(0, 'room ID', hash[:room_id]), esize: 1)
end
serialize_tcp_s_head(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 112
def serialize_tcp_s_head(hash)
  command = hash[:command].to_sym
  command_id = COMMANDS[command]
  unless command_id
    raise InvalidMessageBody
      .new(@msg_type, "unknown command symbol: #{command}")
  end

  rf_flags = if hash.key?(:rf_flags)
               to_int(0, 'RF flags', hash[:rf_flags])
             else
               DEFAULT_RF_FLAGS[command]
             end

  rf_address_from, rf_address_to =
    serialize_tcp_s_head_rf_address(hash)

  unknown = hash.key?(:unknown) ? hash[:unknown] : "\x00"
  write(serialize(unknown, rf_flags, command_id, esize: 1) <<
        serialize(rf_address_from, rf_address_to, esize: 3))

  command
end
serialize_tcp_s_head_rf_address(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 94
def serialize_tcp_s_head_rf_address(hash)
  rf_address_from = if hash.key?(:rf_address_from)
                      hash[:rf_address_from]
                    elsif hash.key?(:rf_address_range)
                      hash[:rf_address_range].min
                    else
                      0
                    end
  rf_address_to = if hash.key?(:rf_address_to)
                    hash[:rf_address_to]
                  elsif hash.key?(:rf_address_range)
                    hash[:rf_address_range].max
                  else
                    hash[:rf_address]
                  end
  to_ints(0, 'RF address range', rf_address_from, rf_address_to)
end
serialize_tcp_s_set_group_address(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 228
def serialize_tcp_s_set_group_address(hash)
  serialize_tcp_s_group_address(hash)
end
serialize_tcp_s_set_program(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 161
def serialize_tcp_s_set_program(hash)
  day_of_week = day_of_week_id(hash[:day])
  day_of_week |= 0x8 if hash[:telegram_set]
  write(to_int(0, 'room ID', hash[:room_id]), day_of_week, esize: 1)

  hash[:program].each do |prog|
    temp_time =
      (to_float('temperature', prog[:temperature]) * 2).to_i << 9 |
      (to_int(0, 'hours until', prog[:hours_until]) * 60 +
       to_int(0, 'minutes until', prog[:minutes_until])) / 5
    write(temp_time, esize: 2)
  end
end
serialize_tcp_s_set_temperature(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 175
def serialize_tcp_s_set_temperature(hash)
  keys = %i[comfort_temperature eco_temperature
            max_setpoint_temperature min_setpoint_temperature
            temperature_offset window_open_temperature].freeze
  temperatures = hash.select { |k| keys.include?(k) }
                     .map { |k, v| to_float(k, v) * 2 }
  temperatures[-2] += 7

  open_duration = to_int(0, 'window open duration',
                         hash[:window_open_duration]) / 5
  write(to_int(0, 'room ID', hash[:room_id]),
        *temperatures.map(&:to_i), open_duration, esize: 1)
end
serialize_tcp_s_set_temperature_mode(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 136
def serialize_tcp_s_set_temperature_mode(hash)
  @mode = hash[:mode].to_sym
  temp_mode = (to_float('temperature', hash[:temperature]) * 2).to_i |
              device_mode_id(@mode) << 6
  write(to_int(0, 'room ID', hash[:room_id]), temp_mode, esize: 1)

  return unless @mode == :vacation

  datetime_until = to_datetime('datetime until',
                               hash[:datetime_until])

  year = datetime_until.year - 2000
  month = datetime_until.month
  day = datetime_until.day
  date_until = year | (month & 1) << 7 |
               day << 8 | (month & 0xe) << 12

  hours = datetime_until.hour << 1
  minutes = datetime_until.min < 30 ? 0 : 1
  time_until = hours | minutes

  write(serialize(date_until, esize: 2) <<
        serialize(time_until, esize: 1))
end
serialize_tcp_s_unset_group_address(hash) click to toggle source
# File lib/maxcube/messages/tcp/type/s.rb, line 232
def serialize_tcp_s_unset_group_address(hash)
  serialize_tcp_s_group_address(hash)
end