<commit_before>require_relative 'abstract_controller'

class SingleCommandController < AbstractController
  attr_reader :cmd

  AVAILABLE_ACTIONS = { "move relative"   => :move_relative,
                        "move absolute"   => :move_absolute,
                        "unknown"         => :unknown,
                        "home x"          => :home_x,
                        "home y"          => :home_y,
                        "home z"          => :home_z,
                        "home all"        => :home_all,
                        "pin write"       => :pin_write,
                        "emergency stop"  => :emergency_stop, }

  def call
    @cmd   = (message.payload || {})
    key    = @cmd["action"].to_s.gsub("_", " ").downcase
    action = AVAILABLE_ACTIONS.fetch(key, :unknown).to_sym
    send(action)
    reply 'single_command', confirmation: true, command: cmd
  end

  def move_relative
    bot.commands.move_relative x: cmd['x'], y: cmd['y'], z: cmd['z']
  end

  def move_absolute
    bot.commands.move_absolute x: cmd['x'], y: cmd['y'], z: cmd['z']
  end

  def home_x
    bot.commands.home_x
  end

  def home_y<commit_msg>fix singleCommandControllers handling of MeshMessages<commit_after>require_relative 'abstract_controller'

class SingleCommandController < AbstractController
  attr_reader :cmd

  AVAILABLE_ACTIONS = { "move relative"   => :move_relative,
                        "move absolute"   => :move_absolute,
                        "unknown"         => :unknown,
                        "home x"          => :home_x,
                        "home y"          => :home_y,
                        "home z"          => :home_z,
                        "home all"        => :home_all,
                        "pin write"       => :pin_write,
                        "emergency stop"  => :emergency_stop, }

  def call
    @cmd   = (message.payload || {}).fetch("command", {})
    key    = @cmd["action"].to_s.downcase.gsub("_", " ").downcase
    action = AVAILABLE_ACTIONS.fetch(key, :unknown).to_sym
    send(action)
    reply 'single_command', confirmation: true, command: cmd
  rescue => qqq
    binding.pry
  end

  def move_relative
    bot.commands.move_relative x: cmd['x'], y: cmd['y'], z: cmd['z']
  end

  def move_absolute
    bot.commands.move_absolute x: cmd['x'], y: cmd['y'], z: cmd['z']
  end

  def home_x
    bot.commands.home_x
  end

  def home_y
{'fraction_non_alphanumeric': 0.12468827930174564, 'fraction_numerical': 0.0, 'mean_word_length': 1.808634772462077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140416', 'n_tokens_mistral': 739, 'n_tokens_neox': 710, 'n_words': 163}