     end
   end
 
+  def write_pin({:peripheral, %{pin: pin}}, mode, value) do
+    write_pin(pin, mode, value)
+  end
+
+  def write_pin({:sensor, %{pin: _pin}}, _mode, _value) do
+    {:error, "cannot write Sensor value. Use a Peripheral"}
+  end
+
+  def write_pin({:box_led, 3}, _mode, value) do
+    Leds.white4(value_to_led(value))
+    :ok
+  end
+
+  def write_pin({:box_led, 4}, _mode, value) do
+    Leds.white5(value_to_led(value))
+    :ok
+  end
+
   def write_pin(pin_number, mode, value) do
     case FarmbotFirmware.command({:pin_write, [p: pin_number, v: value, m: mode]}) do
       :ok ->


  def named_pin("Peripheral", id) do
    case Asset.get_peripheral(id: id) do
      %{pin: pin} -> pin
      nil -> {:error, "Could not find peripheral by id: #{id}"}
    end
  end

  def named_pin("Sensor", id) do
    case Asset.get_sensor(id) do
      %{pin: pin} -> pin
      nil -> {:error, "Could not find peripheral by id: #{id}"}
    end
  end

  def named_pin(kind, id) do

    end
  end

  def get_position() do
    case FarmbotFirmware.request({nil, {:position_read, []}}) do
      {:ok, {_, {:report_position, params}}} ->
        params

      {:error, reason} ->
        {:error, "Firmware error: #{inspect(reason)}"}
    end
  end

  def get_position(axis) do
    axis = assert_axis!(axis)

    case get_position() do
      {:error, _} = error -> error
      position -> Keyword.fetch!(position, axis)
    end
  end

